{"record":{"id":"3120fcdc8f9258af","repo":"NationalSecurityAgency/ghidra","slug":"trace-does-not-contain-referenced-instruction-g","errorCode":null,"errorMessage":"Trace does not contain referenced instruction: ({getStartSnap},{instructionAddress})","messagePattern":"Trace does not contain referenced instruction: \\((.+?),(.+?)\\)","errorType":"exception","errorClass":"UnknownContextException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceInstruction.java","lineNumber":865,"sourceCode":"\tpublic ParserContext getParserContext() throws MemoryAccessException {\n\t\treturn parserContext == null\n\t\t\t\t? parserContext = prototype.getParserContext(getMemBuffer(), getProcessorContext())\n\t\t\t\t: parserContext;\n\t}\n\n\t@Override\n\tpublic ParserContext getParserContext(Address instructionAddress)\n\t\t\tthrows UnknownContextException, MemoryAccessException {\n\t\t// TODO: Why is this a method of Instruction? Seems should be of Listing.\n\t\t// NOTE: Taken from InstructionDB#getParserContext(Address) \n\t\t// Admittedly, I don't understand what it's for\n\t\tif (getAddress().equals(instructionAddress)) {\n\t\t\treturn getParserContext();\n\t\t}\n\t\tDBTraceInstruction instruction =\n\t\t\tspace.manager.instructions.getAt(getStartSnap(), instructionAddress);\n\t\tif (instruction == null) {\n\t\t\tthrow new UnknownContextException(\"Trace does not contain referenced instruction: (\" +\n\t\t\t\tgetStartSnap() + \",\" + instructionAddress + \")\");\n\t\t}\n\t\t// Ensure that prototype is the same implementation\n\t\tInstructionPrototype otherProto = instruction.getPrototype();\n\t\tif (!otherProto.getClass().equals(prototype.getClass())) {\n\t\t\tthrow new UnknownContextException(\"Instruction has incompatible prototype at: (\" +\n\t\t\t\tgetStartSnap() + \",\" + instructionAddress + \")\");\n\t\t}\n\t\treturn instruction.getParserContext();\n\t}\n}\n","sourceCodeStart":847,"sourceCodeEnd":877,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceInstruction.java#L847-L877","documentation":"Thrown by DBTraceInstruction.getParserContext(Address instructionAddress) when the caller requests a parser context at an address different from this instruction's own address, and the trace's instruction manager has no instruction at (getStartSnap(), instructionAddress). This is an UnknownContextException (checked), indicating the referenced instruction does not exist in the trace at the given snap and address. The method first checks if instructionAddress equals this instruction's address (returning its own context); otherwise it performs a lookup that returned null.","triggerScenarios":"Calling getParserContext(someOtherAddress) on a DBTraceInstruction where someOtherAddress is not the instruction's own address, and no DBTraceInstruction exists in space.manager.instructions at (getStartSnap(), someOtherAddress). This happens when the caller passes an address from a flow target that has not yet been disassembled or recorded in the trace.","commonSituations":"During cross-instruction context resolution when following flow (branch targets) that were never disassembled. When a trace was loaded that is missing instructions at referenced addresses. When the snap referenced by the instruction does not have the target instruction recorded.","solutions":["Verify the instruction exists at the referenced address before calling getParserContext by checking space.manager.instructions.getAt(snap, address) is non-null.","Pass the instruction's own address (getAddress()) to get its own parser context instead of a foreign address.","Catch UnknownContextException and handle the missing instruction gracefully (skip, log, or disassemble the target first)."],"exampleFix":"// before\nParserContext ctx = instruction.getParserContext(targetAddress);\n\n// after\nDBTraceInstruction target =\n    space.manager.instructions.getAt(instruction.getStartSnap(), targetAddress);\nParserContext ctx = (target != null)\n    ? instruction.getParserContext(targetAddress)\n    : instruction.getParserContext(); // fall back to own context","handlingStrategy":"validation","validationCode":"// Check the target instruction exists before requesting its parser context\nAddress targetAddr = /* the referenced address */;\nif (instruction.getAddress().equals(targetAddr)) {\n    // safe — own context\n} else {\n    DBTraceInstruction target = space.manager.instructions\n        .getAt(instruction.getStartSnap(), targetAddr);\n    if (target == null) {\n        // no instruction at target; do not call getParserContext(targetAddr)\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    ParserContext ctx = instruction.getParserContext(targetAddress);\n} catch (UnknownContextException e) {\n    // no instruction at the referenced address in this trace/snap\n    // fall back to own context or disassemble target first\n}","preventionTips":["Verify instruction existence at referenced addresses before calling getParserContext.","Use getParserContext() with no args when you need the instruction's own context.","Ensure all flow targets are disassembled before cross-referencing parser contexts."],"tags":["instruction","trace-database","parser-context","checked-exception"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}