{"record":{"id":"a97e506d04c86ba5","repo":"NationalSecurityAgency/ghidra","slug":"base-compiler-spec-cannot-be-a-guest-compiler-spec","errorCode":null,"errorMessage":"Base compiler spec cannot be a guest compiler spec","messagePattern":"Base compiler spec cannot be a guest compiler spec","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/guest/DBTracePlatformManager.java","lineNumber":327,"sourceCode":"\t}\n\n\tprotected DBTraceGuestPlatform doAddGuestPlatform(CompilerSpec compilerSpec) {\n\t\tDBTraceGuestPlatform platformEntry = platformStore.create();\n\t\tplatformEntry.set(compilerSpec);\n\t\ttry {\n\t\t\tplatformEntry.loadDataTypeManager(OpenMode.CREATE, TaskMonitor.DUMMY);\n\t\t}\n\t\tcatch (CancelledException | VersionException | IOException e) {\n\t\t\tthrow new AssertionError(e);\n\t\t}\n\t\tplatformsByCompiler.put(compilerSpec, platformEntry);\n\t\treturn platformEntry;\n\t}\n\n\t@Override\n\tpublic DBTraceGuestPlatform addGuestPlatform(CompilerSpec compilerSpec) {\n\t\tif (trace.getBaseCompilerSpec() == compilerSpec) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Base compiler spec cannot be a guest compiler spec\");\n\t\t}\n\t\tDBTraceGuestPlatform platform;\n\t\ttry (LockHold hold = LockHold.lock(lock.writeLock())) {\n\t\t\tplatform = doAddGuestPlatform(compilerSpec);\n\t\t}\n\t\ttrace.setChanged(new TraceChangeRecord<>(TraceEvents.PLATFORM_ADDED, null, platform));\n\t\treturn platform;\n\t}\n\n\t@Override\n\tpublic InternalTracePlatform getPlatform(CompilerSpec compilerSpec) {\n\t\ttry (LockHold hold = LockHold.lock(lock.readLock())) {\n\t\t\tif (trace.getBaseCompilerSpec() == compilerSpec) {\n\t\t\t\treturn hostPlatform;\n\t\t\t}\n\t\t\treturn platformsByCompiler.get(compilerSpec);\n\t\t}","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/guest/DBTracePlatformManager.java#L309-L345","documentation":"addGuestPlatform rejects adding the trace's own base compiler spec as a guest: if trace.getBaseCompilerSpec() == compilerSpec it throws IllegalArgumentException(\"Base compiler spec cannot be a guest compiler spec\"). A platform cannot guest-host itself.","triggerScenarios":"Calling addGuestPlatform with the host trace's base CompilerSpec; enumerating a language's compiler specs and not excluding the host's own.","commonSituations":"Looping over CompilerSpecs and passing the base one through; copy-paste mapping setup; confusing host and guest configuration.","solutions":["Skip the base compiler spec when enumerating candidate specs.","Pass a CompilerSpec from a different language than the host.","Guard with trace.getBaseCompilerSpec() == compilerSpec before the call."],"exampleFix":"// before\nfor (CompilerSpec cs : lang.getCompilerSpecs()) {\n    mgr.addGuestPlatform(cs);\n}\n\n// after\nCompilerSpec base = trace.getBaseCompilerSpec();\nfor (CompilerSpec cs : lang.getCompilerSpecs()) {\n    if (cs == base) continue;\n    mgr.addGuestPlatform(cs);\n}","handlingStrategy":"validation","validationCode":"CompilerSpec base = trace.getBaseCompilerSpec();\nfor (CompilerSpec cs : candidateSpecs) {\n    if (cs == base) continue; // cannot add host's own as guest\n    mgr.addGuestPlatform(cs);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter out the host's base compiler spec when enumerating guest candidates.","Use reference equality (==) to compare the base compiler spec, matching the source check.","Document that guest platforms must target a different language than the host."],"tags":["guest-platform","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}