{"record":{"id":"b61dc983076a5a63","repo":"NationalSecurityAgency/ghidra","slug":"traceplatform-must-use-a-sleigh-language","errorCode":null,"errorMessage":"TracePlatform must use a Sleigh language","messagePattern":"TracePlatform must use a Sleigh language","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceSleighUtils.java","lineNumber":62,"sourceCode":"\t/**\n\t * Build a p-code executor that operates directly on bytes of the given trace\n\t * \n\t * <p>\n\t * This executor is most suitable for evaluating Sleigh expression on a given trace snapshot,\n\t * and for manipulating or initializing variables using Sleigh code. It is generally not\n\t * suitable for use in an emulator. For that, use {@link PcodeEmulator} with\n\t * {@link TraceEmulationIntegration}.\n\t * \n\t * @param platform the platform\n\t * @param snap the snap\n\t * @param thread the thread, required if register space is used\n\t * @param frame the frame, for when register space is used\n\t * @return the executor\n\t */\n\tpublic static PcodeExecutor<byte[]> buildByteExecutor(TracePlatform platform, long snap,\n\t\t\tTraceThread thread, int frame) {\n\t\tif (!(platform.getLanguage() instanceof SleighLanguage language)) {\n\t\t\tthrow new IllegalArgumentException(\"TracePlatform must use a Sleigh language\");\n\t\t}\n\t\tDefaultPcodeTraceAccess access = new DefaultPcodeTraceAccess(platform, snap);\n\t\tPcodeStateCallbacks cb =\n\t\t\tTraceEmulationIntegration.bytesImmediateWrite(access, thread, frame);\n\t\tBytesPcodeExecutorState state = new BytesPcodeExecutorState(language, cb);\n\t\treturn new PcodeExecutor<>(language, BytesPcodeArithmetic.forLanguage(language), state,\n\t\t\tReason.INSPECT);\n\t}\n\n\t/**\n\t * @see #buildByteExecutor(TracePlatform, long, TraceThread, int)\n\t * @param trace the trace whose host platform to use\n\t * @param snap the snap\n\t * @param thread the thread, required if register space is used\n\t * @param frame the frame, for when register space is used\n\t * @return the executor\n\t */\n\tpublic static PcodeExecutor<byte[]> buildByteExecutor(Trace trace, long snap,","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceSleighUtils.java#L44-L80","documentation":"buildByteExecutor constructs a byte-array p-code executor over a trace platform by compiling/using Sleigh-specific machinery. It requires platform.getLanguage() to be a SleighLanguage; any other Language implementation is rejected because Sleigh expression compilation and the bytes arithmetic depend on it.","triggerScenarios":"Calling TraceSleighUtils.buildByteExecutor(platform, snap, thread, frame) where platform is a guest platform whose language is not a SleighLanguage subclass (a custom or non-Sleigh Language).","commonSituations":"Defining a guest platform backed by a hand-rolled Language. Loading a trace whose base language provider returned a non-Sleigh language. Mixed-language traces where a guest language lacks a Sleigh implementation.","solutions":["Verify platform.getLanguage() instanceof SleighLanguage before calling buildByteExecutor; if not, use the host platform or a Sleigh-backed guest.","Ensure the trace's language provider resolves to a SleighLanguage (proper language ID / .ldefs entry).","If you must evaluate on a non-Sleigh language, implement the byte arithmetic/executor yourself instead of using this helper."],"exampleFix":"// before\nPcodeExecutor<byte[]> exec = TraceSleighUtils.buildByteExecutor(platform, snap, thread, frame);\n\n// after\nif (!(platform.getLanguage() instanceof SleighLanguage)) {\n    throw new IllegalStateException(\"platform not Sleigh-based: \" + platform.getLanguage());\n}\nPcodeExecutor<byte[]> exec = TraceSleighUtils.buildByteExecutor(platform, snap, thread, frame);","handlingStrategy":"type-guard","validationCode":"if (!(platform.getLanguage() instanceof SleighLanguage)) {\n    throw new IllegalStateException(\n        \"platform language is not Sleigh: \" + platform.getLanguage());\n}\nPcodeExecutor<byte[]> exec = TraceSleighUtils.buildByteExecutor(platform, snap, thread, frame);","typeGuard":"static boolean isSleighPlatform(TracePlatform platform) {\n    return platform.getLanguage() instanceof SleighLanguage;\n}","tryCatchPattern":"try {\n    PcodeExecutor<byte[]> exec = TraceSleighUtils.buildByteExecutor(platform, snap, thread, frame);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Sleigh language\")) {\n        // switch to a Sleigh-backed platform or host platform\n    } else throw e;\n}","preventionTips":["Always create guest platforms from a Sleigh language provider.","When loading a trace, assert its host language is Sleigh before invoking Sleigh helpers.","Cache the Sleigh check result per platform to avoid repeated instanceof checks."],"tags":["sleigh","pcode-executor","trace-platform","language"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}