{"record":{"id":"acb0d8f05d978011","repo":"NationalSecurityAgency/ghidra","slug":"trace-must-use-a-sleigh-based-language","errorCode":null,"errorMessage":"Trace must use a sleigh-based language","messagePattern":"Trace must use a sleigh-based language","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceSleighUtils.java","lineNumber":225,"sourceCode":"\t\t\tUtils.bytesToBigInteger(bytes, bytes.length, expr.getLanguage().isBigEndian(), false),\n\t\t\tbytesPair.getRight());\n\t}\n\n\t/**\n\t * Evaluate a Sleigh expression on the given trace\n\t * \n\t * @param expr the expression\n\t * @param trace the trace\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 value of the expression as a byte array\n\t */\n\tpublic static byte[] evaluateBytes(String expr, Trace trace, long snap, TraceThread thread,\n\t\t\tint frame) {\n\t\tLanguage language = trace.getBaseLanguage();\n\t\tif (!(language instanceof SleighLanguage)) {\n\t\t\tthrow new IllegalArgumentException(\"Trace must use a sleigh-based language\");\n\t\t}\n\t\treturn evaluateBytes(\n\t\t\tSleighProgramCompiler.compileExpression((SleighLanguage) language, expr),\n\t\t\ttrace, snap, thread, frame);\n\t}\n\n\t/**\n\t * Evaluate a Sleigh expression on the given trace\n\t * \n\t * @param expr the expression\n\t * @param trace the trace\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 value of the expression as a big integer\n\t */\n\tpublic static BigInteger evaluate(String expr, Trace trace, long snap, TraceThread thread,\n\t\t\tint frame) {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceSleighUtils.java#L207-L243","documentation":"evaluateBytes(String expr, ...) compiles a Sleigh source expression on the trace's base language, then evaluates it. Compilation requires a SleighLanguage; if trace.getBaseLanguage() is any other Language subclass, it cannot compile and is rejected.","triggerScenarios":"Calling the String-expr evaluateBytes overload on a trace whose base language is not a SleighLanguage.","commonSituations":"Trace opened with a custom/non-Sleigh language provider. A trace recorded against an architecture Ghidra models without a Sleigh front-end. Programmatic traces built with a stub Language.","solutions":["Ensure the trace's base language resolves to a SleighLanguage (correct LanguageID / .ldefs).","Prefer the PcodeExpression overload and compile yourself only when you have confirmed a Sleigh language.","Guard: `if (trace.getBaseLanguage() instanceof SleighLanguage)` before calling."],"exampleFix":"// before\nbyte[] v = TraceSleighUtils.evaluateBytes(\"inst_start\", trace, snap, thread, frame);\n\n// after\nif (!(trace.getBaseLanguage() instanceof SleighLanguage)) {\n    throw new IllegalStateException(\"trace language is not Sleigh: \" + trace.getBaseLanguage());\n}\nbyte[] v = TraceSleighUtils.evaluateBytes(\"inst_start\", trace, snap, thread, frame);","handlingStrategy":"validation","validationCode":"if (!(trace.getBaseLanguage() instanceof SleighLanguage)) {\n    throw new IllegalStateException(\"trace not Sleigh: \" + trace.getBaseLanguage());\n}\nbyte[] v = TraceSleighUtils.evaluateBytes(exprText, trace, snap, thread, frame);","typeGuard":"static boolean traceIsSleigh(Trace trace) {\n    return trace.getBaseLanguage() instanceof SleighLanguage;\n}","tryCatchPattern":"try {\n    return TraceSleighUtils.evaluateBytes(exprText, trace, snap, thread, frame);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"sleigh-based language\")) {\n        // language is non-Sleigh; compute the value via direct register/memory reads instead\n    } else throw e;\n}","preventionTips":["Confirm trace base language type before any Sleigh expression API.","Prefer opening traces through the standard Sleigh-providing language service.","Wrap TraceSleighUtils calls behind a facade that validates language type once."],"tags":["sleigh","pcode-expression","language","trace"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}