From 8904c39401d2723e06d04a4831baab30b045a29c Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Sat, 6 Oct 2007 11:03:01 +0000 Subject: [PATCH] Oolite should now build with external debug console support on all platforms. Mac debug OXP is broken. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1191 127b21dd-08f5-0310-b4b7-95ae10353056 --- GNUmakefile | 6 +- Oolite.xcodeproj/project.pbxproj | 80 ++- src/Core/Debug/OODebugMonitor.h | 102 +++ src/Core/Debug/OODebugMonitor.m | 612 ++++++++++++++++++ .../OODebugSupport.h} | 18 +- src/Core/Debug/OODebugSupport.m | 155 +++++ src/Core/Debug/OODebugTCPConsoleClient.h | 1 + src/Core/Debug/OODebugTCPConsoleClient.m | 5 + src/Core/Debug/OODebuggerInterface.h | 70 ++ src/Core/Debug/OOJSConsole.h | 38 ++ src/Core/Debug/OOJSConsole.m | 308 +++++++++ src/Core/Debug/OOTCPStreamDecoder.c | 53 ++ src/Core/Debug/OOTCPStreamDecoder.h | 54 +- .../OOTCPStreamDecoderAbstractionLayer.m | 7 +- src/Core/Materials/OOMaterial.h | 1 + src/Core/Materials/OOMaterial.m | 4 - src/Core/OOColor.h | 3 + src/Core/OOColor.m | 13 + src/Core/OODebugBundleLoader.m | 91 --- src/Core/Scripting/OOJavaScriptEngine.m | 2 +- src/Core/Universe.m | 6 +- 21 files changed, 1496 insertions(+), 133 deletions(-) create mode 100644 src/Core/Debug/OODebugMonitor.h create mode 100644 src/Core/Debug/OODebugMonitor.m rename src/Core/{OODebugBundleLoader.h => Debug/OODebugSupport.h} (86%) create mode 100644 src/Core/Debug/OODebugSupport.m create mode 100644 src/Core/Debug/OODebuggerInterface.h create mode 100644 src/Core/Debug/OOJSConsole.h create mode 100644 src/Core/Debug/OOJSConsole.m delete mode 100644 src/Core/OODebugBundleLoader.m diff --git a/GNUmakefile b/GNUmakefile index b272a0c1..5336b7c7 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -6,7 +6,7 @@ vpath %.h src/SDL:src/Core:src/Core/Entities:src/Core/Materials:src/Core/Scripti vpath %.c src/SDL:src/Core:src/BSDCompat GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_USER_ROOT) ifeq ($(GNUSTEP_HOST_OS),mingw32) - ADDITIONAL_INCLUDE_DIRS = -Ideps/Windows-x86-deps/include -Isrc/SDL -Isrc/Core -Isrc/Core/Scripting -Isrc/Core/Materials -Isrc/Core/Entities -Isrc/Core/OXPVerifier + ADDITIONAL_INCLUDE_DIRS = -Ideps/Windows-x86-deps/include -Isrc/SDL -Isrc/Core -Isrc/Core/Scripting -Isrc/Core/Materials -Isrc/Core/Entities -Isrc/Core/OXPVerifier -Isrc/Debug ADDITIONAL_OBJC_LIBS = -lglu32 -lopengl32 -lpng13 -lmingw32 -lSDLmain -lSDL -lSDL_mixer -lgnustep-base -ljs32 ADDITIONAL_CFLAGS = -DLINUX -DWIN32 -DNEED_STRLCPY `sdl-config --cflags` # note the vpath stuff above isn't working for me, so adding src/SDL and src/Core explicitly @@ -17,7 +17,7 @@ ifeq ($(BUILD_WITH_DEBUG_FUNCTIONALITY),no) endif oolite_LIB_DIRS += -L/usr/local/lib -L$(GNUSTEP_LOCAL_ROOT)/lib -Ldeps/Windows-x86-deps/lib else - ADDITIONAL_INCLUDE_DIRS = -I/usr/include/mozjs -Isrc/SDL -Isrc/Core -Isrc/BSDCompat -Isrc/Core/Scripting -Isrc/Core/Materials -Isrc/Core/Entities -Isrc/Core/OXPVerifier + ADDITIONAL_INCLUDE_DIRS = -I/usr/include/mozjs -Isrc/SDL -Isrc/Core -Isrc/BSDCompat -Isrc/Core/Scripting -Isrc/Core/Materials -Isrc/Core/Entities -Isrc/Core/OXPVerifier -Isrc/Debug ADDITIONAL_OBJC_LIBS = -lpng -ljs -lGLU -lGL -lSDL -lpthread -lSDL_mixer -lgnustep-base ADDITIONAL_CFLAGS = -DLINUX -DNEED_STRLCPY `sdl-config --cflags` ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DLINUX -DXP_UNIX -Wno-import `sdl-config --cflags` @@ -26,7 +26,7 @@ endif OBJC_PROGRAM_NAME = oolite oolite_C_FILES = legacy_random.c strlcpy.c -oolite_OBJC_FILES = Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m OOSound.m SDLMusic.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m +oolite_OBJC_FILES = Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m OOSound.m SDLMusic.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoder.c OOTCPStreamDecoderAbstractionLayer.m include $(GNUSTEP_MAKEFILES)/objc.make include GNUmakefile.postamble diff --git a/Oolite.xcodeproj/project.pbxproj b/Oolite.xcodeproj/project.pbxproj index de8be96f..6ce2192b 100644 --- a/Oolite.xcodeproj/project.pbxproj +++ b/Oolite.xcodeproj/project.pbxproj @@ -315,6 +315,20 @@ 1A2A8E040BC67CCC001E00FB /* OOWeakReference.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A8E020BC67CCC001E00FB /* OOWeakReference.m */; }; 1A2A91520BC6BC66001E00FB /* OOJSQuaternion.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2A91500BC6BC66001E00FB /* OOJSQuaternion.h */; }; 1A2A91530BC6BC66001E00FB /* OOJSQuaternion.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A91510BC6BC66001E00FB /* OOJSQuaternion.m */; }; + 1A2DA2AB0CB4CB5C00DE6823 /* OODebugTCPConsoleProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA2A40CB4CB5C00DE6823 /* OODebugTCPConsoleProtocol.h */; }; + 1A2DA2AE0CB4CB5C00DE6823 /* OODebugTCPConsoleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA2A70CB4CB5C00DE6823 /* OODebugTCPConsoleClient.h */; }; + 1A2DA2AF0CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA2A80CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.h */; }; + 1A2DA2B00CB4CB5C00DE6823 /* OOTCPStreamDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA2A90CB4CB5C00DE6823 /* OOTCPStreamDecoder.h */; }; + 1A2DA34D0CB4D0D800DE6823 /* OOJSConsole.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA3490CB4D0D800DE6823 /* OOJSConsole.h */; }; + 1A2DA34E0CB4D0D800DE6823 /* OODebugMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA34A0CB4D0D800DE6823 /* OODebugMonitor.h */; }; + 1A2DA3550CB4D10800DE6823 /* OODebuggerInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA3540CB4D10800DE6823 /* OODebuggerInterface.h */; }; + 1A2DA3830CB4D25D00DE6823 /* OOTCPStreamDecoderAbstractionLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2DA2AA0CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.m */; }; + 1A2DA3870CB4D27400DE6823 /* OOTCPStreamDecoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A2DA2A60CB4CB5C00DE6823 /* OOTCPStreamDecoder.c */; }; + 1A2DA3920CB4D29300DE6823 /* OODebugTCPConsoleClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2DA2A50CB4CB5C00DE6823 /* OODebugTCPConsoleClient.m */; }; + 1A2DA39E0CB4D2BB00DE6823 /* OODebugMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2DA34C0CB4D0D800DE6823 /* OODebugMonitor.m */; }; + 1A2DA3A40CB4D35800DE6823 /* OOJSConsole.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2DA34B0CB4D0D800DE6823 /* OOJSConsole.m */; }; + 1A2DA3EE0CB4E84900DE6823 /* OODebugSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A2DA3EC0CB4E84900DE6823 /* OODebugSupport.m */; }; + 1A2DA3EF0CB4E84900DE6823 /* OODebugSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2DA3ED0CB4E84900DE6823 /* OODebugSupport.h */; }; 1A34912A0BC25EAA00802DA7 /* world-scripts.plist in Copy Config */ = {isa = PBXBuildFile; fileRef = 1A3491290BC25EAA00802DA7 /* world-scripts.plist */; }; 1A34912E0BC25EBC00802DA7 /* oolite-legacy-script.plist in Copy Scripts */ = {isa = PBXBuildFile; fileRef = 1A34912D0BC25EBC00802DA7 /* oolite-legacy-script.plist */; }; 1A358CE20C1AB80D00E52220 /* ReadMe.rtfd in Resources */ = {isa = PBXBuildFile; fileRef = 1A358CE10C1AB80D00E52220 /* ReadMe.rtfd */; }; @@ -451,8 +465,6 @@ 1A9406B50BAF67BF005F6CF3 /* OOTriangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A9406B30BAF67BF005F6CF3 /* OOTriangle.m */; settings = {COMPILER_FLAGS = "-O3 -falign-loops=32 -falign-loops-max-skip=31 -falign-functions=32"; }; }; 1A95338B0C02089E004EBB58 /* material-defaults.plist in Copy Config */ = {isa = PBXBuildFile; fileRef = 1A9533890C02089E004EBB58 /* material-defaults.plist */; }; 1A95338C0C02089E004EBB58 /* planetinfo.plist in Copy Config */ = {isa = PBXBuildFile; fileRef = 1A95338A0C02089E004EBB58 /* planetinfo.plist */; }; - 1A9590590C7FC94200C112A9 /* OODebugBundleLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A9590570C7FC94200C112A9 /* OODebugBundleLoader.m */; }; - 1A95905A0C7FC94200C112A9 /* OODebugBundleLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9590580C7FC94200C112A9 /* OODebugBundleLoader.h */; }; 1AB01ABE0BB15AED00F1B949 /* OOTextureScaling.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB01ABC0BB15AED00F1B949 /* OOTextureScaling.h */; }; 1AB01B5F0BB1639600F1B949 /* OOTextureScaling.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AB01ABD0BB15AED00F1B949 /* OOTextureScaling.m */; }; 1AB01BBB0BB16A8A00F1B949 /* OOFastArithmetic.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB01BB90BB16A8A00F1B949 /* OOFastArithmetic.h */; }; @@ -1223,6 +1235,20 @@ 1A2A8E020BC67CCC001E00FB /* OOWeakReference.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOWeakReference.m; sourceTree = ""; }; 1A2A91500BC6BC66001E00FB /* OOJSQuaternion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOJSQuaternion.h; sourceTree = ""; }; 1A2A91510BC6BC66001E00FB /* OOJSQuaternion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOJSQuaternion.m; sourceTree = ""; }; + 1A2DA2A40CB4CB5C00DE6823 /* OODebugTCPConsoleProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OODebugTCPConsoleProtocol.h; sourceTree = ""; }; + 1A2DA2A50CB4CB5C00DE6823 /* OODebugTCPConsoleClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OODebugTCPConsoleClient.m; sourceTree = ""; }; + 1A2DA2A60CB4CB5C00DE6823 /* OOTCPStreamDecoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = OOTCPStreamDecoder.c; sourceTree = ""; }; + 1A2DA2A70CB4CB5C00DE6823 /* OODebugTCPConsoleClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OODebugTCPConsoleClient.h; sourceTree = ""; }; + 1A2DA2A80CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOTCPStreamDecoderAbstractionLayer.h; sourceTree = ""; }; + 1A2DA2A90CB4CB5C00DE6823 /* OOTCPStreamDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOTCPStreamDecoder.h; sourceTree = ""; }; + 1A2DA2AA0CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOTCPStreamDecoderAbstractionLayer.m; sourceTree = ""; }; + 1A2DA3490CB4D0D800DE6823 /* OOJSConsole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOJSConsole.h; sourceTree = ""; }; + 1A2DA34A0CB4D0D800DE6823 /* OODebugMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OODebugMonitor.h; sourceTree = ""; }; + 1A2DA34B0CB4D0D800DE6823 /* OOJSConsole.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOJSConsole.m; sourceTree = ""; }; + 1A2DA34C0CB4D0D800DE6823 /* OODebugMonitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OODebugMonitor.m; sourceTree = ""; }; + 1A2DA3540CB4D10800DE6823 /* OODebuggerInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OODebuggerInterface.h; sourceTree = ""; }; + 1A2DA3EC0CB4E84900DE6823 /* OODebugSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OODebugSupport.m; sourceTree = ""; }; + 1A2DA3ED0CB4E84900DE6823 /* OODebugSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OODebugSupport.h; sourceTree = ""; }; 1A2F63950C5CC737003872C8 /* demoshipsSchema.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = demoshipsSchema.plist; sourceTree = ""; }; 1A2F63960C5CC737003872C8 /* hudSchema.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = hudSchema.plist; sourceTree = ""; }; 1A2F63980C5CC737003872C8 /* shipdataEntrySchema.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = shipdataEntrySchema.plist; sourceTree = ""; }; @@ -1365,8 +1391,6 @@ 1A9407BF0BAF7032005F6CF3 /* GNUmakefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GNUmakefile; sourceTree = ""; }; 1A9533890C02089E004EBB58 /* material-defaults.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "material-defaults.plist"; sourceTree = ""; }; 1A95338A0C02089E004EBB58 /* planetinfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = planetinfo.plist; sourceTree = ""; }; - 1A9590570C7FC94200C112A9 /* OODebugBundleLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OODebugBundleLoader.m; path = src/Core/OODebugBundleLoader.m; sourceTree = SOURCE_ROOT; }; - 1A9590580C7FC94200C112A9 /* OODebugBundleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OODebugBundleLoader.h; path = src/Core/OODebugBundleLoader.h; sourceTree = SOURCE_ROOT; }; 1AB01ABC0BB15AED00F1B949 /* OOTextureScaling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OOTextureScaling.h; path = ../OOTextureScaling.h; sourceTree = ""; }; 1AB01ABD0BB15AED00F1B949 /* OOTextureScaling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OOTextureScaling.m; path = ../OOTextureScaling.m; sourceTree = ""; }; 1AB01BB90BB16A8A00F1B949 /* OOFastArithmetic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOFastArithmetic.h; sourceTree = ""; }; @@ -1881,6 +1905,27 @@ name = Graphics; sourceTree = ""; }; + 1A2DA2A00CB4CB3500DE6823 /* Debug */ = { + isa = PBXGroup; + children = ( + 1A2DA3ED0CB4E84900DE6823 /* OODebugSupport.h */, + 1A2DA3EC0CB4E84900DE6823 /* OODebugSupport.m */, + 1A2DA3540CB4D10800DE6823 /* OODebuggerInterface.h */, + 1A2DA34A0CB4D0D800DE6823 /* OODebugMonitor.h */, + 1A2DA34C0CB4D0D800DE6823 /* OODebugMonitor.m */, + 1A2DA3490CB4D0D800DE6823 /* OOJSConsole.h */, + 1A2DA34B0CB4D0D800DE6823 /* OOJSConsole.m */, + 1A2DA2A40CB4CB5C00DE6823 /* OODebugTCPConsoleProtocol.h */, + 1A2DA2A70CB4CB5C00DE6823 /* OODebugTCPConsoleClient.h */, + 1A2DA2A50CB4CB5C00DE6823 /* OODebugTCPConsoleClient.m */, + 1A2DA2A90CB4CB5C00DE6823 /* OOTCPStreamDecoder.h */, + 1A2DA2A60CB4CB5C00DE6823 /* OOTCPStreamDecoder.c */, + 1A2DA2A80CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.h */, + 1A2DA2AA0CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.m */, + ); + path = Debug; + sourceTree = ""; + }; 1A2F63940C5CC737003872C8 /* Schemata */ = { isa = PBXGroup; children = ( @@ -2062,8 +2107,6 @@ children = ( 1A0519340C7CCAC900BA5CCA /* DebugOXP.xcodeproj */, 1A0517D10C7B376700BA5CCA /* debug-exports.exp */, - 1A9590580C7FC94200C112A9 /* OODebugBundleLoader.h */, - 1A9590570C7FC94200C112A9 /* OODebugBundleLoader.m */, ); name = "Debug OXP"; path = src/Cocoa; @@ -2089,6 +2132,7 @@ 2516110C099544390037C2E1 /* GameController.m */, 1A2A1B020BD2768300152975 /* Graphics */, 1A5DBA980BC000DC00D57389 /* Scripting */, + 1A2DA2A00CB4CB3500DE6823 /* Debug */, 1AB2AAE70C4CDF890008CF4E /* OXP Verification */, ); name = Source; @@ -2560,7 +2604,6 @@ 1A73712D0C623DAE0097AC37 /* OOJSStation.h in Headers */, 1A7376BE0C64AE330097AC37 /* OOJSSystem.h in Headers */, 1A73795D0C65CF090097AC37 /* OOLegacyEventHandlerScript.h in Headers */, - 1A95905A0C7FC94200C112A9 /* OODebugBundleLoader.h in Headers */, 1A4FB23A0C8D6A9A00DC8E1F /* jsautocfg.h in Headers */, 1A4FB23C0C8D6AA900DC8E1F /* jsapi.h in Headers */, 1A4FB23F0C8D6AB400DC8E1F /* jspubtd.h in Headers */, @@ -2574,6 +2617,14 @@ 1A6B1F370C9AAA60000717CF /* OOPriorityQueue.h in Headers */, 1A6B228D0C9B40D4000717CF /* OOJSTimer.h in Headers */, 1A6B25EE0C9C2746000717CF /* OOJSClock.h in Headers */, + 1A2DA2AB0CB4CB5C00DE6823 /* OODebugTCPConsoleProtocol.h in Headers */, + 1A2DA2AE0CB4CB5C00DE6823 /* OODebugTCPConsoleClient.h in Headers */, + 1A2DA2AF0CB4CB5C00DE6823 /* OOTCPStreamDecoderAbstractionLayer.h in Headers */, + 1A2DA2B00CB4CB5C00DE6823 /* OOTCPStreamDecoder.h in Headers */, + 1A2DA34D0CB4D0D800DE6823 /* OOJSConsole.h in Headers */, + 1A2DA34E0CB4D0D800DE6823 /* OODebugMonitor.h in Headers */, + 1A2DA3550CB4D10800DE6823 /* OODebuggerInterface.h in Headers */, + 1A2DA3EF0CB4E84900DE6823 /* OODebugSupport.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2903,7 +2954,6 @@ 1A73712E0C623DAE0097AC37 /* OOJSStation.m in Sources */, 1A7376BF0C64AE330097AC37 /* OOJSSystem.m in Sources */, 1A73795E0C65CF090097AC37 /* OOLegacyEventHandlerScript.m in Sources */, - 1A9590590C7FC94200C112A9 /* OODebugBundleLoader.m in Sources */, 1A4FB3360C8DC86800DC8E1F /* OOJSOolite.m in Sources */, 1ACEA34A0C91507000C7CE97 /* OORoleSet.m in Sources */, 1ACEA6C00C91DA3E00C7CE97 /* OOJSGlobal.m in Sources */, @@ -2913,6 +2963,12 @@ 1A6B1F360C9AAA60000717CF /* OOPriorityQueue.m in Sources */, 1A6B228E0C9B40D4000717CF /* OOJSTimer.m in Sources */, 1A6B25EF0C9C2746000717CF /* OOJSClock.m in Sources */, + 1A2DA3830CB4D25D00DE6823 /* OOTCPStreamDecoderAbstractionLayer.m in Sources */, + 1A2DA3870CB4D27400DE6823 /* OOTCPStreamDecoder.c in Sources */, + 1A2DA3920CB4D29300DE6823 /* OODebugTCPConsoleClient.m in Sources */, + 1A2DA39E0CB4D2BB00DE6823 /* OODebugMonitor.m in Sources */, + 1A2DA3A40CB4D35800DE6823 /* OOJSConsole.m in Sources */, + 1A2DA3EE0CB4E84900DE6823 /* OODebugSupport.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3042,7 +3098,7 @@ GCC_PREPROCESSOR_DEFINITIONS = XP_UNIX; GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = ( NDEBUG, - OOLOG_NO_FILE_NAME, + OO_EXCLUDE_DEBUG_SUPPORT, ); GCC_REUSE_STRINGS = YES; GCC_TREAT_WARNINGS_AS_ERRORS = YES; @@ -3147,10 +3203,8 @@ GCC_DEBUGGING_SYMBOLS = used; GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_OPTIMIZATION_LEVEL = s; - GCC_PREPROCESSOR_DEFINITIONS = ( - XP_UNIX, - "OO_SMART_CRASH_REPORT_INSTALL=1", - ); + GCC_PREPROCESSOR_DEFINITIONS = XP_UNIX; + GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = "OO_SMART_CRASH_REPORT_INSTALL=1"; GCC_REUSE_STRINGS = YES; GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_TREAT_WARNINGS_AS_ERRORS = YES; diff --git a/src/Core/Debug/OODebugMonitor.h b/src/Core/Debug/OODebugMonitor.h new file mode 100644 index 00000000..fb8ae5a9 --- /dev/null +++ b/src/Core/Debug/OODebugMonitor.h @@ -0,0 +1,102 @@ +/* + +OODebugMonitor.h + +Debugging services object for Oolite. + +The debug controller implements Oolite's part of debugging support. It can +connect to one debugger object, which conforms to the OODebuggerInterface +formal protocol. This can either be (part of) a debugger loaded into Oolite +itself (as in the Mac Debug OXP), or provide communications with an external +debugger (for instance, over Distributed Objects or TCP/IP). + + +Oolite Debug OXP + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#import "OOCocoa.h" +#import "OOWeakReference.h" +#import "OODebuggerInterface.h" + +@class OOScript; + + +@protocol OODebugMonitorInterface + +// Note: disconnectDebugger:message: will cause a disconnectDebugMonitor:message: message to be sent to the debugger. The debugger should not send disconnectDebugger:message: in response to disconnectDebugMonitor:message:. +- (void)disconnectDebugger:(in id)debugger + message:(in NSString *)message; + + +// *** JavaScript console support. + +// Perform a JS command as though entered at the console, including echoing. +- (oneway void)performJSConsoleCommand:(in NSString *)command; + +- (id)configurationValueForKey:(in NSString *)key; +- (void)setConfigurationValue:(in id)value forKey:(in NSString *)key; + +- (NSString *)sourceCodeForFile:(in NSString *)filePath line:(in unsigned)line; + +@end + + +@interface OODebugMonitor: OOWeakRefObject +{ + id _debugger; + + // JavaScript console support. + OOScript *_script; + struct JSObject *_jsSelf; + + NSDictionary *_configFromOXPs; // Settings from debugConfig.plist + NSMutableDictionary *_configOverrides; // Settings from preferences, modifiable through JS. + + // Caches + NSMutableDictionary *_fgColors, + *_bgColors, + *_sourceFiles; +} + ++ (id)sharedDebugMonitor; +- (BOOL)setDebugger:(id)debugger; + + // *** JavaScript console support. +- (void)appendJSConsoleLine:(id)string + colorKey:(NSString *)colorKey + emphasisRange:(NSRange)emphasisRange; + +- (void)appendJSConsoleLine:(id)string + colorKey:(NSString *)colorKey; + +- (void)clearJSConsole; +- (void)showJSConsole; + +- (id)configurationValueForKey:(NSString *)key class:(Class)class defaultValue:(id)value; +- (long long)configurationIntValueForKey:(NSString *)key defaultValue:(long long)value; + +- (NSArray *)configurationKeys; + +@end + diff --git a/src/Core/Debug/OODebugMonitor.m b/src/Core/Debug/OODebugMonitor.m new file mode 100644 index 00000000..fb044697 --- /dev/null +++ b/src/Core/Debug/OODebugMonitor.m @@ -0,0 +1,612 @@ +/* + +OODebugMonitor.m + + +Oolite Debug OXP + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#ifndef OO_EXCLUDE_DEBUG_SUPPORT + + +#import "OODebugMonitor.h" +#import "OOCollectionExtractors.h" +#import "OOLogging.h" +#import "ResourceManager.h" +#import "NSStringOOExtensions.h" + +#import "OOJSConsole.h" +#import "OOScript.h" +#import "OOJSScript.h" +#import "OOJavaScriptEngine.h" + + +static OODebugMonitor *sSingleton = nil; + + +@interface OODebugMonitor (Private) + +- (void)disconnectDebuggerWithMessage:(NSString *)message; + +- (NSDictionary *)mergedConfiguration; + +/* Convert a configuration dictionary to a standard form. In particular, + convert all colour specifiers to RGBA arrays with values in [0, 1], and + converts "show-console" values to booleans. +*/ +- (NSMutableDictionary *)normalizeConfigDictionary:(NSDictionary *)dictionary; +- (id)normalizeConfigValue:(id)value forKey:(NSString *)key; + +- (NSArray *)loadSourceFile:(NSString *)filePath; + +@end + + +@implementation OODebugMonitor + +- (id)init +{ + NSUserDefaults *defaults = nil; + NSDictionary *jsProps = nil; + NSDictionary *config = nil; + + self = [super init]; + if (self != nil) + { + config = [[ResourceManager dictionaryFromFilesNamed:@"debugConfig.plist" + inFolder:@"Config" + andMerge:YES] mutableCopy]; + _configFromOXPs = [[self normalizeConfigDictionary:config] copy]; + + defaults = [NSUserDefaults standardUserDefaults]; + config = [defaults dictionaryForKey:@"debug-settings-override"]; + config = [self normalizeConfigDictionary:config]; + if (config == nil) config = [NSMutableDictionary dictionary]; + _configOverrides = [config retain]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + + [[OOJavaScriptEngine sharedEngine] setMonitor:self]; + + // Set up JavaScript side of console. + jsProps = [NSDictionary dictionaryWithObject:self forKey:@"console"]; + _script = [[OOScript nonLegacyScriptFromFileNamed:@"oolite-mac-js-console.js" properties:jsProps] retain]; + } + + return self; +} + + +- (void)dealloc +{ + [self disconnectDebuggerWithMessage:@"Debug controller object destroyed while debugging in progress."]; + + [_configFromOXPs release]; + [_configOverrides release]; + + [_fgColors release]; + [_bgColors release]; + [_sourceFiles release]; + + if (_jsSelf != NULL) + { + JS_RemoveRoot([[OOJavaScriptEngine sharedEngine] context], &_jsSelf); + } + + [super dealloc]; +} + + ++ (id)sharedDebugMonitor +{ + // NOTE: assumes single-threaded access. The debug monitor is not, on the whole, thread safe. + if (sSingleton == nil) + { + [[self alloc] init]; + } + + return sSingleton; +} + + +- (BOOL)setDebugger:(id)newDebugger +{ + NSString *error = nil; + + if (newDebugger != _debugger) + { + // Disconnect existing debugger, if any. + if (newDebugger != nil) + { + [self disconnectDebuggerWithMessage:@"New debugger set."]; + } + else + { + [self disconnectDebuggerWithMessage:@"Debugger disconnected programatically."]; + } + + // If a new debugger was specified, try to connect it. + if (newDebugger != nil) + { + NS_DURING + if ([newDebugger connectDebugMonitor:self errorMessage:&error]) + { + [newDebugger debugMonitor:self + noteConfiguration:[self mergedConfiguration]]; + _debugger = [newDebugger retain]; + } + else + { + OOLog(@"debugMonitor.setDebugger.failed", @"Could not connect to debugger %@, because an error occurred: %@", newDebugger, error); + } + NS_HANDLER + OOLog(@"debugMonitor.setDebugger.failed", @"Could not connect to debugger %@, because an exception occurred: %@ -- %@", newDebugger, [localException name], [localException reason]); + NS_ENDHANDLER + } + } + + return _debugger == newDebugger; +} + + +- (oneway void)performJSConsoleCommand:(in NSString *)command +{ + [_script doEvent:@"consolePerformJSCommand" withArgument:command]; +} + + +- (void)appendJSConsoleLine:(id)string + colorKey:(NSString *)colorKey + emphasisRange:(NSRange)emphasisRange +{ + NS_DURING + [_debugger debugMonitor:self + jsConsoleOutput:string + colorKey:colorKey + emphasisRange:emphasisRange]; + NS_HANDLER + OOLog(@"debugMonitor.debuggerConnection.exception", @"Exception while attempting to send JavaScript console text to debugger: %@ -- %@", [localException name], [localException reason]); + NS_ENDHANDLER +} + + +- (void)appendJSConsoleLine:(id)string + colorKey:(NSString *)colorKey +{ + [self appendJSConsoleLine:string + colorKey:colorKey + emphasisRange:NSMakeRange(0, 0)]; +} + + +- (void)clearJSConsole +{ + NS_DURING + [_debugger debugMonitorClearConsole:self]; + NS_HANDLER + OOLog(@"debugMonitor.debuggerConnection.exception", @"Exception while attempting to clear JavaScript console: %@ -- %@", [localException name], [localException reason]); + NS_ENDHANDLER +} + + +- (void)showJSConsole +{ + NS_DURING + [_debugger debugMonitorShowConsole:self]; + NS_HANDLER + OOLog(@"debugMonitor.debuggerConnection.exception", @"Exception while attempting to show JavaScript console: %@ -- %@", [localException name], [localException reason]); + NS_ENDHANDLER +} + + +#pragma mark - + + +- (id)configurationValueForKey:(in NSString *)key +{ + return [self configurationValueForKey:key class:Nil defaultValue:nil]; +} + + +- (id)configurationValueForKey:(NSString *)key class:(Class)class defaultValue:(id)value +{ + id result = nil; + + if (class == Nil) class = [NSObject class]; + + result = [_configOverrides objectForKey:key]; + if (![result isKindOfClass:class] && result != [NSNull null]) result = [_configFromOXPs objectForKey:key]; + if (![result isKindOfClass:class] && result != [NSNull null]) result = [[value retain] autorelease]; + if (result == [NSNull null]) result = nil; + + return result; +} + + +- (long long)configurationIntValueForKey:(NSString *)key defaultValue:(long long)value +{ + long long result; + id object = nil; + + object = [self configurationValueForKey:key]; + if ([object respondsToSelector:@selector(longLongValue)]) result = [object longLongValue]; + else if ([object respondsToSelector:@selector(intValue)]) result = [object intValue]; + else result = value; + + return result; +} + + +- (void)setConfigurationValue:(in id)value forKey:(in NSString *)key +{ + if (key == nil) return; + + value = [self normalizeConfigValue:value forKey:key]; + + if (value == nil) + { + [_configOverrides removeObjectForKey:key]; + } + else + { + if (_configOverrides == nil) _configOverrides = [[NSMutableDictionary alloc] init]; + [_configOverrides setObject:value forKey:key]; + } + + // Send changed value to debugger + if (value == nil) + { + // Setting a nil value removes an override, and may reveal an underlying OXP-defined value + value = [self configurationValueForKey:key]; + } + NS_DURING + [_debugger debugMonitor:self + noteChangedConfigrationValue:value + forKey:key]; + NS_HANDLER + OOLog(@"debugMonitor.debuggerConnection.exception", @"Exception while attempting to send configuration update to debugger: %@ -- %@", [localException name], [localException reason]); + NS_ENDHANDLER +} + + +- (NSArray *)configurationKeys +{ + NSMutableSet *result = nil; + + result = [NSMutableSet setWithCapacity:[_configFromOXPs count] + [_configOverrides count]]; + [result addObjectsFromArray:[_configFromOXPs allKeys]]; + [result addObjectsFromArray:[_configOverrides allKeys]]; + + return [[result allObjects] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; +} + + +- (NSString *)sourceCodeForFile:(in NSString *)filePath line:(in unsigned)line +{ + id linesForFile = nil; + + linesForFile = [_sourceFiles objectForKey:filePath]; + + if (linesForFile == nil) + { + linesForFile = [self loadSourceFile:filePath]; + if (linesForFile == nil) linesForFile = [NSArray arrayWithObject:[NSString stringWithFormat:@"", filePath]]; + + if (_sourceFiles == nil) _sourceFiles = [[NSMutableDictionary alloc] init]; + [_sourceFiles setObject:linesForFile forKey:filePath]; + } + + if ([linesForFile count] < line || line == 0) return @""; + + return [linesForFile objectAtIndex:line - 1]; +} + + +#pragma mark - + +- (void)disconnectDebugger:(in id)debugger + message:(in NSString *)message +{ + if (debugger == nil) return; + + if (debugger == _debugger) + { + [self disconnectDebuggerWithMessage:message]; + } + else + { + OOLog(@"debugMonitor.disconnect.ignored", @"Attempt to disconnect debugger %@, which is not current debugger; ignoring.", debugger); + } +} + + +- (void)applicationWillTerminate:(NSNotification *)notification +{ + if (_configOverrides != nil) + { + [[NSUserDefaults standardUserDefaults] setObject:_configOverrides forKey:@"debug-settings-override"]; + } + + [self disconnectDebuggerWithMessage:@"Oolite is terminating."]; +} + + +@end + + +@implementation OODebugMonitor (Private) + +- (void)disconnectDebuggerWithMessage:(NSString *)message +{ + NS_DURING + [_debugger disconnectDebugMonitor:self message:message]; + NS_HANDLER + OOLog(@"debugMonitor.debuggerConnection.exception", @"Exception while attempting to disconnect debugger: %@ -- %@", [localException name], [localException reason]); + NS_ENDHANDLER + + id debugger = _debugger; + _debugger = nil; + [debugger release]; +} + + +- (NSDictionary *)mergedConfiguration +{ + NSMutableDictionary *result = nil; + + result = [NSMutableDictionary dictionary]; + if (_configFromOXPs != nil) [result addEntriesFromDictionary:_configFromOXPs]; + if (_configOverrides != nil) [result addEntriesFromDictionary:_configOverrides]; + + return result; +} + + +- (NSArray *)loadSourceFile:(NSString *)filePath +{ + NSString *contents = nil; + NSArray *lines = nil; + + if (filePath == nil) return nil; + + contents = [NSString stringWithContentsOfUnicodeFile:filePath]; + if (contents == nil) return nil; + + /* Extract lines from file. +FIXME: this works with CRLF and LF, but not CR. + */ + lines = [contents componentsSeparatedByString:@"\n"]; + return lines; +} + + +- (NSMutableDictionary *)normalizeConfigDictionary:(NSDictionary *)dictionary +{ + NSMutableDictionary *result = nil; + NSEnumerator *keyEnum = nil; + NSString *key = nil; + id value = nil; + + result = [NSMutableDictionary dictionaryWithCapacity:[dictionary count]]; + for (keyEnum = [dictionary keyEnumerator]; (key = [keyEnum nextObject]); ) + { + value = [dictionary objectForKey:key]; + value = [self normalizeConfigValue:value forKey:key]; + + if (key != nil && value != nil) [result setObject:value forKey:key]; + } + + return result; +} + + +- (id)normalizeConfigValue:(id)value forKey:(NSString *)key +{ + OOColor *color = nil; + BOOL boolValue; + + if (value != nil) + { + if ([key hasSuffix:@"-color"] || [key hasSuffix:@"-colour"]) + { + color = [OOColor colorWithDescription:value]; + value = [color normalizedArray]; + } + else if ([key hasPrefix:@"show-console"]) + { + boolValue = OOBooleanFromObject(value, NO); + value = [NSNumber numberWithBool:boolValue]; + } + } + + return value; +} + + +#pragma mark - + +- (oneway void)jsEngine:(in byref OOJavaScriptEngine *)engine + context:(in JSContext *)context + error:(in JSErrorReport *)errorReport + withMessage:(in NSString *)message +{ + NSString *colorKey = nil; + NSString *prefix = nil; + NSString *filePath = nil; + NSString *sourceLine = nil; + NSString *scriptLine = nil; + NSMutableString *formattedMessage = nil; + NSRange emphasisRange; + NSString *showKey = nil; + + if (_debugger == nil) return; + + if (errorReport->flags & JSREPORT_WARNING) + { + colorKey = @"warning"; + prefix = @"Warning"; + } + else if (errorReport->flags & JSREPORT_EXCEPTION) + { + colorKey = @"exception"; + prefix = @"Exception"; + } + else + { + colorKey = @"error"; + prefix = @"Error"; + } + + if (errorReport->flags & JSREPORT_STRICT) + { + prefix = [prefix stringByAppendingString:@" (strict mode)"]; + } + + // Prefix and subsequent colon should be bold: + emphasisRange = NSMakeRange(0, [prefix length] + 1); + + formattedMessage = [NSMutableString stringWithFormat:@"%@: %@", prefix, message]; + + // Note that the "active script" isn't necessarily the one causing the + // error, since one script can call another's methods. + scriptLine = [[OOJSScript currentlyRunningScript] displayName]; + if (scriptLine != nil) + { + [formattedMessage appendFormat:@"\n Active script: %@", scriptLine]; + } + + // Append file name and line + filePath = [NSString stringWithUTF8String:errorReport->filename]; + if ([filePath length] != 0) + { + [formattedMessage appendFormat:@"\n %@, line %u", [filePath lastPathComponent], errorReport->lineno]; + + // Append source code + sourceLine = [self sourceCodeForFile:filePath line:errorReport->lineno]; + if (sourceLine != nil) + { + [formattedMessage appendFormat:@":\n %@", sourceLine]; + } + } + + [self appendJSConsoleLine:formattedMessage + colorKey:colorKey + emphasisRange:emphasisRange]; + + if (errorReport->flags & JSREPORT_WARNING) showKey = @"show-console-on-warning"; + else showKey = @"show-console-on-warning"; + if (OOBooleanFromObject([self configurationValueForKey:showKey], NO)) + { + [self showJSConsole]; + } +} + + +- (oneway void)jsEngine:(in byref OOJavaScriptEngine *)engine + context:(in JSContext *)context + logMessage:(in NSString *)message + ofClass:(in NSString *)messageClass +{ + [self appendJSConsoleLine:message colorKey:@"log"]; + if (OOBooleanFromObject([self configurationValueForKey:@"show-console-on-log"], NO)) + { + [self showJSConsole]; + } +} + + +#pragma mark - + +- (jsval)javaScriptValueInContext:(JSContext *)context +{ + if (context != [[OOJavaScriptEngine sharedEngine] context]) return JSVAL_VOID; + if (_jsSelf == NULL) + { + _jsSelf = DebugMonitorToJSConsole(context, self); + if (_jsSelf != NULL) + { + if (!JS_AddNamedRoot(context, &_jsSelf, "debug console")) + { + _jsSelf = NULL; + } + } + } + + if (_jsSelf != NULL) return OBJECT_TO_JSVAL(_jsSelf); + else return JSVAL_NULL; +} + +@end + + +@implementation OODebugMonitor (Singleton) + +/* Canonical singleton boilerplate. +See Cocoa Fundamentals Guide: Creating a Singleton Instance. +See also +sharedDebugMonitor above. + +NOTE: assumes single-threaded access. +*/ + ++ (id)allocWithZone:(NSZone *)inZone +{ + if (sSingleton == nil) + { + sSingleton = [super allocWithZone:inZone]; + return sSingleton; + } + return nil; +} + + +- (id)copyWithZone:(NSZone *)inZone +{ + return self; +} + + +- (id)retain +{ + return self; +} + + +- (unsigned)retainCount +{ + return UINT_MAX; +} + + +- (void)release +{} + + +- (id)autorelease +{ + return self; +} + +@end + +#endif /* OO_EXCLUDE_DEBUG_SUPPORT */ diff --git a/src/Core/OODebugBundleLoader.h b/src/Core/Debug/OODebugSupport.h similarity index 86% rename from src/Core/OODebugBundleLoader.h rename to src/Core/Debug/OODebugSupport.h index 9636810c..5e083c13 100644 --- a/src/Core/OODebugBundleLoader.h +++ b/src/Core/Debug/OODebugSupport.h @@ -1,8 +1,8 @@ /* -OODebugBundleLoader.h +OODebugSupport.h -Load external bundle with debug features. +Set up debug support. Oolite @@ -48,18 +48,12 @@ SOFTWARE. */ -#import "OOCocoa.h" +#ifndef OO_EXCLUDE_DEBUG_SUPPORT - -#define OO_USE_DEBUG_BUNDLE (!defined (NDEBUG) && OOLITE_MAC_OS_X) - - -#if OO_USE_DEBUG_BUNDLE - -void OOLoadDebugBundle(void); +void OOInitDebugSupport(void); #else -#define OOLoadDebugBundle() do {} while (0) +#define OOInitDebugSupport() do {} while (0) -#endif // OO_USE_DEBUG_BUNDLE +#endif diff --git a/src/Core/Debug/OODebugSupport.m b/src/Core/Debug/OODebugSupport.m new file mode 100644 index 00000000..f33c50b0 --- /dev/null +++ b/src/Core/Debug/OODebugSupport.m @@ -0,0 +1,155 @@ +/* + +OODebugSupport.m + + +Oolite +Copyright (C) 2004-2007 Giles C Williams and contributors + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. + + +This file may also be distributed under the MIT/X11 license: + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#ifndef OO_EXCLUDE_DEBUG_SUPPORT + + +#import "OODebugSupport.h" +#import "ResourceManager.h" +#import "OOCollectionExtractors.h" +#import "OODebugMonitor.h" +#import "OODebugTCPConsoleClient.h" + +#if OOLITE_MAC_OS_X +static id LoadDebugPlugIn(NSString *path); +#else +#define LoadDebugPlugIn(path) nil +#endif + + +@interface NSObject (OODebugPlugInController) + +- (id) setUpDebugger; + +@end + + +void OOInitDebugSupport(void) +{ + NSString *debugOXPPath = nil; + id plugInController = nil; + NSDictionary *debugSettings = nil; + NSString *consoleHost = nil; + unsigned short consolePort = nil; + id debugger = nil; + + // Check that the debug OXP is installed. If not, we don't enable debug support. + debugOXPPath = [ResourceManager pathForFileNamed:@"DebugOXPLocatorBeacon.magic" inFolder:@"nil"]; + if (debugOXPPath != nil) + { + // Load plug-in debugging code on platforms where this is supported. + plugInController = LoadDebugPlugIn(debugOXPPath); + + // Load debug settings. + debugSettings = [ResourceManager dictionaryFromFilesNamed:@"debugConfig.plist" + inFolder:@"Config" + mergeMode:MERGE_BASIC + cache:NO]; + + consoleHost = [debugSettings stringForKey:@"console-host"]; + consolePort = [debugSettings unsignedShortForKey:@"console-port"]; + + // If consoleHost is nil, and the debug plug-in can set up a debugger, use that. + if (consoleHost == nil && [plugInController respondsToSelector:@selector(registerIntegratedDebugConsole)]) + { + debugger = [plugInController setUpDebugger]; + } + + // Otherwise, use TCP debugger connection. + if (debugger == nil) + { + debugger = [[OODebugTCPConsoleClient alloc] initWithAddress:consoleHost + port:consolePort]; + [debugger autorelease]; + } + + // Set up monitor and register debugger, if any. + if (debugger != nil) + { + [[OODebugMonitor sharedDebugMonitor] setDebugger:debugger]; + } + } +} + + +#if OOLITE_MAC_OS_X + +// Note: it should in principle be possible to use this code to load a plug-in under GNUstep, too. +static id LoadDebugPlugIn(NSString *path) +{ + Class principalClass = Nil; + NSString *bundlePath = nil; + NSBundle *bundle = nil; + id debugController = nil; + + bundlePath = [path stringByDeletingLastPathComponent]; + bundle = [NSBundle bundleWithPath:bundlePath]; + if ([bundle load]) + { + principalClass = [bundle principalClass]; + if (principalClass != Nil) + { + // Instantiate principal class of debug bundle, and let it do whatever it wants. + debugController = [[principalClass alloc] init]; + } + else + { + OOLog(@"debugOXP.load.failed", @"Failed to find principal class of debug bundle."); + } + } + else + { + OOLog(@"debugOXP.load.failed", @"Failed to load DebugOXP.bundle from %@.", bundlePath); + } + + return debugController; +} + +#endif + +#endif /* OO_EXCLUDE_DEBUG_SUPPORT */ diff --git a/src/Core/Debug/OODebugTCPConsoleClient.h b/src/Core/Debug/OODebugTCPConsoleClient.h index 984114b0..998e679c 100644 --- a/src/Core/Debug/OODebugTCPConsoleClient.h +++ b/src/Core/Debug/OODebugTCPConsoleClient.h @@ -27,6 +27,7 @@ SOFTWARE. */ + #import #import "OODebuggerInterface.h" diff --git a/src/Core/Debug/OODebugTCPConsoleClient.m b/src/Core/Debug/OODebugTCPConsoleClient.m index 790a1270..6d5fc5c0 100644 --- a/src/Core/Debug/OODebugTCPConsoleClient.m +++ b/src/Core/Debug/OODebugTCPConsoleClient.m @@ -27,6 +27,9 @@ SOFTWARE. */ +#ifndef OO_EXCLUDE_DEBUG_SUPPORT + + #import "OODebugTCPConsoleClient.h" #import "OODebugTCPConsoleProtocol.h" #import "OODebugMonitor.h" @@ -609,3 +612,5 @@ static void DecoderError(void *cbInfo, OOALStringRef errorDesc) { [(OODebugTCPConsoleClient *)cbInfo breakConnectionWithMessage:errorDesc]; } + +#endif /* OO_EXCLUDE_DEBUG_SUPPORT */ diff --git a/src/Core/Debug/OODebuggerInterface.h b/src/Core/Debug/OODebuggerInterface.h new file mode 100644 index 00000000..400a29e8 --- /dev/null +++ b/src/Core/Debug/OODebuggerInterface.h @@ -0,0 +1,70 @@ +/* + +OODebuggerInterface.h + +Protocols for communication between OODebugMonitor and OODebuggerInterface. + + +Oolite Debug OXP + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + + +@class OODebugMonitor; + +// Interface for debugger. + +@protocol OODebuggerInterface + +// Sent to establish connection. +- (BOOL)connectDebugMonitor:(in OODebugMonitor *)debugMonitor + errorMessage:(out NSString **)message; + + // Sent to close connection. +- (void)disconnectDebugMonitor:(in OODebugMonitor *)debugMonitor + message:(in NSString *)message; + + // Sent to print to the JavaScript console. + // colorKey is intended to be used to look up a foreground/background colour pair + // in the configuration. EmphasisRange is to specify a bold section of text. +- (oneway void)debugMonitor:(in OODebugMonitor *)debugMonitor + jsConsoleOutput:(in NSString *)output + colorKey:(in NSString *)colorKey + emphasisRange:(in NSRange)emphasisRange; + + // Sent to clear the JavaScript console. +- (oneway void)debugMonitorClearConsole:(in OODebugMonitor *)debugMonitor; + + // Sent to show the console, for instance in response to a warning or error message. +- (oneway void)debugMonitorShowConsole:(in OODebugMonitor *)debugMonitor; + + // Sent once when the debugger is connected. +- (oneway void)debugMonitor:(in OODebugMonitor *)debugMonitor + noteConfiguration:(in NSDictionary *)configuration; + + // Sent when configuration changes. newValue may be nil. +- (oneway void)debugMonitor:(in OODebugMonitor *)debugMonitor +noteChangedConfigrationValue:(in id)newValue + forKey:(in NSString *)key; + +@end diff --git a/src/Core/Debug/OOJSConsole.h b/src/Core/Debug/OOJSConsole.h new file mode 100644 index 00000000..ccf53c9e --- /dev/null +++ b/src/Core/Debug/OOJSConsole.h @@ -0,0 +1,38 @@ +/* + +OOJSConsole.h + +JavaScript object representing the JavaScript console. + + +Oolite Debug OXP + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#import +#import + +@class OODebugMonitor; + + +JSObject *DebugMonitorToJSConsole(JSContext *context, OODebugMonitor *monitor); diff --git a/src/Core/Debug/OOJSConsole.m b/src/Core/Debug/OOJSConsole.m new file mode 100644 index 00000000..2bca5600 --- /dev/null +++ b/src/Core/Debug/OOJSConsole.m @@ -0,0 +1,308 @@ +/* + +OOJSConsole.m + + +Oolite Debug OXP + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#ifndef OO_EXCLUDE_DEBUG_SUPPORT + +#import "OOJSConsole.h" +#import "OODebugMonitor.h" +#import + +#import "OOJavaScriptEngine.h" +#import "OOJSScript.h" +#import "OOJSVector.h" + + +static JSObject *sConsolePrototype = NULL; +static JSObject *sConsoleSettingsPrototype = NULL; + + +static void ConsoleFinalize(JSContext *context, JSObject *this); + +// Methods +static JSBool ConsoleConsoleMessage(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); +static JSBool ConsoleClearConsole(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); +static JSBool ConsoleScriptStack(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult); + +static JSBool ConsoleSettingsDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue); +static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue); +static JSBool ConsoleSettingsSetProperty(JSContext *context, JSObject *this, jsval name, jsval *value); + + +static JSClass sConsoleClass = +{ + "Console", + JSCLASS_HAS_PRIVATE, + + JS_PropertyStub, // addProperty + JS_PropertyStub, // delProperty + JS_PropertyStub, // getProperty + JS_PropertyStub, // setProperty + JS_EnumerateStub, // enumerate + JS_ResolveStub, // resolve + JS_ConvertStub, // convert + ConsoleFinalize, // finalize + JSCLASS_NO_OPTIONAL_MEMBERS +}; + + +static JSFunctionSpec sConsoleMethods[] = +{ + // JS name Function min args + { "consoleMessage", ConsoleConsoleMessage, 2 }, + { "clearConsole", ConsoleClearConsole, 0 }, + { "scriptStack", ConsoleScriptStack, 0 }, + { 0 } +}; + + +static JSClass sConsoleSettingsClass = +{ + "ConsoleSettings", + JSCLASS_HAS_PRIVATE, + + JS_PropertyStub, // addProperty + ConsoleSettingsDeleteProperty, // delProperty + ConsoleSettingsGetProperty, // getProperty + ConsoleSettingsSetProperty, // setProperty + JS_EnumerateStub, // enumerate. FIXME: this should work. + JS_ResolveStub, // resolve + JS_ConvertStub, // convert + ConsoleFinalize, // finalize (same as Console) + JSCLASS_NO_OPTIONAL_MEMBERS +}; + + +static void InitOOJSConsole(JSContext *context, JSObject *global) +{ + sConsolePrototype = JS_InitClass(context, global, NULL, &sConsoleClass, NULL, 0, NULL, sConsoleMethods, NULL, NULL); + JSRegisterObjectConverter(&sConsoleClass, JSBasicPrivateObjectConverter); + + sConsoleSettingsPrototype = JS_InitClass(context, global, NULL, &sConsoleSettingsClass, NULL, 0, NULL, NULL, NULL, NULL); + JSRegisterObjectConverter(&sConsoleSettingsClass, JSBasicPrivateObjectConverter); +} + + +JSObject *DebugMonitorToJSConsole(JSContext *context, OODebugMonitor *monitor) +{ + OOJavaScriptEngine *engine = nil; + JSObject *object = NULL; + JSObject *settingsObject = NULL; + jsval value; + + engine = [OOJavaScriptEngine sharedEngine]; + if (context == NULL) context = [engine context]; + + if (sConsolePrototype == NULL) + { + InitOOJSConsole(context, [engine globalObject]); + } + + // Create Console object + object = JS_NewObject(context, &sConsoleClass, sConsolePrototype, NULL); + if (object != NULL) + { + if (!JS_SetPrivate(context, object, [monitor weakRetain])) object = NULL; + } + + if (object != NULL) + { + // Create ConsoleSettings object + settingsObject = JS_NewObject(context, &sConsoleSettingsClass, sConsoleSettingsPrototype, NULL); + if (settingsObject != NULL) + { + if (!JS_SetPrivate(context, settingsObject, [monitor weakRetain])) settingsObject = NULL; + } + if (settingsObject != NULL) + { + value = OBJECT_TO_JSVAL(settingsObject); + if (!JS_SetProperty(context, object, "settings", &value)) + { + settingsObject = NULL; + } + } + + if (settingsObject == NULL) object = NULL; + } + + return object; +} + + +static void ConsoleFinalize(JSContext *context, JSObject *this) +{ + [(id)JS_GetPrivate(context, this) release]; + JS_SetPrivate(context, this, nil); +} + + +static JSBool ConsoleSettingsDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue) +{ + NSString *key = nil; + id monitor = nil; + + if (!JSVAL_IS_STRING(name)) return NO; + + key = [NSString stringWithJavaScriptValue:name inContext:context]; + + monitor = JSObjectToObject(context, this); + if (![monitor isKindOfClass:[OODebugMonitor class]]) + { + OOReportJavaScriptError(context, @"Expected OODebugMonitor, got %@ in %s. This is an internal error, please report it.", [monitor class], __PRETTY_FUNCTION__); + return NO; + } + + [monitor setConfigurationValue:nil forKey:key]; + *outValue = JSVAL_TRUE; + return YES; +} + + +static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue) +{ + NSString *key = nil; + id value = nil; + id monitor = nil; + + if (!JSVAL_IS_STRING(name)) return YES; + key = [NSString stringWithJavaScriptValue:name inContext:context]; + + monitor = JSObjectToObject(context, this); + if (![monitor isKindOfClass:[OODebugMonitor class]]) + { + OOReportJavaScriptError(context, @"Expected OODebugMonitor, got %@ in %s. This is an internal error, please report it.", [monitor class], __PRETTY_FUNCTION__); + return YES; + } + + value = [monitor configurationValueForKey:key]; + *outValue = [value javaScriptValueInContext:context]; + + return YES; +} + + +static JSBool ConsoleSettingsSetProperty(JSContext *context, JSObject *this, jsval name, jsval *inValue) +{ + NSString *key = nil; + id value = nil; + id monitor = nil; + + if (!JSVAL_IS_STRING(name)) return YES; + key = [NSString stringWithJavaScriptValue:name inContext:context]; + + monitor = JSObjectToObject(context, this); + if (![monitor isKindOfClass:[OODebugMonitor class]]) + { + OOReportJavaScriptError(context, @"Expected OODebugMonitor, got %@ in %s. This is an internal error, please report it.", [monitor class], __PRETTY_FUNCTION__); + return YES; + } + + if (JSVAL_IS_NULL(*inValue) || JSVAL_IS_VOID(*inValue)) + { + [monitor setConfigurationValue:nil forKey:key]; + } + else + { + value = JSValueToObject(context, *inValue); + if (value != nil) + { + [monitor setConfigurationValue:value forKey:key]; + } + else + { + OOReportJavaScriptWarning(context, @"debugConsole.settings: could not convert %@ to native object.", [NSString stringWithJavaScriptValue:*inValue inContext:context]); + } + } + + return YES; +} + + +// Methods +static JSBool ConsoleConsoleMessage(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) +{ + id monitor = nil; + NSString *colorKey = nil, + *message = nil; + NSRange emphasisRange = {0, 0}; + jsdouble location, length; + + monitor = JSObjectToObject(context, this); + if (![monitor isKindOfClass:[OODebugMonitor class]]) + { + OOReportJavaScriptError(context, @"Expected OODebugMonitor, got %@ in %s. This is an internal error, please report it.", [monitor class], __PRETTY_FUNCTION__); + return NO; + } + + colorKey = [NSString stringWithJavaScriptValue:argv[0] inContext:context]; + message = [NSString stringWithJavaScriptValue:argv[1] inContext:context]; + + if (4 <= argc) + { + // Attempt to get two numbers, specifying an emphasis range. + if (JS_ValueToNumber(context, argv[2], &location) && + JS_ValueToNumber(context, argv[3], &length)) + { + emphasisRange = NSMakeRange(location, length); + } + } + + [monitor appendJSConsoleLine:message + colorKey:colorKey + emphasisRange:emphasisRange]; + return YES; +} + + +static JSBool ConsoleClearConsole(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) +{ + id monitor = nil; + + monitor = JSObjectToObject(context, this); + if (![monitor isKindOfClass:[OODebugMonitor class]]) + { + OOReportJavaScriptError(context, @"Expected OODebugMonitor, got %@ in %s. This is an internal error, please report it.", [monitor class], __PRETTY_FUNCTION__); + return YES; + } + + [monitor clearJSConsole]; + return YES; +} + + +static JSBool ConsoleScriptStack(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult) +{ + NSArray *result = nil; + + result = [OOJSScript scriptStack]; + *outResult = [result javaScriptValueInContext:context]; + OOLog(@"temp", @"Result = %@ -> %p", result, *outResult); + return YES; +} + +#endif /* OO_EXCLUDE_DEBUG_SUPPORT */ diff --git a/src/Core/Debug/OOTCPStreamDecoder.c b/src/Core/Debug/OOTCPStreamDecoder.c index 57ed4001..ed160c88 100755 --- a/src/Core/Debug/OOTCPStreamDecoder.c +++ b/src/Core/Debug/OOTCPStreamDecoder.c @@ -1,3 +1,54 @@ +/* + +OOTCPStreamDecoder.c + + +Oolite +Copyright (C) 2004-2007 Giles C Williams and contributors + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. + + +This file may also be distributed under the MIT/X11 license: + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#ifndef OO_EXCLUDE_DEBUG_SUPPORT + + #include "OOTCPStreamDecoder.h" #include #include @@ -201,3 +252,5 @@ static void Error(OOTCPStreamDecoderRef decoder, OOALStringRef format, ...) OOALRelease(string); } } + +#endif /* OO_EXCLUDE_DEBUG_SUPPORT */ diff --git a/src/Core/Debug/OOTCPStreamDecoder.h b/src/Core/Debug/OOTCPStreamDecoder.h index f3c716f2..ee710e8b 100755 --- a/src/Core/Debug/OOTCPStreamDecoder.h +++ b/src/Core/Debug/OOTCPStreamDecoder.h @@ -1,9 +1,55 @@ -/* OOTCPStreamDecoder.h - - Psuedo-object to take blobs of data, create Oolite TCP debug console - protocol packets. +/* + +OOTCPStreamDecoder.h + +Psuedo-object to take blobs of data, create Oolite TCP debug console +protocol packets. + + +Oolite +Copyright (C) 2004-2007 Giles C Williams and contributors + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +MA 02110-1301, USA. + + +This file may also be distributed under the MIT/X11 license: + +Copyright (C) 2007 Jens Ayton + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + #ifndef INCLUDED_OOTCPStreamDecoder_h #define INCLUDED_OOTCPStreamDecoder_h diff --git a/src/Core/Debug/OOTCPStreamDecoderAbstractionLayer.m b/src/Core/Debug/OOTCPStreamDecoderAbstractionLayer.m index e398fb96..8bc432c1 100644 --- a/src/Core/Debug/OOTCPStreamDecoderAbstractionLayer.m +++ b/src/Core/Debug/OOTCPStreamDecoderAbstractionLayer.m @@ -6,6 +6,7 @@ Foundation implementation. */ +#ifndef OO_EXCLUDE_DEBUG_SUPPORT #import "OOTCPStreamDecoderAbstractionLayer.h" #import "OOCocoa.h" @@ -27,8 +28,8 @@ OOALStringRef OOALGetConstantString(const char *string) value = [sStrings objectForKey:key]; if (value == nil) { - // For portability and compatibility with CoreFoundation and Foundation, non-ASCII characters are not permitted. - value = [NSString stringWithCString:string encoding:NSASCIIStringEncoding]; + // Note: non-ASCII strings are not permitted, but we don't bother to detect them. + value = [NSString stringWithUTF8String:string]; if (value != nil) [sStrings setObject:value forKey:key]; } @@ -122,3 +123,5 @@ OOALObjectRef OOALPropertyListFromData(OOALMutableDataRef data, OOALStringRef *e return result; } + +#endif /* OO_EXCLUDE_DEBUG_SUPPORT */ diff --git a/src/Core/Materials/OOMaterial.h b/src/Core/Materials/OOMaterial.h index 3d16d779..67dbefc4 100644 --- a/src/Core/Materials/OOMaterial.h +++ b/src/Core/Materials/OOMaterial.h @@ -10,6 +10,7 @@ This is an abstract class; actual materials should be subclasses. Currently, only shader materials are supported. Direct use of textures should also be replaced with an OOMaterial subclass. + Oolite Copyright (C) 2004-2007 Giles C Williams and contributors diff --git a/src/Core/Materials/OOMaterial.m b/src/Core/Materials/OOMaterial.m index 6580be91..e3ee111d 100644 --- a/src/Core/Materials/OOMaterial.m +++ b/src/Core/Materials/OOMaterial.m @@ -2,10 +2,6 @@ OOMaterial.m -This is an abstract class; actual materials should be subclasses. - -Currently, only shader materials are supported. Direct use of textures should -also be replaced with an OOMaterial subclass. Oolite Copyright (C) 2004-2007 Giles C Williams and contributors diff --git a/src/Core/OOColor.h b/src/Core/OOColor.h index ce767051..87402ecd 100644 --- a/src/Core/OOColor.h +++ b/src/Core/OOColor.h @@ -98,4 +98,7 @@ MA 02110-1301, USA. // Multiply r, g and b components of a colour by specified factor, clamped to [0..1]. - (OOColor *)colorWithBrightnessFactor:(float)factor; +// r,g,b,a array in 0..1 range. +- (NSArray *)normalizedArray; + @end diff --git a/src/Core/OOColor.m b/src/Core/OOColor.m index 327a81b1..b71e4c42 100644 --- a/src/Core/OOColor.m +++ b/src/Core/OOColor.m @@ -455,4 +455,17 @@ MA 02110-1301, USA. alpha:rgba[3]]; } + +- (NSArray *)normalizedArray +{ + float r, g, b, a; + [self getRed:&r green:&g blue:&b alpha:&a]; + return [NSArray arrayWithObjects: + [NSNumber numberWithFloat:r], + [NSNumber numberWithFloat:g], + [NSNumber numberWithFloat:b], + [NSNumber numberWithFloat:a], + nil]; +} + @end diff --git a/src/Core/OODebugBundleLoader.m b/src/Core/OODebugBundleLoader.m deleted file mode 100644 index 5cdfda9a..00000000 --- a/src/Core/OODebugBundleLoader.m +++ /dev/null @@ -1,91 +0,0 @@ -/* - - OODebugBundleLoader.m - - - Oolite - Copyright (C) 2004-2007 Giles C Williams and contributors - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, USA. - - - This file may also be distributed under the MIT/X11 license: - - Copyright (C) 2007 Jens Ayton - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - - */ - -#import "OODebugBundleLoader.h" - -#if OO_USE_DEBUG_BUNDLE - -#import "ResourceManager.h" - - -void OOLoadDebugBundle(void) -{ - NSString *bundlePath = nil; - NSBundle *bundle = nil; - Class principalClass = Nil; - - bundlePath = [ResourceManager pathForFileNamed:@"DebugOXPLocatorBeacon.magic" inFolder:@"nil"]; - if (bundlePath != nil) - { - bundlePath = [bundlePath stringByDeletingLastPathComponent]; - bundle = [NSBundle bundleWithPath:bundlePath]; - if ([bundle load]) - { - principalClass = [bundle principalClass]; - if (principalClass != Nil) - { - // Instantiate principal class of debug bundle, and let it do whatever it wants. - [[principalClass alloc] init]; - } - else - { - OOLog(@"debugOXP.load.failed", @"Failed to find principal class of DebugOXP.bundle."); - } - } - else - { - OOLog(@"debugOXP.load.failed", @"Failed to load DebugOXP.bundle from %@.", bundlePath); - } - } - else - { - OOLog(@"debugOXP.load.none", @"Debug.oxp not found."); - } -} - -#endif diff --git a/src/Core/Scripting/OOJavaScriptEngine.m b/src/Core/Scripting/OOJavaScriptEngine.m index 93b76ab9..1ee8f584 100644 --- a/src/Core/Scripting/OOJavaScriptEngine.m +++ b/src/Core/Scripting/OOJavaScriptEngine.m @@ -175,7 +175,7 @@ static void ReportJSError(JSContext *context, const char *message, JSErrorReport // create a context and associate it with the JS run time context = JS_NewContext(runtime, 8192); - JS_SetOptions(context, JSOPTION_VAROBJFIX | JSOPTION_STRICT | JSOPTION_COMPILE_N_GO | JSOPTION_NATIVE_BRANCH_CALLBACK); + JS_SetOptions(context, JSOPTION_VAROBJFIX | JSOPTION_STRICT | JSOPTION_NATIVE_BRANCH_CALLBACK); JS_SetVersion(context, JSVERSION_1_7); // if context does not have a value, end the program here diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 78c2fc94..c7069d6a 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -46,7 +46,7 @@ MA 02110-1301, USA. #import "Octree.h" #import "CollisionRegion.h" #import "OOGraphicsResetManager.h" -#import "OODebugBundleLoader.h" +#import "OODebugSupport.h" #import "OOCharacter.h" @@ -270,7 +270,7 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, doProcedurallyTexturedPlanets = NO; #endif - OOLoadDebugBundle(); + OOInitDebugSupport(); [player completeInitialSetUp]; @@ -365,7 +365,7 @@ static NSComparisonResult comparePrice(NSDictionary *dict1, NSDictionary *dict2, { if (strict == value) return; - strict = value; + strict = !!value; [OOTexture clearCache]; // Force reload of texutres, since search paths effectively change [self reinit];