Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7407: final? errata GP-7407: final? errata GP-7407: one more? GP-7407: missed these GP-7407: help (needs help) GP-7407: better names GP-7407: taint service GP-7407: common edit controls GP-7407: flatten EmulateAction GP-7407: review, medium GP-7407: review, easy stuff first GP-7407: menu stuff GP-7407: var/arr GP-7407: set/del taint GP-7407: minor mod again again GP-7407: minor mod again GP-7407: minor mod GP-7407: menu actions GP-7407: fix for taint mode GP-7407: saner context GP-7407: unneeded constructor GP-7407: help GP-7407: help GP-7407: passing tests GP-7407: better menus GP-7407: re-emulate GP-7407: add EmulateTarget GP-7407: refactoring to EmulateAction GP-7407: override from mode GP-7407: add emulators GP-7407: enum -> abstract GP-7407: better icon behavior GP-7407: test working GP-7407: first pass

d-millarf8cd972e16a3
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerControlService.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerControlService.java
index f592f55f90..edf03e63d0 100644
--- a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerControlService.java
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerControlService.java
@@ -58,7 +58,7 @@ public interface DebuggerControlService {
ControlMode getCurrentMode(Trace trace);
- void setCurrentMode(Trace trace, ControlMode mode);
+ void setCurrentMode(Trace trace, ControlMode mode, boolean canEdit);
void addModeChangeListener(ControlModeChangeListener listener);
@@ -75,4 +75,5 @@ public interface DebuggerControlService {
StateEditor createStateEditor(Trace trace);
StateEditor createStateEditor(TraceProgramView view);
+
}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerEmulationService.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerEmulationService.java
index b997b13a35..d9886dd45c 100644
--- a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerEmulationService.java
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/DebuggerEmulationService.java
@@ -319,4 +319,5 @@ public interface DebuggerEmulationService {
* @param listener the listener
*/
void removeStateListener(EmulatorStateListener listener);
+
}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/EmulationTaintInjectionService.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/EmulationTaintInjectionService.java
new file mode 100644
index 0000000000..be7ee020b7
--- /dev/null
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/app/services/EmulationTaintInjectionService.java
@@ -0,0 +1,28 @@
+/* ###
+ * 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.app.services;
+
+import ghidra.framework.plugintool.ServiceInfo;
+import ghidra.pcode.emu.PcodeMachine;
+
+@ServiceInfo(
+ defaultProviderName = "ghidra.app.plugin.core.debug.service.taint.EmulationTaintInjectionServicePlugin",
+ description = "Centralized service for manipulating taint"
+)
+public interface EmulationTaintInjectionService {
+
+ public void injectTaint(PcodeMachine<?> emu);
+}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/ControlMode.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/ControlMode.java
index 7bad8baae5..c465c1ec2b 100644
--- a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/ControlMode.java
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/ControlMode.java
@@ -15,339 +15,47 @@
*/
package ghidra.debug.api.control;
-import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
import java.util.concurrent.CompletableFuture;
import javax.swing.Icon;
-import db.Transaction;
-import generic.theme.GIcon;
-import ghidra.app.services.DebuggerTraceManagerService;
import ghidra.app.services.DebuggerTraceManagerService.ActivationCause;
import ghidra.debug.api.target.Target;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
-import ghidra.program.model.address.AddressRange;
-import ghidra.program.model.lang.Language;
-import ghidra.program.model.lang.Register;
-import ghidra.program.model.mem.MemoryAccessException;
-import ghidra.trace.model.Trace;
import ghidra.trace.model.guest.TracePlatform;
-import ghidra.trace.model.memory.TraceMemoryOperations;
-import ghidra.trace.model.memory.TraceMemorySpace;
-import ghidra.trace.model.program.TraceVariableSnapProgramView;
-import ghidra.trace.model.thread.TraceThread;
-import ghidra.trace.model.time.schedule.PatchStep;
import ghidra.trace.model.time.schedule.TraceSchedule;
import ghidra.trace.model.time.schedule.TraceSchedule.ScheduleForm;
-import ghidra.trace.util.TraceRegisterUtils;
/**
* The control / state editing modes
*/
-public enum ControlMode {
- /**
- * Control actions, breakpoint commands are directed to the target, but state edits are
- * rejected.
- */
- RO_TARGET("Control Target w/ Edits Disabled", new GIcon(
- "icon.debugger.control.mode.ro.target")) {
- @Override
- public boolean isTarget() {
- return true;
- }
-
- @Override
- public boolean followsPresent() {
- return true;
- }
-
- @Override
- public boolean canEdit(DebuggerCoordinates coordinates) {
- return false;
- }
-
- @Override
- public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
- int length) {
- return false;
- }
-
- @Override
- public CompletableFuture<Void> setVariable(PluginTool tool,
- DebuggerCoordinates coordinates, Address address, byte[] data) {
- return CompletableFuture.failedFuture(new MemoryAccessException("Read-only mode"));
- }
-
- @Override
- public boolean useEmulatedBreakpoints() {
- return false;
- }
-
- @Override
- public boolean isSelectable(DebuggerCoordinates coordinates) {
- return coordinates.isAlive();
- }
-
- @Override
- public ControlMode getAlternative(DebuggerCoordinates coordinates) {
- return RW_EMULATOR;
- }
- },
- /**
- * Control actions, breakpoint commands, and state edits are all directed to the target.
- */
- RW_TARGET("Control Target", new GIcon("icon.debugger.control.mode.rw.target")) {
- @Override
- public boolean isTarget() {
- return true;
- }
-
- @Override
- public boolean followsPresent() {
- return true;
- }
-
- @Override
- public boolean canEdit(DebuggerCoordinates coordinates) {
- return coordinates.isAliveAndPresent();
- }
-
- @Override
- public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
- int length) {
- if (!coordinates.isAliveAndPresent()) {
- return false;
- }
- Target target = coordinates.getTarget();
- return target.isVariableExists(platformFor(coordinates, address),
- coordinates.getThread(), coordinates.getFrame(), address, length);
- }
-
- @Override
- public CompletableFuture<Void> setVariable(PluginTool tool,
- DebuggerCoordinates coordinates, Address address, byte[] data) {
- Target target = coordinates.getTarget();
- if (target == null) {
- return CompletableFuture
- .failedFuture(new MemoryAccessException("Trace has no live target"));
- }
- if (!coordinates.isAliveAndPresent()) {
- return CompletableFuture
- .failedFuture(new MemoryAccessException("View is not the present"));
- }
- return target.writeVariableAsync(platformFor(coordinates, address),
- coordinates.getThread(), coordinates.getFrame(), address, data);
- }
-
- @Override
- public boolean useEmulatedBreakpoints() {
- return false;
- }
-
- @Override
- public boolean isSelectable(DebuggerCoordinates coordinates) {
- return coordinates.isAlive();
- }
-
- @Override
- public ControlMode getAlternative(DebuggerCoordinates coordinates) {
- return RW_EMULATOR;
- }
- },
- /**
- * Control actions activate trace snapshots, breakpoint commands are directed to the emulator,
- * and state edits are rejected.
- */
- RO_TRACE("Control Trace w/ Edits Disabled", new GIcon("icon.debugger.control.mode.ro.trace")) {
- @Override
- public boolean isTarget() {
- return false;
- }
-
- @Override
- public boolean followsPresent() {
- return false;
- }
-
- @Override
- public boolean canEdit(DebuggerCoordinates coordinates) {
- return false;
- }
-
- @Override
- public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
- int length) {
- return false;
- }
-
- @Override
- public CompletableFuture<Void> setVariable(PluginTool tool,
- DebuggerCoordinates coordinates, Address address, byte[] data) {
- return CompletableFuture.failedFuture(new MemoryAccessException("Read-only mode"));
- }
-
- @Override
- public boolean useEmulatedBreakpoints() {
- return true;
- }
- },
- /**
- * Control actions activate trace snapshots, breakpoint commands are directed to the emulator,
- * and state edits modify the current trace snapshot.
- */
- RW_TRACE("Control Trace", new GIcon("icon.debugger.control.mode.rw.trace")) {
- @Override
- public boolean isTarget() {
- return false;
- }
-
- @Override
- public boolean followsPresent() {
- return false;
- }
-
- @Override
- public boolean canEdit(DebuggerCoordinates coordinates) {
- return coordinates.getTrace() != null;
- }
-
- @Override
- public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
- int length) {
- return address.isMemoryAddress() || coordinates.getThread() != null;
- }
-
- @Override
- public CompletableFuture<Void> setVariable(PluginTool tool,
- DebuggerCoordinates coordinates, Address guestAddress, byte[] data) {
- Trace trace = coordinates.getTrace();
- TracePlatform platform = platformFor(coordinates, guestAddress);
- long snap = coordinates.getViewSnap();
- Address hostAddress = platform.mapGuestToHost(guestAddress);
- if (hostAddress == null) {
- throw new IllegalArgumentException(
- "Guest address " + guestAddress + " is not mapped");
- }
- TraceMemoryOperations memOrRegs;
- Address overlayAddress;
- try (Transaction tx = trace.openTransaction("Edit Variable")) {
- if (hostAddress.isRegisterAddress()) {
- TraceThread thread = coordinates.getThread();
- if (thread == null) {
- throw new IllegalArgumentException("Register edits require a thread.");
- }
- TraceMemorySpace regs = trace.getMemoryManager()
- .getMemoryRegisterSpace(thread, coordinates.getFrame(),
- true);
- memOrRegs = regs;
- overlayAddress = regs.getAddressSpace().getOverlayAddress(hostAddress);
- }
- else {
- memOrRegs = trace.getMemoryManager();
- overlayAddress = hostAddress;
- }
- if (memOrRegs.putBytes(snap, overlayAddress,
- ByteBuffer.wrap(data)) != data.length) {
- return CompletableFuture.failedFuture(new MemoryAccessException());
- }
- }
- return CompletableFuture.completedFuture(null);
- }
-
- @Override
- public boolean useEmulatedBreakpoints() {
- return true;
- }
- },
- /**
- * Control actions, breakpoint commands, and state edits are directed to the emulator.
- *
- * <p>
- * Edits are accomplished by appending patch steps to the current schedule and activating that
- * schedule.
- */
- RW_EMULATOR("Control Emulator", new GIcon("icon.debugger.control.mode.rw.emulator")) {
- @Override
- public boolean isTarget() {
- return false;
- }
+public abstract class ControlMode {
- @Override
- public boolean followsPresent() {
- return false;
- }
+ // LATER: these should be instance fields of the plugin
+ private static final List<ControlMode> ALL_INTERNAL = new ArrayList<>();
+ public static final List<ControlMode> ALL = Collections.unmodifiableList(ALL_INTERNAL);
- @Override
- public boolean canEdit(DebuggerCoordinates coordinates) {
- return coordinates.getTrace() != null;
- }
+ public static final TargetControlMode TARGET = new TargetControlMode();
+ public static final TraceControlMode TRACE = new TraceControlMode();
+ public static final EmulatorControlMode EMULATOR = new EmulatorControlMode();
- @Override
- public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
- int length) {
- if (coordinates.getThread() == null) {
- // A limitation in TraceSchedule, which is used to manifest patches
- return false;
- }
- if (!RW_TRACE.isVariableEditable(coordinates, address, length)) {
- return false;
- }
- // TODO: Limitation from using Sleigh for patching
- Register ctxReg = coordinates.getTrace().getBaseLanguage().getContextBaseRegister();
- if (ctxReg == Register.NO_CONTEXT) {
- return true;
- }
- AddressRange ctxRange = TraceRegisterUtils.rangeForRegister(ctxReg);
- if (ctxRange.contains(address)) {
- return false;
- }
- return true;
- }
-
- @Override
- public CompletableFuture<Void> setVariable(PluginTool tool,
- DebuggerCoordinates coordinates, Address address, byte[] data) {
- if (!(coordinates.getView() instanceof TraceVariableSnapProgramView)) {
- throw new IllegalArgumentException("Cannot emulate using a Fixed Program View");
- }
- TraceThread thread = coordinates.getThread();
- if (thread == null) {
- // TODO: Well, technically, only for register edits
- // It's a limitation in TraceSchedule. Every step requires a thread
- throw new IllegalArgumentException("Emulator edits require a thread.");
- }
- Language language = coordinates.getPlatform().getLanguage();
- TraceSchedule time = coordinates.getTime()
- .patched(thread, language,
- PatchStep.generateSleigh(language, address, data));
-
- DebuggerCoordinates withTime = coordinates.time(time);
- DebuggerTraceManagerService traceManager =
- Objects.requireNonNull(tool.getService(DebuggerTraceManagerService.class),
- "No trace manager service");
-
- return traceManager.activateAndNotify(withTime, ActivationCause.EMU_STATE_EDIT);
- }
-
- @Override
- public boolean useEmulatedBreakpoints() {
- return true;
- }
- };
-
- public static final List<ControlMode> ALL = List.of(values());
- public static final ControlMode DEFAULT = RO_TARGET;
+ public static final ControlMode DEFAULT = TARGET;
public final String name;
- public final Icon icon;
+ public Icon icon;
+ public Icon iconEditable;
+ public Icon iconUneditable;
+ protected boolean isEditEnabled = false;
- private ControlMode(String name, Icon icon) {
+ protected ControlMode(String name, Icon iconEditable, Icon iconUneditable) {
this.name = name;
- this.icon = icon;
+ this.icon = iconUneditable;
+ this.iconEditable = iconEditable;
+ this.iconUneditable = iconUneditable;
+ ALL_INTERNAL.add(this);
}
/**
@@ -478,7 +186,7 @@ public enum ControlMode {
* If the mode can no longer be selected for new coordinates, get the new mode
*
* <p>
- * For example, if a target terminates while the mode is {@link #RO_TARGET}, this specifies the
+ * For example, if a target terminates while the mode is {@link #TARGET}, this specifies the
* new mode.
*
* @param coordinates the new coordinates
@@ -511,4 +219,32 @@ public enum ControlMode {
* @return true if it controls the target
*/
public abstract boolean isTarget();
+
+ /**
+ * Toggles canEdit and associated icon
+ */
+ public void toggleEditable() {
+ isEditEnabled = !isEditEnabled;
+ icon = isEditEnabled ? iconEditable : iconUneditable;
+ }
+
+ /**
+ * Does the mode support editing
+ *
+ * @return true if editable, false if not
+ */
+ public boolean isEditable() {
+ return isEditEnabled;
+ }
+
+ /**
+ * Set the mode as editable
+ *
+ * @param editable is editable
+ */
+ public void setEditable(boolean editable) {
+ this.isEditEnabled = editable;
+ icon = isEditEnabled ? iconEditable : iconUneditable;
+ }
+
}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/EmulatorControlMode.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/EmulatorControlMode.java
new file mode 100644
index 0000000000..a826a3eaf4
--- /dev/null
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/EmulatorControlMode.java
@@ -0,0 +1,116 @@
+/* ###
+ * 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.control;
+
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+
+import generic.theme.GIcon;
+import ghidra.app.services.DebuggerTraceManagerService;
+import ghidra.app.services.DebuggerTraceManagerService.ActivationCause;
+import ghidra.debug.api.emulation.EmulatorFactory;
+import ghidra.debug.api.tracemgr.DebuggerCoordinates;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressRange;
+import ghidra.program.model.lang.Language;
+import ghidra.program.model.lang.Register;
+import ghidra.trace.model.program.TraceVariableSnapProgramView;
+import ghidra.trace.model.thread.TraceThread;
+import ghidra.trace.model.time.schedule.PatchStep;
+import ghidra.trace.model.time.schedule.TraceSchedule;
+import ghidra.trace.util.TraceRegisterUtils;
+
+public class EmulatorControlMode extends ControlMode {
+
+ public EmulatorControlMode() {
+ super("Default Concrete P-code Emulator",
+ new GIcon("icon.debugger.control.mode.rw.emulator"),
+ new GIcon("icon.debugger.emulate"));
+ }
+
+ public EmulatorControlMode(EmulatorFactory factory) {
+ super(factory.getTitle(), new GIcon("icon.debugger.control.mode.rw.emulator"),
+ new GIcon("icon.debugger.emulate"));
+ }
+
+ @Override
+ public boolean isTarget() {
+ return false;
+ }
+
+ @Override
+ public boolean followsPresent() {
+ return false;
+ }
+
+ @Override
+ public boolean canEdit(DebuggerCoordinates coordinates) {
+ return isEditEnabled && coordinates.getTrace() != null;
+ }
+
+ @Override
+ public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
+ int length) {
+ if (coordinates.getThread() == null) {
+ // A limitation in TraceSchedule, which is used to manifest patches
+ return false;
+ }
+ if (!address.isMemoryAddress() && coordinates.getThread() == null) {
+ return false;
+ }
+ // LATER: Limitation from using Sleigh for patching
+ Register ctxReg = coordinates.getTrace().getBaseLanguage().getContextBaseRegister();
+ if (ctxReg == Register.NO_CONTEXT) {
+ return true;
+ }
+ AddressRange ctxRange = TraceRegisterUtils.rangeForRegister(ctxReg);
+ if (ctxRange.contains(address)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public CompletableFuture<Void> setVariable(PluginTool tool,
+ DebuggerCoordinates coordinates, Address address, byte[] data) {
+ if (!(coordinates.getView() instanceof TraceVariableSnapProgramView)) {
+ throw new IllegalArgumentException("Cannot emulate using a Fixed Program View");
+ }
+ TraceThread thread = coordinates.getThread();
+ if (thread == null) {
+ // TODO: Well, technically, only for register edits
+ // It's a limitation in TraceSchedule. Every step requires a thread
+ throw new IllegalArgumentException("Emulator edits require a thread.");
+ }
+ Language language = coordinates.getPlatform().getLanguage();
+ TraceSchedule time = coordinates.getTime()
+ .patched(thread, language, PatchStep.generateSleigh(language, address, data));
+
+ DebuggerCoordinates withTime = coordinates.time(time);
+ DebuggerTraceManagerService traceManager =
+ Objects.requireNonNull(tool.getService(DebuggerTraceManagerService.class),
+ "No trace manager service");
+
+ return traceManager.activateAndNotify(withTime, ActivationCause.EMU_STATE_EDIT);
+ }
+
+ @Override
+ public boolean useEmulatedBreakpoints() {
+ return true;
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/TargetControlMode.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/TargetControlMode.java
new file mode 100644
index 0000000000..59790cfd9f
--- /dev/null
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/TargetControlMode.java
@@ -0,0 +1,93 @@
+/* ###
+ * 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.control;
+
+import java.util.concurrent.CompletableFuture;
+
+import generic.theme.GIcon;
+import ghidra.debug.api.target.Target;
+import ghidra.debug.api.tracemgr.DebuggerCoordinates;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.mem.MemoryAccessException;
+
+public class TargetControlMode extends ControlMode {
+
+ public TargetControlMode() {
+ super("Target", new GIcon("icon.debugger.control.mode.rw.target"), new GIcon(
+ "icon.debugger.control.mode.ro.target"));
+ }
+
+ @Override
+ public boolean isTarget() {
+ return true;
+ }
+
+ @Override
+ public boolean followsPresent() {
+ return true;
+ }
+
+ @Override
+ public boolean canEdit(DebuggerCoordinates coordinates) {
+ return isEditEnabled && coordinates.isAliveAndPresent();
+ }
+
+ @Override
+ public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
+ int length) {
+ if (!canEdit(coordinates)) {
+ return false;
+ }
+ Target target = coordinates.getTarget();
+ return target.isVariableExists(platformFor(coordinates, address),
+ coordinates.getThread(), coordinates.getFrame(), address, length);
+ }
+
+ @Override
+ public CompletableFuture<Void> setVariable(PluginTool tool,
+ DebuggerCoordinates coordinates, Address address, byte[] data) {
+ if (!isEditEnabled) {
+ return CompletableFuture.failedFuture(new MemoryAccessException("Read-only mode"));
+ }
+ Target target = coordinates.getTarget();
+ if (target == null) {
+ return CompletableFuture
+ .failedFuture(new MemoryAccessException("Trace has no live target"));
+ }
+ if (!coordinates.isAliveAndPresent()) {
+ return CompletableFuture
+ .failedFuture(new MemoryAccessException("View is not the present"));
+ }
+ return target.writeVariableAsync(platformFor(coordinates, address),
+ coordinates.getThread(), coordinates.getFrame(), address, data);
+ }
+
+ @Override
+ public boolean useEmulatedBreakpoints() {
+ return false;
+ }
+
+ @Override
+ public boolean isSelectable(DebuggerCoordinates coordinates) {
+ return coordinates.isAlive();
+ }
+
+ @Override
+ public ControlMode getAlternative(DebuggerCoordinates coordinates) {
+ return EMULATOR;
+ }
+}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/TraceControlMode.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/TraceControlMode.java
new file mode 100644
index 0000000000..5fd75b7033
--- /dev/null
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/api/control/TraceControlMode.java
@@ -0,0 +1,109 @@
+/* ###
+ * 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.control;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.CompletableFuture;
+
+import db.Transaction;
+import generic.theme.GIcon;
+import ghidra.debug.api.tracemgr.DebuggerCoordinates;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.mem.MemoryAccessException;
+import ghidra.trace.model.Trace;
+import ghidra.trace.model.guest.TracePlatform;
+import ghidra.trace.model.memory.TraceMemoryOperations;
+import ghidra.trace.model.memory.TraceMemorySpace;
+import ghidra.trace.model.thread.TraceThread;
+
+public class TraceControlMode extends ControlMode {
+
+ public TraceControlMode() {
+ super("Trace", new GIcon("icon.debugger.control.mode.rw.trace"), new GIcon(
+ "icon.debugger.control.mode.ro.trace"));
+ }
+
+ @Override
+ public boolean isTarget() {
+ return false;
+ }
+
+ @Override
+ public boolean followsPresent() {
+ return false;
+ }
+
+ @Override
+ public boolean canEdit(DebuggerCoordinates coordinates) {
+ return isEditEnabled && coordinates.getTrace() != null;
+ }
+
+ @Override
+ public boolean isVariableEditable(DebuggerCoordinates coordinates, Address address,
+ int length) {
+ if (!canEdit(coordinates)) {
+ return false;
+ }
+ return address.isMemoryAddress() || coordinates.getThread() != null;
+ }
+
+ @Override
+ public CompletableFuture<Void> setVariable(PluginTool tool,
+ DebuggerCoordinates coordinates, Address guestAddress, byte[] data) {
+ if (!isEditEnabled) {
+ return CompletableFuture.failedFuture(new MemoryAccessException("Read-only mode"));
+ }
+ Trace trace = coordinates.getTrace();
+ TracePlatform platform = platformFor(coordinates, guestAddress);
+ long snap = coordinates.getViewSnap();
+ Address hostAddress = platform.mapGuestToHost(guestAddress);
+ if (hostAddress == null) {
+ throw new IllegalArgumentException(
+ "Guest address " + guestAddress + " is not mapped");
+ }
+ TraceMemoryOperations memOrRegs;
+ Address overlayAddress;
+ try (Transaction _ = trace.openTransaction("Edit Variable")) {
+ if (hostAddress.isRegisterAddress()) {
+ TraceThread thread = coordinates.getThread();
+ if (thread == null) {
+ throw new IllegalArgumentException("Register edits require a thread.");
+ }
+ TraceMemorySpace regs = trace.getMemoryManager()
+ .getMemoryRegisterSpace(thread, coordinates.getFrame(),
+ true);
+ memOrRegs = regs;
+ overlayAddress = regs.getAddressSpace().getOverlayAddress(hostAddress);
+ }
+ else {
+ memOrRegs = trace.getMemoryManager();
+ overlayAddress = hostAddress;
+ }
+ if (memOrRegs.putBytes(snap, overlayAddress,
+ ByteBuffer.wrap(data)) != data.length) {
+ return CompletableFuture.failedFuture(new MemoryAccessException());
+ }
+ }
+ return CompletableFuture.completedFuture(null);
+ }
+
+ @Override
+ public boolean useEmulatedBreakpoints() {
+ return true;
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java
index bf8db1b8f6..5177660c73 100644
--- a/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java
+++ b/Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java
@@ -1225,6 +1225,17 @@ public interface FlatDebuggerAPI {
return requireService(DebuggerControlService.class);
}
+ /**
+ * Set the control mode of the given trace
+ *
+ * @param trace the trace
+ * @param mode the mode
+ * @param canEdit allow edits to state
+ */
+ default void setControlMode(Trace trace, ControlMode mode, boolean canEdit) {
+ requireService(DebuggerControlService.class).setCurrentMode(trace, mode, canEdit);
+ }
+
/**
* Set the control mode of the given trace
*
@@ -1232,7 +1243,7 @@ public interface FlatDebuggerAPI {
* @param mode the mode
*/
default void setControlMode(Trace trace, ControlMode mode) {
- requireService(DebuggerControlService.class).setCurrentMode(trace, mode);
+ requireService(DebuggerControlService.class).setCurrentMode(trace, mode, mode.isEditable());
}
/**
diff --git a/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProvider.java b/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProvider.java
index ecc170c747..3a5136d5bc 100644
--- a/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProvider.java
+++ b/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProvider.java
@@ -299,7 +299,7 @@ public class TraceRmiConnectionManagerProvider extends ComponentProviderAdapter
return;
}
if (!controlService.getCurrentMode(target.getTrace()).isTarget()) {
- controlService.setCurrentMode(target.getTrace(), ControlMode.RO_TARGET);
+ controlService.setCurrentMode(target.getTrace(), ControlMode.TARGET, false);
}
}
}
diff --git a/Ghidra/Debug/Debugger-rmi-trace/src/test/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProviderTest.java b/Ghidra/Debug/Debugger-rmi-trace/src/test/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProviderTest.java
index 34b9dfc376..0a71ce06c4 100644
--- a/Ghidra/Debug/Debugger-rmi-trace/src/test/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProviderTest.java
+++ b/Ghidra/Debug/Debugger-rmi-trace/src/test/java/ghidra/app/plugin/core/debug/gui/tracermi/connection/TraceRmiConnectionManagerProviderTest.java
@@ -430,20 +430,22 @@ public class TraceRmiConnectionManagerProviderTest extends AbstractGhidraHeadedD
waitForPass(
() -> assertEquals(node, Unique.assertOne(provider.tree.getSelectedNodes())));
- controlService.setCurrentMode(target.getTrace(), ControlMode.RO_TRACE);
+ controlService.setCurrentMode(target.getTrace(), ControlMode.TRACE, false);
waitForSwing();
traceManager.activateSnap(0);
waitForPass(() -> {
assertEquals(0, traceManager.getCurrentSnap());
- assertEquals(ControlMode.RO_TRACE,
- controlService.getCurrentMode(target.getTrace()));
+ ControlMode currentMode = controlService.getCurrentMode(target.getTrace());
+ assertEquals(ControlMode.TRACE, currentMode);
+ assertFalse(currentMode.isEditable());
});
triggerEnter(provider.tree);
waitForPass(() -> {
assertEquals(1, traceManager.getCurrentSnap());
- assertEquals(ControlMode.RO_TARGET,
- controlService.getCurrentMode(target.getTrace()));
+ ControlMode currentMode = controlService.getCurrentMode(target.getTrace());
+ assertEquals(ControlMode.TARGET, currentMode);
+ assertFalse(currentMode.isEditable());
});
}
}
diff --git a/Ghidra/Debug/Debugger/certification.manifest b/Ghidra/Debug/Debugger/certification.manifest
index 1103faf45a..c8363f723c 100644
--- a/Ghidra/Debug/Debugger/certification.manifest
+++ b/Ghidra/Debug/Debugger/certification.manifest
@@ -9,7 +9,6 @@ README.md||GHIDRA||||END|
data/ExtensionPoint.manifest||GHIDRA||||END|
data/debugger.theme.properties||GHIDRA||||END|
src/main/help/help/TOC_Source.xml||GHIDRA||||END|
-src/main/help/help/topics/BentoServicePlugin/BentoServicePlugin.html||GHIDRA||||END|
src/main/help/help/topics/BreakpointTimelinePlugin/BreakpointTimelinePlugin.html||GHIDRA||||END|
src/main/help/help/topics/BreakpointTimelinePlugin/images/BreakpointTimelinePlugin.png||GHIDRA||||END|
src/main/help/help/topics/BreakpointTimelinePlugin/images/BreakpointTimelinePluginNoGrid.png||GHIDRA||||END|
diff --git a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerControlPlugin/DebuggerControlPlugin.html b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerControlPlugin/DebuggerControlPlugin.html
index 10007e094f..37d3fee682 100644
--- a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerControlPlugin/DebuggerControlPlugin.html
+++ b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerControlPlugin/DebuggerControlPlugin.html
@@ -27,35 +27,22 @@
<H3><A name="control_mode"></A>Control Mode</H3>
<P>This action changes the mode for the active trace and, if applicable, its associated live
- target. It is always displayed, but only available when a trace is active. The possible modes
- are:</P>
+ target. It is always displayed, but only available when a trace is active. "Emulation Mode"
+ actions are placed in the menu for each kind of emulator known to Ghidra. These are extensible
+ and may include various system simulations and/or data models. The current baseline modes are:</P>
<UL>
- <LI><IMG alt="" src="icon.debugger.control.mode.ro.target"> <B>Control Target w/Edits
- Disabled:</B> The default, this presents actions for controlling the live target but rejects
- all machine-state edits. Breakpoint commands are directed to the live target. When active,
- the UI automatically follows the latest snapshot recorded, and navigating back in time is not
- permitted. If the target is terminated and the trace remains open, the mode is automatically
- switched to <B>Control Trace</B>.</LI>
-
- <LI><IMG alt="" src="icon.debugger.control.mode.rw.target"> <B>Control Target:</B> This
- presents actions for controlling the live target and directs edits to the live target.
- Breakpoint commands are directed to the live target. When active, the UI automatically
- follows the latest snapshot recorded, an navigating back in time is not permitted. If the
- target is terminated and the trace remains open, the mode is automatically switched to
- <B>Control Emulator</B>.</LI>
-
- <LI><IMG alt="" src="icon.debugger.control.mode.ro.trace"> <B>Control Trace w/Edits
- Disabled:</B> This presents actions for navigating trace snapshots but rejects all
- machine-state edits. Breakpoint commands are directed to the emulator.</LI>
-
- <LI><IMG alt="" src="icon.debugger.control.mode.rw.trace"> <B>Control Trace:</B> This
- presents actions for navigating trace snapshots. It directs all edits to the trace database.
- Edits are generally always accepted, and they are applied directly to the trace. Breakpoint
- commands are directed to the emulator.</LI>
-
- <LI><IMG alt="" src="icon.debugger.control.mode.rw.emulator"> <B>Control Emulator:</B> This
- presents actions for controlling the integrated emulator. Breakpoint commands are directed to
+ <LI><IMG alt="" src="icon.debugger.control.mode.ro.target"> <B>Target:</B> The default,
+ this presents actions for controlling the live target. Breakpoint commands are directed to the live target.
+ When active, the UI automatically follows the latest snapshot recorded, and navigating back in
+ time is not permitted.</LI>
+
+ <LI><IMG alt="" src="icon.debugger.control.mode.ro.trace"> <B>Trace:</B> This presents
+ actions for navigating trace snapshots. Edits are generally always accepted, and they are applied directly
+ to the trace. Breakpoint commands are directed to the emulator.</LI>
+
+ <LI><IMG alt="" src="icon.debugger.control.mode.rw.emulator"> <B>Default Concrete P-code Emulator:
+ </B> This presents actions for controlling the integrated emulator. Breakpoint commands are directed to
the emulator. This can be used for interpolating and extrapolating execution from the current
snapshot, without affecting the live target. It directs edits to the integrated emulator by
generating patch steps and appending them to the emulation schedule. See the <A href=
@@ -63,8 +50,23 @@
Essentially, the change is applied in the trace's scratch space, leaving the original
recording in tact. Due to implementation details, a thread must be selected, even if edits
only affect memory. Additionally, the disassembly context register cannot be modified.</LI>
+
+ <LI><IMG alt="" src="icon.debugger.control.mode.rw.emulator"> <B>Symbolic Z3 Summary with Concrete
+ Emulation: </B> This presents actions for controlling the integrated emulator, but simultaneously
+ tracks the propagation of symbolic values displayed in the debugger's <B>Z3 Summary</B> window.</LI>
+
+ <LI><IMG alt="" src="icon.debugger.control.mode.rw.emulator"> <B>Taint Analyzer with Concrete
+ Emulation: </B> This presents actions for controlling the integrated emulator, but simultaneously
+ tracks the propagation of taint.</LI>
</UL>
+ <H3><A name="enable_edits"></A><IMG alt="" src="icon.debugger.enable.edits"> Enable editing of recorded or live values</H3>
+
+ <P>This action toggles the edit state of the current control mode. In Target mode, edits
+ are directed to the target. In Trace mode, they are applied directly to the trace.
+ In Emulate mode, they are scheduled as patches.
+ </P>
+
<H2>Target Control Actions</H2>
<P>These actions are visible when a <B>Control Target</B> mode is selected. They are available
@@ -189,25 +191,14 @@
<H2>Recommendations</H2>
- <P>The default mode is <B>Control Target w/Edits Disabled</B>, because in most cases, this is
- the desired behavior. When the target dies, the mode becomes <B>Control Trace w/Edits
- Disabled</B>. For the most part, modifying the recorded trace itself is discouraged. There are
- few reasons to edit a trace, perhaps including 1) Hand-generating an experimental trace; 2)
- Generating a trace from a script, e.g., importing an event log, recording an emulated target;
- 3) Patching in state missed by the original recording. Be wary of <B>Control Trace</B> mode,
- especially after emulating, since you could accidentally edit scratch space in the trace. It is
- allowed but can produce non-intuitive and erroneous results, since the emulator caches its
- snapshots in scratch space.</P>
-
- <P>To modify state in a live target, use the <B>Control Target</B> mode. <B>NOTE:</B> Some UI
- components will also require you to toggle a write protector. This also affects scripts that
- use the state editing service. However, disabling edits cannot prevent a script from directly
- accessing Ghidra's Target API to modify a target. Nor can it prevent edits via the connected
- debugger's command-line interpreter. The following components all use the service: <A href=
- "help/topics/DebuggerListingPlugin/DebuggerListingPlugin.html">Dynamic Listing</A>, <A href=
- "help/topics/DebuggerMemoryBytesPlugin/DebuggerMemoryBytesPlugin.html">Memory (Dynamic
- Bytes)</A>, <A href=
- "help/topics/DebuggerRegistersPlugin/DebuggerRegistersPlugin.html">Registers</A>, and <A href=
- "help/topics/DebuggerWatchesPlugin/DebuggerWatchesPlugin.html">Watches</A>.</P>
+ <P>The default mode is <B>Control Target</B> without edits, because in most cases, this is
+ the desired behavior. When the target dies, the mode becomes <B>Control Trace</B>. For the most
+ part, modifying the recorded trace itself is discouraged. There are few reasons to edit a trace,
+ perhaps including 1) Hand-generating an experimental trace; 2) Generating a trace from a script,
+ e.g., importing an event log, recording an emulated target; 3) Patching in state missed by the
+ original recording. Be wary of <B>Control Trace</B> mode, especially after emulating, since you
+ could accidentally edit scratch space in the trace. It is allowed but can produce non-intuitive
+ and erroneous results, since the emulator caches its snapshots in scratch space. To modify state
+ in a live target, use the <B>Control Target</B> mode and enable edits. </P>
</BODY>
</HTML>
diff --git a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerEmulationServicePlugin/DebuggerEmulationServicePlugin.html b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerEmulationServicePlugin/DebuggerEmulationServicePlugin.html
index 8651258391..2cccbf7f63 100644
--- a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerEmulationServicePlugin/DebuggerEmulationServicePlugin.html
+++ b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerEmulationServicePlugin/DebuggerEmulationServicePlugin.html
@@ -18,7 +18,10 @@
Manager</A> and provides actions for launching emulated traces from programs, i.e., without
requiring a connected debugger. Please note that "pure emulation" of a target program, while it
doesn't require a platform to execute the target natively, it typically does require
- significant state initialization and dependency stubbing, except in limited circumstances.</P>
+ significant state initialization and dependency stubbing, except in limited circumstances.
+ Control of the mode of emulation is governed by the <A
+ href="help/topics/DebuggerControlPlugin/DebuggerControlPlugin.html#control_mode">control-mode plugin</A>
+ and may be set to one of a variety of emulators. </P>
<H2>Actions</H2>
@@ -39,6 +42,20 @@
without modifying the emulator's memory map. Note that customizing the stack initialization may
prevent you from adding a second thread.</P>
+ <H3><A name="emulate_target"></A> Emulate Target</H3>
+
+ <P>This action is available whenever a trace is active. It derives the emulator state from
+ the current trace, switches the control mode to the default p-code emulator. The debugger controls
+ then dictate the emulation until the control mode is returned to target mode. This is basically
+ a convenience option and has the same affects as switching the control mode during an active
+ debugging session.</P>
+
+ <H3><A name="emulate_function"></A> Emulate Function</H3>
+
+ <P>This action is available whenever the cursor is within a function in the Static Listing. It
+ displays a <A href="#emulate_function_dialog">dialog</A> for harnessing and emulating the
+ current function.</P>
+
<H3><A name="add_emulated_thread"></A> Add Emulated Thread</H3>
<P>This action is available whenever a "pure emulation" trace is active. It spawns a new thread
@@ -48,23 +65,11 @@
Optionally, other registers can be initialized via the UI or a script. The new thread is
activated so that control actions will affect it by default.</P>
- <H3><A name="emulate_function"></A> Emulate Function</H3>
-
- <P>This action is available whenever the cursor is within a function in the Static Listing. It
- displays a <A href="#emulate_function_dialog">dialog</A> for harnessing and emulating the
- current function.</P>
-
- <H3><A name="configure_emulator"></A> Configure Emulator</H3>
-
- <P>This action is always available. It lists emulators available for configuration. Selecting
- one will set it as the current emulator. The next time emulation is activated, it will use the
- selected emulator.</P>
-
<H3><A name="invalidate_cache"></A> Invalidate Emulator Cache</H3>
<P>This action is available whenever a trace is active. It invalidates all the scratch
snapshots in the current trace, which are used for caching emulated machine states. This is
- recommended when you change the emulator configuration, when you change the Sleigh code of an
+ recommended when you change the emulator, when you change the Sleigh code of an
emulated breakpoint, or when you patch the trace database. If you do not invalidate the cache,
the effects of your change may not appear, since the trace manager may recall a cached snapshot
instead of actually emulating.</P>
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/ControlModeAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/ControlModeAction.java
index 10b93e4012..65ceb24d19 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/ControlModeAction.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/ControlModeAction.java
@@ -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.
@@ -15,6 +15,7 @@
*/
package ghidra.app.plugin.core.debug.gui.control;
+import java.util.List;
import java.util.stream.Collectors;
import docking.ActionContext;
@@ -40,15 +41,15 @@ class ControlModeAction extends MultiStateDockingAction<ControlMode> {
setDescription(DESCRIPTION);
setToolBarData(new ToolBarData(DebuggerResources.ICON_BLANK, GROUP, ""));
setHelpLocation(new HelpLocation(getOwner(), HELP_ANCHOR));
- setActionStates(ControlMode.ALL.stream()
+ List<ActionState<ControlMode>> modes = ControlMode.ALL.stream()
.map(m -> new ActionState<>(m.name, m.icon, m))
- .collect(Collectors.toList()));
- setEnabled(false);
+ .collect(Collectors.toList());
+ setActionStates(modes);
}
@Override
public boolean isEnabledForContext(ActionContext context) {
- return plugin.current.getTrace() != null;
+ return true;
}
@Override
@@ -61,4 +62,5 @@ class ControlModeAction extends MultiStateDockingAction<ControlMode> {
EventTrigger trigger) {
plugin.activateControlMode(newActionState, trigger);
}
+
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPlugin.java
index 6db944c954..89f7945be8 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPlugin.java
@@ -16,13 +16,12 @@
package ghidra.app.plugin.core.debug.gui.control;
import java.util.*;
+import java.util.stream.Collectors;
import docking.ActionContext;
import docking.DockingContextListener;
-import docking.action.DockingAction;
-import docking.action.DockingActionIf;
+import docking.action.*;
import docking.menu.ActionState;
-import docking.menu.MultiStateDockingAction;
import docking.widgets.EventTrigger;
import ghidra.app.context.ProgramLocationActionContext;
import ghidra.app.plugin.PluginCategoryNames;
@@ -30,13 +29,15 @@ import ghidra.app.plugin.core.debug.AbstractDebuggerPlugin;
import ghidra.app.plugin.core.debug.DebuggerPluginPackage;
import ghidra.app.plugin.core.debug.event.TraceActivatedPluginEvent;
import ghidra.app.plugin.core.debug.event.TraceClosedPluginEvent;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
import ghidra.app.services.*;
import ghidra.app.services.DebuggerControlService.ControlModeChangeListener;
import ghidra.app.services.DebuggerEmulationService.CachedEmulator;
import ghidra.app.services.DebuggerEmulationService.EmulatorStateListener;
import ghidra.app.services.DebuggerTraceManagerService.ActivationCause;
import ghidra.async.AsyncUtils;
-import ghidra.debug.api.control.ControlMode;
+import ghidra.debug.api.control.*;
+import ghidra.debug.api.emulation.EmulatorFactory;
import ghidra.debug.api.model.DebuggerObjectActionContext;
import ghidra.debug.api.target.ActionName;
import ghidra.debug.api.target.Target;
@@ -70,7 +71,8 @@ import ghidra.util.Swing;
servicesRequired = {
DebuggerControlService.class,
DebuggerTraceManagerService.class,
- })
+ }
+)
public class DebuggerControlPlugin extends AbstractDebuggerPlugin
implements DockingContextListener {
@@ -110,7 +112,8 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
protected DebuggerCoordinates current = DebuggerCoordinates.NOWHERE;
- protected MultiStateDockingAction<ControlMode> actionControlMode;
+ protected ControlModeAction actionControlMode;
+ protected ToggleDockingAction actionEnableEdits;
DockingAction actionTargetResume;
DockingAction actionTargetInterrupt;
@@ -154,18 +157,12 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
}
protected Set<DockingAction> getActionSet(ControlMode mode) {
- switch (mode) {
- case RO_TARGET:
- case RW_TARGET:
- return actionsTargetAll;
- case RO_TRACE:
- case RW_TRACE:
- return actionsTrace;
- case RW_EMULATOR:
- return actionsEmulate;
- default:
- throw new AssertionError();
- }
+ return switch(mode) {
+ case TargetControlMode _ -> actionsTargetAll;
+ case TraceControlMode _ -> actionsTrace;
+ case EmulatorControlMode _ -> actionsEmulate;
+ default -> throw new AssertionError();
+ };
}
protected Set<DockingAction> getActionSet() {
@@ -222,6 +219,11 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
protected void createActions() {
actionControlMode = new ControlModeAction(this);
tool.addAction(actionControlMode);
+ actionEnableEdits = DebuggerResources.EnableEditsAction.builder(this)
+ .enabledWhen(_ -> current.getTrace() != null)
+ .onAction(_ -> toggleEnableEdits())
+ .toolBarGroup(DebuggerResources.GROUP_CONTROL, "")
+ .buildAndInstall(tool);
actionTargetResume = TargetResumeAction.builder(this)
.build();
@@ -282,6 +284,13 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
updateActions();
}
+ private void toggleEnableEdits() {
+ ControlMode mode = computeCurrentControlMode();
+ mode.toggleEditable();
+ actionControlMode.setToolBarData(
+ new ToolBarData(mode.icon, DebuggerResources.GROUP_CONTROL, ""));
+ }
+
protected void addTargetStepExtActions(Target target) {
for (ActionEntry entry : target
.collectActions(ActionName.STEP_EXT, context,
@@ -337,7 +346,20 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
if (controlService == null) {
return;
}
- controlService.setCurrentMode(current.getTrace(), state.getUserData());
+ ControlMode mode = state.getUserData();
+ controlService.setCurrentMode(current.getTrace(), mode, mode.isEditable());
+ if (mode instanceof EmulatorControlMode emode) {
+ // Post GP-3090, this can be replaced
+ Collection<EmulatorFactory> emulatorFactories = emulationService.getEmulatorFactories();
+ for (EmulatorFactory factory : emulatorFactories) {
+ if (emode.name.equals(factory.getTitle())) {
+ emulationService.setEmulatorFactory(factory);
+ }
+ }
+ }
+ actionControlMode.setToolBarData(
+ new ToolBarData(mode.icon, DebuggerResources.GROUP_CONTROL, ""));
+ actionEnableEdits.setSelected(mode.isEditable());
// TODO: Limit selectable modes?
// No sense showing Write Target, if the trace can never be live, again....
}
@@ -525,7 +547,7 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
return ControlMode.DEFAULT;
}
if (current.getTrace() == null) {
- return ControlMode.DEFAULT;
+ return ControlMode.DEFAULT.getAlternative(current);
}
return controlService.getCurrentMode(current.getTrace());
}
@@ -590,12 +612,23 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
@AutoServiceConsumed
private void setEmulationService(DebuggerEmulationService emulationService) {
+ List<String> names = actionControlMode.getAllActionStates()
+ .stream()
+ .map(state -> state.getName())
+ .collect(Collectors.toList());
if (this.emulationService != null) {
this.emulationService.removeStateListener(listenerForEmuStateChanges);
}
this.emulationService = emulationService;
if (this.emulationService != null) {
this.emulationService.addStateListener(listenerForEmuStateChanges);
+ Collection<EmulatorFactory> emulatorFactories = emulationService.getEmulatorFactories();
+ for (EmulatorFactory factory : emulatorFactories) {
+ EmulatorControlMode m = new EmulatorControlMode(factory);
+ if (!names.contains(m.name)) {
+ actionControlMode.addActionState(new ActionState<>(m.name, m.icon, m));
+ }
+ }
}
updateActions();
}
@@ -610,4 +643,5 @@ public class DebuggerControlPlugin extends AbstractDebuggerPlugin
traceClosed(ev.getTrace());
}
}
+
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/DebuggerEmulateFunctionDialog.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/DebuggerEmulateFunctionDialog.java
index d7decc1230..a6a3f2253a 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/DebuggerEmulateFunctionDialog.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/emulation/DebuggerEmulateFunctionDialog.java
@@ -1044,7 +1044,8 @@ public class DebuggerEmulateFunctionDialog extends DialogComponentProvider {
}
if (controlService != null) {
- controlService.setCurrentMode(harness.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(harness.trace, ControlMode.EMULATOR,
+ true);
}
}
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java
index dba4cfb77f..532fc74c88 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProvider.java
@@ -278,6 +278,7 @@ public class DebuggerMemoryBytesProvider extends ProgramByteViewerComponentProvi
autoServiceWiring = AutoService.wireServicesConsumed(plugin, this);
createActions();
addDisplayListener(readsMemTrait.getDisplayListener());
+ setEditMode(true);
JPanel northPanel = new JPanel(new BorderLayout());
northPanel.add(locationLabel);
@@ -703,9 +704,9 @@ public class DebuggerMemoryBytesProvider extends ProgramByteViewerComponentProvi
}
protected void doGoToTracked() {
- if (editModeAction.isSelected()) {
- return;
- }
+// if (editModeAction.isSelected()) {
+// return;
+// }
ProgramLocation loc = trackingTrait.getTrackedLocation();
if (loc == null) {
return;
@@ -848,4 +849,10 @@ public class DebuggerMemoryBytesProvider extends ProgramByteViewerComponentProvi
options.setBytesPerLine(bytesPerLine);
updateConfigOptions(options, Set.of(hexColumn, "Chars"));
}
+
+ @Override
+ public boolean hasEditAction() {
+ return false;
+ }
+
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java
index 2c6588a29c..a0b4ef0edb 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java
@@ -32,7 +32,8 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import db.Transaction;
import docking.*;
-import docking.action.*;
+import docking.action.DockingAction;
+import docking.action.DockingActionIf;
import docking.action.builder.ActionBuilder;
import docking.actions.PopupActionProvider;
import docking.widgets.AbstractGCellRenderer;
@@ -150,12 +151,10 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
protected enum RegisterTableColumns
implements EnumeratedTableColumn<RegisterTableColumns, RegisterRow> {
- FAV("Fav", 1, Boolean.class, RegisterRow::isFavorite, RegisterRow::setFavorite, r -> true,
- SortDirection.DESCENDING),
+ FAV("Fav", 1, Boolean.class, RegisterRow::isFavorite, RegisterRow::setFavorite, r -> true, SortDirection.DESCENDING),
NUMBER("#", 1, Integer.class, RegisterRow::getNumber),
NAME("Name", 40, String.class, RegisterRow::getName),
- VALUE("Value", 100, BigInteger.class, RegisterRow::getValue, RegisterRow::setValue,
- RegisterRow::isValueEditable, SortDirection.ASCENDING) {
+ VALUE("Value", 100, BigInteger.class, RegisterRow::getValue, RegisterRow::setValue, RegisterRow::isValueEditable, SortDirection.ASCENDING) {
@Override
public GColumnRenderer<BigInteger> getRenderer() {
@@ -172,16 +171,13 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
return VALUE_DEFS;
}
},
- TYPE("Type", 40, DataType.class, RegisterRow::getDataType, RegisterRow::setDataType,
- r -> true, SortDirection.ASCENDING) {
+ TYPE("Type", 40, DataType.class, RegisterRow::getDataType, RegisterRow::setDataType, r -> true, SortDirection.ASCENDING) {
@Override
public TableCellEditor getEditor() {
return TYPE_EDITOR;
}
},
- REPR("Repr", 100, String.class, RegisterRow::getRepresentation,
- RegisterRow::setRepresentation, RegisterRow::isRepresentationEditable,
- SortDirection.ASCENDING);
+ REPR("Repr", 100, String.class, RegisterRow::getRepresentation, RegisterRow::setRepresentation, RegisterRow::isRepresentationEditable, SortDirection.ASCENDING);
private final String header;
private final int width;
@@ -554,7 +550,6 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
DockingAction actionSelectRegisters;
DockingAction actionCreateSnapshot;
- ToggleDockingAction actionEnableEdits;
DockingAction actionClearDataType;
DockingAction actionDataTypeSettings;
@@ -742,11 +737,6 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
.onAction(c -> cloneWindowActivated())
.buildAndInstallLocal(this);
}
- actionEnableEdits = DebuggerResources.EnableEditsAction.builder(plugin)
- .enabledWhen(c -> current.getThread() != null)
- .onAction(c -> {
- })
- .buildAndInstallLocal(this);
actionClearDataType = ClearRegisterType.builder(plugin)
.enabledWhen(c -> current.getThread() != null)
.keyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0))
@@ -842,7 +832,6 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
if (currentTrace == trace) {
return;
}
- actionEnableEdits.setSelected(false);
removeOldTraceListener();
this.currentTrace = trace;
addNewTraceListener();
@@ -1121,7 +1110,7 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
}
private boolean isEditsEnabled() {
- return actionEnableEdits.isSelected();
+ return controlService.getCurrentMode(currentTrace).isEditable();
}
/**
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerModel.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerModel.java
index eed148aaf7..5ff26518c2 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerModel.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerModel.java
@@ -15,16 +15,19 @@
*/
package ghidra.app.plugin.core.debug.gui.variable;
-import javax.swing.*;
-import javax.swing.table.TableCellEditor;
-import javax.swing.table.TableModel;
-import java.awt.*;
+import static docking.widgets.table.CustomToStringCellRenderer.CustomFont.*;
+
+import java.awt.Color;
+import java.awt.Component;
import java.awt.event.MouseEvent;
import java.util.*;
-import java.util.List;
import java.util.function.*;
import java.util.stream.Collectors;
+import javax.swing.*;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableModel;
+
import db.Transaction;
import docking.Tool;
import docking.widgets.table.*;
@@ -42,8 +45,6 @@ import ghidra.util.datastruct.Accumulator;
import ghidra.util.table.column.GColumnRenderer;
import ghidra.util.task.TaskMonitor;
-import static docking.widgets.table.CustomToStringCellRenderer.CustomFont.MONOSPACED;
-
public class DebuggerVariableViewerModel
extends ThreadedTableModelStub<AbstractDebuggerVariableViewerVarValue> {
private static class DataTypeEditor extends AbstractDataTypeTableCellEditor {
@@ -356,7 +357,7 @@ public class DebuggerVariableViewerModel
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (getColumn(
columnIndex) instanceof AbstractDebuggerVariableColumn<?, ?> abstractDebuggerVariableColumn) {
- return provider.actionEnableEdits.isSelected() &&
+ return provider.isEditable() &&
abstractDebuggerVariableColumn.isEditable() && getRowObject(rowIndex).canEdit();
}
return false;
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerProvider.java
index 7022e741fc..e9c8a02bf2 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/variable/DebuggerVariableViewerProvider.java
@@ -117,7 +117,6 @@ public class DebuggerVariableViewerProvider extends ComponentProviderAdapter
private CompletableFuture<List<AbstractDebuggerVariableViewerVarValue>> currentFuture;
private DebuggerVariableActionContext myActionContext;
- ToggleDockingAction actionEnableEdits;
MultiStateDockingAction<VariableViewerStates> actionShowVariables;
@SuppressWarnings("unused")
@@ -170,14 +169,6 @@ public class DebuggerVariableViewerProvider extends ComponentProviderAdapter
component = panel;
- actionEnableEdits = DebuggerResources.EnableEditsAction.builder(plugin)
- .enabledWhen(
- c -> currentCoordinates != null && currentCoordinates.getTrace() != null)
- .onAction(c -> {
- })
- .helpLocation(new HelpLocation("DebuggerVariableViewerPlugin", "enable_edits"))
- .buildAndInstallLocal(this);
-
actionShowVariables =
new MultiStateActionBuilder<VariableViewerStates>("Show/hide variables",
this.getName()).onActionStateChanged((a, e) -> model.reload())
@@ -454,4 +445,8 @@ public class DebuggerVariableViewerProvider extends ComponentProviderAdapter
})
.build());
}
+
+ public boolean isEditable() {
+ return controlService.getCurrentMode(currentCoordinates.getTrace()).isEditable();
+ }
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProvider.java
index 7417bbf7b7..1439a6932d 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProvider.java
@@ -35,7 +35,6 @@ import db.Transaction;
import docking.ActionContext;
import docking.WindowPosition;
import docking.action.DockingAction;
-import docking.action.ToggleDockingAction;
import docking.action.builder.ActionBuilder;
import docking.widgets.table.*;
import generic.theme.GColor;
@@ -394,7 +393,6 @@ public class DebuggerWatchesProvider extends ComponentProviderAdapter
protected GhidraTable watchTable;
protected GhidraTableFilterPanel<DefaultWatchRow> watchFilterPanel;
- ToggleDockingAction actionEnableEdits;
DockingAction actionApplyDataType;
DockingAction actionSelectRange;
DockingAction actionSelectAllReads;
@@ -533,11 +531,6 @@ public class DebuggerWatchesProvider extends ComponentProviderAdapter
}
protected void createActions() {
- actionEnableEdits = DebuggerResources.EnableEditsAction.builder(plugin)
- .enabledWhen(c -> current.getTrace() != null)
- .onAction(c -> {
- })
- .buildAndInstallLocal(this);
actionApplyDataType = ApplyDataTypeAction.builder(plugin)
.withContext(DebuggerWatchActionContext.class)
.enabledWhen(ctx -> current.getTrace() != null && selHasDataType(ctx))
@@ -1017,7 +1010,10 @@ public class DebuggerWatchesProvider extends ComponentProviderAdapter
}
public boolean isEditsEnabled() {
- return actionEnableEdits.isSelected();
+ if (currentTrace == null) {
+ return false;
+ }
+ return controlService.getCurrentMode(currentTrace).isEditable();
}
public void goToTime(TraceSchedule time) {
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServicePlugin.java
index 508300556c..6c553631be 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServicePlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServicePlugin.java
@@ -152,10 +152,11 @@ public class DebuggerControlServicePlugin extends AbstractDebuggerPlugin
}
@Override
- public void setCurrentMode(Trace trace, ControlMode newMode) {
+ public void setCurrentMode(Trace trace, ControlMode newMode, boolean canEdit) {
ControlMode oldMode;
synchronized (currentModes) {
oldMode = currentModes.getOrDefault(Objects.requireNonNull(trace), ControlMode.DEFAULT);
+ newMode.setEditable(canEdit);
if (newMode != oldMode) {
currentModes.put(trace, newMode);
}
@@ -221,4 +222,5 @@ public class DebuggerControlServicePlugin extends AbstractDebuggerPlugin
coordinatesActivated(ev.getActiveCoordinates(), ev.getCause());
}
}
+
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/AbstractEmulateAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/AbstractEmulateAction.java
new file mode 100644
index 0000000000..c49f01d7ea
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/AbstractEmulateAction.java
@@ -0,0 +1,106 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import docking.ActionContext;
+import docking.action.DockingAction;
+import docking.action.MenuData;
+import ghidra.app.context.ProgramLocationActionContext;
+import ghidra.app.services.CodeViewerService;
+import ghidra.framework.plugintool.PluginTool;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Program;
+import ghidra.program.util.ProgramLocation;
+import ghidra.util.HelpLocation;
+
+public abstract class AbstractEmulateAction extends DockingAction {
+ final DebuggerEmulationServicePlugin plugin;
+ final PluginTool tool;
+ final String compressedPath;
+ protected Program program;
+
+ public AbstractEmulateAction(DebuggerEmulationServicePlugin plugin, String name) {
+ this(plugin, name, null);
+ }
+
+ public AbstractEmulateAction(DebuggerEmulationServicePlugin plugin, String name,
+ Program program) {
+ super(name, plugin.getName());
+ this.plugin = plugin;
+ this.tool = plugin.getTool();
+ this.program = program;
+ MenuData menuData = computeMenuData();
+ setPopupMenuData(menuData);
+ String path = menuData.getMenuPathAsString();
+ compressedPath = path.replaceAll("\\.\\.\\.->", "").toLowerCase();
+ }
+
+ protected static String[] prependMenuPath(String pre, List<String> menuPath) {
+ return Stream.concat(Stream.of(pre), menuPath.stream()).toArray(String[]::new);
+ }
+
+ abstract MenuData computeMenuData();
+
+ String getTopGroup(Program currentProgram) {
+ return "";
+ }
+
+ String getTopOrder(Program currentProgram) {
+ return "";
+ }
+
+ public String getCompressedPath() {
+ return compressedPath;
+ }
+
+ protected Program getProgramFromContext(ActionContext context) {
+ if (context instanceof ProgramLocationActionContext plctx) {
+ return plctx.getProgram();
+ }
+ return program;
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ return true;
+ }
+
+ @Override
+ public abstract void actionPerformed(ActionContext context);
+
+ @Override
+ public abstract HelpLocation getHelpLocation();
+
+ protected ProgramLocation getCurrentLocation() {
+ CodeViewerService service = tool.getService(CodeViewerService.class);
+ if (service == null) {
+ return null;
+ }
+ return service.getCurrentLocation();
+ }
+
+ protected Address getCurrentAddress() {
+ ProgramLocation currentLocation = getCurrentLocation();
+ if (currentLocation == null) {
+ return null;
+ }
+ return currentLocation.getAddress();
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java
index f68cc4aab9..a83bf0167c 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePlugin.java
@@ -16,32 +16,23 @@
package ghidra.app.plugin.core.debug.service.emulation;
import java.io.IOException;
-import java.lang.invoke.MethodHandles;
import java.util.*;
-import java.util.Map.Entry;
import java.util.concurrent.*;
import java.util.stream.Collectors;
-
-import javax.swing.Icon;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
+import java.util.stream.Stream;
import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.jdom2.Element;
+import org.jdom2.JDOMException;
import db.Transaction;
-import docking.ActionContext;
-import docking.action.DockingAction;
+import docking.action.DockingActionIf;
import docking.action.ToggleDockingAction;
-import docking.action.builder.ActionBuilder;
-import docking.action.builder.ToggleActionBuilder;
-import ghidra.app.context.ProgramLocationActionContext;
import ghidra.app.events.ProgramActivatedPluginEvent;
import ghidra.app.events.ProgramClosedPluginEvent;
import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.core.debug.DebuggerPluginPackage;
import ghidra.app.plugin.core.debug.event.TraceClosedPluginEvent;
-import ghidra.app.plugin.core.debug.gui.DebuggerResources;
-import ghidra.app.plugin.core.debug.gui.emulation.DebuggerEmulateFunctionDialog;
import ghidra.app.plugin.core.debug.service.emulation.data.DefaultPcodeDebuggerAccess;
import ghidra.app.services.*;
import ghidra.async.AsyncLazyMap;
@@ -50,6 +41,7 @@ import ghidra.debug.api.emulation.EmulatorFactory;
import ghidra.debug.api.modules.DebuggerStaticMappingChangeListener;
import ghidra.debug.api.target.Target;
import ghidra.debug.api.tracemgr.DebuggerCoordinates;
+import ghidra.framework.model.DomainFile;
import ghidra.framework.options.SaveState;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.annotation.AutoConfigStateField;
@@ -63,25 +55,24 @@ import ghidra.pcode.exec.trace.TraceEmulationIntegration.Writer;
import ghidra.pcode.exec.trace.data.DefaultPcodeTraceAccess;
import ghidra.pcode.exec.trace.data.PcodeTraceAccess;
import ghidra.program.model.address.*;
-import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
-import ghidra.program.util.ProgramLocation;
-import ghidra.trace.model.*;
+import ghidra.program.model.listing.ProgramUserData;
+import ghidra.trace.model.Lifespan;
+import ghidra.trace.model.Trace;
import ghidra.trace.model.breakpoint.*;
import ghidra.trace.model.breakpoint.TraceBreakpointKind.CommonSet;
import ghidra.trace.model.guest.TracePlatform;
-import ghidra.trace.model.program.TraceProgramView;
import ghidra.trace.model.thread.TraceThread;
import ghidra.trace.model.time.TraceSnapshot;
import ghidra.trace.model.time.schedule.*;
import ghidra.trace.model.time.schedule.Scheduler.RunResult;
-import ghidra.util.HelpLocation;
import ghidra.util.Msg;
import ghidra.util.classfinder.ClassSearcher;
import ghidra.util.datastruct.ListenerSet;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.Task;
import ghidra.util.task.TaskMonitor;
+import ghidra.util.xml.XmlUtilities;
@PluginInfo(
shortDescription = "Debugger Emulation Service Plugin",
@@ -100,114 +91,17 @@ import ghidra.util.task.TaskMonitor;
},
servicesProvided = {
DebuggerEmulationService.class
- })
-public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEmulationService {
- protected static final int MAX_CACHE_SIZE = 5;
-
- private static final AutoConfigState.ClassHandler<
- DebuggerEmulationServicePlugin> CONFIG_STATE_HANDLER =
- AutoConfigState.wireHandler(DebuggerEmulationServicePlugin.class,
- MethodHandles.lookup());
-
- public interface EmulateProgramAction {
- String NAME = "Emulate Program in new Trace";
- String DESCRIPTION = "Emulate the current program in a new trace starting at the cursor";
- Icon ICON = DebuggerResources.ICON_EMULATE;
- String GROUP = DebuggerResources.GROUP_GENERAL;
- String HELP_ANCHOR = "emulate_program";
-
- static ActionBuilder builder(Plugin owner) {
- String ownerName = owner.getName();
- return new ActionBuilder(NAME, ownerName)
- .description(DESCRIPTION)
- .toolBarIcon(ICON)
- .toolBarGroup(GROUP)
- .menuPath(DebuggerPluginPackage.NAME, NAME)
- .menuIcon(ICON)
- .menuGroup(GROUP)
- .popupMenuPath(NAME)
- .popupMenuIcon(ICON)
- .popupMenuGroup(GROUP)
- .helpLocation(new HelpLocation(ownerName, HELP_ANCHOR));
- }
- }
-
- interface EmulateFunctionAction {
- String NAME = "Emulate Function";
- String DESCRIPTION = "Emulate the current function in a new trace";
- Icon ICON = DebuggerResources.ICON_EMULATE;
- String GROUP = DebuggerResources.GROUP_GENERAL;
- String HELP_ANCHOR = "emulate_function";
-
- static ActionBuilder builder(Plugin owner) {
- String ownerName = owner.getName();
- return new ActionBuilder(NAME, ownerName)
- .description(DESCRIPTION)
- .menuPath(DebuggerPluginPackage.NAME, NAME)
- .menuIcon(ICON)
- .menuGroup(GROUP)
- .popupMenuPath(NAME)
- .popupMenuIcon(ICON)
- .popupMenuGroup(GROUP)
- .helpLocation(new HelpLocation(ownerName, HELP_ANCHOR));
- }
- }
-
- interface EmulateAddThreadAction {
- String NAME = "Add Emulated Thread to Trace";
- String DESCRIPTION = "Add an emulated thread to the current trace starting here";
- Icon ICON = DebuggerResources.ICON_THREAD;
- String GROUP = DebuggerResources.GROUP_GENERAL;
- String HELP_ANCHOR = "add_emulated_thread";
-
- static ActionBuilder builder(Plugin owner) {
- String ownerName = owner.getName();
- return new ActionBuilder(NAME, ownerName)
- .description(DESCRIPTION)
- .menuPath(DebuggerPluginPackage.NAME, NAME)
- .menuIcon(ICON)
- .menuGroup(GROUP)
- .popupMenuPath(NAME)
- .popupMenuIcon(ICON)
- .popupMenuGroup(GROUP)
- .helpLocation(new HelpLocation(ownerName, HELP_ANCHOR));
- }
- }
-
- interface ConfigureEmulatorAction {
- String NAME = "Configure Emulator";
- String DESCRIPTION = "Choose and configure the current emulator";
- String GROUP = DebuggerResources.GROUP_GENERAL;
- String HELP_ANCHOR = "configure_emulator";
-
- static ToggleActionBuilder builder(Plugin owner) {
- String ownerName = owner.getName();
- return new ToggleActionBuilder(NAME, ownerName)
- .description(DESCRIPTION)
- .menuGroup(GROUP)
- .helpLocation(new HelpLocation(ownerName, HELP_ANCHOR));
- }
}
+)
+public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEmulationService {
+ protected static final String KEY_DBGEMU = "DBGEMU";
+ protected static final String PREFIX_DBGEMU = "DBGEMU";
+ protected static final String KEY_LAST = "last";
- interface InvalidateEmulatorCacheAction {
- String NAME = "Invalidate Emulator Cache";
- String DESCRIPTION =
- "Prevent the emulation service from using cached snapshots from the current trace";
- String GROUP = DebuggerResources.GROUP_MAINTENANCE;
- String HELP_ANCHOR = "invalidate_cache";
-
- static ActionBuilder builder(Plugin owner) {
- String ownerName = owner.getName();
- return new ActionBuilder(NAME, ownerName)
- .description(DESCRIPTION)
- .menuPath(DebuggerPluginPackage.NAME, ConfigureEmulatorAction.NAME, NAME)
- .menuGroup(GROUP)
- .helpLocation(new HelpLocation(ownerName, HELP_ANCHOR));
- }
- }
+ protected static final int MAX_CACHE_SIZE = 5;
protected static class CacheKey implements Comparable<CacheKey> {
- // TODO: Should key on platform, not trace
+
protected final Trace trace;
protected final TracePlatform platform;
protected final TraceSchedule time;
@@ -333,8 +227,8 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
protected final NavigableMap<CacheKey, CachedEmulator> cache = new TreeMap<>();
protected final AsyncLazyMap<CacheKey, Long> requests =
new AsyncLazyMap<>(new HashMap<>(), this::doBackgroundEmulate)
- .forgetErrors((key, t) -> true)
- .forgetValues((key, l) -> true);
+ .forgetErrors((_, _) -> true)
+ .forgetValues((_, _) -> true);
protected final Map<CachedEmulator, Integer> busy = new LinkedHashMap<>();
protected final ListenerSet<EmulatorStateListener> stateListeners =
new ListenerSet<>(EmulatorStateListener.class, true);
@@ -393,17 +287,28 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
private DebuggerStaticMappingService staticMappings;
@AutoServiceConsumed
private DebuggerControlService controlService;
+ @AutoServiceConsumed
+ private EmulationTaintInjectionService taintService;
@SuppressWarnings("unused")
private AutoService.Wiring autoServiceWiring;
- DockingAction actionEmulateProgram;
- DockingAction actionEmulateFunction;
- DockingAction actionEmulateAddThread;
- DockingAction actionInvalidateCache;
+ String EMULATE_PROGRAM = "Emulate Program";
+ String EMULATE_TARGET = "Emulate Target";
+ String EMULATE_FUNCTION = "Emulate Function";
+ String ADD_THREAD = "Add Emulated Thread to Trace";
+ String INVALIDATE_CACHE = "Invalidate Emulator Cache";
+
Map<Class<? extends EmulatorFactory>, ToggleDockingAction> actionsChooseEmulatorFactory =
new HashMap<>();
+ private Map<String, EmulatorFactory> emulatorMap = new HashMap<>();
- final ChangeListener classChangeListener = this::classesChanged;
+ protected EmulateMultiAction emulateAction;
+ // We add these to the tool independently as menu items with a null
+ // program to signal viewer dependent behavior
+ protected EmulateProgramAction emulateProgramAction;
+ protected EmulateFunctionAction emulateFunctionAction;
+
+ protected SaveState toolLaunchConfigs = new SaveState();
public DebuggerEmulationServicePlugin(PluginTool tool) {
super(tool);
@@ -417,231 +322,38 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
}
protected void createActions() {
- actionEmulateProgram = EmulateProgramAction.builder(this)
- .withContext(ProgramLocationActionContext.class)
- .enabledWhen(this::emulateProgramEnabled)
- .popupWhen(this::emulateProgramEnabled)
- .onAction(this::emulateProgramActivated)
- .buildAndInstall(tool);
- actionEmulateFunction = EmulateFunctionAction.builder(this)
- .withContext(ProgramLocationActionContext.class)
- .enabledWhen(this::emulateFunctionEnabled)
- .popupWhen(this::emulateFunctionEnabled)
- .onAction(this::emulateFunctionActivated)
- .buildAndInstall(tool);
- actionEmulateAddThread = EmulateAddThreadAction.builder(this)
- .withContext(ProgramLocationActionContext.class)
- .enabledWhen(this::emulateAddThreadEnabled)
- .popupWhen(this::emulateAddThreadEnabled)
- .onAction(this::emulateAddThreadActivated)
- .buildAndInstall(tool);
- actionInvalidateCache = InvalidateEmulatorCacheAction.builder(this)
- .enabledWhen(this::invalidateCacheEnabled)
- .onAction(this::invalidateCacheActivated)
- .buildAndInstall(tool);
- ClassSearcher.addChangeListener(classChangeListener);
- updateConfigureEmulatorStates();
- }
-
- private void classesChanged(ChangeEvent e) {
- updateConfigureEmulatorStates();
- }
-
- private ToggleDockingAction createActionChooseEmulator(EmulatorFactory factory) {
- ToggleDockingAction action = ConfigureEmulatorAction.builder(this)
- .menuPath(DebuggerPluginPackage.NAME, ConfigureEmulatorAction.NAME,
- factory.getTitle())
- .onAction(ctx -> configureEmulatorActivated(factory))
- .buildAndInstall(tool);
- String[] path = action.getMenuBarData().getMenuPath();
- tool.setMenuGroup(Arrays.copyOf(path, path.length - 1), "zz");
- return action;
- }
-
- private void updateConfigureEmulatorStates() {
- Map<Class<? extends EmulatorFactory>, EmulatorFactory> byClass =
- getEmulatorFactories().stream()
- .collect(Collectors.toMap(EmulatorFactory::getClass, Objects::requireNonNull));
- Iterator<Entry<Class<? extends EmulatorFactory>, ToggleDockingAction>> it =
- actionsChooseEmulatorFactory.entrySet().iterator();
- while (it.hasNext()) {
- Entry<Class<? extends EmulatorFactory>, ToggleDockingAction> ent = it.next();
- if (!byClass.keySet().contains(ent.getKey())) {
- tool.removeAction(ent.getValue());
- }
- }
- for (Entry<Class<? extends EmulatorFactory>, EmulatorFactory> ent : byClass.entrySet()) {
- if (!actionsChooseEmulatorFactory.containsKey(ent.getKey())) {
- ToggleDockingAction action = createActionChooseEmulator(ent.getValue());
- action.setSelected(ent.getKey() == emulatorFactory.getClass());
- actionsChooseEmulatorFactory.put(ent.getKey(), action);
- }
- }
- }
-
- private boolean emulateProgramEnabled(ProgramLocationActionContext ctx) {
- Program program = ctx.getProgram();
- // To avoid confusion of "forked from trace," only permit action from static context
- if (program == null || program instanceof TraceProgramView) {
- return false;
- }
- /*MemoryBlock block = program.getMemory().getBlock(ctx.getAddress());
- if (!block.isExecute()) {
- return false;
- }*/
- return true;
- }
+ emulateAction = new EmulateMultiAction(this);
+ tool.addAction(emulateAction);
- private void emulateProgramActivated(ProgramLocationActionContext ctx) {
- Program program = ctx.getProgram();
- if (program == null) {
- return;
- }
- Trace trace = null;
- try {
- trace = ProgramEmulationUtils.launchEmulationTrace(program, ctx.getAddress(), this);
- traceManager.openTrace(trace);
- traceManager.activateTrace(trace);
- if (controlService != null) {
- controlService.setCurrentMode(trace, ControlMode.RW_EMULATOR);
- }
- }
- catch (IOException e) {
- Msg.showError(this, null, actionEmulateProgram.getDescription(),
- "Could not create trace for emulation", e);
- }
- finally {
- if (trace != null) {
- trace.release(this);
- }
- }
- }
-
- private boolean emulateFunctionEnabled(ProgramLocationActionContext ctx) {
- Program program = ctx.getProgram();
- Address address = ctx.getAddress();
- if (program == null || program instanceof TraceProgramView || address == null) {
- return false;
- }
- Function function = program.getFunctionManager().getFunctionContaining(address);
- if (function == null) {
- return false;
- }
- return true;
- }
-
- private void emulateFunctionActivated(ProgramLocationActionContext ctx) {
- Program program = ctx.getProgram();
- Address address = ctx.getAddress();
- if (program == null || address == null) {
- return;
- }
- Function function = program.getFunctionManager().getFunctionContaining(address);
- if (function == null) {
- return;
- }
- tool.showDialog(new DebuggerEmulateFunctionDialog(tool, function));
- }
-
- private boolean emulateAddThreadEnabled(ProgramLocationActionContext ctx) {
- Program programOrView = ctx.getProgram();
- if (programOrView instanceof TraceProgramView view) {
- if (!ProgramEmulationUtils.isEmulatedProgram(view.getTrace())) {
- return false;
- }
- /*MemoryBlock block = view.getMemory().getBlock(ctx.getAddress());
- return block.isExecute();*/
- return true;
- }
+ emulateProgramAction = new EmulateProgramAction(this, null);
+ tool.addAction(emulateProgramAction);
- // Action was probably activated in a static listing.
- // Bail if current trace is not emulated. Otherwise map and check region.
- DebuggerCoordinates current = traceManager.getCurrent();
- if (current.getTrace() == null ||
- !ProgramEmulationUtils.isEmulatedProgram(current.getTrace())) {
- return false;
- }
- ProgramLocation programLoc = ctx.getLocation();
- if (programLoc == null) {
- return false;
- }
- TraceLocation traceLoc = staticMappings.getOpenMappedLocation(
- current.getTrace(), programLoc, current.getSnap());
- if (traceLoc == null) {
- return false;
- }
- /*TraceMemoryRegion region = current.getTrace()
- .getMemoryManager()
- .getRegionContaining(current.getSnap(), traceLoc.getAddress());
- return region != null && region.isExecute();*/
- return true;
+ emulateFunctionAction = new EmulateFunctionAction(this, null);
+ tool.addAction(emulateFunctionAction);
}
- private void emulateAddThreadActivated(ProgramLocationActionContext ctx) {
- Program programOrView = ctx.getProgram();
- if (programOrView instanceof TraceProgramView view) {
- Trace trace = view.getTrace();
- Address tracePc = ctx.getAddress();
+ protected void tryEmulatorFromMode(Trace trace) {
+ if (controlService != null && trace != null) {
+ ControlMode mode = controlService.getCurrentMode(trace);
+ emulatorFactory = emulatorMap.get(mode.name);
- /*MemoryBlock block = view.getMemory().getBlock(tracePc);
- if (!block.isExecute()) {
- return;
- }*/
-
- long snap =
- view.getViewport().getOrderedSnaps().stream().filter(s -> s >= 0).findFirst().get();
- ProgramLocation progLoc = staticMappings.getOpenMappedLocation(
- new DefaultTraceLocation(trace, null, Lifespan.at(snap), tracePc));
- Program program = progLoc == null ? null : progLoc.getProgram();
- Address programPc = progLoc == null ? null : progLoc.getAddress();
-
- TraceThread thread = ProgramEmulationUtils.launchEmulationThread(trace, snap, program,
- tracePc, programPc);
- traceManager.activateThread(thread);
- }
- else {
- Program program = programOrView;
- Address programPc = ctx.getAddress();
-
- DebuggerCoordinates current = traceManager.getCurrent();
- long snap = current.getSnap();
- Trace trace = current.getTrace();
- TraceLocation traceLoc =
- staticMappings.getOpenMappedLocation(trace, ctx.getLocation(), snap);
- if (traceLoc == null) {
+ if (emulatorFactory == null) {
+ mode = ControlMode.EMULATOR;
+ emulatorFactory = new DefaultEmulatorFactory();
+ defaultEmulator = emulatorFactory.getTitle();
+ controlService.setCurrentMode(trace, mode, mode.isEditable());
return;
}
- Address tracePc = traceLoc.getAddress();
- /*TraceMemoryRegion region =
- trace.getMemoryManager().getRegionContaining(snap, tracePc);
- if (region == null || !region.isExecute()) {
- return;
- }*/
- TraceThread thread = ProgramEmulationUtils.launchEmulationThread(trace, snap, program,
- tracePc, programPc);
- traceManager.activateThread(thread);
+ defaultEmulator = emulatorFactory.getTitle();
}
}
- private boolean invalidateCacheEnabled(ActionContext ignored) {
- return traceManager.getCurrentTrace() != null;
- }
-
- private void invalidateCacheActivated(ActionContext ignored) {
- invalidateCache();
- }
-
- private void configureEmulatorActivated(EmulatorFactory factory) {
- // TODO: Pull up config page. Tool Options? Program/Trace Options?
- setEmulatorFactory(factory);
- }
-
@Override
public void invalidateCache() {
DebuggerCoordinates current = traceManager.getCurrent();
Trace trace = current.getTrace();
long version = trace.getEmulatorCacheVersion();
- try (Transaction tx = trace.openTransaction("Invalidate Emulator Cache")) {
+ try (Transaction _ = trace.openTransaction("Invalidate Emulator Cache")) {
trace.setEmulatorCacheVersion(version + 1);
}
// Do not call clearUndo() here. This is supposed to be undoable.
@@ -660,6 +372,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
public synchronized void setEmulatorFactory(EmulatorFactory factory) {
emulatorFactory = Objects.requireNonNull(factory);
defaultEmulator = emulatorFactory.getTitle();
+ emulatorMap.put(defaultEmulator, factory);
for (ToggleDockingAction toggle : actionsChooseEmulatorFactory.values()) {
toggle.setSelected(false);
}
@@ -754,6 +467,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
Trace trace = key.trace;
TracePlatform platform = key.platform;
TraceSchedule time = key.time;
+ tryEmulatorFromMode(trace);
TraceSnapshot tracePrefix = trace.getTimeManager().findSnapshotWithNearestPrefix(time);
if (tracePrefix != null && tracePrefix.isSnapOnly(true)) {
@@ -779,6 +493,9 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
emu.clearAllInjects();
emu.clearAccessBreakpoints();
emu.setSuspended(false);
+ if (taintService != null) {
+ taintService.injectTaint(be.ce.emulator());
+ }
installBreakpoints(key.trace, key.time.getSnap(), be.ce.emulator());
monitor.initialize(time.totalTickCount() - prevKey.time.totalTickCount());
@@ -796,6 +513,9 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
PcodeMachine<?> emu = emulatorFactory.create(from, writer);
try (BusyEmu be = new BusyEmu(new CachedEmulator(key.trace, emu, writer))) {
+ if (taintService != null) {
+ taintService.injectTaint(be.ce.emulator());
+ }
installBreakpoints(key.trace, key.time.getSnap(), be.ce.emulator());
monitor.initialize(time.totalTickCount() -
(tracePrefix != null ? tracePrefix.getSchedule().totalTickCount() : 0));
@@ -829,7 +549,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
protected TraceSnapshot writeToScratch(CacheKey key, CachedEmulator ce) {
TraceSnapshot destSnap;
- try (Transaction tx = key.trace.openTransaction("Emulate")) {
+ try (Transaction _ = key.trace.openTransaction("Emulate")) {
destSnap = key.trace.getTimeManager().findScratchSnapshot(key.time);
destSnap.setDescription("Emulated");
try {
@@ -885,7 +605,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
// Cause object-register support to copy values into new register spaces
// TODO: I wish this were not necessary
monitor.setMessage("Creating register spaces");
- try (Transaction tx = trace.openTransaction("Prepare emulation")) {
+ try (Transaction _ = trace.openTransaction("Prepare emulation")) {
for (TraceThread thread : time.getThreads(trace)) {
trace.getMemoryManager().getMemoryRegisterSpace(thread, 0, true);
}
@@ -960,6 +680,7 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
public EmulationResult run(TracePlatform platform, TraceSchedule from, TaskMonitor monitor,
Scheduler scheduler) throws CancelledException {
Trace trace = platform.getTrace();
+ tryEmulatorFromMode(trace);
requireOpen(trace);
return doRun(new CacheKey(platform, from), monitor, scheduler);
}
@@ -1014,18 +735,167 @@ public class DebuggerEmulationServicePlugin extends Plugin implements DebuggerEm
}
}
+ protected void executeTask(Task task) {
+ ProgressService progressService = tool.getService(ProgressService.class);
+ if (progressService != null) {
+ progressService.execute(task);
+ }
+ else {
+ tool.execute(task);
+ }
+ }
+
+ protected static String getProgramName(Program program) {
+ if (program == null) {
+ return "";
+ }
+ DomainFile df = program.getDomainFile();
+ if (df != null) {
+ return df.getName();
+ }
+ return program.getName();
+ }
+
@Override
public void readConfigState(SaveState saveState) {
- CONFIG_STATE_HANDLER.readConfigState(this, saveState);
-
- for (ToggleDockingAction toggle : actionsChooseEmulatorFactory.values()) {
- toggle.setSelected(toggle.getMenuBarData().getMenuItemName().equals(defaultEmulator));
+ super.readConfigState(saveState);
+ SaveState read = saveState.getSaveState(KEY_DBGEMU);
+ if (read != null) {
+ toolLaunchConfigs = read;
}
}
@Override
public void writeConfigState(SaveState saveState) {
- CONFIG_STATE_HANDLER.writeConfigState(this, saveState);
+ super.writeConfigState(saveState);
+ if (toolLaunchConfigs != null) {
+ saveState.putSaveState(KEY_DBGEMU, toolLaunchConfigs);
+ }
+ }
+
+ protected SaveState readProgramLaunchConfig(Program program, String actionName,
+ boolean forPrompt) {
+ SaveState state = readToolLaunchConfig(actionName);
+ if (program == null) {
+ return state;
+ }
+ ProgramUserData userData = program.getProgramUserData();
+ String property = userData.getStringProperty(PREFIX_DBGEMU + actionName, null);
+ if (property == null) {
+ return state;
+ }
+ try {
+ Element element = XmlUtilities.fromString(property);
+ return new SaveState(element);
+ }
+ catch (JDOMException | IOException e) {
+ if (forPrompt) {
+ Msg.error(this,
+ "Saved launcher args are corrupt, or launcher parameters changed. Defaulting.",
+ e);
+ return state;
+ }
+ throw new RuntimeException(
+ "Saved launcher args are corrupt, or launcher parameters changed. Not launching.",
+ e);
+ }
+ }
+
+ protected SaveState readToolLaunchConfig(String actionName) {
+ if (!toolLaunchConfigs.hasValue(actionName)) {
+ return new SaveState();
+ }
+ return toolLaunchConfigs.getSaveState(actionName);
+ }
+
+ protected void writeProgramLaunchConfig(Program program, String actionName, SaveState state) {
+ if (program == null) {
+ writeToolLaunchConfig(actionName, state);
+ return;
+ }
+ ProgramUserData userData = program.getProgramUserData();
+ state.putLong(KEY_LAST, System.currentTimeMillis());
+ try (Transaction _ = userData.openTransaction()) {
+ Element element = state.saveToXml();
+ userData.setStringProperty(PREFIX_DBGEMU + actionName, XmlUtilities.toString(element));
+ }
+ }
+
+ protected void writeToolLaunchConfig(String actionName, SaveState state) {
+ state.putLong(KEY_LAST, System.currentTimeMillis());
+ toolLaunchConfigs.putSaveState(actionName, state);
+ }
+
+ protected record ConfigLast(String configName, long last, Program program) {}
+
+ protected ConfigLast checkSavedConfig(Program program, ProgramUserData userData,
+ String propName) {
+ if (!propName.startsWith(PREFIX_DBGEMU)) {
+ return null;
+ }
+ String configName = propName.substring(PREFIX_DBGEMU.length());
+ String propVal = Objects.requireNonNull(
+ userData.getStringProperty(propName, null));
+ Element element;
+ try {
+ element = XmlUtilities.fromString(propVal);
+ }
+ catch (JDOMException | IOException e) {
+ Msg.error(this, "Could not load launcher config for " + configName + ": " + e, e);
+ return null;
+ }
+ return checkSavedConfig(program, configName, new SaveState(element));
+ }
+
+ protected ConfigLast checkSavedConfig(Program program, String saveName, SaveState state) {
+ if (!state.hasValue(KEY_LAST)) {
+ return null;
+ }
+ return new ConfigLast(saveName, state.getLong(KEY_LAST, 0), program);
+ }
+
+ protected Stream<ConfigLast> streamSavedConfigs(Program program) {
+ if (program == null) {
+ return Stream.of(toolLaunchConfigs.getNames())
+ .map(n -> checkSavedConfig(null, n, toolLaunchConfigs.getSaveState(n)))
+ .filter(c -> c != null);
+ }
+ ProgramUserData userData = program.getProgramUserData();
+ return userData.getStringPropertyNames()
+ .stream()
+ .map(n -> checkSavedConfig(program, userData, n))
+ .filter(c -> c != null);
+ }
+
+ protected ConfigLast findMostRecentConfig() {
+ return Stream.concat(Stream.of(tool.getService(ProgramManager.class).getAllOpenPrograms())
+ .flatMap(this::streamSavedConfigs),
+ this.streamSavedConfigs(null))
+ .max(Comparator.comparing(c -> c.last))
+ .orElse(null);
+ }
+
+ protected Map<String, Long> loadSavedConfigs(Program program) {
+ return streamSavedConfigs(program)
+ .collect(Collectors.toMap(c -> c.configName(), c -> c.last()));
+ }
+
+ public DebuggerTraceManagerService getTraceManager() {
+ return traceManager;
+ }
+
+ public DebuggerStaticMappingService getStaticMappings() {
+ return staticMappings;
+ }
+
+ DockingActionIf getAction(String actionName) {
+ List<DockingActionIf> actionList = emulateAction.getRestrictedActionList();
+ for (DockingActionIf a : actionList) {
+ if (a.getName().equals(actionName)) {
+ return a;
+ }
+ }
+ return null;
}
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateAddThreadAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateAddThreadAction.java
new file mode 100644
index 0000000000..325868cdee
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateAddThreadAction.java
@@ -0,0 +1,169 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import java.util.List;
+
+import docking.ActionContext;
+import docking.action.MenuData;
+import ghidra.app.context.ProgramLocationActionContext;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.services.DebuggerStaticMappingService;
+import ghidra.app.services.DebuggerTraceManagerService;
+import ghidra.debug.api.tracemgr.DebuggerCoordinates;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Program;
+import ghidra.program.util.ProgramLocation;
+import ghidra.trace.model.*;
+import ghidra.trace.model.program.TraceProgramView;
+import ghidra.trace.model.thread.TraceThread;
+import ghidra.util.HelpLocation;
+
+public class EmulateAddThreadAction extends AbstractEmulateAction {
+
+ public EmulateAddThreadAction(DebuggerEmulationServicePlugin plugin) {
+ super(plugin, plugin.ADD_THREAD, null);
+ }
+
+ @Override
+ MenuData computeMenuData() {
+ return new MenuData(
+ prependMenuPath("Add an emulated thread", List.of()),
+ DebuggerResources.ICON_THREAD, DebuggerResources.GROUP_GENERAL, 0, "c");
+ }
+
+ @Override
+ String getTopGroup(Program currentProgram) {
+ return "4";
+ }
+
+ @Override
+ String getTopOrder(Program currentProgram) {
+ return program == currentProgram ? "1" : "2";
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ if (!(context instanceof ProgramLocationActionContext plctx)) {
+ return false;
+ }
+ Program programOrView = plctx.getProgram();
+ if (programOrView instanceof TraceProgramView view) {
+ if (!ProgramEmulationUtils.isEmulatedProgram(view.getTrace())) {
+ return false;
+ }
+ /*MemoryBlock block = view.getMemory().getBlock(ctx.getAddress());
+ return block.isExecute();*/
+ return true;
+ }
+
+ DebuggerTraceManagerService traceManager = plugin.getTraceManager();
+ DebuggerStaticMappingService staticMappings = plugin.getStaticMappings();
+ if (traceManager == null || staticMappings == null) {
+ return false;
+ }
+
+ // Action was probably activated in a static listing.
+ // Bail if current trace is not emulated. Otherwise map and check region.
+ DebuggerCoordinates current = traceManager.getCurrent();
+ if (current.getTrace() == null ||
+ !ProgramEmulationUtils.isEmulatedProgram(current.getTrace())) {
+ return false;
+ }
+ ProgramLocation programLoc = getCurrentLocation();
+ if (programLoc == null) {
+ return false;
+ }
+ TraceLocation traceLoc = staticMappings.getOpenMappedLocation(
+ current.getTrace(), programLoc, current.getSnap());
+ if (traceLoc == null) {
+ return false;
+ }
+ /*TraceMemoryRegion region = current.getTrace()
+ .getMemoryManager()
+ .getRegionContaining(current.getSnap(), traceLoc.getAddress());
+ return region != null && region.isExecute();*/
+ return true;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ if (!(context instanceof ProgramLocationActionContext plctx)) {
+ return;
+ }
+ Program programOrView = plctx.getProgram();
+ DebuggerTraceManagerService traceManager = plugin.getTraceManager();
+ DebuggerStaticMappingService staticMappings = plugin.getStaticMappings();
+ if (traceManager == null || staticMappings == null) {
+ return;
+ }
+
+ ProgramLocation loc = getCurrentLocation();
+ Address pc = getCurrentAddress();
+ if (pc == null) {
+ return;
+ }
+
+ if (programOrView instanceof TraceProgramView view) {
+ Trace trace = view.getTrace();
+
+ /*MemoryBlock block = view.getMemory().getBlock(tracePc);
+ if (!block.isExecute()) {
+ return;
+ }*/
+
+ long snap = view.getViewport()
+ .getOrderedSnaps()
+ .stream()
+ .filter(s -> s >= 0)
+ .findFirst()
+ .orElse(0L);
+ ProgramLocation progLoc = staticMappings.getOpenMappedLocation(
+ new DefaultTraceLocation(trace, null, Lifespan.at(snap), pc));
+ Program program = progLoc == null ? null : progLoc.getProgram();
+ Address programPc = progLoc == null ? null : progLoc.getAddress();
+
+ TraceThread thread = ProgramEmulationUtils.launchEmulationThread(trace, snap, program,
+ pc, programPc);
+ traceManager.activateThread(thread);
+ }
+ else {
+ DebuggerCoordinates current = traceManager.getCurrent();
+ long snap = current.getSnap();
+ Trace trace = current.getTrace();
+ TraceLocation traceLoc =
+ staticMappings.getOpenMappedLocation(trace, loc, snap);
+ if (traceLoc == null) {
+ return;
+ }
+ Address tracePc = traceLoc.getAddress();
+ /*TraceMemoryRegion region =
+ trace.getMemoryManager().getRegionContaining(snap, tracePc);
+ if (region == null || !region.isExecute()) {
+ return;
+ }*/
+ TraceThread thread = ProgramEmulationUtils.launchEmulationThread(trace, snap,
+ programOrView, tracePc, pc);
+ traceManager.activateThread(thread);
+ }
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(plugin.getName(), "add_emulated_thread");
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateFunctionAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateFunctionAction.java
new file mode 100644
index 0000000000..ed3f160a8c
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateFunctionAction.java
@@ -0,0 +1,103 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import java.util.List;
+
+import docking.ActionContext;
+import docking.action.MenuData;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.plugin.core.debug.gui.emulation.DebuggerEmulateFunctionDialog;
+import ghidra.app.services.CodeViewerService;
+import ghidra.framework.options.SaveState;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.*;
+import ghidra.program.util.ProgramLocation;
+import ghidra.trace.model.program.TraceProgramView;
+import ghidra.util.HelpLocation;
+
+public class EmulateFunctionAction extends AbstractEmulateAction {
+
+ public EmulateFunctionAction(DebuggerEmulationServicePlugin plugin) {
+ super(plugin, plugin.EMULATE_FUNCTION);
+ }
+
+ public EmulateFunctionAction(DebuggerEmulationServicePlugin plugin, Program program) {
+ super(plugin, plugin.EMULATE_FUNCTION, program);
+ }
+
+ @Override
+ MenuData computeMenuData() {
+ CodeViewerService service = tool.getService(CodeViewerService.class);
+ String current = "current function";
+ if (service != null) {
+ ProgramLocation loc = service.getCurrentLocation();
+ if (loc != null) {
+ FunctionManager functionManager = loc.getProgram().getFunctionManager();
+ Function f = functionManager.getFunctionContaining(loc.getAddress());
+ if (f != null) {
+ current = f.getName();
+ }
+ }
+ }
+ return new MenuData(
+ prependMenuPath("Emulate %s".formatted(current), List.of()),
+ DebuggerResources.ICON_EMULATE, DebuggerResources.GROUP_GENERAL, 0, "a3");
+ }
+
+ @Override
+ String getTopGroup(Program currentProgram) {
+ return "1";
+ }
+
+ @Override
+ String getTopOrder(Program currentProgram) {
+ return "3";
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ Address address = getCurrentAddress();
+ if (program == null || program instanceof TraceProgramView || address == null) {
+ return false;
+ }
+ Function function = program.getFunctionManager().getFunctionContaining(address);
+ if (function == null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ SaveState state = new SaveState();
+ plugin.writeProgramLaunchConfig(program, this.getName(), state);
+ Address address = getCurrentAddress();
+ if (program == null || address == null) {
+ return;
+ }
+ Function function = program.getFunctionManager().getFunctionContaining(address);
+ if (function == null) {
+ return;
+ }
+ tool.showDialog(new DebuggerEmulateFunctionDialog(tool, function));
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(plugin.getName(), "emulate_function");
+ }
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateMultiAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateMultiAction.java
new file mode 100644
index 0000000000..ee294c9896
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateMultiAction.java
@@ -0,0 +1,165 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import static ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin.*;
+
+import java.util.*;
+import java.util.stream.Stream;
+
+import javax.swing.*;
+
+import docking.ActionContext;
+import docking.PopupMenuHandler;
+import docking.action.*;
+import docking.menu.*;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.plugin.core.debug.gui.listing.DebuggerListingActionContext;
+import ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin.ConfigLast;
+import ghidra.app.services.ProgramManager;
+import ghidra.program.model.listing.Program;
+import ghidra.util.HelpLocation;
+import ghidra.util.Swing;
+
+public class EmulateMultiAction extends MultiActionDockingAction {
+ public static final String NAME = "Emulate";
+ public static final Icon ICON = DebuggerResources.ICON_EMULATE;
+ public static final String GROUP = DebuggerResources.GROUP_GENERAL;
+ public static final String HELP_ANCHOR = "emulate_program";
+
+ private final DebuggerEmulationServicePlugin plugin;
+ private MenuActionDockingToolbarButton button;
+
+ public EmulateMultiAction(DebuggerEmulationServicePlugin plugin) {
+ super(NAME, plugin.getName());
+ this.plugin = plugin;
+ setToolBarData(new ToolBarData(ICON, GROUP, "B"));
+ setHelpLocation(new HelpLocation(plugin.getName(), HELP_ANCHOR));
+ }
+
+ protected static String[] prependMenuPath(String pre, List<String> menuPath) {
+ return Stream.concat(Stream.of(pre), menuPath.stream()).toArray(String[]::new);
+ }
+
+ public void collectActionsForProgram(List<DockingActionIf> actions, Program program) {
+ actions.add(new EmulateProgramAction(plugin, program));
+ actions.add(new EmulateTargetAction(plugin, program));
+ actions.add(new EmulateFunctionAction(plugin, program));
+ }
+
+ @Override
+ public List<DockingActionIf> getActionList(ActionContext context) {
+ List<DockingActionIf> actions = getRestrictedActionList();
+ if (context instanceof DebuggerListingActionContext plctx) {
+ actions.add(new EmulateTargetAction(plugin, plctx.getProgram()));
+ }
+ ConfigLast last = plugin.findMostRecentConfig();
+ if (last != null) {
+ actions.add(new TopEmulateAction(plugin, last.configName(), last.program()));
+ }
+ return actions;
+ }
+
+ List<DockingActionIf> getRestrictedActionList() {
+ ProgramManager programManager = plugin.getTool().getService(ProgramManager.class);
+ List<Program> allPrograms = List.of(programManager.getAllOpenPrograms());
+ List<DockingActionIf> actions = new ArrayList<>();
+ for (Program program : allPrograms) {
+ collectActionsForProgram(actions, program);
+ }
+ actions.add(new EmulateAddThreadAction(plugin));
+ actions.add(new InvalidateEmulatorCacheAction(plugin));
+ return actions;
+ }
+
+ class MenuActionDockingToolbarButton extends MultipleActionDockingToolbarButton {
+ public MenuActionDockingToolbarButton(MultiActionDockingActionIf action) {
+ super(action);
+ }
+
+ @Override
+ protected JPopupMenu doCreateMenu() {
+ ProgramManager programManager = plugin.getTool().getService(ProgramManager.class);
+ Program currentProgram =
+ programManager == null ? null : programManager.getCurrentProgram();
+ ActionContext context = getActionContext();
+ List<DockingActionIf> actionList = getActionList(context);
+ MenuHandler handler =
+ new PopupMenuHandler(plugin.getTool().getWindowManager(), context);
+ MenuGroupMap groupMap = new MenuGroupMap();
+ MenuManager manager =
+ new MenuManager("Emulate", (char) 0, GROUP, true, handler, groupMap);
+ for (DockingActionIf action : actionList) {
+ if (action instanceof AbstractEmulateAction ea) {
+ String[] path = action.getPopupMenuData().getMenuPath();
+ String[] topPath = Arrays.copyOf(path, 1);
+ groupMap.setMenuGroup(topPath,
+ ea.getTopGroup(currentProgram),
+ ea.getTopOrder(currentProgram));
+ }
+ action.setEnabled(action.isEnabledForContext(context));
+ if (manager.getAction(action.getName()) == null) {
+ manager.addAction(action);
+ }
+ }
+ return manager.getPopupMenu();
+ }
+
+ @Override
+ protected JPopupMenu showPopup() {
+ // Make accessible to this file
+ return super.showPopup();
+ }
+
+ @Override
+ public String getToolTipText() {
+ return getDescription();
+ }
+ }
+
+ @Override
+ public JButton doCreateButton() {
+ return button = new MenuActionDockingToolbarButton(this);
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ return true;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ ConfigLast last = plugin.findMostRecentConfig();
+ if (last == null) {
+ Swing.runLater(() -> button.showPopup());
+ }
+ DockingActionIf action = plugin.getAction(last.configName());
+ action.actionPerformed(context);
+ }
+
+ @Override
+ public String getDescription() {
+ ConfigLast last = plugin.findMostRecentConfig();
+ if (last == null) {
+ return "Emulate ...";
+ }
+ if (last.program() == null) {
+ return "Empty session";
+ }
+ return "Re-emulate %s".formatted(getProgramName(last.program()));
+ }
+
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateProgramAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateProgramAction.java
new file mode 100644
index 0000000000..d0dfc8f969
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateProgramAction.java
@@ -0,0 +1,105 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import static ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin.*;
+
+import java.io.IOException;
+import java.util.List;
+
+import docking.ActionContext;
+import docking.action.MenuData;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.services.DebuggerTraceManagerService;
+import ghidra.framework.options.SaveState;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Program;
+import ghidra.trace.model.Trace;
+import ghidra.trace.model.program.TraceProgramView;
+import ghidra.util.HelpLocation;
+import ghidra.util.Msg;
+
+public class EmulateProgramAction extends AbstractEmulateAction {
+
+ public EmulateProgramAction(DebuggerEmulationServicePlugin plugin) {
+ super(plugin, plugin.EMULATE_PROGRAM);
+ }
+
+ public EmulateProgramAction(DebuggerEmulationServicePlugin plugin, Program program) {
+ super(plugin, plugin.EMULATE_PROGRAM, program);
+ }
+
+ @Override
+ MenuData computeMenuData() {
+ if (program == null) {
+ return new MenuData(
+ prependMenuPath("Emulate from cursor", List.of()),
+ DebuggerResources.ICON_EMULATE, DebuggerResources.GROUP_GENERAL, 0, "a1");
+ }
+ return new MenuData(
+ prependMenuPath("Emulate %s ...".formatted(getProgramName(program)),
+ List.of(" from cursor (new trace)")),
+ DebuggerResources.ICON_EMULATE, DebuggerResources.GROUP_GENERAL, 0, "a1");
+ }
+
+ @Override
+ String getTopGroup(Program currentProgram) {
+ return "1";
+ }
+
+ @Override
+ String getTopOrder(Program currentProgram) {
+ return program == currentProgram ? "1" : "2";
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ // To avoid confusion of "forked from trace," only permit action from static context
+ if (program == null || program instanceof TraceProgramView) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ SaveState state = new SaveState();
+ plugin.writeProgramLaunchConfig(program, this.getName(), state);
+ Trace trace = null;
+ try {
+ Address currentAddress = getCurrentAddress();
+ trace = ProgramEmulationUtils.launchEmulationTrace(program, currentAddress, this);
+ DebuggerTraceManagerService traceManager = plugin.getTraceManager();
+ traceManager.openTrace(trace);
+ traceManager.activateTrace(trace);
+ plugin.tryEmulatorFromMode(trace);
+ }
+ catch (IOException e) {
+ Msg.showError(this, null, this.getDescription(),
+ "Could not create trace for emulation", e);
+ }
+ finally {
+ if (trace != null) {
+ trace.release(this);
+ }
+ }
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(plugin.getName(), "emulate_program");
+ }
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateTargetAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateTargetAction.java
new file mode 100644
index 0000000000..2b58f12200
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/EmulateTargetAction.java
@@ -0,0 +1,76 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import static ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin.*;
+
+import java.util.List;
+
+import docking.ActionContext;
+import docking.action.MenuData;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.services.DebuggerTraceManagerService;
+import ghidra.framework.options.SaveState;
+import ghidra.program.model.listing.Program;
+import ghidra.trace.model.Trace;
+import ghidra.util.HelpLocation;
+
+public class EmulateTargetAction extends AbstractEmulateAction {
+
+ public EmulateTargetAction(DebuggerEmulationServicePlugin plugin, Program program) {
+ super(plugin, plugin.EMULATE_TARGET, program);
+ }
+
+ @Override
+ MenuData computeMenuData() {
+ return new MenuData(
+ prependMenuPath("Emulate %s ...".formatted(getProgramName(program)),
+ List.of(" using debugger target")),
+ DebuggerResources.ICON_EMULATE, DebuggerResources.GROUP_GENERAL, 0, "a2");
+ }
+
+ @Override
+ String getTopGroup(Program currentProgram) {
+ return "1";
+ }
+
+ @Override
+ String getTopOrder(Program currentProgram) {
+ return program == currentProgram ? "1" : "2";
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ DebuggerTraceManagerService traceManager = plugin.getTraceManager();
+ return traceManager != null && traceManager.getCurrentTrace() != null;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ SaveState state = new SaveState();
+ plugin.writeProgramLaunchConfig(program, this.getName(), state);
+
+ DebuggerTraceManagerService traceManager = plugin.getTraceManager();
+ Trace trace = traceManager.getCurrentTrace();
+ traceManager.activateTrace(trace);
+ plugin.tryEmulatorFromMode(trace);
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(plugin.getName(), "emulate_target");
+ }
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/InvalidateEmulatorCacheAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/InvalidateEmulatorCacheAction.java
new file mode 100644
index 0000000000..5ae1f0d910
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/InvalidateEmulatorCacheAction.java
@@ -0,0 +1,60 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import java.util.List;
+
+import docking.ActionContext;
+import docking.action.MenuData;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.services.DebuggerTraceManagerService;
+import ghidra.program.model.listing.Program;
+import ghidra.util.HelpLocation;
+
+public class InvalidateEmulatorCacheAction extends AbstractEmulateAction {
+
+ public InvalidateEmulatorCacheAction(DebuggerEmulationServicePlugin plugin) {
+ super(plugin, plugin.INVALIDATE_CACHE, null);
+ }
+
+ @Override
+ MenuData computeMenuData() {
+ return new MenuData(
+ prependMenuPath("Invalidate emulator cache", List.of()),
+ null, DebuggerResources.GROUP_MAINTENANCE, 0, "");
+ }
+
+ @Override
+ String getTopGroup(Program currentProgram) {
+ return "5";
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ DebuggerTraceManagerService traceManager = plugin.getTraceManager();
+ return traceManager != null && traceManager.getCurrentTrace() != null;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ plugin.invalidateCache();
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(plugin.getName(), "invalidate_cache");
+ }
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/TopEmulateAction.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/TopEmulateAction.java
new file mode 100644
index 0000000000..e3f9261694
--- /dev/null
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/TopEmulateAction.java
@@ -0,0 +1,72 @@
+/* ###
+ * 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.app.plugin.core.debug.service.emulation;
+
+import static ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin.*;
+
+import docking.ActionContext;
+import docking.action.*;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.program.model.listing.Program;
+import ghidra.util.HelpLocation;
+
+public class TopEmulateAction extends AbstractEmulateAction {
+ private String configName;
+
+ public TopEmulateAction(DebuggerEmulationServicePlugin plugin, String configName,
+ Program program) {
+ this.configName = configName;
+ super(plugin, "Re-emulate", program);
+ }
+
+ @Override
+ MenuData computeMenuData() {
+ String title = "Re-emulate %s".formatted(getProgramName(program));
+ DockingActionIf action = plugin.getAction(configName);
+ if (action instanceof AbstractEmulateAction eaction) {
+ title = "Re-" + eaction.getCompressedPath();
+ }
+ return new MenuData(new String[] { title }, DebuggerResources.ICON_EMULATE, "0: top");
+ }
+
+ @Override
+ String getTopGroup(Program currentProgram) {
+ return "0";
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ DockingActionIf action = plugin.getAction(configName);
+ return action != null ? action.isEnabledForContext(context) : false;
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ DockingActionIf action = plugin.getAction(configName);
+ if (action != null) {
+ action.actionPerformed(context);
+ }
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ DockingActionIf action = plugin.getAction(configName);
+ if (action instanceof DockingAction daction) {
+ return daction.getHelpLocation();
+ }
+ return null;
+ }
+}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServicePlugin.java
index ce56c1943a..66bb95ad92 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServicePlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServicePlugin.java
@@ -635,7 +635,7 @@ public class DebuggerTraceManagerServicePlugin extends Plugin
private ControlMode getEffectiveControlMode(Trace trace) {
if (trace == null) {
- return ControlMode.RO_TRACE;
+ return ControlMode.TRACE;
}
return controlService == null ? ControlMode.DEFAULT : controlService.getCurrentMode(trace);
}
@@ -809,9 +809,9 @@ public class DebuggerTraceManagerServicePlugin extends Plugin
}
/**
- * NOTE: We can actually reach this point in RO_TARGET mode, though ordinarily, it should
- * only reach here in RW_EMULATOR mode. The reason is because during many automated tests,
- * the "default" mode of RO_TARGET is taken as the effective mode, and the tests still
+ * NOTE: We can actually reach this point in TARGET mode, though ordinarily, it should
+ * only reach here in EMULATOR mode. The reason is because during many automated tests,
+ * the "default" mode of TARGET is taken as the effective mode, and the tests still
* expect emulation behavior. So do it.
*/
diff --git a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/DebuggerStackPluginScreenShots.java b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/DebuggerStackPluginScreenShots.java
index ed72f8427e..6f5690bdbf 100644
--- a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/DebuggerStackPluginScreenShots.java
+++ b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/DebuggerStackPluginScreenShots.java
@@ -315,7 +315,7 @@ public class DebuggerStackPluginScreenShots extends GhidraScreenShotGenerator
traceManager.activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = controlService.createStateEditor(tb.trace);
DebuggerCoordinates atSetup = traceManager.getCurrent();
diff --git a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/vars/VariableValueHoverPluginScreenShots.java b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/vars/VariableValueHoverPluginScreenShots.java
index e3e8068854..8919cc266e 100644
--- a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/vars/VariableValueHoverPluginScreenShots.java
+++ b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/stack/vars/VariableValueHoverPluginScreenShots.java
@@ -263,7 +263,7 @@ public class VariableValueHoverPluginScreenShots extends GhidraScreenShotGenerat
}
waitForDomainObject(tb.trace);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = controlService.createStateEditor(tb.trace);
DebuggerCoordinates atSetup = traceManager.getCurrent();
diff --git a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePluginScreenShots.java b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePluginScreenShots.java
index bf95664191..a09b590d38 100644
--- a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePluginScreenShots.java
+++ b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServicePluginScreenShots.java
@@ -98,7 +98,7 @@ public class DebuggerEmulationServicePluginScreenShots extends GhidraScreenShotG
@SuppressWarnings("unchecked")
<T extends DataType> T resolve(T dt) {
- try (Transaction tx = program.openTransaction("Resolved %s".formatted(dt))) {
+ try (Transaction _ = program.openTransaction("Resolved %s".formatted(dt))) {
DataTypeConflictHandler handler = DataTypeConflictHandler.DEFAULT_HANDLER;
return (T) dtm.resolve(dt, handler);
}
@@ -109,7 +109,7 @@ public class DebuggerEmulationServicePluginScreenShots extends GhidraScreenShotG
program = createDefaultProgram("game", ToyProgramBuilder._X64, this);
intoProject(program);
dtm = program.getDataTypeManager();
- try (Transaction tx = program.openTransaction("Create Function")) {
+ try (Transaction _ = program.openTransaction("Create Function")) {
program.getMemory()
.createInitializedBlock(".text", addr(program, 0x00400000), 0x10000, (byte) 0,
MONITOR, false);
@@ -134,7 +134,7 @@ public class DebuggerEmulationServicePluginScreenShots extends GhidraScreenShotG
}
programManager.openProgram(program);
goTo(tool, progam, function.getEntryPoint());
- performAction(emuService.actionEmulateFunction, false);
+ performAction(emuService.getAction(emuService.EMULATE_FUNCTION), false);
DebuggerEmulateFunctionDialog dialog =
waitForDialogComponent(DebuggerEmulateFunctionDialog.class);
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblyTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblyTest.java
index 1d9296fd9b..33ac735de2 100644
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblyTest.java
+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/disassemble/DebuggerDisassemblyTest.java
@@ -623,7 +623,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
createTrace("ARM:LE:32:v8", 0x00400000, () -> tb.buf(0x00, 0x00, 0x00, 0x00));
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, null, 0));
@@ -651,7 +651,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
// Don't cheat here and choose v8T!
createTrace("ARM:LE:32:v8", 0x00400000, () -> tb.buf(0x00, 0x00));
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, null, 0));
@@ -683,7 +683,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
TraceThread thread =
createPolyglotTrace("armv8le", 0x00400000, () -> tb.buf(0x00, 0x00, 0x00, 0x00));
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, thread.getObject(), 0));
@@ -713,7 +713,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
TraceThread thread =
createPolyglotTrace("armv8le", 0x00400000, () -> tb.buf(0x00, 0x00));
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, thread.getObject(), 0));
@@ -762,7 +762,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
createTrace("ARM:LE:32:v8", 0x00400000, () -> tb.buf());
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, null, 0));
@@ -781,7 +781,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
TraceThread thread = createPolyglotTrace("armv8le", 0x00400000, () -> tb.buf());
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, thread.getObject(), 0));
@@ -800,7 +800,7 @@ public class DebuggerDisassemblyTest extends AbstractGhidraHeadedDebuggerTest {
TraceThread thread = createPolyglotTrace("armv8le", 0x00400000, () -> tb.buf());
Address start = tb.addr(0x00400000);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
// Ensure the mapper is added to the trace
assertNotNull(platformService.getMapper(tb.trace, thread.getObject(), 0));
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServiceTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServiceTest.java
index 0b7f4cdf69..4abb33d98f 100644
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServiceTest.java
+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerEmulationServiceTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import db.Transaction;
+import docking.action.DockingActionIf;
import generic.Unique;
import generic.test.category.NightlyCategory;
import ghidra.app.plugin.assembler.*;
@@ -97,7 +98,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regPC = program.getRegister("pc");
Register regR0 = program.getRegister("r0");
Register regR1 = program.getRegister("r1");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -113,8 +114,10 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- assertTrue(emulationPlugin.actionEmulateProgram.isEnabled());
- performAction(emulationPlugin.actionEmulateProgram);
+ DockingActionIf actionEmulateProgram =
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM);
+ assertTrue(actionEmulateProgram.isEnabled());
+ performAction(actionEmulateProgram);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -152,7 +155,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regPC = program.getRegister("pc");
Register regR0 = program.getRegister("r0");
Register regR1 = program.getRegister("r1");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -169,8 +172,10 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- assertTrue(emulationPlugin.actionEmulateProgram.isEnabled());
- performAction(emulationPlugin.actionEmulateProgram);
+ DockingActionIf actionEmulateProgram =
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM);
+ assertTrue(actionEmulateProgram.isEnabled());
+ performAction(actionEmulateProgram);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -210,7 +215,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regPC = program.getRegister("PC");
Register regW0 = program.getRegister("W0");
Register regW1 = program.getRegister("W1");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -227,8 +232,10 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- assertTrue(emulationPlugin.actionEmulateProgram.isEnabled());
- performAction(emulationPlugin.actionEmulateProgram);
+ DockingActionIf actionEmulateProgram =
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM);
+ assertTrue(actionEmulateProgram.isEnabled());
+ performAction(actionEmulateProgram);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -272,7 +279,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Memory memory = program.getMemory();
Address addrText = addr(program, 0x00400000);
Address addrData = addr(program, 0x00600000);
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock("text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -292,7 +299,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
CompletableFuture<Void> settled;
TraceThread thread;
TraceMemorySpace regs;
- try (Transaction tx = tb.startTransaction()) {
+ try (Transaction _ = tb.startTransaction()) {
tb.createRootObject(buildContext(), "Target");
thread = tb.getOrAddThread("Threads[0]", 0);
tb.createObjectsFramesAndRegs(thread, Lifespan.nowOn(0), tb.host, 1);
@@ -327,7 +334,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
AssemblyBuffer buf = new AssemblyBuffer(asm, tb.addr(x64, 0x00400000));
TraceMemoryManager mem = tb.trace.getMemoryManager();
TraceThread thread;
- try (Transaction tx = tb.startTransaction()) {
+ try (Transaction _ = tb.startTransaction()) {
tb.createRootObject(buildContext(), "Target");
thread = tb.getOrAddThread("Threads[0]", 0);
tb.createObjectsFramesAndRegs(thread, Lifespan.nowOn(0), tb.host, 1);
@@ -355,7 +362,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
waitForPass(() -> assertEquals(x64, traceManager.getCurrentPlatform().getLanguage()));
TracePlatform platform = traceManager.getCurrentPlatform();
- try (Transaction tx = tb.startTransaction()) {
+ try (Transaction _ = tb.startTransaction()) {
tb.exec(platform, 0, thread, 0, "RIP = 0x00400000;");
}
@@ -377,7 +384,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Address addrText = addr(program, 0x00400000);
Register regPC = program.getRegister("pc");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -390,7 +397,8 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -421,7 +429,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regR1 = program.getRegister("r1");
Register regR2 = program.getRegister("r2");
Address addrI2;
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -439,7 +447,8 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -447,7 +456,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
TraceThread thread = Unique.assertOne(trace.getThreadManager().getAllThreads());
TraceMemorySpace regs = trace.getMemoryManager().getMemoryRegisterSpace(thread, false);
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
trace.getBreakpointManager()
.addBreakpoint("Breakpoints[0]", Lifespan.nowOn(0), addrI2, Set.of(thread),
CommonSet.SWX.kinds(), true, "test");
@@ -480,7 +489,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Address addrText = addr(program, 0x00400000);
Address addrI1;
Address addrI2;
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -498,14 +507,15 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
TraceThread thread = Unique.assertOne(trace.getThreadManager().getAllThreads());
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
trace.getBreakpointManager()
.addBreakpoint("Breakpoints[0]", Lifespan.nowOn(0), addrText, Set.of(thread),
CommonSet.SWX.kinds(), true, "test");
@@ -555,7 +565,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Memory memory = program.getMemory();
Address addrText = addr(program, 0x00400000);
Address addrI1;
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -572,14 +582,15 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
TraceThread thread = Unique.assertOne(trace.getThreadManager().getAllThreads());
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
trace.getBreakpointManager()
.addBreakpoint("Breakpoints[0]", Lifespan.nowOn(0), addrText, Set.of(thread),
CommonSet.SWX.kinds(), true, "test");
@@ -624,7 +635,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Memory memory = program.getMemory();
Address addrText = addr(program, 0x00400000);
Address addrI1;
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -641,14 +652,15 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
TraceThread thread = Unique.assertOne(trace.getThreadManager().getAllThreads());
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
TraceBreakpointLocation tb = trace.getBreakpointManager()
.addBreakpoint("Breakpoints[1]", Lifespan.nowOn(0), addrI1, Set.of(thread),
CommonSet.SWX.kinds(), true, "test");
@@ -697,7 +709,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regR1 = program.getRegister("r1");
Register regR2 = program.getRegister("r2");
Address addrI2;
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -715,7 +727,8 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -723,7 +736,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
TraceThread thread = Unique.assertOne(trace.getThreadManager().getAllThreads());
TraceMemorySpace regs = trace.getMemoryManager().getMemoryRegisterSpace(thread, false);
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
TraceBreakpointLocation tb = trace.getBreakpointManager()
.addBreakpoint("Breakpoints[0]", Lifespan.nowOn(0), addrI2, Set.of(thread),
CommonSet.SWX.kinds(), true, "test");
@@ -764,7 +777,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regR0 = program.getRegister("r0");
Register regR1 = program.getRegister("r1");
Register regR2 = program.getRegister("r2");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -781,7 +794,8 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -790,7 +804,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
TraceMemoryManager mem = trace.getMemoryManager();
TraceMemorySpace regs = mem.getMemoryRegisterSpace(thread, false);
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
trace.getBreakpointManager()
.addBreakpoint("Breakpoints[0]", Lifespan.nowOn(0), addr(trace, 0x1234),
Set.of(thread), CommonSet.READ.kinds(), true, "test");
@@ -827,7 +841,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Register regR0 = program.getRegister("r0");
Register regR2 = program.getRegister("r2");
Address addrI2;
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -845,7 +859,8 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionEmulateProgram, true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM), true);
DebuggerCoordinates current = traceManager.getCurrent();
Trace trace = current.getTrace();
@@ -868,7 +883,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
regs.getViewValue(scratch, regR2).getUnsignedValue());
// Inject some logic that would require a cache refresh to materialize
- try (Transaction tx = trace.openTransaction("Add breakpoint")) {
+ try (Transaction _ = trace.openTransaction("Add breakpoint")) {
TraceBreakpointLocation tb = trace.getBreakpointManager()
.addBreakpoint("Breakpoints[0]", Lifespan.nowOn(0), addrI2, Set.of(thread),
CommonSet.SWX.kinds(), true, "test");
@@ -890,8 +905,8 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
regs.getViewValue(scratch, regR2).getUnsignedValue());
// Invalidate the cache. View should update immediately
- performEnabledAction(codeBrowser.getProvider(), emulationPlugin.actionInvalidateCache,
- true);
+ performEnabledAction(codeBrowser.getProvider(),
+ emulationPlugin.getAction(emulationPlugin.INVALIDATE_CACHE), true);
waitForTasks();
assertEquals(new BigInteger("5678", 16),
regs.getViewValue(scratch, regR2).getUnsignedValue());
@@ -905,7 +920,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Memory memory = program.getMemory();
Address addrText = addr(program, 0x00400000);
Register regSP = program.getRegister("sp");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -920,8 +935,10 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- assertTrue(emulationPlugin.actionEmulateProgram.isEnabled());
- performAction(emulationPlugin.actionEmulateProgram);
+ DockingActionIf actionEmulateProgram =
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM);
+ assertTrue(actionEmulateProgram.isEnabled());
+ performAction(actionEmulateProgram);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -939,7 +956,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Memory memory = program.getMemory();
Address addrText = addr(program, 0x00400000);
Register regSP = program.getRegister("sp");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, TaskMonitor.DUMMY, false);
blockText.setExecute(true);
@@ -952,8 +969,10 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
codeBrowser.goTo(new ProgramLocation(program, addrText));
waitForSwing();
- assertTrue(emulationPlugin.actionEmulateProgram.isEnabled());
- performAction(emulationPlugin.actionEmulateProgram);
+ DockingActionIf actionEmulateProgram =
+ emulationPlugin.getAction(emulationPlugin.EMULATE_PROGRAM);
+ assertTrue(actionEmulateProgram.isEnabled());
+ performAction(actionEmulateProgram);
Trace trace = traceManager.getCurrentTrace();
assertNotNull(trace);
@@ -970,14 +989,14 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
intoProject(program);
long restartEmuSnap = 3;
- try (Transaction tx = tb.startTransaction()) {
+ try (Transaction _ = tb.startTransaction()) {
tb.trace.getObjectManager().createRootObject(ProgramEmulationUtils.EMU_SESSION_SCHEMA);
tb.trace.getTimeManager().getSnapshot(restartEmuSnap, true);
}
traceManager.activateTrace(tb.trace);
traceManager.activateSnap(restartEmuSnap);
- try (Transaction tx = tb.startTransaction()) {
+ try (Transaction _ = tb.startTransaction()) {
TracePlatform host = tb.trace.getPlatformManager().getHostPlatform();
DefaultPcodeDebuggerAccess access =
new DefaultPcodeDebuggerAccess(tool, null, host, restartEmuSnap);
@@ -1035,7 +1054,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
Address addrText = addr(program, 0x00400000);
Address addrData = addr(program, 0x00000000);
Register regR0 = program.getRegister("r0");
- try (Transaction tx = program.openTransaction("Initialize")) {
+ try (Transaction _ = program.openTransaction("Initialize")) {
MemoryBlock blockText = memory.createInitializedBlock(".text", addrText, 0x1000,
(byte) 0, monitor, false);
blockText.setExecute(true);
@@ -1064,7 +1083,7 @@ public class DebuggerEmulationServiceTest extends AbstractGhidraHeadedDebuggerTe
traceManager.openTrace(trace);
waitForSwing();
- try (Transaction tx = tb.startTransaction()) {
+ try (Transaction _ = tb.startTransaction()) {
TraceSnapshot snapshot = tb.trace.getTimeManager().getSnapshot(0, true);
long snap = snapshot.getKey();
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java
index 36b1692f73..818385e274 100644
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java
+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/stack/StackUnwinderTest.java
@@ -887,7 +887,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
traceManager.activateThread(thread);
waitForSwing();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = editingService.createStateEditor(tb.trace);
DebuggerCoordinates atSetup = traceManager.getCurrent();
@@ -947,7 +947,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
traceManager.activateThread(thread);
waitForSwing();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = editingService.createStateEditor(tb.trace);
DebuggerCoordinates atSetup = traceManager.getCurrent();
@@ -1179,7 +1179,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
traceManager.activateThread(thread);
waitForSwing();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = editingService.createStateEditor(tb.trace);
DebuggerCoordinates atSetup = traceManager.getCurrent();
@@ -1226,7 +1226,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
traceManager.activateThread(thread);
waitForSwing();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = editingService.createStateEditor(tb.trace);
// Move stack where it shows in UI. Not required, but nice for debugging.
Register sp = program.getCompilerSpec().getStackPointer();
@@ -1267,7 +1267,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
traceManager.activateThread(thread);
waitForSwing();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = editingService.createStateEditor(tb.trace);
// Move stack where it shows in UI. Not required, but nice for debugging.
Register sp = program.getCompilerSpec().getStackPointer();
@@ -1308,7 +1308,7 @@ public class StackUnwinderTest extends AbstractGhidraHeadedDebuggerTest {
traceManager.activateThread(thread);
waitForSwing();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
StateEditor editor = editingService.createStateEditor(tb.trace);
// Move stack where it shows in UI. Not required, but nice for debugging.
Register sp = program.getCompilerSpec().getStackPointer();
diff --git a/Ghidra/Debug/TaintAnalysis/build.gradle b/Ghidra/Debug/TaintAnalysis/build.gradle
index b9977c8815..bea56be10d 100644
--- a/Ghidra/Debug/TaintAnalysis/build.gradle
+++ b/Ghidra/Debug/TaintAnalysis/build.gradle
@@ -14,6 +14,7 @@
* limitations under the License.
*/
apply from: "${rootProject.projectDir}/gradle/javaProject.gradle"
+apply from: "${rootProject.projectDir}/gradle/helpProject.gradle"
apply from: "${rootProject.projectDir}/gradle/jacocoProject.gradle"
apply from: "${rootProject.projectDir}/gradle/javaTestProject.gradle"
apply from: "${rootProject.projectDir}/gradle/distributableGhidraModule.gradle"
diff --git a/Ghidra/Debug/TaintAnalysis/certification.manifest b/Ghidra/Debug/TaintAnalysis/certification.manifest
index 6841c5219a..cf0e183e1d 100644
--- a/Ghidra/Debug/TaintAnalysis/certification.manifest
+++ b/Ghidra/Debug/TaintAnalysis/certification.manifest
@@ -1,3 +1,5 @@
##VERSION: 2.0
Module.manifest||GHIDRA||||END|
README.md||GHIDRA||||END|
+src/main/help/help/TOC_Source.xml||GHIDRA||||END|
+src/main/help/help/topics/EmulationTaintInjectionServicePlugin/EmulationTaintInjectionServicePlugin.html||GHIDRA||||END|
diff --git a/Ghidra/Debug/TaintAnalysis/src/main/help/help/TOC_Source.xml b/Ghidra/Debug/TaintAnalysis/src/main/help/help/TOC_Source.xml
new file mode 100644
index 0000000000..ae9fd96a1d
--- /dev/null
+++ b/Ghidra/Debug/TaintAnalysis/src/main/help/help/TOC_Source.xml
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='ISO-8859-1'?>
+<!-- See Base's TOC_Source.xml for help -->
+<tocroot>
+ <tocref id="DebuggerEmulationServicePlugin">
+ <tocdef id="EmulationTaintInjectionServicePlugin" text="Taint Injection"
+ sortgroup="c"
+ target="help/topics/EmulationTaintInjectionServicePlugin/EmulationTaintInjectionServicePlugin.html" />
+ </tocref>
+</tocroot>
diff --git a/Ghidra/Debug/TaintAnalysis/src/main/help/help/topics/EmulationTaintInjectionServicePlugin/EmulationTaintInjectionServicePlugin.html b/Ghidra/Debug/TaintAnalysis/src/main/help/help/topics/EmulationTaintInjectionServicePlugin/EmulationTaintInjectionServicePlugin.html
new file mode 100644
index 0000000000..0bce3597d5
--- /dev/null
+++ b/Ghidra/Debug/TaintAnalysis/src/main/help/help/topics/EmulationTaintInjectionServicePlugin/EmulationTaintInjectionServicePlugin.html
@@ -0,0 +1,41 @@
+<!DOCTYPE doctype PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN">
+
+<HTML>
+ <HEAD>
+ <META name="generator" content=
+ "HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net">
+
+ <TITLE>Emulation: Injecting Taint</TITLE>
+ <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
+ <LINK rel="stylesheet" type="text/css" href="help/shared/DefaultStyle.css">
+ </HEAD>
+
+ <BODY lang="EN-US">
+ <H1><A name="plugin"></A>Emulation: Injecting Taint</H1>
+
+ <P>This plugin presents actions for injecting taint directly into the emulator's p-code.
+ Depending on the current context (decompiler, disassembly, or p-code instruction),
+ the actions select the left-most identifiable varnode and attempt to generate sleigh
+ instructions to be injected into the emulated stream.
+ </P>
+
+ <H2>Actions</H2>
+
+ <P>The plugin provides several actions which are enabled when the debugger's <A
+ href="help/topics/DebuggerControlPlugin/DebuggerControlPlugin.html#control_mode">control-mode</A>
+ is set to emulation.</P>
+
+ <H3><A name="taint_by_arr"></A>Toggle taint by array</H3>
+
+ <P>This action toggles the taint of the given machine variable with an array of taint symbols,
+ as described in the <B>TaintPcodeUserOpLibrary</B>
+ </P>
+
+
+ <H3><A name="taint_by_var"></A>Toggle taint by var</H3>
+
+ <P>This action toggles the taint the given machine variable with a single taint symbol.
+ </P>
+
+ </BODY>
+</HTML>
diff --git a/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/app/core/debug/service/taint/EmulationTaintInjectionServicePlugin.java b/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/app/core/debug/service/taint/EmulationTaintInjectionServicePlugin.java
new file mode 100644
index 0000000000..85cde2ce7d
--- /dev/null
+++ b/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/app/core/debug/service/taint/EmulationTaintInjectionServicePlugin.java
@@ -0,0 +1,142 @@
+/* ###
+ * 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.app.core.debug.service.taint;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import ghidra.app.context.ProgramLocationActionContext;
+import ghidra.app.plugin.PluginCategoryNames;
+import ghidra.app.plugin.core.debug.DebuggerPluginPackage;
+import ghidra.app.services.*;
+import ghidra.debug.api.tracemgr.DebuggerCoordinates;
+import ghidra.framework.options.SaveState;
+import ghidra.framework.plugintool.*;
+import ghidra.framework.plugintool.annotation.AutoServiceConsumed;
+import ghidra.framework.plugintool.util.PluginStatus;
+import ghidra.pcode.emu.PcodeMachine;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.Program;
+import ghidra.program.util.ProgramLocation;
+import ghidra.trace.model.*;
+import ghidra.trace.model.program.TraceProgramView;
+
+@PluginInfo(
+ shortDescription = "Emulation Taint Injection Service Plugin",
+ description = "Manages emulator taint",
+ category = PluginCategoryNames.DEBUGGER,
+ packageName = DebuggerPluginPackage.NAME,
+ status = PluginStatus.UNSTABLE,
+ servicesRequired = {
+ DebuggerEmulationService.class
+ },
+ servicesProvided = {
+ EmulationTaintInjectionService.class
+ }
+)
+public class EmulationTaintInjectionServicePlugin extends Plugin implements EmulationTaintInjectionService {
+
+ @AutoServiceConsumed
+ private DebuggerTraceManagerService traceManager;
+ @AutoServiceConsumed
+ private DebuggerStaticMappingService staticMappings;
+ @AutoServiceConsumed
+ private DebuggerEmulationService emuService;
+ @SuppressWarnings("unused")
+ private AutoService.Wiring autoServiceWiring;
+
+ private Map<Address, String> taintMap = new HashMap<>();
+
+ protected EmulatorTaintAction emulatorInjectAction;
+ protected EmulatorTaintAction emulatorInjectArrayAction;
+
+ protected SaveState toolLaunchConfigs = new SaveState();
+
+ public EmulationTaintInjectionServicePlugin(PluginTool tool) {
+ super(tool);
+ autoServiceWiring = AutoService.wireServicesProvidedAndConsumed(this);
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+ createActions();
+ }
+
+ protected void createActions() {
+ emulatorInjectAction = new EmulatorTaintAction(this, false);
+ emulatorInjectArrayAction = new EmulatorTaintAction(this, true);
+ tool.addAction(emulatorInjectAction);
+ tool.addAction(emulatorInjectArrayAction);
+ }
+
+ @Override
+ public void injectTaint(PcodeMachine<?> emu) {
+ for (Entry<Address, String> entry : taintMap.entrySet()) {
+ emu.inject(entry.getKey(), entry.getValue());
+ }
+ }
+
+ public String getTaint(ProgramLocationActionContext plctx) {
+ Address targetPc = getPcFromContext(plctx);
+ return targetPc == null ? null : taintMap.get(targetPc);
+ }
+
+ public void toggleTaint(ProgramLocationActionContext plctx, String sleigh) {
+ Address targetPc = getPcFromContext(plctx);
+ if (taintMap.containsKey(targetPc) || sleigh == null) {
+ taintMap.remove(targetPc);
+ }
+ else {
+ taintMap.put(targetPc, sleigh);
+ }
+ }
+
+ Address getPcFromContext(ProgramLocationActionContext plctx) {
+ Program programOrView = plctx.getProgram();
+ Address targetPc = null;
+ if (programOrView instanceof TraceProgramView view) {
+ Trace trace = view.getTrace();
+ long snap = view.getViewport()
+ .getOrderedSnaps()
+ .stream()
+ .filter(s -> s >= 0)
+ .findFirst()
+ .orElse(0L);
+ ProgramLocation progLoc = staticMappings.getOpenMappedLocation(
+ new DefaultTraceLocation(trace, null, Lifespan.at(snap), plctx.getAddress()));
+ targetPc = progLoc == null ? null : progLoc.getAddress();
+ }
+ else {
+ DebuggerCoordinates current = traceManager.getCurrent();
+ long snap = current.getSnap();
+ Trace trace = current.getTrace();
+ TraceLocation traceLoc =
+ staticMappings.getOpenMappedLocation(trace, plctx.getLocation(), snap);
+ if (traceLoc == null) {
+ return null;
+ }
+ targetPc = traceLoc.getAddress();
+ }
+ return targetPc;
+ }
+
+ public boolean usingEmulator() {
+ return emuService.getEmulatorFactory() != null;
+ }
+
+}
diff --git a/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/app/core/debug/service/taint/EmulatorTaintAction.java b/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/app/core/debug/service/taint/EmulatorTaintAction.java
new file mode 100644
index 0000000000..734e9292e5
--- /dev/null
+++ b/Ghidra/Debug/TaintAnalysis/src/main/java/ghidra/app/core/debug/service/taint/EmulatorTaintAction.java
@@ -0,0 +1,149 @@
+/* ###
+ * 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.app.core.debug.service.taint;
+
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.util.List;
+
+import db.Transaction;
+import docking.ActionContext;
+import docking.action.*;
+import ghidra.app.context.ProgramLocationActionContext;
+import ghidra.app.decompiler.ClangToken;
+import ghidra.app.decompiler.location.DefaultDecompilerLocation;
+import ghidra.app.plugin.core.debug.gui.DebuggerResources;
+import ghidra.app.plugin.core.debug.gui.breakpoint.DebuggerSleighSemanticInputDialog;
+import ghidra.pcode.exec.SleighUtils;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.listing.*;
+import ghidra.program.model.pcode.PcodeOp;
+import ghidra.program.model.pcode.Varnode;
+import ghidra.program.util.*;
+import ghidra.util.HelpLocation;
+
+public class EmulatorTaintAction extends DockingAction {
+
+ public static final String SET_TAINT_BY_ARR = """
+ %s=taint_arr(%s);
+ emu_exec_decoded();
+ """;
+
+ public static final String SET_TAINT_BY_VAR = """
+ %s=taint_var(%s);
+ emu_exec_decoded();
+ """;
+
+ private EmulationTaintInjectionServicePlugin plugin;
+ private boolean byArray;
+ private boolean verify = true;
+
+
+ public EmulatorTaintAction(EmulationTaintInjectionServicePlugin plugin, boolean byArray) {
+ super(byArray ? "TaintArr" : "TaintVar", plugin.getName());
+ this.plugin = plugin;
+ this.byArray = byArray;
+ MenuData menuData =
+ new MenuData(new String[] { "Toggle taint", byArray ? "by array" : "by var" },
+ DebuggerResources.ICON_EMULATE, DebuggerResources.GROUP_GENERAL);
+ setKeyBindingData(
+ new KeyBindingData(KeyEvent.VK_T, byArray ? InputEvent.SHIFT_DOWN_MASK : 0));
+ setPopupMenuData(menuData);
+ }
+
+ @Override
+ public boolean isEnabledForContext(ActionContext context) {
+ return plugin.usingEmulator();
+ }
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ if (!(context instanceof ProgramLocationActionContext plctx)) {
+ return;
+ }
+ Program currentProgram = plctx.getProgram();
+ BookmarkManager bookmarkManager = currentProgram.getBookmarkManager();
+ String sleigh = null;
+ if (plugin.getTaint(plctx) == null) {
+ sleigh = deriveCurrentSleighFromContext(plctx);
+ if (sleigh == null) {
+ sleigh = SleighUtils.UNCONDITIONAL_BREAK;
+ }
+ if (verify) {
+ sleigh =
+ DebuggerSleighSemanticInputDialog.INSTANCE.prompt(plugin.getTool(), sleigh);
+ if (sleigh == null) {
+ return;
+ }
+ }
+ try (Transaction _ = currentProgram.openTransaction("set bookmark")) {
+ bookmarkManager.setBookmark(plctx.getAddress(), BookmarkType.INFO, "Taint Source",
+ sleigh);
+ }
+ }
+ else {
+ try (Transaction _ = currentProgram.openTransaction("clear bookmark")) {
+ Bookmark bookmark = bookmarkManager.getBookmark(plctx.getAddress(),
+ BookmarkType.INFO, "Taint Source");
+ bookmarkManager.removeBookmark(bookmark);
+ }
+ }
+ plugin.toggleTaint(plctx, sleigh);
+ }
+
+ private String deriveCurrentSleighFromContext(ProgramLocationActionContext plctx) {
+ String sleigh = null;
+ Program currentProgram = plctx.getProgram();
+ ProgramLocation location = plctx.getLocation();
+ Address address = location.getAddress();
+ int row = location.getRow();
+ int offset = location.getCharOffset();
+
+ String cmds = byArray ? SET_TAINT_BY_ARR : SET_TAINT_BY_VAR;
+ if (location instanceof PcodeFieldLocation pfl) {
+ List<String> pcodeStrings = pfl.getPcodeStrings();
+ String test = pcodeStrings.get(row);
+ int lastSpace = test.lastIndexOf(" ");
+ int index = offset > lastSpace ? 1 : 0;
+ Instruction inst =
+ currentProgram.getListing().getInstructionContaining(address);
+ PcodeOp[] pcode = inst.getPcode();
+ PcodeOp op = pcode[row];
+ if (index >= op.getNumInputs()) {
+ index--;
+ }
+ Varnode vn = op.getInput(index);
+ String vnid = vn.toString(currentProgram.getLanguage());
+ sleigh = cmds.formatted(vnid, vnid);
+ }
+ else if (location instanceof DefaultDecompilerLocation ddl) {
+ ClangToken token = ddl.getToken();
+ Varnode vn = token.getVarnode();
+ String vnid = vn.toString(currentProgram.getLanguage());
+ sleigh = cmds.formatted(vnid, vnid);
+ }
+ else if (location instanceof OperandFieldLocation ofl) {
+ String opid = ofl.getOperandRepresentation();
+ sleigh = cmds.formatted(opid, opid);
+ }
+ return sleigh;
+ }
+
+ @Override
+ public HelpLocation getHelpLocation() {
+ return new HelpLocation(plugin.getName(), "set_injection");
+ }
+}
diff --git a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponentProvider.java b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponentProvider.java
index 4db6e2098f..97bd8f6a05 100644
--- a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponentProvider.java
+++ b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ByteViewerComponentProvider.java
@@ -172,17 +172,19 @@ public abstract class ByteViewerComponentProvider extends ComponentProviderAdapt
}
private void createActions() {
- editModeAction =
- new ToggleActionBuilder("Enable/Disable Byteviewer Editing", plugin.getName())
- .selected(false)
- .description("Enable/Disable editing of bytes in Byte Viewer panels.")
- .toolBarIcon(new GIcon("icon.base.edit.bytes"))
- .toolBarGroup("Byteviewer")
- .keyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_E,
- DockingUtils.CONTROL_KEY_MODIFIER_MASK | InputEvent.ALT_DOWN_MASK))
- .enabledWhen(ac -> blockSet != null && blockSet.isValid())
- .onAction(ac -> setEditMode(editModeAction.isSelected()))
- .buildAndInstallLocal(this);
+ if (hasEditAction()) {
+ editModeAction =
+ new ToggleActionBuilder("Enable/Disable Byteviewer Editing", plugin.getName())
+ .selected(false)
+ .description("Enable/Disable editing of bytes in Byte Viewer panels.")
+ .toolBarIcon(new GIcon("icon.base.edit.bytes"))
+ .toolBarGroup("Byteviewer")
+ .keyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_E,
+ DockingUtils.CONTROL_KEY_MODIFIER_MASK | InputEvent.ALT_DOWN_MASK))
+ .enabledWhen(ac -> blockSet != null && blockSet.isValid())
+ .onAction(ac -> setEditMode(editModeAction.isSelected()))
+ .buildAndInstallLocal(this);
+ }
optionsAction = new ActionBuilder("Byte Viewer Options", plugin.getName())
.description("Set Byte Viewer Options")
@@ -642,4 +644,13 @@ public abstract class ByteViewerComponentProvider extends ComponentProviderAdapt
panel.removeDisplayListener(listener);
}
+ /**
+ * Panel uses an action to determine edits
+ *
+ * @return edits can be toggled
+ */
+ public boolean hasEditAction() {
+ return true;
+ }
+
}
diff --git a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java
index 70964136d0..8686f902ba 100644
--- a/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java
+++ b/Ghidra/Features/ByteViewer/src/main/java/ghidra/app/plugin/core/byteviewer/ProgramByteViewerComponentProvider.java
@@ -727,7 +727,7 @@ public class ProgramByteViewerComponentProvider extends ByteViewerComponentProvi
}
@Override
- void setEditMode(boolean isEditable) {
+ protected void setEditMode(boolean isEditable) {
super.setEditMode(isEditable);
enablePaste(isEditable);
}
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/screen/java/ghidraclass/debugger/screenshot/TutorialDebuggerScreenShots.java b/Ghidra/Test/DebuggerIntegrationTest/src/screen/java/ghidraclass/debugger/screenshot/TutorialDebuggerScreenShots.java
index 2df50940e4..94bcb19d18 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/screen/java/ghidraclass/debugger/screenshot/TutorialDebuggerScreenShots.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/screen/java/ghidraclass/debugger/screenshot/TutorialDebuggerScreenShots.java
@@ -68,7 +68,6 @@ import ghidra.app.plugin.core.debug.gui.tracermi.connection.TraceRmiConnectionMa
import ghidra.app.plugin.core.debug.gui.tracermi.launcher.TraceRmiLaunchDialog;
import ghidra.app.plugin.core.debug.gui.watch.DebuggerWatchesProvider;
import ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin;
-import ghidra.app.plugin.core.debug.service.emulation.DebuggerEmulationServicePlugin.EmulateProgramAction;
import ghidra.app.plugin.core.debug.stack.StackUnwinderTest;
import ghidra.app.plugin.core.debug.stack.StackUnwinderTest.HoverLocation;
import ghidra.app.plugin.core.debug.stack.UnwindStackCommand;
@@ -201,7 +200,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
@Override
public void loadProgram() throws Exception {
loadProgram("termmines");
- try (Transaction tx = program.openTransaction("Set exe path")) {
+ try (Transaction _ = program.openTransaction("Set exe path")) {
program.setExecutablePath(TERMMINES_PATH);
}
intoProject(program);
@@ -252,7 +251,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
Pty pty = PtyFactory.local().openpty();
pty.getChild().session(new String[] { TERMMINES_PATH }, Map.of("TERM", "xterm-256color"));
PtyParent parent = pty.getParent();
- try (Terminal terminal =
+ try (Terminal _ =
terminalService.createWithStreams(Charset.forName("utf8"), parent.getInputStream(),
parent.getOutputStream())) {
@@ -440,7 +439,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
DebuggerStaticMappingService mappings = tool.getService(DebuggerStaticMappingService.class);
ModuleMapProposal proposal =
mappings.proposeModuleMap(modLibC, flatDbg.getCurrentSnap(), progLibC);
- try (Transaction tx = modLibC.getTrace().openTransaction("Map")) {
+ try (Transaction _ = modLibC.getTrace().openTransaction("Map")) {
mappings.addModuleMappings(proposal.computeMap().values(), monitor, true);
}
@@ -468,7 +467,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
DebuggerStaticMappingService mappings = tool.getService(DebuggerStaticMappingService.class);
ModuleMapProposal proposal =
mappings.proposeModuleMap(modLibC, flatDbg.getCurrentSnap(), progLibC);
- try (Transaction tx = modLibC.getTrace().openTransaction("Map")) {
+ try (Transaction _ = modLibC.getTrace().openTransaction("Map")) {
mappings.addModuleMappings(proposal.computeMap().values(), monitor, true);
}
@@ -582,7 +581,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
DebuggerStaticMappingService mappings = tool.getService(DebuggerStaticMappingService.class);
ModuleMapProposal proposal =
mappings.proposeModuleMap(modLibC, flatDbg.getCurrentSnap(), progLibC);
- try (Transaction tx = modLibC.getTrace().openTransaction("Map")) {
+ try (Transaction _ = modLibC.getTrace().openTransaction("Map")) {
mappings.addModuleMappings(proposal.computeMap().values(), monitor, true);
}
@@ -605,7 +604,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
DebuggerStaticMappingService mappings = tool.getService(DebuggerStaticMappingService.class);
ModuleMapProposal proposal =
mappings.proposeModuleMap(modLibC, flatDbg.getCurrentSnap(), progLibC);
- try (Transaction tx = modLibC.getTrace().openTransaction("Map")) {
+ try (Transaction _ = modLibC.getTrace().openTransaction("Map")) {
mappings.addModuleMappings(proposal.computeMap().values(), monitor, true);
}
@@ -637,7 +636,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
placeBreakpointsRand();
Address pc = flatDbg.getProgramCounter();
long snapA = flatDbg.getCurrentSnap();
- try (Transaction tx = result.trace().openTransaction("Name snapshot")) {
+ try (Transaction _ = result.trace().openTransaction("Name snapshot")) {
result.trace()
.getTimeManager()
.getSnapshot(snapA, false)
@@ -673,7 +672,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
placeBreakpointsRand();
Address pc = flatDbg.getProgramCounter();
long snapA = flatDbg.getCurrentSnap();
- try (Transaction tx = result.trace().openTransaction("Name snapshot")) {
+ try (Transaction _ = result.trace().openTransaction("Name snapshot")) {
result.trace()
.getTimeManager()
.getSnapshot(snapA, false)
@@ -753,7 +752,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
DebuggerStaticMappingService mappings = tool.getService(DebuggerStaticMappingService.class);
ModuleMapProposal proposal =
mappings.proposeModuleMap(modLibC, flatDbg.getCurrentSnap(), progLibC);
- try (Transaction tx = modLibC.getTrace().openTransaction("Map")) {
+ try (Transaction _ = modLibC.getTrace().openTransaction("Map")) {
mappings.addModuleMappings(proposal.computeMap().values(), monitor, true);
}
@@ -836,7 +835,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
protected void emulateCommandLineParser() throws Throwable {
Function function = findCommandLineParser();
goToStaticUntilContext(function.getEntryPoint());
- performAction(EmulateProgramAction.NAME,
+ performAction("Emulate Program",
PluginUtils.getPluginNameFromClass(DebuggerEmulationServicePlugin.class),
getCodeViewerProvider(), true);
@@ -933,7 +932,7 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
TraceProgramView view = flatDbg.getCurrentView();
waitForCondition(() -> view.getSnap() != 0);
- try (Transaction tx = view.openTransaction("Place units")) {
+ try (Transaction _ = view.openTransaction("Place units")) {
Listing listing = view.getListing();
Data datArgv =
listing.createData(addrArgv, new ArrayDataType(PointerDataType.dataType, 3, 8));
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/AbstractDebuggerBreakpointsProviderTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/AbstractDebuggerBreakpointsProviderTest.java
index 56fa44bb94..5161919d82 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/AbstractDebuggerBreakpointsProviderTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/AbstractDebuggerBreakpointsProviderTest.java
@@ -556,7 +556,7 @@ public abstract class AbstractDebuggerBreakpointsProviderTest<T, P>
T target = createTarget1();
Trace trace = getTrace(target);
- controlService.setCurrentMode(trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(trace, ControlMode.EMULATOR, true);
createProgramFromTrace(trace);
intoProject(trace);
intoProject(program);
@@ -846,7 +846,7 @@ public abstract class AbstractDebuggerBreakpointsProviderTest<T, P>
return newRow;
});
- controlService.setCurrentMode(trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(trace, ControlMode.EMULATOR, true);
lbRow1.setEnabled(true);
TraceBreakpointLocation emuBpt = waitForValue(
() -> Unique.assertAtMostOne(trace.getBreakpointManager().getAllBreakpointLocations()));
@@ -863,12 +863,12 @@ public abstract class AbstractDebuggerBreakpointsProviderTest<T, P>
});
for (int i = 0; i < 3; i++) {
- controlService.setCurrentMode(trace, ControlMode.RO_TARGET);
+ controlService.setCurrentMode(trace, ControlMode.TARGET, false);
waitOn(breakpointService.changesSettled());
waitForSwing();
assertEquals(0, breakpointsProvider.locationTableModel.getModelData().size());
- controlService.setCurrentMode(trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(trace, ControlMode.EMULATOR, true);
waitOn(breakpointService.changesSettled());
waitForSwing();
assertEquals(1, breakpointsProvider.locationTableModel.getModelData().size());
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPluginTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPluginTest.java
index 7d901bc4ce..a64adade53 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPluginTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/control/DebuggerControlPluginTest.java
@@ -70,8 +70,8 @@ import ghidra.util.Swing;
* Tests for target control and state editing
*
* <p>
- * In these and other control service integration tests, we use {@link ControlMode#RW_EMULATOR} as a
- * stand-in for any mode. We also use {@link ControlMode#RO_TARGET} just to verify the mode is
+ * In these and other control service integration tests, we use {@link ControlMode#EMULATOR} as a
+ * stand-in for any mode. We also use {@link ControlMode#TARGET} just to verify the mode is
* heeded. Other modes may be tested if bugs crop up in various combinations.
*/
public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerIntegrationTest {
@@ -278,7 +278,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testEmulateResumeAction() throws Throwable {
TraceThread thread = createToyLoopTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
traceManager.activateThread(thread);
waitForSwing();
@@ -301,7 +301,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testEmulateResumeActionAfterPcodeStep() throws Throwable {
TraceThread thread = createToyLoopTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
traceManager.activateThread(thread);
traceManager.activateTime(TraceSchedule.parse("0:.t%d-2".formatted(thread.getKey())));
@@ -319,7 +319,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testEmulateInterruptAction() throws Throwable {
TraceThread thread = createToyLoopTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
traceManager.activateThread(thread);
waitForSwing();
@@ -341,7 +341,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testEmulateStepBackAction() throws Throwable {
TraceThread thread = createToyLoopTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
traceManager.activateThread(thread);
waitForSwing();
@@ -360,7 +360,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testEmulateStepIntoAction() throws Throwable {
TraceThread thread = createToyLoopTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
traceManager.activateThread(thread);
waitForSwing();
@@ -374,7 +374,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testEmulateSkipOverAction() throws Throwable {
TraceThread thread = createToyLoopTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
traceManager.activateThread(thread);
waitForSwing();
@@ -396,7 +396,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testTraceSnapBackwardAction() throws Throwable {
create2SnapTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
traceManager.activateTrace(tb.trace);
waitForSwing();
@@ -413,7 +413,7 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
@Test
public void testTraceSnapForwardAction() throws Throwable {
create2SnapTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
traceManager.activateTrace(tb.trace);
waitForSwing();
@@ -455,14 +455,14 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
assertTrue(controlPlugin.actionControlMode.isEnabled());
runSwing(() -> controlPlugin.actionControlMode
- .setCurrentActionStateByUserData(ControlMode.RO_TARGET));
- assertEquals(ControlMode.RO_TARGET, controlService.getCurrentMode(tb.trace));
+ .setCurrentActionStateByUserData(ControlMode.TARGET));
+ assertEquals(ControlMode.TARGET, controlService.getCurrentMode(tb.trace));
assertFalse(
helper.patchInstructionAction.isAddToPopup(listingProvider.getActionContext(null)));
runSwing(() -> controlPlugin.actionControlMode
- .setCurrentActionStateByUserData(ControlMode.RW_EMULATOR));
- assertEquals(ControlMode.RW_EMULATOR, controlService.getCurrentMode(tb.trace));
+ .setCurrentActionStateByUserData(ControlMode.EMULATOR));
+ assertEquals(ControlMode.EMULATOR, controlService.getCurrentMode(tb.trace));
assertTrue(
helper.patchInstructionAction.isAddToPopup(listingProvider.getActionContext(null)));
@@ -511,13 +511,13 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
assertTrue(controlPlugin.actionControlMode.isEnabled());
runSwing(() -> controlPlugin.actionControlMode
- .setCurrentActionStateByUserData(ControlMode.RO_TARGET));
- assertEquals(ControlMode.RO_TARGET, controlService.getCurrentMode(tb.trace));
+ .setCurrentActionStateByUserData(ControlMode.TARGET));
+ assertEquals(ControlMode.TARGET, controlService.getCurrentMode(tb.trace));
assertFalse(helper.patchDataAction.isAddToPopup(listingProvider.getActionContext(null)));
runSwing(() -> controlPlugin.actionControlMode
- .setCurrentActionStateByUserData(ControlMode.RW_EMULATOR));
- assertEquals(ControlMode.RW_EMULATOR, controlService.getCurrentMode(tb.trace));
+ .setCurrentActionStateByUserData(ControlMode.EMULATOR));
+ assertEquals(ControlMode.EMULATOR, controlService.getCurrentMode(tb.trace));
goTo(listingProvider.getListingPanel(), new ProgramLocation(view, tb.addr(0x00400123)));
assertTrue(helper.patchDataAction.isAddToPopup(listingProvider.getActionContext(null)));
@@ -567,15 +567,15 @@ public class DebuggerControlPluginTest extends AbstractGhidraHeadedDebuggerInteg
assertTrue(controlPlugin.actionControlMode.isEnabled());
runSwing(() -> controlPlugin.actionControlMode
- .setCurrentActionStateByUserData(ControlMode.RO_TARGET));
- assertEquals(ControlMode.RO_TARGET, controlService.getCurrentMode(tb.trace));
+ .setCurrentActionStateByUserData(ControlMode.TARGET));
+ assertEquals(ControlMode.TARGET, controlService.getCurrentMode(tb.trace));
ctx = listingProvider.getActionContext(null);
assertTrue(pasteAction.isAddToPopup(ctx));
assertFalse(pasteAction.isEnabledForContext(ctx));
runSwing(() -> controlPlugin.actionControlMode
- .setCurrentActionStateByUserData(ControlMode.RW_EMULATOR));
- assertEquals(ControlMode.RW_EMULATOR, controlService.getCurrentMode(tb.trace));
+ .setCurrentActionStateByUserData(ControlMode.EMULATOR));
+ assertEquals(ControlMode.EMULATOR, controlService.getCurrentMode(tb.trace));
goTo(listingPlugin.getListingPanel(), new ProgramLocation(view, tb.addr(0x00400123)));
ctx = listingProvider.getActionContext(null);
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java
index 34e5d2aa3f..8e1a57821a 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java
@@ -971,7 +971,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerInt
TraceObject process = tb.obj("Processes[1]");
traceManager.activateTrace(tb.trace);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RO_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, false);
waitForSwing();
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
@@ -990,7 +990,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerInt
rmiCx.setLastSnapshot(tb.trace, 1);
traceManager.activateSnap(1);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RO_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, false);
traceManager.activateSnap(0);
waitForSwing();
assertFalse(listingProvider.actionRefreshSelectedMemory.isEnabled());
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProviderTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProviderTest.java
index 69d66b0e55..ea5cd225dd 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProviderTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/memory/DebuggerMemoryBytesProviderTest.java
@@ -16,7 +16,7 @@
package ghidra.app.plugin.core.debug.gui.memory;
import static org.junit.Assert.*;
-import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
@@ -800,7 +800,7 @@ public class DebuggerMemoryBytesProviderTest extends AbstractGhidraHeadedDebugge
TraceObject process = tb.obj("Processes[1]");
traceManager.activateTrace(tb.trace);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RO_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, false);
waitForSwing();
assertFalse(memBytesProvider.actionRefreshSelectedMemory.isEnabled());
@@ -819,7 +819,7 @@ public class DebuggerMemoryBytesProviderTest extends AbstractGhidraHeadedDebugge
rmiCx.setLastSnapshot(tb.trace, 1);
traceManager.activateSnap(1);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RO_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, false);
traceManager.activateSnap(0);
waitForSwing();
assertFalse(memBytesProvider.actionRefreshSelectedMemory.isEnabled());
@@ -1136,7 +1136,7 @@ public class DebuggerMemoryBytesProviderTest extends AbstractGhidraHeadedDebugge
traceManager.activateTrace(tb.trace);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
DockingActionIf actionEdit = getAction(memBytesPlugin, "Enable/Disable Byteviewer Editing");
performAction(actionEdit);
@@ -1179,7 +1179,7 @@ public class DebuggerMemoryBytesProviderTest extends AbstractGhidraHeadedDebugge
traceManager.activateTrace(tb.trace);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
DockingActionIf actionEdit = getAction(memBytesPlugin, "Enable/Disable Byteviewer Editing");
performAction(actionEdit);
@@ -1223,7 +1223,7 @@ public class DebuggerMemoryBytesProviderTest extends AbstractGhidraHeadedDebugge
traceManager.activateTrace(tb.trace);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
DockingActionIf actionEdit = getAction(memBytesPlugin, "Enable/Disable Byteviewer Editing");
performAction(actionEdit);
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRmiRegistersProviderTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRmiRegistersProviderTest.java
index 75ec52e151..bd7da8b4db 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRmiRegistersProviderTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRmiRegistersProviderTest.java
@@ -15,8 +15,7 @@
*/
package ghidra.app.plugin.core.debug.gui.register;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.util.Objects;
@@ -60,10 +59,8 @@ public class DebuggerRmiRegistersProviderTest extends AbstractDebuggerRegistersP
setUpRmiTarget();
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
-
- assertTrue(registersProvider.actionEnableEdits.isEnabled());
- performAction(registersProvider.actionEnableEdits);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
+ assertTrue(controlService.getCurrentMode(tb.trace).isEditable());
RegisterRow row = findRegisterRow(r0);
@@ -78,10 +75,9 @@ public class DebuggerRmiRegistersProviderTest extends AbstractDebuggerRegistersP
setUpRmiTarget();
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
- assertTrue(registersProvider.actionEnableEdits.isEnabled());
- performAction(registersProvider.actionEnableEdits);
+ assertTrue(controlService.getCurrentMode(tb.trace).isEditable());
RegisterRow row = findRegisterRow(r0);
assertFalse(row.isRepresentationEditable());
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerTraceRegistersProviderTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerTraceRegistersProviderTest.java
index 4c1d89b72f..27927addcc 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerTraceRegistersProviderTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/register/DebuggerTraceRegistersProviderTest.java
@@ -151,10 +151,10 @@ public class DebuggerTraceRegistersProviderTest extends AbstractDebuggerRegister
activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
-
- assertTrue(registersProvider.actionEnableEdits.isEnabled());
- performAction(registersProvider.actionEnableEdits);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
+ assertTrue(controlService.getCurrentMode(tb.trace).isEditable());
+ //assertTrue(registersProvider.actionEnableEdits.isEnabled());
+ //performAction(registersProvider.actionEnableEdits);
addRegisterValues(thread);
waitForDomainObject(tb.trace);
@@ -183,10 +183,10 @@ public class DebuggerTraceRegistersProviderTest extends AbstractDebuggerRegister
activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
-
- assertTrue(registersProvider.actionEnableEdits.isEnabled());
- performAction(registersProvider.actionEnableEdits);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
+ assertTrue(controlService.getCurrentMode(tb.trace).isEditable());
+ //assertTrue(registersProvider.actionEnableEdits.isEnabled());
+ //performAction(registersProvider.actionEnableEdits);
addRegisterValues(thread);
waitForDomainObject(tb.trace);
@@ -357,26 +357,6 @@ public class DebuggerTraceRegistersProviderTest extends AbstractDebuggerRegister
assertR0RowTypeEmpty();
}
- @Test
- public void testActionEnableEdits() throws Exception {
- traceManager.openTrace(tb.trace);
- TraceThread thread = addThread();
- waitForSwing();
-
- assertFalse(registersProvider.actionEnableEdits.isEnabled());
-
- activateThread(thread);
- waitForSwing();
-
- assertTrue(registersProvider.actionEnableEdits.isEnabled());
-
- // NB, can't activate "null" trace. Manager ignores it.
- traceManager.closeTrace(tb.trace);
- waitForSwing();
-
- assertFalse(registersProvider.actionEnableEdits.isEnabled());
- }
-
@Test
public void testActivateThenAddValuesTypesInFutureHasNoEffect() throws Exception {
traceManager.openTrace(tb.trace);
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProviderTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProviderTest.java
index 0d34524be2..81b64d5d66 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProviderTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/gui/watch/DebuggerWatchesProviderTest.java
@@ -376,13 +376,10 @@ public class DebuggerWatchesProviderTest extends AbstractGhidraHeadedDebuggerInt
assertFalse(row.isRawValueEditable());
traceManager.openTrace(tb.trace);
traceManager.activateThread(thread);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
waitForWatches();
assertNoErr(row);
- assertFalse(row.isRawValueEditable());
-
- performAction(watchesProvider.actionEnableEdits);
assertEquals(expectWritable, row.isRawValueEditable());
}
@@ -410,11 +407,9 @@ public class DebuggerWatchesProviderTest extends AbstractGhidraHeadedDebuggerInt
traceManager.openTrace(tb.trace);
traceManager.activateThread(thread);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
waitForWatches();
- performAction(watchesProvider.actionEnableEdits);
-
return row;
}
@@ -585,8 +580,7 @@ public class DebuggerWatchesProviderTest extends AbstractGhidraHeadedDebuggerInt
DefaultWatchRow row = Unique.assertOne(watchesProvider.watchTableModel.getModelData());
row.setExpression(expression);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
- performAction(watchesProvider.actionEnableEdits);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
return row;
}
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/AbstractDebuggerLogicalBreakpointServiceTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/AbstractDebuggerLogicalBreakpointServiceTest.java
index 4489004c9a..3e39156d85 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/AbstractDebuggerLogicalBreakpointServiceTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/AbstractDebuggerLogicalBreakpointServiceTest.java
@@ -1596,7 +1596,7 @@ public abstract class AbstractDebuggerLogicalBreakpointServiceTest<T, MR>
createTrace();
traceManager.openTrace(tb.trace);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
createProgramFromTrace();
intoProject(program);
programManager.openProgram(program);
@@ -1651,7 +1651,7 @@ public abstract class AbstractDebuggerLogicalBreakpointServiceTest<T, MR>
createTrace();
traceManager.openTrace(tb.trace);
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
createProgramFromTrace();
intoProject(program);
programManager.openProgram(program);
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerRmiLogicalBreakpointServiceTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerRmiLogicalBreakpointServiceTest.java
index 0254e2b91e..6764ac5f0a 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerRmiLogicalBreakpointServiceTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerRmiLogicalBreakpointServiceTest.java
@@ -15,8 +15,7 @@
*/
package ghidra.app.plugin.core.debug.service.breakpoint;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.*;
import java.util.*;
@@ -39,8 +38,9 @@ import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.trace.database.ToyDBTraceBuilder;
import ghidra.trace.model.*;
-import ghidra.trace.model.breakpoint.*;
import ghidra.trace.model.breakpoint.TraceBreakpointKind.CommonSet;
+import ghidra.trace.model.breakpoint.TraceBreakpointLocation;
+import ghidra.trace.model.breakpoint.TraceBreakpointSpec;
import ghidra.trace.model.memory.TraceMemoryRegion;
import ghidra.trace.model.modules.TraceStaticMapping;
import ghidra.trace.model.target.TraceObject;
@@ -272,7 +272,7 @@ public class DebuggerRmiLogicalBreakpointServiceTest extends
traceManager.openTrace(tb.trace);
traceManager.activate(DebuggerCoordinates.NOWHERE.trace(tb.trace).snap(1));
// Needs to have a target or be emulated for the breakpoint service to care
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
TraceBreakpointLocation bpt;
try (Transaction tid = tb.startTransaction()) {
@@ -316,7 +316,7 @@ public class DebuggerRmiLogicalBreakpointServiceTest extends
traceManager.openTrace(tb.trace);
traceManager.activate(DebuggerCoordinates.NOWHERE.trace(tb.trace).snap(1));
// Needs to have a target or be emulated for the breakpoint service to care
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
TraceBreakpointLocation bpt;
try (Transaction tid = tb.startTransaction()) {
@@ -368,7 +368,7 @@ public class DebuggerRmiLogicalBreakpointServiceTest extends
traceManager.openTrace(tb.trace);
traceManager.activate(DebuggerCoordinates.NOWHERE.trace(tb.trace).snap(1));
// Needs to have a target or be emulated for the breakpoint service to care
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
createProgramFromTrace();
intoProject(program);
@@ -420,7 +420,7 @@ public class DebuggerRmiLogicalBreakpointServiceTest extends
traceManager.openTrace(tb.trace);
traceManager.activate(DebuggerCoordinates.NOWHERE.trace(tb.trace).snap(1));
// Needs to have a target or be emulated for the breakpoint service to care
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
createProgramFromTrace();
intoProject(program);
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServiceTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServiceTest.java
index dbc5c55014..21081b9b93 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServiceTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/control/DebuggerControlServiceTest.java
@@ -109,7 +109,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
createAndOpenTrace();
activateTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
StateEditor editor = createStateEditor();
assertFalse(editor.isVariableEditable(tb.addr(0x00400000), 4));
@@ -121,7 +121,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuRegisterNoThreadErr() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
activateTrace();
waitForSwing();
@@ -144,7 +144,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuMemory() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
try (Transaction tx = tb.startTransaction()) {
// NB. TraceManager should automatically activate the first thread
@@ -170,7 +170,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuRegister() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
TraceThread thread;
try (Transaction tx = tb.startTransaction()) {
@@ -200,7 +200,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuMemoryAfterStep() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
TraceThread thread;
try (Transaction tx = tb.startTransaction()) {
@@ -215,7 +215,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
tb.exec(getPlatform(), 0, thread, 0, "pc = 0x00400000;");
}
activateTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
waitForSwing();
TraceSchedule step1 = TraceSchedule.snap(0).steppedForward(thread, 1);
@@ -240,7 +240,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuRegisterAfterStep() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
TraceThread thread;
try (Transaction tx = tb.startTransaction()) {
@@ -255,7 +255,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
tb.exec(getPlatform(), 0, thread, 0, "pc = 0x00400000;");
}
activateTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
waitForSwing();
TraceSchedule step1 = TraceSchedule.snap(0).steppedForward(thread, 1);
@@ -281,7 +281,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuMemoryTwice() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
try (Transaction tx = tb.startTransaction()) {
// NB. TraceManager should automatically activate the first thread
@@ -311,7 +311,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
@Test
public void testWriteEmuRegisterTwice() throws Throwable {
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
TraceThread thread;
try (Transaction tx = tb.startTransaction()) {
@@ -343,7 +343,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
public void testWriteTraceMemory() throws Throwable {
// NB. Definitely no thread required
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
activateTrace();
waitForSwing();
@@ -366,7 +366,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
public void testWriteTraceRegisterNoThreadErr() throws Throwable {
// NB. Definitely no thread required
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
activateTrace();
waitForSwing();
@@ -382,7 +382,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
public void testWriteTraceRegister() throws Throwable {
// NB. Definitely no thread required
createAndOpenTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ controlService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
TraceThread thread;
try (Transaction tx = tb.startTransaction()) {
@@ -439,7 +439,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
activateTrace(); // platform
traceManager.activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
StateEditor editor = createStateEditor();
assertTrue(editor.isVariableEditable(tb.addr(0x00400000), 4));
@@ -459,7 +459,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
activateTrace(); // platform
traceManager.activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
StateEditor editor = createStateEditor();
assertTrue(editor.isRegisterEditable(r0));
@@ -480,7 +480,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
activateTrace(); // platform
traceManager.activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
StateEditor editor = createStateEditor();
assertTrue(editor.isRegisterEditable(r0));
@@ -509,24 +509,24 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
traceManager.activateThread(thread);
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
waitForSwing();
assertEquals(target.getSnap(), traceManager.getCurrentSnap());
traceManager.activateSnap(traceManager.getCurrentSnap() - 1);
waitForSwing();
assertEquals(
- "Cannot navigate time in Control Target mode. Switch to Trace or Emulate mode first.",
+ "Cannot navigate time in Target mode. Switch to Trace or Emulate mode first.",
tool.getStatusInfo());
assertEquals(target.getSnap(), traceManager.getCurrentSnap());
- controlService.setCurrentMode(tb.trace, ControlMode.RW_EMULATOR);
+ controlService.setCurrentMode(tb.trace, ControlMode.EMULATOR, true);
waitForSwing();
traceManager.activateSnap(traceManager.getCurrentSnap() - 1);
waitForSwing();
- assertEquals(ControlMode.RW_EMULATOR, controlService.getCurrentMode(tb.trace));
+ assertEquals(ControlMode.EMULATOR, controlService.getCurrentMode(tb.trace));
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
waitForSwing();
assertEquals(target.getSnap(), traceManager.getCurrentSnap());
}
@@ -536,7 +536,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
createAndOpenTrace();
activateTrace();
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
waitForSwing();
StateEditor editor = createStateEditor();
@@ -551,7 +551,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
createAndOpenTrace();
activateTrace();
waitForSwing();
- controlService.setCurrentMode(tb.trace, ControlMode.RW_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, true);
waitForSwing();
StateEditor editor = createStateEditor();
@@ -566,7 +566,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
createAndOpenTrace();
targetService.publishTarget(new MockTarget(tb.trace));
activateTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RO_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, false);
StateEditor editor = createStateEditor();
assertFalse(editor.isVariableEditable(tb.addr(0x00400000), 4));
@@ -580,7 +580,7 @@ public class DebuggerControlServiceTest extends AbstractGhidraHeadedDebuggerInte
createAndOpenTrace();
targetService.publishTarget(new MockTarget(tb.trace));
activateTrace();
- controlService.setCurrentMode(tb.trace, ControlMode.RO_TARGET);
+ controlService.setCurrentMode(tb.trace, ControlMode.TARGET, false);
StateEditor editor = createStateEditor();
assertFalse(editor.isRegisterEditable(r0));
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServiceTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServiceTest.java
index 59f852ea0b..f49b28000b 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServiceTest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/app/plugin/core/debug/service/tracemgr/DebuggerTraceManagerServiceTest.java
@@ -363,7 +363,7 @@ public class DebuggerTraceManagerServiceTest extends AbstractGhidraHeadedDebugge
traceManager.activateThread(thread);
waitForSwing();
- assertEquals(ControlMode.RO_TARGET, editingService.getCurrentMode(tb.trace));
+ assertEquals(ControlMode.TARGET, editingService.getCurrentMode(tb.trace));
long initSnap = target.getSnap();
assertEquals(initSnap, traceManager.getCurrentSnap());
@@ -374,7 +374,7 @@ public class DebuggerTraceManagerServiceTest extends AbstractGhidraHeadedDebugge
assertEquals(initSnap + 1, target.getSnap());
assertEquals(initSnap + 1, traceManager.getCurrentSnap());
- editingService.setCurrentMode(tb.trace, ControlMode.RO_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, false);
rmiCx.setLastSnapshot(tb.trace, initSnap + 2);
rmiCx.synthActivate(thread.getObject());
@@ -383,7 +383,7 @@ public class DebuggerTraceManagerServiceTest extends AbstractGhidraHeadedDebugge
assertEquals(initSnap + 2, target.getSnap());
assertEquals(initSnap + 1, traceManager.getCurrentSnap());
- editingService.setCurrentMode(tb.trace, ControlMode.RO_TARGET);
+ editingService.setCurrentMode(tb.trace, ControlMode.TARGET, false);
waitForSwing();
assertEquals(initSnap + 2, target.getSnap());
diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/debug/flatapi/AbstractFlatDebuggerAPITest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/debug/flatapi/AbstractFlatDebuggerAPITest.java
index 4456c23c01..d0bd396c6b 100644
--- a/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/debug/flatapi/AbstractFlatDebuggerAPITest.java
+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test/java/ghidra/debug/flatapi/AbstractFlatDebuggerAPITest.java
@@ -228,7 +228,7 @@ public abstract class AbstractFlatDebuggerAPITest<API extends FlatDebuggerAPI>
@Test
public void testWriteMemoryGivenContext() throws Throwable {
createTraceWithBinText();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
assertTrue(api.writeMemory(tb.trace, 0, tb.addr(0x00400123), tb.arr(3, 2, 1)));
ByteBuffer buf = ByteBuffer.allocate(3);
@@ -239,7 +239,7 @@ public abstract class AbstractFlatDebuggerAPITest<API extends FlatDebuggerAPI>
@Test
public void testWriteMemoryCurrentContext() throws Throwable {
createTraceWithBinText();
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
assertTrue(api.writeMemory(tb.addr(0x00400123), tb.arr(3, 2, 1)));
ByteBuffer buf = ByteBuffer.allocate(3);
@@ -250,7 +250,7 @@ public abstract class AbstractFlatDebuggerAPITest<API extends FlatDebuggerAPI>
@Test
public void testWriteRegisterGivenContext() throws Throwable {
TraceThread thread = createTraceWithThreadAndStack(true);
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
traceManager.activateThread(thread);
waitForSwing();
@@ -266,7 +266,7 @@ public abstract class AbstractFlatDebuggerAPITest<API extends FlatDebuggerAPI>
@Test
public void testWriteRegisterCurrentContext() throws Throwable {
TraceThread thread = createTraceWithThreadAndStack(true);
- editingService.setCurrentMode(tb.trace, ControlMode.RW_TRACE);
+ editingService.setCurrentMode(tb.trace, ControlMode.TRACE, true);
traceManager.activateThread(thread);
waitForSwing();