Oolite 1.91.0.7644-241112-7f5034b
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#ifndef OO_EXCLUDE_DEBUG_SUPPORT
29
30
31#import "OODebugSupport.h"
32#import "ResourceManager.h"
34#import "OODebugMonitor.h"
36#import "GameController.h"
38
39
40#if OOLITE_MAC_OS_X
41static id LoadDebugPlugIn(void);
42#else
43#define LoadDebugPlugIn() nil
44#endif
45
46
48
49
50@interface NSObject (OODebugPlugInController)
51
52- (id<OODebuggerInterface>) setUpDebugger;
53
54@end
55
56
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];
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];
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.
112 }
113}
114
115
116#if OOLITE_MAC_OS_X
117
118static 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
147
148 return debugController;
149}
150
151#endif
152
153#endif /* OO_EXCLUDE_DEBUG_SUPPORT */
#define OO_DEBUG_POP_PROGRESS()
#define OO_DEBUG_PUSH_PROGRESS(...)
static id sDebugPlugInController
void OOInitDebugSupport(void)
#define LoadDebugPlugIn()
#define OOLog(class, format,...)
Definition OOLogging.h:88
return nil
id< OODebuggerInterface > setUpDebugger()
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)