NationalSecurityAgency/ghidra · error · UnknownContextException

Instruction has incompatible prototype at: ({getStartSnap},{

Error message

Instruction has incompatible prototype at: ({getStartSnap},{instructionAddress})

What it means

Thrown by DBTraceInstruction.getParserContext(Address instructionAddress) when an instruction exists at the referenced address but its InstructionPrototype implementation class differs from this instruction's prototype class. The method enforces prototype class equality via otherProto.getClass().equals(prototype.getClass()) to ensure compatible parser implementations. An UnknownContextException signals the prototype mismatch means the parser context cannot be safely shared.

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceInstruction.java:871

	@Override
	public ParserContext getParserContext(Address instructionAddress)
			throws UnknownContextException, MemoryAccessException {
		// TODO: Why is this a method of Instruction? Seems should be of Listing.
		// NOTE: Taken from InstructionDB#getParserContext(Address) 
		// Admittedly, I don't understand what it's for
		if (getAddress().equals(instructionAddress)) {
			return getParserContext();
		}
		DBTraceInstruction instruction =
			space.manager.instructions.getAt(getStartSnap(), instructionAddress);
		if (instruction == null) {
			throw new UnknownContextException("Trace does not contain referenced instruction: (" +
				getStartSnap() + "," + instructionAddress + ")");
		}
		// Ensure that prototype is the same implementation
		InstructionPrototype otherProto = instruction.getPrototype();
		if (!otherProto.getClass().equals(prototype.getClass())) {
			throw new UnknownContextException("Instruction has incompatible prototype at: (" +
				getStartSnap() + "," + instructionAddress + ")");
		}
		return instruction.getParserContext();
	}
}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Verify prototype class compatibility before calling getParserContext: check the target instruction's getPrototype().getClass() matches the source instruction's.
  2. Ensure all instructions at the referenced address were created with the same language/platform as the source instruction.
  3. Catch UnknownContextException and obtain the parser context directly from the target instruction instead (target.getParserContext() with its own address).

Example fix

// before
ParserContext ctx = instruction.getParserContext(targetAddress);

// after
DBTraceInstruction target =
    space.manager.instructions.getAt(instruction.getStartSnap(), targetAddress);
if (target != null &&
    target.getPrototype().getClass().equals(instruction.getPrototype().getClass())) {
    ParserContext ctx = instruction.getParserContext(targetAddress);
} else {
    ParserContext ctx = target.getParserContext();
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify prototype class compatibility
DBTraceInstruction target = space.manager.instructions
    .getAt(instruction.getStartSnap(), targetAddress);
if (target == null ||
    !target.getPrototype().getClass().equals(instruction.getPrototype().getClass())) {
    // incompatible or missing; do not call getParserContext(targetAddress)
}

Try / catch

try {
    ParserContext ctx = instruction.getParserContext(targetAddress);
} catch (UnknownContextException e) {
    // prototype mismatch or missing instruction
    // obtain context directly from the target instruction instead
}

Prevention

When it happens

Trigger: Calling getParserContext(instructionAddress) where the instruction at (getStartSnap(), instructionAddress) was created by a different language or disassembler, producing a different InstructionPrototype subclass (e.g., one from a different processor language or a different prototype implementation).

Common situations: When a trace contains instructions from multiple platforms/languages at the same snap, and the caller assumes prototype compatibility. When a trace was migrated or its language definition changed between sessions, causing prototype class mismatches.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/83710bf74b329aed. Report an issue: GitHub.