GP-3303: Display model actions only in Control Target mode

This commit is contained in:
Dan 2023-04-20 14:40:43 -04:00
parent 9dcc504965
commit 2147d0c436
3 changed files with 51 additions and 1 deletions

View file

@ -37,6 +37,7 @@ import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.util.MarkerLocation; import ghidra.program.util.MarkerLocation;
import ghidra.program.util.ProgramLocation; import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.Trace;
import ghidra.trace.model.program.TraceProgramView; import ghidra.trace.model.program.TraceProgramView;
import ghidra.trace.model.target.TraceObject; import ghidra.trace.model.target.TraceObject;
import ghidra.util.Msg; import ghidra.util.Msg;
@ -98,6 +99,8 @@ public class DebuggerMethodActionsPlugin extends Plugin implements PopupActionPr
private DebuggerStaticMappingService mappingService; private DebuggerStaticMappingService mappingService;
@AutoServiceConsumed @AutoServiceConsumed
private DebuggerConsoleService consoleService; private DebuggerConsoleService consoleService;
@AutoServiceConsumed
private DebuggerControlService controlService;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final AutoService.Wiring autoServiceWiring; private final AutoService.Wiring autoServiceWiring;
@ -107,8 +110,23 @@ public class DebuggerMethodActionsPlugin extends Plugin implements PopupActionPr
tool.addPopupActionProvider(this); tool.addPopupActionProvider(this);
} }
protected boolean isControlTarget() {
if (controlService == null || traceManager == null) {
return true;
}
Trace trace = traceManager.getCurrentTrace();
if (trace == null) {
return true;
}
ControlMode mode = controlService.getCurrentMode(trace);
return mode.isTarget();
}
@Override @Override
public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context) { public List<DockingActionIf> getPopupActions(Tool tool, ActionContext context) {
if (!isControlTarget()) {
return List.of();
}
TargetObject curObj = getCurrentTargetObject(); TargetObject curObj = getCurrentTargetObject();
if (curObj == null) { if (curObj == null) {
return List.of(); return List.of();

View file

@ -55,6 +55,11 @@ public enum ControlMode {
*/ */
RO_TARGET("Control Target w/ Edits Disabled", new GIcon( RO_TARGET("Control Target w/ Edits Disabled", new GIcon(
"icon.debugger.control.mode.ro.target")) { "icon.debugger.control.mode.ro.target")) {
@Override
public boolean isTarget() {
return true;
}
@Override @Override
public boolean followsPresent() { public boolean followsPresent() {
return true; return true;
@ -96,6 +101,11 @@ public enum ControlMode {
* Control actions, breakpoint commands, and state edits are all directed to the target. * 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")) { RW_TARGET("Control Target", new GIcon("icon.debugger.control.mode.rw.target")) {
@Override
public boolean isTarget() {
return true;
}
@Override @Override
public boolean followsPresent() { public boolean followsPresent() {
return true; return true;
@ -153,6 +163,11 @@ public enum ControlMode {
* and state edits are rejected. * and state edits are rejected.
*/ */
RO_TRACE("Control Trace w/ Edits Disabled", new GIcon("icon.debugger.control.mode.ro.trace")) { RO_TRACE("Control Trace w/ Edits Disabled", new GIcon("icon.debugger.control.mode.ro.trace")) {
@Override
public boolean isTarget() {
return false;
}
@Override @Override
public boolean followsPresent() { public boolean followsPresent() {
return false; return false;
@ -185,6 +200,11 @@ public enum ControlMode {
* and state edits modify the current trace snapshot. * and state edits modify the current trace snapshot.
*/ */
RW_TRACE("Control Trace", new GIcon("icon.debugger.control.mode.rw.trace")) { RW_TRACE("Control Trace", new GIcon("icon.debugger.control.mode.rw.trace")) {
@Override
public boolean isTarget() {
return false;
}
@Override @Override
public boolean followsPresent() { public boolean followsPresent() {
return false; return false;
@ -251,6 +271,11 @@ public enum ControlMode {
* schedule. * schedule.
*/ */
RW_EMULATOR("Control Emulator", new GIcon("icon.debugger.control.mode.rw.emulator")) { RW_EMULATOR("Control Emulator", new GIcon("icon.debugger.control.mode.rw.emulator")) {
@Override
public boolean isTarget() {
return false;
}
@Override @Override
public boolean followsPresent() { public boolean followsPresent() {
return false; return false;
@ -430,4 +455,11 @@ public enum ControlMode {
} }
return getAlternative(coordinates); return getAlternative(coordinates);
} }
/**
* Indicates whether this mode controls the target
*
* @return true if it controls the target
*/
public abstract boolean isTarget();
} }

View file

@ -81,7 +81,7 @@ public class DebuggerMethodActionsPluginTest extends AbstractGhidraHeadedDebugge
List<String> commands = Collections.synchronizedList(new ArrayList<>()); List<String> commands = Collections.synchronizedList(new ArrayList<>());
@Before @Before
public void setUpMethodAcitonsTest() throws Exception { public void setUpMethodActionsTest() throws Exception {
listingPlugin = addPlugin(tool, DebuggerListingPlugin.class); listingPlugin = addPlugin(tool, DebuggerListingPlugin.class);
mappingService = addPlugin(tool, DebuggerStaticMappingServicePlugin.class); mappingService = addPlugin(tool, DebuggerStaticMappingServicePlugin.class);
methodsPlugin = addPlugin(tool, DebuggerMethodActionsPlugin.class); methodsPlugin = addPlugin(tool, DebuggerMethodActionsPlugin.class);