LCOV - code coverage report
Current view: top level - Core/Debug - OODebugSupport.m (source / functions) Hit Total Coverage
Test: coverxygen.info Lines: 0 5 0.0 %
Date: 2025-05-28 07:50:54 Functions: 0 0 -

          Line data    Source code
       1           0 : /*
       2             : 
       3             : OODebugSupport.m
       4             : 
       5             : 
       6             : Copyright (C) 2007-2013 Jens Ayton
       7             : 
       8             : Permission is hereby granted, free of charge, to any person obtaining a copy
       9             : of this software and associated documentation files (the "Software"), to deal
      10             : in the Software without restriction, including without limitation the rights
      11             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      12             : copies of the Software, and to permit persons to whom the Software is
      13             : furnished to do so, subject to the following conditions:
      14             : 
      15             : The above copyright notice and this permission notice shall be included in all
      16             : copies or substantial portions of the Software.
      17             : 
      18             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      19             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      20             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      21             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      22             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      23             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      24             : SOFTWARE.
      25             : 
      26             : */
      27             : 
      28             : #ifndef OO_EXCLUDE_DEBUG_SUPPORT
      29             : 
      30             : 
      31             : #import "OODebugSupport.h"
      32             : #import "ResourceManager.h"
      33             : #import "OOCollectionExtractors.h"
      34             : #import "OODebugMonitor.h"
      35             : #import "OODebugTCPConsoleClient.h"
      36             : #import "GameController.h"
      37             : #import "OOJavaScriptEngine.h"
      38             : 
      39             : 
      40             : #if OOLITE_MAC_OS_X
      41             : static id LoadDebugPlugIn(void);
      42             : #else
      43           0 : #define LoadDebugPlugIn() nil
      44             : #endif
      45             : 
      46             : 
      47           0 : static id sDebugPlugInController;
      48             : 
      49             : 
      50             : @interface NSObject (OODebugPlugInController)
      51             : 
      52           0 : - (id<OODebuggerInterface>) setUpDebugger;
      53             : 
      54             : @end
      55             : 
      56             : 
      57           0 : void OOInitDebugSupport(void)
      58             : {
      59             :         NSString                                *debugOXPPath = nil;
      60             :         NSDictionary                    *debugSettings = nil;
      61             :         NSString                                *consoleHost = nil;
      62             :         unsigned short                  consolePort = 0;
      63             :         id<OODebuggerInterface>   debugger = nil;
      64             :         BOOL                                    activateDebugConsole = NO;
      65             :         
      66             :         // Load debug settings.
      67             :         debugSettings = [ResourceManager dictionaryFromFilesNamed:@"debugConfig.plist"
      68             :                                                                                                          inFolder:@"Config"
      69             :                                                                                                         mergeMode:MERGE_BASIC
      70             :                                                                                                                 cache:NO];
      71             :         
      72             :         // Check that the debug OXP is installed. If not, we don't enable debug support.
      73             :         debugOXPPath = [ResourceManager pathForFileNamed:@"DebugOXPLocatorBeacon.magic" inFolder:@"nil"];
      74             :         if (debugOXPPath != nil)
      75             :         {
      76             :                 // Load plug-in debugging code on platforms where this is supported.
      77             :                 sDebugPlugInController = [LoadDebugPlugIn() retain];
      78             :                 
      79             :                 consoleHost = [debugSettings oo_stringForKey:@"console-host"];
      80             :                 consolePort = [debugSettings oo_unsignedShortForKey:@"console-port"];
      81             :                 
      82             :                 // If consoleHost is nil, and the debug plug-in can set up a debugger, use that.
      83             :                 if (consoleHost == nil && [sDebugPlugInController respondsToSelector:@selector(setUpDebugger)])
      84             :                 {
      85             :                         debugger = [sDebugPlugInController setUpDebugger];
      86             :                         [[OODebugMonitor sharedDebugMonitor] setUsingPlugInController:YES];
      87             :                 }
      88             :                 
      89             :                 // Otherwise, use TCP debugger connection.
      90             :                 if (debugger == nil)
      91             :                 {
      92             :                         debugger = [[OODebugTCPConsoleClient alloc] initWithAddress:consoleHost
      93             :                                                                                                                                    port:consolePort];
      94             :                         [debugger autorelease];
      95             :                         [[OODebugMonitor sharedDebugMonitor] setUsingPlugInController:NO];
      96             :                 }
      97             :                 
      98             :                 activateDebugConsole = (debugger != nil);
      99             :         }
     100             :         
     101             :         if (!activateDebugConsole)
     102             :         {
     103             :                 activateDebugConsole = [debugSettings oo_boolForKey:@"always-load-debug-console"];
     104             :         }
     105             :         
     106             :         
     107             :         if (activateDebugConsole)
     108             :         {
     109             :                 // Set up monitor and register debugger, if any.
     110             :                 [[OODebugMonitor sharedDebugMonitor] setDebugger:debugger];
     111             :                 [[OOJavaScriptEngine sharedEngine] enableDebuggerStatement];
     112             :         }
     113             : }
     114             : 
     115             : 
     116             : #if OOLITE_MAC_OS_X
     117             : 
     118             : static id LoadDebugPlugIn()
     119             : {
     120             :         OO_DEBUG_PUSH_PROGRESS(@"Loading debug plug-in");
     121             :         
     122             :         id debugController = nil;
     123             :         
     124             :         NSURL *plugInURL = NSBundle.mainBundle.builtInPlugInsURL;
     125             :         plugInURL = [plugInURL URLByAppendingPathComponent:@"Debug.bundle"];
     126             :         NSBundle *debugBundle = [NSBundle bundleWithURL:plugInURL];
     127             :         
     128             :         if ([debugBundle load])
     129             :         {
     130             :                 Class principalClass = debugBundle.principalClass;
     131             :                 if (principalClass != Nil)
     132             :                 {
     133             :                         // Instantiate principal class of debug bundle, and let it do whatever it wants.
     134             :                         debugController = [[principalClass new] autorelease];
     135             :                 }
     136             :                 else
     137             :                 {
     138             :                         OOLog(@"debugSupport.load.failed", @"Failed to find principal class of debug bundle.");
     139             :                 }
     140             :         }
     141             :         else
     142             :         {
     143             :                 OOLog(@"debugSupport.load.failed", @"Failed to load debug OXP plug-in from %@.", plugInURL.path);
     144             :         }
     145             :         
     146             :         OO_DEBUG_POP_PROGRESS();
     147             :         
     148             :         return debugController;
     149             : }
     150             : 
     151             : #endif
     152             : 
     153             : #endif  /* OO_EXCLUDE_DEBUG_SUPPORT */

Generated by: LCOV version 1.14