GP-5879: Add callbacks to PcodeEmulator. Refactor for composition vice inheritance.

This commit is contained in:
Dan 2025-07-30 16:45:40 +00:00
parent c0127326f8
commit 72001639a8
162 changed files with 5298 additions and 5887 deletions

View file

@ -19,9 +19,10 @@ import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import ghidra.debug.api.emulation.DebuggerPcodeEmulatorFactory;
import ghidra.debug.api.emulation.DebuggerPcodeMachine;
import ghidra.debug.api.emulation.EmulatorFactory;
import ghidra.framework.plugintool.ServiceInfo;
import ghidra.pcode.emu.PcodeMachine;
import ghidra.pcode.exec.trace.TraceEmulationIntegration.Writer;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.trace.model.Trace;
@ -68,11 +69,12 @@ public interface DebuggerEmulationService {
*
* @param trace the trace the emulator is bound to
* @param emulator the emulator itself
* @param writer the callbacks with delayed writes for trace/UI integration
* @param version the cache version. See {@link #isValid()}.
*/
record CachedEmulator(Trace trace, DebuggerPcodeMachine<?> emulator, long version) {
public CachedEmulator(Trace trace, DebuggerPcodeMachine<?> emulator) {
this(trace, emulator, trace.getEmulatorCacheVersion());
record CachedEmulator(Trace trace, PcodeMachine<?> emulator, Writer writer, long version) {
public CachedEmulator(Trace trace, PcodeMachine<?> emulator, Writer writer) {
this(trace, emulator, writer, trace.getEmulatorCacheVersion());
}
/**
@ -96,7 +98,7 @@ public interface DebuggerEmulationService {
* @return the emulator
*/
@Override
public DebuggerPcodeMachine<?> emulator() {
public PcodeMachine<?> emulator() {
return emulator;
}
@ -136,7 +138,7 @@ public interface DebuggerEmulationService {
*
* @return the collection of factories
*/
Collection<DebuggerPcodeEmulatorFactory> getEmulatorFactories();
Collection<EmulatorFactory> getEmulatorFactories();
/**
* Set the current emulator factory
@ -153,14 +155,14 @@ public interface DebuggerEmulationService {
*
* @param factory the chosen factory
*/
void setEmulatorFactory(DebuggerPcodeEmulatorFactory factory);
void setEmulatorFactory(EmulatorFactory factory);
/**
* Get the current emulator factory
*
* @return the factory
*/
DebuggerPcodeEmulatorFactory getEmulatorFactory();
EmulatorFactory getEmulatorFactory();
/**
* Load the given program into a trace suitable for emulation in the UI, starting at the given
@ -290,7 +292,7 @@ public interface DebuggerEmulationService {
* @param time the time coordinates, including initial snap, steps, and p-code steps
* @return the copied p-code frame
*/
DebuggerPcodeMachine<?> getCachedEmulator(Trace trace, TraceSchedule time);
PcodeMachine<?> getCachedEmulator(Trace trace, TraceSchedule time);
/**
* Get the emulators which are current executing

View file

@ -1,26 +0,0 @@
/* ###
* IP: GHIDRA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.debug.api.emulation;
import ghidra.pcode.exec.trace.TracePcodeMachine;
/**
* A Debugger-integrated emulator (or p-code machine)
*
* @param <T> the type of values in the machine's memory and registers
*/
public interface DebuggerPcodeMachine<T> extends TracePcodeMachine<T> {
}

View file

@ -15,15 +15,14 @@
*/
package ghidra.debug.api.emulation;
import ghidra.debug.api.target.Target;
import ghidra.framework.plugintool.PluginTool;
import ghidra.trace.model.guest.TracePlatform;
import ghidra.pcode.emu.PcodeMachine;
import ghidra.pcode.exec.trace.TraceEmulationIntegration.Writer;
import ghidra.util.classfinder.ExtensionPoint;
/**
* A factory for configuring and creating a Debugger-integrated emulator
*/
public interface DebuggerPcodeEmulatorFactory extends ExtensionPoint {
public interface EmulatorFactory extends ExtensionPoint {
// TODO: Config options, use ModelFactory as a model
/**
@ -33,23 +32,12 @@ public interface DebuggerPcodeEmulatorFactory extends ExtensionPoint {
*/
String getTitle();
/**
* Create the emulator
*
* @param tool the tool creating the emulator
* @param platform the user's current trace platform from which the emulator should load state
* @param snap the user's current snap from which the emulator should load state
* @param target if applicable, the live target
* @return the emulator
*/
DebuggerPcodeMachine<?> create(PluginTool tool, TracePlatform platform, long snap,
Target target);
/**
* Create the emulator
*
* @param access the trace-and-debugger access shim
* @return the emulator
* @param writer the Debugger's emulation callbacks for UI integration
* @return the emulator with callbacks installed
*/
DebuggerPcodeMachine<?> create(PcodeDebuggerAccess access);
PcodeMachine<?> create(PcodeDebuggerAccess access, Writer writer);
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -17,7 +17,7 @@ package ghidra.debug.api.emulation;
import java.util.concurrent.CompletableFuture;
import ghidra.generic.util.datastruct.SemisparseByteArray;
import ghidra.pcode.exec.PcodeExecutorStatePiece;
import ghidra.pcode.exec.trace.data.PcodeTraceMemoryAccess;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView;
@ -53,11 +53,12 @@ public interface PcodeDebuggerMemoryAccess
* image was relocated with fixups, reads at those fixups which fall through to static images
* will be incorrect, and may lead to undefined behavior in the emulated program.
*
* @param bytes the destination byte store
* @param piece the destination state piece
* @param unknown the address set to read
* @return true if any bytes were read, false if there was no effect
* @return the parts of {@code unknown} that <em>still haven't</em> been read
*/
boolean readFromStaticImages(SemisparseByteArray bytes, AddressSetView unknown);
AddressSetView readFromStaticImages(PcodeExecutorStatePiece<byte[], byte[]> piece,
AddressSetView unknown);
/**
* Instruct the associated recorder to write target memory