Interface DebuggerEmulationService
Managed emulators are employed by the UI and trace manager to perform emulation requested by the user. Scripts may interact with these managed emulators, or they may instantiate their own unmanaged emulators, without using this service.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordAn emulator managed by this servicestatic interfacestatic interfaceA listener for changes in emulator statestatic final recordThe result of letting the emulator "run free" -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a listener for emulator state changesbackgroundEmulate(TracePlatform platform, TraceSchedule time) Invokeemulate(Trace, TraceSchedule, TaskMonitor)in the backgroundbackgroundRun(TracePlatform platform, TraceSchedule from, Scheduler scheduler) Invokerun(TracePlatform, TraceSchedule, TaskMonitor, Scheduler)in the backgroundlongemulate(TracePlatform platform, TraceSchedule time, TaskMonitor monitor) Perform emulation to realize the machine state of the given time coordinatesdefault longemulate(Trace trace, TraceSchedule time, TaskMonitor monitor) Emulate using the trace's "host" platformGet the emulators which are current executingPcodeMachine<?> getCachedEmulator(Trace trace, TraceSchedule time) Get the cached emulator for the given trace and timeGet the available emulator factoriesGet the current emulator factoryvoidInvalidate the trace's cache of emulated states.launchProgram(Program program, Address address) Load the given program into a trace suitable for emulation in the UI, starting at the given addressvoidRemove a listener for emulator state changesrun(TracePlatform platform, TraceSchedule from, TaskMonitor monitor, Scheduler scheduler) Allow the emulator to "run free" until it is interrupted or encounters an errorvoidsetEmulatorFactory(EmulatorFactory factory) Set the current emulator factory
-
Method Details
-
getEmulatorFactories
Collection<EmulatorFactory> getEmulatorFactories()Get the available emulator factories- Returns:
- the collection of factories
-
setEmulatorFactory
Set the current emulator factoryTODO: Should this be set on a per-program, per-trace basis? Need to decide what is saved to the tool and what is saved to the program/trace. My inclination is to save current factory to the tool, but the config options for each factory to the program/trace.
TODO: Should there be some opinion service for choosing default configs? Seems overly complicated for what it offers. For now, we won't save anything, we'll default to the (built-in) concrete emulator, and we won't have configuration options.
- Parameters:
factory- the chosen factory
-
getEmulatorFactory
EmulatorFactory getEmulatorFactory()Get the current emulator factory- Returns:
- the factory
-
launchProgram
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
-
emulate
long emulate(TracePlatform platform, TraceSchedule time, TaskMonitor monitor) throws CancelledException Perform emulation to realize the machine state of the given time coordinatesOnly those address ranges actually modified during emulation are written into the scratch space. It is the responsibility of anyone reading from scratch space to retrieve state and/or annotations from the initial snap, when needed. The scratch snapshot is given the description "
emu:[time]", where[time]is the given time parameter as a string.The service may use a cached emulator in order to realize the requested machine state. This is especially important to ensure that a user stepping forward does not incur ever increasing costs. On the other hand, the service should be careful to invalidate cached results when the recorded machine state in a trace changes.
- Parameters:
platform- the trace platform containing the initial statetime- the time coordinates, including initial snap, steps, and p-code stepsmonitor- a monitor for cancellation and progress reporting- Returns:
- the snap in the trace's scratch space where the realized state is stored
- Throws:
CancelledException- if the emulation is cancelled
-
emulate
default long emulate(Trace trace, TraceSchedule time, TaskMonitor monitor) throws CancelledException Emulate using the trace's "host" platform- Parameters:
trace- the trace containing the initial statetime- the time coordinates, including initial snap, steps, and p-code stepsmonitor- a monitor for cancellation and progress reporting- Returns:
- the snap in the trace's scratch space where the realize state is stored
- Throws:
CancelledException- if the emulation is cancelled- See Also:
-
run
DebuggerEmulationService.EmulationResult run(TracePlatform platform, TraceSchedule from, TaskMonitor monitor, Scheduler scheduler) throws CancelledException Allow the emulator to "run free" until it is interrupted or encounters an errorThe service may perform some preliminary emulation to realize the machine's initial state. If the monitor cancels during preliminary emulation, this method throws a
CancelledException. If the monitor cancels the emulation during the run, it is treated the same as interruption. The machine state will be written to the trace in a scratch snap and the result returned. Note that the machine could be interrupted having only partially executed an instruction. Thus, the schedule may specify p-code operations. The schedule will place the program counter on the instruction (or p-code op) causing the interruption. Thus, except for breakpoints, attempting to step again will interrupt the emulator again.- Parameters:
platform- the trace platform containing the initial statefrom- a schedule for the machine's initial statemonitor- a monitor cancellationscheduler- a thread scheduler for the emulator- Returns:
- the result of emulation
- Throws:
CancelledException- if the user cancels the task
-
backgroundEmulate
Invokeemulate(Trace, TraceSchedule, TaskMonitor)in the backgroundThis is the preferred means of performing definite emulation. Because the underlying emulator may request a blocking read from a target, it is important that
emulateis never called by the Swing thread.- Parameters:
platform- the trace platform containing the initial statetime- the time coordinates, including initial snap, steps, and p-code steps- Returns:
- a future which completes with the result of
emulate
-
backgroundRun
CompletableFuture<DebuggerEmulationService.EmulationResult> backgroundRun(TracePlatform platform, TraceSchedule from, Scheduler scheduler) Invokerun(TracePlatform, TraceSchedule, TaskMonitor, Scheduler)in the backgroundThis is the preferred means of performing indefinite emulation, for the same reasons as
emulate.- Parameters:
platform- the trace platform containing the initial statefrom- a schedule for the machine's initial statescheduler- a thread scheduler for the emulator- Returns:
- a future which completes with the result of
run.
-
getCachedEmulator
Get the cached emulator for the given trace and timeTo guarantee the emulator is present, call
backgroundEmulate(TracePlatform, TraceSchedule)first.WARNING: This emulator belongs to this service. Stepping it, or otherwise manipulating it without the service's knowledge can lead to unintended consequences.
TODO: Should cache by (Platform, Time) instead, but need a way to distinguish platform in the trace's time table.
- Parameters:
trace- the trace containing the initial statetime- the time coordinates, including initial snap, steps, and p-code steps- Returns:
- the copied p-code frame
-
getBusyEmulators
Collection<DebuggerEmulationService.CachedEmulator> getBusyEmulators()Get the emulators which are current executing- Returns:
- the collection
-
invalidateCache
void invalidateCache()Invalidate the trace's cache of emulated states. -
addStateListener
Add a listener for emulator state changes- Parameters:
listener- the listener
-
removeStateListener
Remove a listener for emulator state changes- Parameters:
listener- the listener
-