Class JitPassage
Note that the generated p-code ops include those injected by the emulator's client using
PcodeMachine.inject(Address, String)
and PcodeThread.inject(Address, String)
,
which also includes breakpoints, i.e, PcodeMachine.addBreakpoint(Address, String)
.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
An address-context pairstatic interface
A branch in the p-codestatic class
An extension ofPcodeOp
that carries along with it the address and decode context where it occurred.static class
An instruction denoting a decode errorstatic class
A synthetic p-code op denoting a decode errorstatic class
A synthetic op representing the initial seed of a decoded passage.static final record
A "branch" representing an errorstatic class
A synthetic p-code op that represents a return from theJitCompiledPassage.run(int)
method.static final record
A branch to an address (and context value) not in the same passagestatic final record
A branch to a dynamic addressstatic final record
A branch to another p-code op in the same passagestatic class
A synthetic p-code op meant to encode "no operation"Nested classes/interfaces inherited from class ghidra.pcode.exec.PcodeProgram
PcodeProgram.MyAppender, PcodeProgram.MyFormatter
-
Field Summary
Fields inherited from class ghidra.pcode.exec.PcodeProgram
code, language, useropNames
-
Constructor Summary
ConstructorsConstructorDescriptionJitPassage
(SleighLanguage language, JitPassage.AddrCtx entry, List<PcodeOp> code, PcodeUseropLibrary<Object> decodeLibrary, List<Instruction> instructions, Map<PcodeOp, JitPassage.Branch> branches, Map<PcodeOp, JitPassage.AddrCtx> entries) Construct a new passage -
Method Summary
Modifier and TypeMethodDescriptiondecodeError
(Language language, Address address, RegisterValue ctx, String message) Create an instruction to indicate a decode errorGet all of the (non-fall-through) branches in the passagegetCode()
Get the userop library that was used during decode of the passagegetEntry()
Get the initial seed of this passage.If the given p-code op is known to cause an error, e.g., an unimplemented instruction, get the error message.protected static RegisterValue
getInCtx
(InstructionContext insCtx) Derive the decode context value from the given instruction contextprotected static RegisterValue
getInCtx
(Instruction instruction) Derive the decode context value from the given instructionGet all of the instructions in the passage.getOpEntry
(PcodeOp op) Check if a given p-code op is the first of an instruction.static boolean
Check if a given p-code op could fall throughtoString()
Methods inherited from class ghidra.pcode.exec.PcodeProgram
execute, format, format, fromInject, fromInstruction, fromInstruction, getHead, getLanguage
-
Constructor Details
-
JitPassage
public JitPassage(SleighLanguage language, JitPassage.AddrCtx entry, List<PcodeOp> code, PcodeUseropLibrary<Object> decodeLibrary, List<Instruction> instructions, Map<PcodeOp, JitPassage.Branch> branches, Map<PcodeOp, JitPassage.AddrCtx> entries) Construct a new passage- Parameters:
language
- the translation source language, i.e., the emulation target language. SeePcodeProgram.getLanguage()
entry
- seegetEntry()
code
- the p-code ops, grouped by stride. Within each stride, they are ordered as decoded and produced by their instructions. The strides are sorted by seed, with precedence to the decode context value. SeegetInstructions()
. SeegetCode()
.decodeLibrary
- seegetDecodeLibrary()
instructions
- seegetInstructions()
branches
- seegetBranches()
entries
- seegetOpEntry(PcodeOp)
-
-
Method Details
-
hasFallthrough
Check if a given p-code op could fall throughConditional branches and non-branching ops are the only ones that can fall through. Note that for JIT purposes, a
CALL
op does not fall through! For decompilation, it hints that it's branching to a subroutine that usually returns back to the caller, but the JIT compiler does not take that hint. 1) There's no guarantee it will actually return. 2) Even if it did, it would be via aPcodeOp.RETURN
, which is an indirect branch. An indirect branch is not sufficient to join two strides in the same passage. Thus, we have little to gain by falling through a call, and the more likely outcome is the JIT and/or ASM library will eliminate the code following the call.- Parameters:
op
- the op to consider- Returns:
- true if the op does or could fall through
-
getInCtx
Derive the decode context value from the given instruction context- Parameters:
insCtx
- the context- Returns:
- the input decode context from the instruction whose context was given
-
getInCtx
Derive the decode context value from the given instruction- Parameters:
instruction
- the instruction- Returns:
- the input decode context from the instruction
-
decodeError
public static JitPassage.DecodeErrorInstruction decodeError(Language language, Address address, RegisterValue ctx, String message) Create an instruction to indicate a decode errorThe resulting instruction will produce a single
JitPassage.DecodeErrorPcodeOp
. The translator will generate code that throws aDecodePcodeExecutionException
should execution reach it.- Parameters:
language
- the emulation target languageaddress
- the address where decode was attemptedctx
- the input decode contextmessage
- a message for theDecodePcodeExecutionException
- Returns:
- the new "instruction"
-
getInstructions
Get all of the instructions in the passage.These are grouped by stride. Within each stride, the instructions are listed in decode order. The strides are ordered by seed address-context pair, with context value taking precedence.
- Returns:
- the list of instructions
-
getCode
Conventionally, the first instruction of the program is the entry. Note this might not be the initial seed. If the decoded passage contains a branch to an address preceding the seed, and a stride results from it, then that stride's p-code will occur earlier in the list. This is not a problem. The code generator will export many entry points, and the seed must be among them. "Entering" at that seed is achieved using a switch table at the start of the generated bytecode.
- Overrides:
getCode
in classPcodeProgram
-
getEntry
Get the initial seed of this passage.This is informational only. It should be used in naming things and/or in diagnostics.
- Returns:
- the address-context pair
-
getDecodeLibrary
Get the userop library that was used during decode of the passageThis often wraps the emulator's userop library. Downstream components, namely the
JitDataFlowModel
, will need this when translatingcalls
to userops.- Returns:
- the library
-
getBranches
Get all of the (non-fall-through) branches in the passage- Returns:
- the branches, keyed by
JitPassage.Branch.from()
.
-
toString
- Overrides:
toString
in classPcodeProgram
-
getOpEntry
Check if a given p-code op is the first of an instruction.NOTE: If an instruction is at an address with an inject, then the first op produced by the inject is considered the "entry" to the instruction. This is to ensure that any control flow to the injected address executes the injected code, not just the instruction's code.
- Parameters:
op
- the op to check.- Returns:
- the address-context pair that generated the op, if it is the first there, or
null
-
getErrorMessage
If the given p-code op is known to cause an error, e.g., an unimplemented instruction, get the error message.- Parameters:
op
- the p-code op causing the error- Returns:
- the message for the error caused
-