Package ghidra.pcode.emulate
Class Emulate
java.lang.Object
ghidra.pcode.emulate.Emulate
- Direct Known Subclasses:
ModifiedPcodeThread.GlueEmulate
A SLEIGH based implementation of the Emulate interface
This implementation uses a Translate object to translate machine instructions into pcode and caches pcode ops for later use by the emulator. The pcode is cached as soon as the execution address is set, either explicitly, or via branches and fallthrus. There are additional methods for inspecting the pcode ops in the current instruction as a sequence.
-
Constructor Summary
ConstructorsConstructorDescriptionEmulate
(SleighLanguage lang, MemoryState s, BreakTable b) Creates a newEmulate
object -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
void
Since the full instruction is cached, we can do relative branches properlyvoid
This routine performs a standard pcode branch indirect operation on the memory statevoid
This routine performs a standard pcode call operation on the memory statevoid
This routine performs a standard pcode call indirect operation on the memory statevoid
Give instuctionStateModifier first shot at executing custom pcodeop, if not supported look for a breakpoint for the given user-defined op and invoke it.void
void
This kind of pcode op should not come up in ordinary emulation, so this routine throws an exception.void
executeInstruction
(boolean stopAtBreakpoint, TaskMonitor monitor) This routine executes an entire machine instruction at once, as a conventional debugger step function would do.void
This routine performs a standard pcode load operation on the memory statevoid
This kind of pcode op should not come up in ordinary emulation, so this routine throws an exception.void
This routine performs a standard pcode store operation on the memory statevoid
Update the iterator into the current pcode cache, and if necessary, generate the pcode for the fallthru instruction and reset the iterator.Returns the current context register value.Returns the currently executing machine address.Returns the current emulator execution state.Returns the last address.Returns the memory state object which this emulator uses.boolean
Since the emulator can single step through individual pcode operations, the machine state may be halted in the middle of a single machine instruction, unlike conventional debuggers.void
setContextRegisterValue
(RegisterValue regValue) Sets the context register value at the current execute address.void
setExecuteAddress
(Address addr) Set the current execution address and cache the pcode translation of the machine instruction at that address
-
Constructor Details
-
Emulate
Creates a newEmulate
object- Parameters:
lang
- is the SLEIGH languages
- is the MemoryState the emulator should manipulateb
- is the table of breakpoints the emulator should invoke
-
-
Method Details
-
dispose
public void dispose() -
getLanguage
-
isInstructionStart
public boolean isInstructionStart()Since the emulator can single step through individual pcode operations, the machine state may be halted in the middle of a single machine instruction, unlike conventional debuggers. This routine can be used to determine if execution is actually at the beginning of a machine instruction.- Returns:
- true if the next pcode operation is at the start of the instruction translation
-
getExecutionState
Returns the current emulator execution state.- Returns:
- the current emulator execution state
-
getExecuteAddress
Returns the currently executing machine address.- Returns:
- the currently executing machine address
-
getLastExecuteAddress
Returns the last address.- Returns:
- the last address
-
getNewDisassemblerContext
-
getContextRegisterValue
Returns the current context register value. The context value returned reflects its state when the previously executed instruction was parsed/executed. The context value returned will feed into the next instruction to be parsed with its non-flowing bits cleared and any future context state merged in. If no instruction has been executed, the explicitly set context will be returned. A null value is returned if no context register is defined by the language or initial context has not been set. -
setContextRegisterValue
Sets the context register value at the current execute address. The Emulator should not be running when this method is invoked. Only flowing context bits should be set, as non-flowing bits will be cleared prior to parsing on instruction. In addition, any future context state set by the pcode emitter will take precedence over context set using this method. This method is primarily intended to be used to establish the initial context state.- Parameters:
regValue
-
-
fallthruOp
public void fallthruOp()Update the iterator into the current pcode cache, and if necessary, generate the pcode for the fallthru instruction and reset the iterator. -
executeConditionalBranch
-
executeBranch
Since the full instruction is cached, we can do relative branches properly- Parameters:
op
- is the particular branch op being executed
-
executeCallother
Give instuctionStateModifier first shot at executing custom pcodeop, if not supported look for a breakpoint for the given user-defined op and invoke it. If it doesn't exist, or doesn't replace the action, throw an exception- Parameters:
op
- is the particular user-defined op being executed- Throws:
UnimplementedCallOtherException
-
setExecuteAddress
Set the current execution address and cache the pcode translation of the machine instruction at that address- Parameters:
addr
- is the address where execution should continue
-
executeInstruction
public void executeInstruction(boolean stopAtBreakpoint, TaskMonitor monitor) throws CancelledException, LowlevelError, InstructionDecodeException This routine executes an entire machine instruction at once, as a conventional debugger step function would do. If execution is at the start of an instruction, the breakpoints are checked and invoked as needed for the current address. If this routine is invoked while execution is in the middle of a machine instruction, execution is continued until the current instruction completes.- Parameters:
stopAtBreakpoint
-monitor
-- Throws:
CancelledException
LowlevelError
InstructionDecodeException
-
getMemoryState
Returns the memory state object which this emulator uses.- Returns:
- the memory state object which this emulator uses
-
executeLoad
This routine performs a standard pcode load operation on the memory state- Parameters:
op
- is the particular load op being executed
-
executeStore
This routine performs a standard pcode store operation on the memory state- Parameters:
op
- is the particular store op being executed
-
executeBranchind
This routine performs a standard pcode branch indirect operation on the memory state- Parameters:
op
- is the particular branchind op being executed
-
executeCall
This routine performs a standard pcode call operation on the memory state- Parameters:
op
- is the particular call op being executed
-
executeCallind
This routine performs a standard pcode call indirect operation on the memory state- Parameters:
op
- is the particular callind op being executed
-
executeMultiequal
This kind of pcode op should not come up in ordinary emulation, so this routine throws an exception.- Parameters:
op
- is the particular multiequal op being executed
-
executeIndirect
This kind of pcode op should not come up in ordinary emulation, so this routine throws an exception.- Parameters:
op
- is the particular indirect op being executed
-