Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1395: Double-click in listing margin toggles breakpoints.

Dan77f8906a2312
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java
index 910e1ca898..abb8bf5e2b 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPlugin.java
@@ -37,6 +37,7 @@ import ghidra.app.plugin.core.debug.gui.DebuggerResources;
import ghidra.app.plugin.core.debug.gui.DebuggerResources.*;
import ghidra.app.services.*;
import ghidra.app.services.LogicalBreakpoint.Enablement;
+import ghidra.app.util.viewer.listingpanel.MarkerClickedListener;
import ghidra.async.AsyncDebouncer;
import ghidra.async.AsyncTimer;
import ghidra.framework.options.AutoOptions;
@@ -480,6 +481,15 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
}
}
+ private class ToggleBreakpointsMarkerClickedListener implements MarkerClickedListener {
+ @Override
+ public void markerDoubleClicked(MarkerLocation location) {
+ doToggleBreakpointsAt(ToggleBreakpointAction.NAME,
+ new ProgramLocationActionContext(null, location.getProgram(),
+ new ProgramLocation(location.getProgram(), location.getAddr()), null, null));
+ }
+ }
+
protected static Enablement computeEnablement(LogicalBreakpoint breakpoint,
Program programOrView) {
if (programOrView instanceof TraceProgramView) {
@@ -524,47 +534,7 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
@Override
public void actionPerformed(ActionContext context) {
- if (breakpointService == null) {
- return;
- }
- ProgramLocation loc = getLocationFromContext(context);
- if (loc == null) {
- return;
- }
- Set<LogicalBreakpoint> bs = breakpointService.getBreakpointsAt(loc);
- if (bs == null || bs.isEmpty()) {
- Set<TraceBreakpointKind> supported = getSupportedKindsFromContext(context);
- if (supported.isEmpty()) {
- breakpointError(NAME,
- "It seems this target does not support breakpoints.");
- return;
- }
- Set<TraceBreakpointKind> kinds = computeDefaultKinds(context, supported);
- long length = computeDefaultLength(context, kinds);
- placeBreakpointDialog.prompt(tool, breakpointService, NAME, loc, length, kinds);
- return;
- }
- Enablement en = breakpointService.computeEnablement(bs, loc);
- /**
- * If we're in the static listing, this will return null, indicating we should use the
- * program's perspective. The methods taking trace should accept a null trace and behave
- * accordingly. If in the dynamic listing, we act in the context of the returned trace.
- */
- Trace trace = getTraceFromContext(context);
- boolean mapped = breakpointService.anyMapped(bs, trace);
- Enablement toggled = en = en.getToggled(mapped);
- if (toggled.enabled) {
- breakpointService.enableAll(bs, trace).exceptionally(ex -> {
- breakpointError(NAME, "Could not enable breakpoints", ex);
- return null;
- });
- }
- else {
- breakpointService.disableAll(bs, trace).exceptionally(ex -> {
- breakpointError(NAME, "Could not disable breakpoints", ex);
- return null;
- });
- }
+ doToggleBreakpointsAt(NAME, context);
}
@Override
@@ -733,7 +703,7 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
}
}
- @AutoServiceConsumed
+ // @AutoServiceConsumed via method
private MarkerService markerService;
// @AutoServiceConsumed via method
private DebuggerLogicalBreakpointService breakpointService;
@@ -811,6 +781,8 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
private final LogicalBreakpointsChangeListener updateMarksListener =
new UpdateMarksBreakpointRecordChangeListener();
+ private final MarkerClickedListener markerClickedListener =
+ new ToggleBreakpointsMarkerClickedListener();
private final AsyncDebouncer<Void> updateDebouncer =
new AsyncDebouncer<>(AsyncTimer.DEFAULT_TIMER, 100);
@@ -964,6 +936,50 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
.collect(Collectors.toSet());
}
+ protected void doToggleBreakpointsAt(String title, ActionContext context) {
+ // TODO: Seems like this should be in logical breakpoint service?
+ if (breakpointService == null) {
+ return;
+ }
+ ProgramLocation loc = getLocationFromContext(context);
+ if (loc == null) {
+ return;
+ }
+ Set<LogicalBreakpoint> bs = breakpointService.getBreakpointsAt(loc);
+ if (bs == null || bs.isEmpty()) {
+ Set<TraceBreakpointKind> supported = getSupportedKindsFromContext(context);
+ if (supported.isEmpty()) {
+ breakpointError(title, "It seems this target does not support breakpoints.");
+ return;
+ }
+ Set<TraceBreakpointKind> kinds = computeDefaultKinds(context, supported);
+ long length = computeDefaultLength(context, kinds);
+ placeBreakpointDialog.prompt(tool, breakpointService, title, loc, length, kinds);
+ return;
+ }
+ Enablement en = breakpointService.computeEnablement(bs, loc);
+ /**
+ * If we're in the static listing, this will return null, indicating we should use the
+ * program's perspective. The methods taking trace should accept a null trace and behave
+ * accordingly. If in the dynamic listing, we act in the context of the returned trace.
+ */
+ Trace trace = getTraceFromContext(context);
+ boolean mapped = breakpointService.anyMapped(bs, trace);
+ Enablement toggled = en = en.getToggled(mapped);
+ if (toggled.enabled) {
+ breakpointService.enableAll(bs, trace).exceptionally(ex -> {
+ breakpointError(title, "Could not enable breakpoints", ex);
+ return null;
+ });
+ }
+ else {
+ breakpointService.disableAll(bs, trace).exceptionally(ex -> {
+ breakpointError(title, "Could not disable breakpoints", ex);
+ return null;
+ });
+ }
+ }
+
/**
* Instantiate a marker set for the given program or trace view
*
@@ -1031,6 +1047,15 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
}
}
+ @AutoServiceConsumed
+ private void setMarkerService(MarkerService markerService) {
+ this.markerService = markerService;
+ // NB. There's no way to remove such a listener...
+ if (markerService != null) {
+ markerService.setMarkerClickedListener(markerClickedListener);
+ }
+ }
+
@AutoServiceConsumed
private void setLogicalBreakpointService(DebuggerLogicalBreakpointService breakpointService) {
if (this.breakpointService != null) {
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java
index e1d506d6b5..70c600d489 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProvider.java
@@ -15,7 +15,8 @@
*/
package ghidra.app.plugin.core.debug.gui.listing;
-import static ghidra.app.plugin.core.debug.gui.DebuggerResources.*;
+import static ghidra.app.plugin.core.debug.gui.DebuggerResources.ICON_REGISTER_MARKER;
+import static ghidra.app.plugin.core.debug.gui.DebuggerResources.OPTION_NAME_COLORS_TRACKING_MARKERS;
import java.awt.Color;
import java.awt.datatransfer.Transferable;
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointHistoryProviderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointHistoryProviderTest.java
deleted file mode 100644
index d9c625da04..0000000000
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointHistoryProviderTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.plugin.core.debug.gui.breakpoint;
-
-import static ghidra.lifecycle.Unfinished.TODO;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-@Ignore
-public class DebuggerBreakpointHistoryProviderTest {
- @Test
- public void testSomething() {
- TODO();
- }
-}