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