Interface FlatDebuggerAPI
- All Known Subinterfaces:
FlatDebuggerRmiAPI
To use this "mix-in" interface, extend GhidraScript as you normally would for your
script, but also add this interface to the implements clause of your script, e.g.,
class MyDebuggerScript extends GhidraScript implements FlatDebuggerAPI.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classClass that implementsexpectBreakpointChanges() -
Method Summary
Modifier and TypeMethodDescriptiondefault voidactivateFrame(int frame) Make the given frame the active framedefault voidactivateSnap(long snap) Make the given snapshot the active snapshotdefault voidactivateThread(TraceThread thread) Make the given thread the active threaddefault voidactivateTrace(Trace trace) Make the given trace the active tracedefault booleanbreakpointsClear(ProgramLocation location) Clear the breakpoints at a given locationdefault Set<LogicalBreakpoint> breakpointsDisable(ProgramLocation location) Disable the breakpoints at a given locationdefault Set<LogicalBreakpoint> breakpointsEnable(ProgramLocation location) Enable the breakpoints at a given locationdefault Set<LogicalBreakpoint> breakpointSet(ProgramLocation location, long length, TraceBreakpointKind.TraceBreakpointKindSet kinds, String name) Set a breakpoint at the given locationdefault Set<LogicalBreakpoint> breakpointSetAccess(ProgramLocation location, int length, String name) Set an access breakpoint at the given locationdefault Set<LogicalBreakpoint> breakpointSetHardwareExecute(ProgramLocation location, String name) Set a hardware breakpoint at the given locationdefault Set<LogicalBreakpoint> breakpointSetRead(ProgramLocation location, int length, String name) Set a read breakpoint at the given locationdefault Set<LogicalBreakpoint> breakpointSetSoftwareExecute(ProgramLocation location, String name) Set a software breakpoint at the given locationdefault Set<LogicalBreakpoint> breakpointSetWrite(ProgramLocation location, int length, String name) Set a write breakpoint at the given locationdefault Set<LogicalBreakpoint> breakpointsToggle(ProgramLocation location) Toggle the breakpoints at a given locationdefault voidcloseTrace(Trace trace) Close the given trace in the UIdefault ActionContextcreateContext(TraceObject object) default ActionContextcreateContext(TraceThread thread) default ActionContextcreateContext(Trace trace) Create a state editor for the current context, adhering to the current control modecreateStateEditor(DebuggerCoordinates coordinates) Create a state editor for the given context, adhering to its current control modecreateStateEditor(TraceThread thread, int frame, long snap) Create a state editor suitable for register or memory edits for the given contextcreateStateEditor(Trace trace, long snap) Create a state editor suitable for memory edits for the given contextdefault ObjectdoAction(Target target, ActionName name, ActionContext context) default booleandoThreadAction(TraceThread thread, ActionName name) default booleandoTraceAction(Trace trace, ActionName name) default ProgramLocationdynamicLocation(Address address) Create a dynamic location at the given address in the current trace and snapdefault ProgramLocationdynamicLocation(TraceProgramView view, Address address) Create a dynamic location at the given address in the given viewdefault ProgramLocationdynamicLocation(TraceProgramView view, String addrString) Create a dynamic location at the given address in the given viewdefault ProgramLocationdynamicLocation(Trace trace, long snap, Address address) Create a dynamic location at the given address in the given trace at the given snapdefault ProgramLocationdynamicLocation(Trace trace, long snap, String addrString) Create a dynamic location at the given address in the given trace at the given snapdefault ProgramLocationdynamicLocation(Trace trace, Address address) Create a dynamic location at the given address in the given trace's primary viewdefault ProgramLocationdynamicLocation(Trace trace, String addrString) Create a dynamic location at the given address in the given trace's primary viewdefault ProgramLocationdynamicLocation(String addrString) Create a dynamic location at the given address in the current trace and snapdefault booleanemulate(TracePlatform platform, TraceSchedule time, TaskMonitor monitor) Emulate the given trace platform as specified in the given schedule and display the result in the UIdefault booleanemulate(TraceSchedule time, TaskMonitor monitor) Emulate the current trace as specified and display the resultdefault booleanemulate(Trace trace, TraceSchedule time, TaskMonitor monitor) Emulate the given trace as specified in the given schedule and display the result in the UIdefault TraceemulateLaunch(Address address) Does the same asemulateLaunch(Program, Address), for the current programdefault TraceemulateLaunch(Program program, Address address) Load the given program into a trace suitable for emulation in the UI, starting at the given addressdefault BigIntegerevaluate(DebuggerCoordinates coordinates, String expression) Evaluate a Sleigh expression in the given contextdefault BigIntegerEvaluate a Sleigh expression in the current contextdefault booleanExecute a command on the live debugger for the given tracedefault booleanExecute a command on the live debugger for the current tracedefault StringexecuteCapture(Trace trace, String command) Execute a command on the live debugger for the given trace, capturing the outputdefault StringexecuteCapture(String command) Execute a command on the live debugger for the current trace, capturing the outputPerform some operations expected to cause changes, and then wait for those changes to settledefault Target.ActionEntryfindAction(Target target, ActionName action, ActionContext context) default booleanflushAsyncPipelines(Trace trace) Flush each stage of the asynchronous processing pipelines from end to enddefault Set<LogicalBreakpoint> Get all the breakpointsdefault NavigableMap<Address, Set<LogicalBreakpoint>> getBreakpoints(Program program) Get the breakpoints in the given program, indexed by addressdefault NavigableMap<Address, Set<LogicalBreakpoint>> getBreakpoints(Trace trace) Get the breakpoints in the given trace, indexed by (dynamic) addressdefault Set<LogicalBreakpoint> getBreakpointsAt(ProgramLocation location) Get the breakpoints at a given locationdefault DebuggerLogicalBreakpointServiceGet the breakpoint servicedefault Set<LogicalBreakpoint> getBreakpointsNamed(String name) Get the breakpoints having the given name (from any open program or trace)default DebuggerControlServiceGet the control servicedefault AddressGet the current dynamic addressdefault DebuggerCoordinatesGet the current "coordinates", i.e., trace, thread, frame, snap, etc., usually for the active target.default ProgramLocationGet the current trace program view and addressdefault TraceScheduleGet the current emulation scheduledefault intGet the current frame, 0 being the innermostdefault TracePlatformGet the current trace platformdefault ProgramGet the current programdefault longGet the current snap, i.e., snapshot keydefault TraceThreadGet the current threaddefault TraceGet the current tracedefault TraceProgramViewGet the current trace program viewdefault DebuggerListingServiceGet the dynamic listing servicedefault DebuggerEmulationServiceGet the emulation servicedefault TraceExecutionStategetExecutionState(TraceThread thread) Get the current state of the given threaddefault TraceExecutionStategetExecutionState(Trace trace) Get the current state of the given tracedefault DebuggerStaticMappingServiceGet the static mapping servicedefault AddressGet the program counter for the current contextdefault AddressgetProgramCounter(DebuggerCoordinates coordinates) Get the program counter for the given contextdefault AddressGet the stack pointer for the current contextdefault AddressgetStackPointer(DebuggerCoordinates coordinates) Get the stack pointer for the given contextgetState()Get the script statedefault DebuggerTargetServiceThe target servicedefault TracegetTrace(ProgramLocation location) If the location is dynamic, get its tracedefault DebuggerTraceManagerServiceGet the trace manager servicedefault booleangoToDynamic(Address address) Go to the given dynamic address in the dynamic listingdefault booleangoToDynamic(ProgramLocation location) Go to the given dynamic location in the dynamic listingdefault booleangoToDynamic(String addrString) Go to the given dynamic address in the dynamic listingdefault booleanInterrupt execution of the current thread or tracedefault booleaninterrupt(TraceThread thread) Interrupt execution of the live target for the given trace threaddefault booleanInterrupt execution of the live target for the given tracedefault booleanCheck if the current target is alivedefault booleanisTargetAlive(Trace trace) Check if the given trace's target is alivedefault booleanCheck if the current target thread is alivedefault booleanisThreadAlive(TraceThread thread) Check if the given trace thread's target is alivedefault booleankill()Terminate execution of the current thread or tracedefault booleankill(TraceThread thread) Terminate execution of the live target for the given trace threaddefault booleanTerminate execution of the live target for the given tracedefault voidOpen the given trace in the UIdefault booleanpatchEmu(String sleigh, TaskMonitor monitor) Apply the given Sleigh patch to the emulatordefault intreadMemory(Address start, byte[] buffer, TaskMonitor monitor) Read memory from the current trace view into the given buffer, refreshing from target if neededdefault byte[]readMemory(Address start, int length, TaskMonitor monitor) Read memory for the current trace view, refreshing from target if neededdefault intreadMemory(Trace trace, long snap, Address start, byte[] buffer, TaskMonitor monitor) Read memory into the given buffer, refreshing from target if neededdefault byte[]readMemory(Trace trace, long snap, Address start, int length, TaskMonitor monitor) Read memory, refreshing from target if neededdefault RegisterValuereadRegister(Register register) Read a register from the current context, refreshing from the target if neededdefault RegisterValuereadRegister(TracePlatform platform, Register register) Read a register from the current context, refreshing from the target if neededdefault RegisterValuereadRegister(TracePlatform platform, TraceThread thread, int frame, long snap, Register register) Read a registerdefault RegisterValuereadRegister(String name) Read a register from the current context, refreshing from the target if neededdefault List<RegisterValue> readRegisters(TracePlatform platform, TraceThread thread, int frame, long snap, Collection<Register> registers) Read several registers from the given context, refreshing from target if neededdefault List<RegisterValue> readRegisters(Collection<Register> registers) Read several registers from the current context, refreshing from the target if neededdefault List<RegisterValue> readRegistersNamed(Collection<String> names) Read several registers from the current context, refreshing from the target if neededdefault voidrefreshMemoryIfLive(Trace trace, long snap, Address start, int length, TaskMonitor monitor) Copy memory from target to trace, if applicable and not already cacheddefault voidrefreshRegistersIfLive(TracePlatform platform, TraceThread thread, int frame, long snap, Collection<Register> registers) Copy registers from target to trace, if applicable and not already cacheddefault TracePlatformGet the current trace platform, throwing an exception if there isn't onedefault ProgramGet the current program, throwing an exception if there isn't one.default TraceThreadGet the current thread, throwing an exception if there isn't onedefault TraceGet the current trace, throwing an exception if there isn't onedefault TraceProgramViewGet the current trace view, throwing an exception if there isn't onedefault TracePlatformrequirePlatform(TracePlatform platform) Require that the given platform is not nulldefault <T> TrequireService(Class<T> cls) Require a service from the tooldefault TraceThreadrequireThread(TraceThread thread) Require that the given thread is not nulldefault TracerequireTrace(Trace trace) Require that the given trace is not nulldefault booleanresume()Resume execution of the current thread or tracedefault booleanresume(TraceThread thread) Resume execution of the live target for the given trace threaddefault booleanResume execution of the live target for the given tracedefault AddressRangeCreate an address range, avoiding address overflow by truncatingdefault AddresssearchMemory(Trace trace, long snap, AddressRange range, byte[] data, byte[] mask, boolean forward, TaskMonitor monitor) default AddresssearchMemory(Trace trace, long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) Search trace memory for a given masked byte sequencedefault voidsetControlMode(ControlMode mode) Set the control mode of the current tracedefault voidsetControlMode(Trace trace, ControlMode mode) Set the control mode of the given tracedefault booleanskipEmuInstruction(long count, TaskMonitor monitor) Step the current trace count skipped instructions via emulationdefault booleanskipEmuPcodeOp(int count, TaskMonitor monitor) Step the current trace count skipped p-code operations via emulationdefault ProgramLocationstaticLocation(Address address) Create a static location at the given address in the current programdefault ProgramLocationstaticLocation(Program program, Address address) Create a static location at the given address in the current programdefault ProgramLocationstaticLocation(Program program, String addrString) Create a static location at the given address in the current programdefault ProgramLocationstaticLocation(String addrString) Create a static location at the given address in the current programdefault booleanstepEmuInstruction(long count, TaskMonitor monitor) Step the current trace count instructions via emulationdefault booleanstepEmuPcodeOp(int count, TaskMonitor monitor) Step the current trace count p-code operations via emulationdefault booleanstepInto()Step the current thread, stepping into subroutinesdefault booleanstepInto(TraceThread thread) Step the given thread, stepping into subroutinesdefault booleanstepOut()Step the current thread, until it returns from the current subroutinedefault booleanstepOut(TraceThread thread) Step the given thread, until it returns from the current subroutinedefault booleanstepOver()Step the current thread, stepping over subroutinesdefault booleanstepOver(TraceThread thread) Step the given thread, stepping over subroutinesdefault AddresstranslateDynamicToStatic(Address address) Translate the given dynamic address to the corresponding static addressdefault ProgramLocationtranslateDynamicToStatic(ProgramLocation location) Translate the given dynamic location to the corresponding static locationdefault AddresstranslateStaticToDynamic(Address address) Translate the given static address to the corresponding dynamic addressdefault ProgramLocationtranslateStaticToDynamic(ProgramLocation location) Translate the given static location to the corresponding dynamic locationdefault RegistervalidateRegisterName(Language language, String name) Validate and retrieve the name registervalidateRegisterNames(Language language, Collection<String> names) Validate and retrieve the named registersdefault voidwaitForBreak(long timeout, TimeUnit unit) Wait for the current target to breakdefault voidwaitForBreak(Trace trace, long timeout, TimeUnit unit) Wait for the trace's target to breakdefault <T> TwaitOn(CompletableFuture<T> cf) The method used to wait on futures.default booleanwriteMemory(DebuggerControlService.StateEditor editor, Address start, byte[] data) Patch memory using the given editordefault booleanwriteMemory(Address start, byte[] data) Patch memory of the current target, according to the current control modedefault booleanwriteMemory(Trace trace, long snap, Address start, byte[] data) Patch memory of the given target, according to its current control modedefault booleanPatch a register using the given editordefault booleanPatch a register of the current thread, according to the current control modedefault booleanwriteRegister(TraceThread thread, int frame, long snap, RegisterValue rv) Patch a register of the given context, according to its current control modedefault booleanwriteRegister(TraceThread thread, int frame, long snap, String name, BigInteger value) Patch a register of the given context, according to its current control modedefault booleanwriteRegister(String name, BigInteger value) Patch a register of the current thread, according to the current control mode
-
Method Details
-
waitOn
default <T> T waitOn(CompletableFuture<T> cf) throws InterruptedException, ExecutionException, TimeoutException The method used to wait on futures.By default, this waits at most 1 minute.
- Type Parameters:
T- the type of the result- Parameters:
cf- the future- Returns:
- the result
- Throws:
InterruptedException- if execution is interruptedExecutionException- if an error occursTimeoutException- if the future does not complete in time
-
getState
GhidraState getState()Get the script stateThis is required to get various debugger services. It should be implemented by virtue of extending
GhidraScript.- Returns:
- the state
-
requireService
Require a service from the toolIf the service is missing, an exception is thrown directing the user to run the script from the Debugger tool.
- Type Parameters:
T- the type of the service- Parameters:
cls- the class of the service- Returns:
- the service
- Throws:
IllegalStateException- if the service is missing
-
getTraceManager
Get the trace manager service- Returns:
- the service
-
openTrace
Open the given trace in the UI- Parameters:
trace- the trace
-
closeTrace
Close the given trace in the UI- Parameters:
trace- the trace
-
getCurrentDebuggerCoordinates
Get the current "coordinates", i.e., trace, thread, frame, snap, etc., usually for the active target.- Returns:
- the coordinates
-
getCurrentTrace
Get the current trace- Returns:
- the trace, or null
- See Also:
-
requireCurrentTrace
Get the current trace, throwing an exception if there isn't one- Returns:
- the trace
- Throws:
IllegalStateException- if there is no current trace
-
requireTrace
Require that the given trace is not null- Parameters:
trace- the trace- Returns:
- the trace
- Throws:
IllegalStateException- if the trace is null
-
getCurrentPlatform
Get the current trace platform- Returns:
- the trace platform, or null
-
requireCurrentPlatform
Get the current trace platform, throwing an exception if there isn't one- Returns:
- the trace platform
- Throws:
IllegalStateException- if there is no current trace platform
-
requirePlatform
Require that the given platform is not null- Parameters:
platform- the platform- Returns:
- the platform
- Throws:
IllegalStateException- if the platform is null
-
getCurrentThread
Get the current threadWhile uncommon, it is possible for there to be a current trace, but no current thread.
- Returns:
- the thread
- See Also:
-
requireCurrentThread
Get the current thread, throwing an exception if there isn't one- Returns:
- the thread
- Throws:
IllegalStateException- if there is no current thread
-
requireThread
Require that the given thread is not null- Parameters:
thread- the thread- Returns:
- the thread
- Throws:
IllegalStateException- if the thread is null
-
getCurrentView
Get the current trace program viewThe view is an adapter for traces that allows them to be used as a
Program. However, it only works for a chosen snapshot. Typically,TraceProgramView.getSnap()for this view will give the same result asgetCurrentSnap(). The exception is when the UI is displaying emulated (scratch) machine state. In that case,getCurrentSnap()will give the "source" snapshot of the emulated state, andTraceProgramView.getSnap()will give the "destination" scratch snapshot. SeegetCurrentEmulationSchedule().- Returns:
- the view
- See Also:
-
requireCurrentView
Get the current trace view, throwing an exception if there isn't one- Returns:
- the trace view
- Throws:
IllegalStateException- if there is no current trace view
-
getCurrentFrame
default int getCurrentFrame()Get the current frame, 0 being the innermostIf the target doesn't support frames, this will return 0
- Returns:
- the frame
- See Also:
-
getCurrentSnap
default long getCurrentSnap()Get the current snap, i.e., snapshot keySnaps are the trace's notion of time. Positive keys should be monotonic with respect to time: a higher value implies a later point in time. Negative keys do not; they are used as scratch space, usually for displaying emulated machine states. This value defaults to 0, so it is only meaningful if there is a current trace.
- Returns:
- the snap
- See Also:
-
getCurrentEmulationSchedule
Get the current emulation scheduleThis constitutes the current snapshot and an optional schedule of emulation steps. If there is a schedule, then the view's snap will be the destination scratch snap rather than the current snap.
- Returns:
- the emulation schedule
-
activateTrace
Make the given trace the active traceIf the trace is not already open in the tool, it will be opened automatically
- Parameters:
trace- the trace
-
activateThread
Make the given thread the active threadif the trace is not already open in the tool, it will be opened automatically
- Parameters:
thread- the thread
-
activateFrame
default void activateFrame(int frame) Make the given frame the active frame- Parameters:
frame- the frame level, 0 being the innermost
-
activateSnap
default void activateSnap(long snap) Make the given snapshot the active snapshotActivating negative snapshot keys is not recommended. The trace manager uses negative keys for emulation scratch space and will activate them indirectly as needed.
- Parameters:
snap- the snapshot key
-
getDebuggerListing
Get the dynamic listing service- Returns:
- the service
-
getCurrentDebuggerProgramLocation
Get the current trace program view and addressThis constitutes a portion of the debugger coordinates plus the current dynamic address. The program given by
ProgramLocation.getProgram()can be safely cast toTraceProgramView, which should give the same result asgetCurrentView().- Returns:
- the location
-
getCurrentDebuggerAddress
Get the current dynamic address- Returns:
- the dynamic address
-
goToDynamic
Go to the given dynamic location in the dynamic listingTo "go to" a point in time, use
activateSnap(long)oremulate(Trace, TraceSchedule, TaskMonitor).- Parameters:
location- the location, e.g., fromdynamicLocation(String)- Returns:
- true if successful, false otherwise
-
goToDynamic
Go to the given dynamic address in the dynamic listing- Parameters:
address- the destination address- Returns:
- true if successful, false otherwise
- See Also:
-
goToDynamic
Go to the given dynamic address in the dynamic listing- Parameters:
addrString- the destination address, as a string- Returns:
- true if successful, false otherwise
- See Also:
-
getMappingService
Get the static mapping service- Returns:
- the service
-
getCurrentProgram
Get the current programThis is implemented by virtue of extending
FlatProgramAPI, which is inherited viaGhidraScript.- Returns:
- the current program
-
requireCurrentProgram
Get the current program, throwing an exception if there isn't one.- Returns:
- the current program
- Throws:
IllegalStateException- if there is no current program
-
translateStaticToDynamic
Translate the given static location to the corresponding dynamic locationThis uses the trace's static mappings (see
Trace.getStaticMappingManager()andDebuggerStaticMappingService) to translate a static location to the corresponding dynamic location in the current trace. If there is no current trace or the location cannot be translated to the current trace, the result is null. This accommodates link-load-time relocation, particularly from address-space layout randomization (ASLR).- Parameters:
location- the static location, e.g., fromstaticLocation(String)- Returns:
- the dynamic location, or null if not translated
-
translateStaticToDynamic
Translate the given static address to the corresponding dynamic addressThis does the same as
translateStaticToDynamic(ProgramLocation), but assumes the address is for the current program. The returned address is for the current trace view.- Parameters:
address- the static address- Returns:
- the dynamic address, or null if not translated
-
translateDynamicToStatic
Translate the given dynamic location to the corresponding static locationThis does the opposite of
translateStaticToDynamic(ProgramLocation). The resulting static location could be for any open program, not just the current one, since a target may load several images. For example, a single user-space process typically has several modules: the executable image and several libraries.- Parameters:
location- the dynamic location, e.g., fromdynamicLocation(String)- Returns:
- the static location, or null if not translated
-
translateDynamicToStatic
Translate the given dynamic address to the corresponding static addressThis does the same as
translateDynamicToStatic(ProgramLocation), but assumes the address is for the current trace view. The returned address is for the current program. If there is not current view or program, or if the address cannot be translated to the current program, null is returned.- Parameters:
address- the dynamic address- Returns:
- the static address
-
getEmulationService
Get the emulation service- Returns:
- the service
-
emulateLaunch
Load the given program into a trace suitable for emulation in the UI, starting at the given addressNote that the program bytes are not actually loaded into the trace. Rather a static mapping is generated, allowing the emulator to load bytes from the target program lazily. The trace is automatically loaded into the UI (trace manager).
- Parameters:
program- the target programaddress- the initial program counter- Returns:
- the resulting trace
- Throws:
IOException- if the trace cannot be created
-
emulateLaunch
Does the same asemulateLaunch(Program, Address), for the current program- Parameters:
address- the initial program counter- Returns:
- the resulting trace
- Throws:
IOException- if the trace cannot be created
-
emulate
default boolean emulate(TracePlatform platform, TraceSchedule time, TaskMonitor monitor) throws CancelledException Emulate the given trace platform as specified in the given schedule and display the result in the UI- Parameters:
platform- the trace platformtime- the schedule of stepsmonitor- a monitor for the emulation- Returns:
- true if successful
- Throws:
CancelledException- if the user cancelled via the given monitor
-
emulate
default boolean emulate(Trace trace, TraceSchedule time, TaskMonitor monitor) throws CancelledException Emulate the given trace as specified in the given schedule and display the result in the UI- Parameters:
trace- the tracetime- the schedule of stepsmonitor- a monitor for the emulation- Returns:
- true if successful
- Throws:
CancelledException- if the user cancelled via the given monitor
-
emulate
Emulate the current trace as specified and display the result- Parameters:
time- the schedule of stepsmonitor- the monitor for the emulation- Returns:
- true if successful
- Throws:
CancelledException- if the user cancelled via the given monitorIllegalStateException- if there is no current trace
-
stepEmuInstruction
Step the current trace count instructions via emulation- Parameters:
count- the number of instructions to step, negative to step in reversemonitor- a monitor for the emulation- Returns:
- true if successful, false otherwise
- Throws:
CancelledException- if the user cancelled via the given monitorIllegalStateException- if there is no current trace or thread
-
stepEmuPcodeOp
Step the current trace count p-code operations via emulation- Parameters:
count- the number of operations to step, negative to step in reversemonitor- a monitor for the emulation- Returns:
- true if successful, false otherwise
- Throws:
CancelledException- if the user cancelled via the given monitor
-
skipEmuInstruction
Step the current trace count skipped instructions via emulationNote there's no such thing as "skipping in reverse." If a negative count is given, this will behave the same as
stepEmuInstruction(long, TaskMonitor).- Parameters:
count- the number of instructions to skip, negative to step in reversemonitor- a monitor for the emulation- Returns:
- true if successful, false otherwise
- Throws:
CancelledException- if the user cancelled via the given monitor
-
skipEmuPcodeOp
Step the current trace count skipped p-code operations via emulationNote there's no such thing as "skipping in reverse." If a negative count is given, this will behave the same as
stepEmuPcodeOp(int, TaskMonitor).- Parameters:
count- the number of operations to skip, negative to step in reversemonitor- a monitor for the emulation- Returns:
- true if successful, false otherwise
- Throws:
CancelledException- if the user cancelled via the given monitor
-
patchEmu
Apply the given Sleigh patch to the emulator- Parameters:
sleigh- the Sleigh source, without terminating semicolonmonitor- a monitor for the emulation- Returns:
- true if successful, false otherwise
- Throws:
CancelledException- if the user cancelled via the given monitor
-
safeRange
Create an address range, avoiding address overflow by truncatingIf the length would cause address overflow, it is adjusted such that the range's maximum address is the space's maximum address.
- Parameters:
start- the minimum addresslength- the desired length- Returns:
- the range
-
getTargetService
The target service- Returns:
- the service
-
refreshMemoryIfLive
default void refreshMemoryIfLive(Trace trace, long snap, Address start, int length, TaskMonitor monitor) throws CancelledException Copy memory from target to trace, if applicable and not already cached- Parameters:
trace- the trace to updatesnap- the snap the snap, to determine whether target bytes are applicablestart- the starting addresslength- the number of bytes to make freshmonitor- a monitor for progress- Throws:
CancelledException- if the operation was cancelled
-
readMemory
default int readMemory(Trace trace, long snap, Address start, byte[] buffer, TaskMonitor monitor) throws CancelledException Read memory into the given buffer, refreshing from target if needed- Parameters:
trace- the source tracesnap- the source snapstart- the source starting addressbuffer- the destination buffermonitor- a monitor for live read progress- Returns:
- the number of bytes read
- Throws:
CancelledException- if the operation was cancelled
-
readMemory
default byte[] readMemory(Trace trace, long snap, Address start, int length, TaskMonitor monitor) throws CancelledException Read memory, refreshing from target if needed- Parameters:
trace- the source tracesnap- the source snapstart- the source starting addresslength- the desired number of bytesmonitor- a monitor for live read progress- Returns:
- the array of bytes read, can be shorter than desired
- Throws:
CancelledException- if the operation was cancelled
-
readMemory
Read memory from the current trace view into the given buffer, refreshing from target if needed- Parameters:
start- the starting addressbuffer- the destination buffermonitor- a monitor for live read progress- Returns:
- the number of bytes read
- Throws:
CancelledException- if the operation was cancelled
-
readMemory
Read memory for the current trace view, refreshing from target if needed- Parameters:
start- the starting addresslength- the desired number of bytesmonitor- a monitor for live read progress- Returns:
- the array of bytes read, can be shorter than desired
- Throws:
CancelledException- if the operation was cancelled
-
searchMemory
default Address searchMemory(Trace trace, long snap, AddressRange range, ByteBuffer data, ByteBuffer mask, boolean forward, TaskMonitor monitor) Search trace memory for a given masked byte sequenceNOTE: This searches the trace only. It will not interrogate the live target. There are two mechanisms for searching a live target's full memory: 1) Capture the full memory (or the subset to search) -- using, e.g.,
refreshMemoryIfLive(Trace, long, Address, int, TaskMonitor)-- then search the trace. 2) If possible, invoke the target debugger's search functions -- using, e.g.,executeCapture(String).This delegates to
TraceMemoryOperations.findBytes(long, AddressRange, ByteBuffer, ByteBuffer, boolean, TaskMonitor). It culls out ranges that have never been recorded, effectively excluding default00s. This can only search a single snapshot per invocation, but it does include stale bytes, i.e., those from a previous snapshot without a more up-to-date record. In particular, a stale00is matched as usual, as is any stale byte. Only those ranges which have never been recorded are culled. While not required, memory is conventionally read and recorded in pages, so culling tends to occur at page boundaries.Be wary of leading or trailing wildcards, i.e., masked-out bytes. The full data array must fit within the given range after culling. For example, suppose the byte
12is recorded atram:00400000. The full page is recorded, but the preceding page has never been recorded. Thus, the byte atram:003fffffis a default00. Searching for the pattern?? 12in the rangeram:00400000:00400fffwill not find the match. This much is intuitive, because the match starts atram:003fffff, which is outside the specified range. However, this rule also affects trailing wildcards. Furthermore, because the preceding page was never recorded, even if the specified range wereram:003ff000:00400fff, the range would be culled, and the match would still be excluded. Nothing -- not even a wildcard -- can match a default00.- Parameters:
trace- the trace to searchsnap- the snapshot of the trace to searchrange- the range within to searchdata- the bytes to search formask- a mask on the bits to search, or null to match exactly.forward- true to start at the min address going forward, false to start at the max address going backwardmonitor- a monitor for search progress- Returns:
- the minimum address of the matched bytes, or null if not found
-
searchMemory
default Address searchMemory(Trace trace, long snap, AddressRange range, byte[] data, byte[] mask, boolean forward, TaskMonitor monitor) - Parameters:
trace- the trace to searchsnap- the snapshot of the trace to searchrange- the range within to searchdata- the bytes to search formask- a mask on the bits to search, or null to match exactly.forward- true to start at the min address going forward, false to start at the max address going backwardmonitor- a monitor for search progress- Returns:
- the minimum address of the matched bytes, or null if not found
- See Also:
-
refreshRegistersIfLive
default void refreshRegistersIfLive(TracePlatform platform, TraceThread thread, int frame, long snap, Collection<Register> registers) Copy registers from target to trace, if applicable and not already cached- Parameters:
platform- the platform whose language defines the registersthread- the trace thread to updateframe- the frame level, 0 being the innermostsnap- the snap, to determine whether target values are applicableregisters- the registers to make fresh
-
readRegisters
default List<RegisterValue> readRegisters(TracePlatform platform, TraceThread thread, int frame, long snap, Collection<Register> registers) Read several registers from the given context, refreshing from target if needed- Parameters:
platform- the platform whose language defines the registersthread- the trace threadframe- the source frame level, 0 being the innermostsnap- the source snapregisters- the source registers- Returns:
- the list of register values, or null on error
-
readRegister
default RegisterValue readRegister(TracePlatform platform, TraceThread thread, int frame, long snap, Register register) Read a register- Parameters:
platform- the platform whose language defines the registersthread- the trace threadframe- the source frame level, 0 being the innermostsnap- the source snapregister- the source register- Returns:
- the register's value, or null on error
- See Also:
-
readRegisters
Read several registers from the current context, refreshing from the target if needed- Parameters:
registers- the source registers- Returns:
- the list of register values, or null on error
- See Also:
-
validateRegisterNames
Validate and retrieve the named registers- Parameters:
language- the language defining the registersnames- the names- Returns:
- the registers, in the same order
- Throws:
IllegalArgumentException- if any name is invalid
-
validateRegisterName
Validate and retrieve the name register- Parameters:
language- the language defining the registername- the name- Returns:
- the register
- Throws:
IllegalArgumentException- if the name is invalid
-
readRegistersNamed
Read several registers from the current context, refreshing from the target if needed- Parameters:
names- the source register names- Returns:
- the list of register values, or null on error
- Throws:
IllegalArgumentException- if any name is invalid- See Also:
-
readRegister
Read a register from the current context, refreshing from the target if needed- Parameters:
platform- the platform whose language defines the registerregister- the register- Returns:
- the value, or null on error
-
readRegister
Read a register from the current context, refreshing from the target if needed- Parameters:
register- the register- Returns:
- the value, or null on error
-
readRegister
Read a register from the current context, refreshing from the target if needed- Parameters:
name- the register name- Returns:
- the value, or null on error
- Throws:
IllegalArgumentException- if the name is invalid- See Also:
-
evaluate
Evaluate a Sleigh expression in the given context- Parameters:
coordinates- the contextexpression- the Sleigh expression- Returns:
- the value
-
evaluate
Evaluate a Sleigh expression in the current context- Parameters:
expression- the Sleigh expression- Returns:
- the value
-
getProgramCounter
Get the program counter for the given context- Parameters:
coordinates- the context- Returns:
- the program counter, or null if not known
-
getProgramCounter
Get the program counter for the current context- Returns:
- the program counter, or null if not known
-
getStackPointer
Get the stack pointer for the given context- Parameters:
coordinates- the context- Returns:
- the stack pointer, or null if not known
-
getStackPointer
Get the stack pointer for the current context- Returns:
- the stack pointer, or null if not known
-
getControlService
Get the control service- Returns:
- the service
-
setControlMode
Set the control mode of the given trace- Parameters:
trace- the tracemode- the mode
-
setControlMode
Set the control mode of the current trace- Parameters:
mode- the mode
-
createStateEditor
Create a state editor for the given context, adhering to its current control mode- Parameters:
coordinates- the context- Returns:
- the editor
-
createStateEditor
Create a state editor suitable for memory edits for the given context- Parameters:
trace- the tracesnap- the snap- Returns:
- the editor
-
createStateEditor
default DebuggerControlService.StateEditor createStateEditor(TraceThread thread, int frame, long snap) Create a state editor suitable for register or memory edits for the given context- Parameters:
thread- the threadframe- the framesnap- the snap- Returns:
- the editor
-
createStateEditor
Create a state editor for the current context, adhering to the current control mode- Returns:
- the editor
-
writeMemory
Patch memory using the given editorThe success or failure of this method depends on a few factors. First is the user-selected control mode for the trace. See
setControlMode(ControlMode). In read-only mode, this will always fail. When editing traces, a write almost always succeeds. Exceptions would probably indicate I/O errors. When editing via emulation, a write should almost always succeed. Second, when editing the target, the state of the target matters. If the trace has no target, this will always fail. If the target is not accepting commands, e.g., because the target or debugger is busy, this may fail or be delayed. If the target doesn't support editing the given space, this will fail. Some debuggers may also deny modification due to permissions.- Parameters:
editor- the editorstart- the starting addressdata- the bytes to write- Returns:
- true if successful, false otherwise
-
writeMemory
Patch memory of the given target, according to its current control modeIf you intend to apply several patches, consider using
createStateEditor(Trace,long)andwriteMemory(StateEditor, Address, byte[])- Parameters:
trace- the tracesnap- the snapshotstart- the starting addressdata- the bytes to write- Returns:
- true if successful, false otherwise
-
writeMemory
Patch memory of the current target, according to the current control modeIf you intend to apply several patches, consider using
createStateEditor()andwriteMemory(StateEditor, Address, byte[])- Parameters:
start- the starting addressdata- the bytes to write- Returns:
- true if successful, false otherwise
-
writeRegister
Patch a register using the given editorThe success or failure of this methods depends on a few factors. First is the user-selected control mode for the trace. See
setControlMode(ControlMode). In read-only mode, this will always fail. When editing traces, a write almost always succeeds. Exceptions would probably indicate I/O errors. When editing via emulation, a write should only fail if the register is not accessible to Sleigh, e.g., the context register. Second, when editing the target, the state of the target matters. If the trace has no target, this will always fail. If the target is not accepting commands, e.g., because the target or debugger is busy, this may fail or be delayed. If the target doesn't support editing the given register, this will fail.- Parameters:
editor- the editorrv- the register value- Returns:
- true if successful, false otherwise
-
writeRegister
Patch a register of the given context, according to its current control modeIf you intend to apply several patches, consider using
createStateEditor(TraceThread,int,long)andwriteRegister(StateEditor, RegisterValue).- Parameters:
thread- the threadframe- the framesnap- the snaprv- the register value- Returns:
- true if successful, false otherwise
-
writeRegister
default boolean writeRegister(TraceThread thread, int frame, long snap, String name, BigInteger value) Patch a register of the given context, according to its current control mode- Parameters:
thread- the threadframe- the framesnap- the snapname- the register namevalue- the value- Returns:
- true if successful, false otherwise
- Throws:
IllegalArgumentException- if the register name is invalid- See Also:
-
writeRegister
Patch a register of the current thread, according to the current control modeIf you intend to apply several patches, consider using
createStateEditor()andwriteRegister(StateEditor, RegisterValue).- Parameters:
rv- the register value- Returns:
- true if successful, false otherwise
-
writeRegister
Patch a register of the current thread, according to the current control mode- Parameters:
name- the register namevalue- the value- Returns:
- true if successful, false otherwise
- Throws:
IllegalArgumentException- if the register name is invalid- See Also:
-
createContext
-
createContext
-
createContext
-
findAction
-
doAction
-
doThreadAction
-
doTraceAction
-
stepInto
Step the given thread, stepping into subroutines- Parameters:
thread- the thread to step- Returns:
- true if successful, false otherwise
-
stepInto
default boolean stepInto()Step the current thread, stepping into subroutines- Returns:
- true if successful, false otherwise
-
stepOver
Step the given thread, stepping over subroutines- Parameters:
thread- the thread to step- Returns:
- true if successful, false otherwise
-
stepOver
default boolean stepOver()Step the current thread, stepping over subroutines- Returns:
- true if successful, false otherwise
-
stepOut
Step the given thread, until it returns from the current subroutine- Parameters:
thread- the thread to step- Returns:
- true if successful, false otherwise
-
stepOut
default boolean stepOut()Step the current thread, until it returns from the current subroutine- Returns:
- true if successful, false otherwise
-
resume
Resume execution of the live target for the given trace threadThis is commonly called "continue" or "go," as well.
- Parameters:
thread- the thread- Returns:
- true if successful, false otherwise
-
resume
Resume execution of the live target for the given traceThis is commonly called "continue" or "go," as well.
- Parameters:
trace- the trace- Returns:
- true if successful, false otherwise
-
resume
default boolean resume()Resume execution of the current thread or trace- Returns:
- true if successful, false otherwise
-
interrupt
Interrupt execution of the live target for the given trace threadThis is commonly called "pause" or "break," as well, but not "stop."
- Parameters:
thread- the thread to interrupt (may interrupt the whole target)- Returns:
- true if successful, false otherwise
-
interrupt
Interrupt execution of the live target for the given traceThis is commonly called "pause" or "break," as well, but not "stop."
- Parameters:
trace- the trace whose target to interrupt- Returns:
- true if successful, false otherwise
-
interrupt
default boolean interrupt()Interrupt execution of the current thread or trace- Returns:
- true if successful, false otherwise
-
kill
Terminate execution of the live target for the given trace threadThis is commonly called "stop" as well.
- Parameters:
thread- the thread to kill (may kill the whole target)- Returns:
- true if successful, false otherwise
-
kill
Terminate execution of the live target for the given traceThis is commonly called "stop" as well.
- Parameters:
trace- the trace whose target to kill- Returns:
- true if successful, false otherwise
-
kill
default boolean kill()Terminate execution of the current thread or trace- Returns:
- true if successful, false otherwise
-
getExecutionState
Get the current state of the given traceIf the trace does not have a live target, it is considered
TraceExecutionState.TERMINATED(even if the trace never technically had a live target.) Otherwise, this gets the state of that live target. NOTE: This does not consider the current snap. It only considers a live target in the present.- Parameters:
trace- the trace- Returns:
- the trace's execution state
-
getExecutionState
Get the current state of the given threadIf the thread does not have a corresponding live target thread, it is considered
TraceExecutionState.TERMINATED(even if the thread never technically had a live target thread.) Otherwise, this gets the state of that live target thread. NOTE: This does not consider the current snap. It only considers a live target thread in the present. In other words, if the user rewinds trace history to a point where the thread was alive, this method still considers that thread terminated. To compute state with respect to trace history, useTraceThread.isValid(long).- Parameters:
thread-- Returns:
- the thread's execution state
-
isTargetAlive
Check if the given trace's target is alive- Parameters:
trace- the trace- Returns:
- true if alive
-
isTargetAlive
default boolean isTargetAlive()Check if the current target is aliveNOTE: To be "current," the target must be recorded, and its trace must be the current trace.
- Returns:
- true if alive
-
isThreadAlive
Check if the given trace thread's target is alive- Parameters:
thread- the thread- Returns:
- true if alive
-
isThreadAlive
default boolean isThreadAlive()Check if the current target thread is aliveNOTE: To be the "current" target thread, the target must be recorded, and its trace thread must be the current thread.
- Returns:
- true if alive
-
waitForBreak
Wait for the trace's target to breakIf the trace has no target, this method returns immediately, i.e., it assumes the target has terminated.
- Parameters:
trace- the tracetimeout- the maximum amount of time to waitunit- the units for time- Throws:
TimeoutException- if the timeout expires
-
waitForBreak
Wait for the current target to break- Parameters:
timeout- the maximumunit- the units for time- Throws:
TimeoutException- if the timeout expiresIllegalStateException- if there is no current trace- See Also:
-
executeCapture
Execute a command on the live debugger for the given trace, capturing the output- Parameters:
trace- the tracecommand- the command- Returns:
- the output, or null if there is no live interpreter
-
executeCapture
Execute a command on the live debugger for the current trace, capturing the output- Parameters:
command- the command- Returns:
- the output, or null if there is no live interpreter
- Throws:
IllegalStateException- if there is no current trace
-
execute
Execute a command on the live debugger for the given trace- Parameters:
trace- the tracecommand- the command- Returns:
- true if successful
-
execute
Execute a command on the live debugger for the current trace- Parameters:
command- the command- Returns:
- true if successful
- Throws:
IllegalStateException- if there is no current trace
-
getBreakpointService
Get the breakpoint service- Returns:
- the service
-
staticLocation
Create a static location at the given address in the current program- Parameters:
program- the (static) programaddress- the address- Returns:
- the location
-
staticLocation
Create a static location at the given address in the current program- Parameters:
program- the (static) programaddrString- the address string- Returns:
- the location
-
staticLocation
Create a static location at the given address in the current program- Parameters:
address- the address- Returns:
- the location
-
staticLocation
Create a static location at the given address in the current program- Parameters:
addrString- the address string- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the given view- Parameters:
view- the (dynamic) trace viewaddress- the address- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the given view- Parameters:
view- the (dynamic) trace viewaddrString- the address string- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the current trace and snap- Parameters:
address- the address- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the current trace and snap- Parameters:
addrString- the address string- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the given trace's primary view- Parameters:
trace- the traceaddress- the address- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the given trace's primary view- Parameters:
trace- the traceaddrString- the address string- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the given trace at the given snap- Parameters:
trace- the tracesnap- the snapaddress- the address- Returns:
- the location
-
dynamicLocation
Create a dynamic location at the given address in the given trace at the given snap- Parameters:
trace- the tracesnap- the snapaddrString- the address string- Returns:
- the location
-
getAllBreakpoints
Get all the breakpointsThis returns all logical breakpoints among all open programs and traces (targets)
- Returns:
- the breakpoints
-
getBreakpoints
Get the breakpoints in the given program, indexed by address- Parameters:
program- the program- Returns:
- the address-breakpoint-set map
-
getBreakpoints
Get the breakpoints in the given trace, indexed by (dynamic) address- Parameters:
trace- the trace- Returns:
- the address-breakpoint-set map
-
getBreakpointsAt
Get the breakpoints at a given location- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).- Returns:
- the (possibly empty) set of breakpoints at that location
-
getBreakpointsNamed
Get the breakpoints having the given name (from any open program or trace)- Parameters:
name- the name- Returns:
- the breakpoints
-
expectBreakpointChanges
Perform some operations expected to cause changes, and then wait for those changes to settleUse this via a try-with-resources block containing the operations causing changes.
- Returns:
- a closable object for a try-with-resources block
-
breakpointsToggle
Toggle the breakpoints at a given location- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).- Returns:
- the (possibly empty) set of breakpoints at that location, or null if failed
-
breakpointSet
default Set<LogicalBreakpoint> breakpointSet(ProgramLocation location, long length, TraceBreakpointKind.TraceBreakpointKindSet kinds, String name) Set a breakpoint at the given locationNOTE: Many asynchronous events take place when creating a breakpoint, esp., among several live targets. Furthermore, some targets may adjust the breakpoint specification just slightly. This method does its best to identify the resulting breakpoint(s) once things have settled. Namely, it retrieves breakpoints at the specific location having the specified name and assumes those are the result. It is possible this command succeeds, but this method fails to identify the result. In that case, the returned result will be the empty set.
- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).length- the length, for "access breakpoints" or "watchpoints"kinds- the kinds, not all combinations are reasonablename- a user-defined name- Returns:
- the resulting breakpoint(s), or null if failed
-
breakpointSetSoftwareExecute
Set a software breakpoint at the given location- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).name- a user-defined name- Returns:
- true if successful
-
breakpointSetHardwareExecute
Set a hardware breakpoint at the given location- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).name- a user-defined name- Returns:
- true if successful
-
breakpointSetRead
Set a read breakpoint at the given locationThis might also be called a "read watchpoint" or a "read access breakpoint."
- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).length- the lengthname- a user-defined name- Returns:
- true if successful
-
breakpointSetWrite
default Set<LogicalBreakpoint> breakpointSetWrite(ProgramLocation location, int length, String name) Set a write breakpoint at the given locationThis might also be called a "write watchpoint" or a "write access breakpoint."
- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).length- the lengthname- a user-defined name- Returns:
- true if successful
-
breakpointSetAccess
default Set<LogicalBreakpoint> breakpointSetAccess(ProgramLocation location, int length, String name) Set an access breakpoint at the given locationThis might also be called a "watchpoint."
- Parameters:
location- the location, e.g., fromstaticLocation(String)anddynamicLocation(String).length- the lengthname- a user-defined name- Returns:
- true if successful
-
getTrace
If the location is dynamic, get its trace- Parameters:
location- the location- Returns:
- the trace, or null if a static location
-
breakpointsEnable
Enable the breakpoints at a given location- Parameters:
location- the location, can be static or dynamic- Returns:
- the (possibly empty) set of breakpoints at that location, or null if failed
-
breakpointsDisable
Disable the breakpoints at a given location- Parameters:
location- the location, can be static or dynamic- Returns:
- the (possibly empty) set of breakpoints at that location, or null if failed
-
breakpointsClear
Clear the breakpoints at a given location- Parameters:
location- the location, can be static or dynamic- Returns:
- true if successful, false otherwise
-
flushAsyncPipelines
Flush each stage of the asynchronous processing pipelines from end to endThis method includes as many components as its author knows to flush. It flushes the trace's event queue. Then, it waits for various services' changes to settle, in dependency order. Currently, that is the static mapping service followed by the logical breakpoint service. Note that some stages use timeouts. It's also possible the target had not generated all the expected events by the time this method began flushing its queue. Thus, callers should still check that some expected condition is met and possibly repeat the flush before proceeding.
There are additional dependents in the GUI; however, scripts should not depend on them, so we do not wait on them.
- Parameters:
trace- the trace whose events need to be completely processed before continuing.- Returns:
- true if all stages were flushed, false if there were errors
-