Skip to content

Ghidra is a software reverse engineering (SRE) framework

Gp-1559: Adding breakpoint name column and prompt for program breakpoints.

Danb4d038fe3066
diff --git a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/DebuggerBreakpointMarkerPlugin.html b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/DebuggerBreakpointMarkerPlugin.html
index 5b91cfbe78..8c45dd570b 100644
--- a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/DebuggerBreakpointMarkerPlugin.html
+++ b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/DebuggerBreakpointMarkerPlugin.html
@@ -84,6 +84,9 @@
<LI>Kinds - the kind(s) of breakpoint. Only the reasonable combinations are presented, but
the user may type any desired combination. A connected debugger may not support the desired
combination.</LI>
+
+ <LI>Name - the user-defined name of the breakpoint. The name is saved to the program
+ containing its static location, if applicable.</LI>
</UL>
<H3><A name="enable_breakpoint"></A><IMG alt="" src="images/breakpoint-enable.png"> Enable
diff --git a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/images/DebuggerPlaceBreakpointDialog.png b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/images/DebuggerPlaceBreakpointDialog.png
index 87db1282ca..8a98249704 100644
Binary files a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/images/DebuggerPlaceBreakpointDialog.png and b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointMarkerPlugin/images/DebuggerPlaceBreakpointDialog.png differ
diff --git a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/DebuggerBreakpointsPlugin.html b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/DebuggerBreakpointsPlugin.html
index f8768e79c7..5970c45476 100644
--- a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/DebuggerBreakpointsPlugin.html
+++ b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/DebuggerBreakpointsPlugin.html
@@ -69,27 +69,31 @@
<LI>Enabled - displays an icon indicating the state of the breakpoint. Clicking the icon
toggles the breakpoint.</LI>
- <UL style="list-style-type: none">
- <LI><IMG alt="" src="images/breakpoint-enable.png"> Enabled</LI>
+ <UL style="list-style-type: none">
+ <LI><IMG alt="" src="images/breakpoint-enable.png"> Enabled</LI>
- <LI><IMG alt="" src="images/breakpoint-disable.png"> Disabled</LI>
+ <LI><IMG alt="" src="images/breakpoint-disable.png"> Disabled</LI>
- <LI><IMG alt="" src="images/breakpoint-mixed-ed.png"> Inconsistent: Enabled with disabled
- locations</LI>
+ <LI><IMG alt="" src="images/breakpoint-mixed-ed.png"> Inconsistent: Enabled with disabled
+ locations</LI>
- <LI><IMG alt="" src="images/breakpoint-mixed-de.png"> Inconsistent: Disabled with enabled
- locations</LI>
+ <LI><IMG alt="" src="images/breakpoint-mixed-de.png"> Inconsistent: Disabled with enabled
+ locations</LI>
- <LI><IMG alt="" src="images/breakpoint-ineffective-e.png"> Enabled but ineffective</LI>
+ <LI><IMG alt="" src="images/breakpoint-ineffective-e.png"> Enabled but ineffective</LI>
- <LI><IMG alt="" src="images/breakpoint-ineffective-d.png"> Disabled and ineffective</LI>
- </UL>
+ <LI><IMG alt="" src="images/breakpoint-ineffective-d.png"> Disabled and ineffective</LI>
+ </UL>
- <LI>Image - gives the name of the Ghidra program, if the breakpoint is mapped to one.</LI>
+ <LI>Name - gives the user-defined name of the breakpoint. This cell is only populated and
+ modifiable when the breakpoint is mapped and saved to a program, since the name is associated
+ with the static location.</LI>
- <LI>Address - gives the address of the breakpoint. For a breakpoint mapped to a Ghidra
- program, this gives the address in that program. For a breakpoint not mapped, this gives the
- address in its trace.</LI>
+ <LI>Address - gives the address of the breakpoint. For a breakpoint mapped to a program, this
+ gives the address in that program. For a breakpoint not mapped, this gives the address in its
+ trace.</LI>
+
+ <LI>Image - gives the name of the program, if the breakpoint is mapped to one.</LI>
<LI>Length - usually 1. For access breakpoints, this notes the length in bytes of the address
range.</LI>
diff --git a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/images/DebuggerBreakpointsPlugin.png b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/images/DebuggerBreakpointsPlugin.png
index 88f4df0a83..9eca75a21e 100644
Binary files a/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/images/DebuggerBreakpointsPlugin.png and b/Ghidra/Debug/Debugger/src/main/help/help/topics/DebuggerBreakpointsPlugin/images/DebuggerBreakpointsPlugin.png differ
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 f3825cb243..7ff8928bb6 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
@@ -567,7 +567,8 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
}
ProgramLocation location = getLocationFromContext(context);
long length = computeDefaultLength(context, kinds);
- placeBreakpointDialog.prompt(tool, breakpointService, NAME, location, length, kinds);
+ placeBreakpointDialog.prompt(tool, breakpointService, NAME, location, length, kinds,
+ "");
}
@Override
@@ -954,7 +955,7 @@ public class DebuggerBreakpointMarkerPlugin extends Plugin
}
Set<TraceBreakpointKind> kinds = computeDefaultKinds(context, supported);
long length = computeDefaultLength(context, kinds);
- placeBreakpointDialog.prompt(tool, breakpointService, title, loc, length, kinds);
+ placeBreakpointDialog.prompt(tool, breakpointService, title, loc, length, kinds, "");
return;
}
Enablement en = breakpointService.computeEnablement(bs, loc);
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProvider.java
index 0870a87769..f250acc9f2 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProvider.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProvider.java
@@ -18,8 +18,7 @@ package ghidra.app.plugin.core.debug.gui.breakpoint;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.util.*;
-import java.util.function.BiConsumer;
-import java.util.function.Function;
+import java.util.function.*;
import java.util.stream.Collectors;
import javax.swing.*;
@@ -60,32 +59,44 @@ public class DebuggerBreakpointsProvider extends ComponentProviderAdapter
protected enum LogicalBreakpointTableColumns
implements EnumeratedTableColumn<LogicalBreakpointTableColumns, LogicalBreakpointRow> {
- ENABLED("", Enablement.class, LogicalBreakpointRow::getEnablement, LogicalBreakpointRow::setEnablement, true),
- IMAGE("Image", String.class, LogicalBreakpointRow::getImageName, true),
+ ENABLED("", Enablement.class, LogicalBreakpointRow::getEnablement, //
+ LogicalBreakpointRow::setEnablement, true),
+ NAME("Name", String.class, LogicalBreakpointRow::getName, LogicalBreakpointRow::setName, //
+ LogicalBreakpointRow::isNamable, true),
ADDRESS("Address", Address.class, LogicalBreakpointRow::getAddress, true),
+ IMAGE("Image", String.class, LogicalBreakpointRow::getImageName, true),
LENGTH("Length", Long.class, LogicalBreakpointRow::getLength, true),
KINDS("Kinds", String.class, LogicalBreakpointRow::getKinds, true),
LOCATIONS("Locations", Integer.class, LogicalBreakpointRow::getLocationCount, true);
private final String header;
+ private final Class<?> cls;
private final Function<LogicalBreakpointRow, ?> getter;
private final BiConsumer<LogicalBreakpointRow, Object> setter;
+ private final Predicate<LogicalBreakpointRow> editable;
private final boolean sortable;
- private final Class<?> cls;
<T> LogicalBreakpointTableColumns(String header, Class<T> cls,
Function<LogicalBreakpointRow, T> getter, boolean sortable) {
- this(header, cls, getter, null, sortable);
+ this(header, cls, getter, null, null, sortable);
}
- @SuppressWarnings("unchecked")
<T> LogicalBreakpointTableColumns(String header, Class<T> cls,
Function<LogicalBreakpointRow, T> getter,
BiConsumer<LogicalBreakpointRow, T> setter, boolean sortable) {
+ this(header, cls, getter, setter, null, sortable);
+ }
+
+ @SuppressWarnings("unchecked")
+ <T> LogicalBreakpointTableColumns(String header, Class<T> cls,
+ Function<LogicalBreakpointRow, T> getter,
+ BiConsumer<LogicalBreakpointRow, T> setter,
+ Predicate<LogicalBreakpointRow> editable, boolean sortable) {
this.header = header;
this.cls = cls;
this.getter = getter;
this.setter = (BiConsumer<LogicalBreakpointRow, Object>) setter;
+ this.editable = editable;
this.sortable = sortable;
}
@@ -106,7 +117,7 @@ public class DebuggerBreakpointsProvider extends ComponentProviderAdapter
@Override
public boolean isEditable(LogicalBreakpointRow row) {
- return setter != null;
+ return setter != null && (editable == null || editable.test(row));
}
@Override
@@ -961,10 +972,16 @@ public class DebuggerBreakpointsProvider extends ComponentProviderAdapter
new DebuggerBreakpointEnablementTableCellEditor(breakpointFilterPanel));
bptEnCol.setMaxWidth(24);
bptEnCol.setMinWidth(24);
+ TableColumn bptNameCol =
+ bptColModel.getColumn(LogicalBreakpointTableColumns.NAME.ordinal());
+ bptNameCol.setPreferredWidth(150);
TableColumn bptAddrCol =
bptColModel.getColumn(LogicalBreakpointTableColumns.ADDRESS.ordinal());
bptAddrCol.setPreferredWidth(150);
bptAddrCol.setCellRenderer(CustomToStringCellRenderer.MONO_OBJECT);
+ TableColumn bptImgCol =
+ bptColModel.getColumn(LogicalBreakpointTableColumns.IMAGE.ordinal());
+ bptImgCol.setPreferredWidth(100);
TableColumn lenCol = bptColModel.getColumn(LogicalBreakpointTableColumns.LENGTH.ordinal());
lenCol.setPreferredWidth(60);
lenCol.setCellRenderer(CustomToStringCellRenderer.MONO_ULONG_HEX);
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerPlaceBreakpointDialog.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerPlaceBreakpointDialog.java
index ecfd541b0f..3d0800351f 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerPlaceBreakpointDialog.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerPlaceBreakpointDialog.java
@@ -34,6 +34,7 @@ import ghidra.program.util.ProgramLocation;
import ghidra.trace.model.breakpoint.TraceBreakpointKind;
import ghidra.trace.model.breakpoint.TraceBreakpointKind.TraceBreakpointKindSet;
import ghidra.util.MessageType;
+import ghidra.util.Swing;
import ghidra.util.layout.PairLayout;
public class DebuggerPlaceBreakpointDialog extends DialogComponentProvider {
@@ -42,10 +43,12 @@ public class DebuggerPlaceBreakpointDialog extends DialogComponentProvider {
private Address address;
private long length;
private Set<TraceBreakpointKind> kinds;
+ private String name;
private JTextField fieldAddress;
private JTextField fieldLength;
private JComboBox<String> fieldKinds;
+ private JTextField fieldName;
public DebuggerPlaceBreakpointDialog() {
super(AbstractSetBreakpointAction.NAME, true, true, true, false);
@@ -81,6 +84,11 @@ public class DebuggerPlaceBreakpointDialog extends DialogComponentProvider {
panel.add(labelKinds);
panel.add(fieldKinds);
+ JLabel labelName = new JLabel("Name");
+ fieldName = new JTextField();
+ panel.add(labelName);
+ panel.add(fieldName);
+
addWorkPanel(panel);
addOKButton();
@@ -88,16 +96,18 @@ public class DebuggerPlaceBreakpointDialog extends DialogComponentProvider {
}
public void prompt(PluginTool tool, DebuggerLogicalBreakpointService service, String title,
- ProgramLocation loc, long length, Collection<TraceBreakpointKind> kinds) {
+ ProgramLocation loc, long length, Collection<TraceBreakpointKind> kinds, String name) {
this.service = service;
this.program = loc.getProgram();
this.address = loc.getAddress(); // byte address can be confusing here.
this.length = length;
this.kinds = Set.copyOf(kinds);
+ this.name = name;
this.fieldAddress.setText(address.toString());
this.fieldLength.setText(Long.toUnsignedString(length));
this.fieldKinds.setSelectedItem(TraceBreakpointKindSet.encode(kinds));
+ this.fieldName.setText("");
clearStatusText();
@@ -128,8 +138,10 @@ public class DebuggerPlaceBreakpointDialog extends DialogComponentProvider {
return;
}
+ name = fieldName.getText();
+
ProgramLocation loc = new ProgramLocation(program, address);
- service.placeBreakpointAt(loc, length, kinds).thenAccept(__ -> {
+ service.placeBreakpointAt(loc, length, kinds, name).thenAccept(__ -> {
close();
}).exceptionally(ex -> {
ex = AsyncUtils.unwrapThrowable(ex);
@@ -137,4 +149,10 @@ public class DebuggerPlaceBreakpointDialog extends DialogComponentProvider {
return null;
});
}
+
+ /* testing */
+ void setName(String name) {
+ this.name = name;
+ Swing.runNow(() -> this.fieldName.setText(name));
+ }
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java
index 9b386fe550..6af9fc4a67 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/breakpoint/LogicalBreakpointRow.java
@@ -83,6 +83,18 @@ public class LogicalBreakpointRow {
}
}
+ public String getName() {
+ return lb.getName();
+ }
+
+ public void setName(String name) {
+ lb.setName(name);
+ }
+
+ public boolean isNamable() {
+ return lb.getProgramBookmark() != null;
+ }
+
public String getImageName() {
Program program = lb.getProgram();
if (program == null) {
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerLogicalBreakpointServicePlugin.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerLogicalBreakpointServicePlugin.java
index 4b0f4ce7e3..ccffde9009 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerLogicalBreakpointServicePlugin.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/DebuggerLogicalBreakpointServicePlugin.java
@@ -331,15 +331,19 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
private void breakpointBookmarkChanged(Bookmark bookmark) {
synchronized (lock) {
- breakpointBookmarkDeleted(bookmark);
+ breakpointBookmarkDeleted(bookmark, true);
breakpointBookmarkAdded(bookmark);
}
}
private void breakpointBookmarkDeleted(Bookmark bookmark) {
+ breakpointBookmarkDeleted(bookmark, false);
+ }
+
+ private void breakpointBookmarkDeleted(Bookmark bookmark, boolean forChange) {
try (RemoveCollector c = new RemoveCollector(changeListeners.fire)) {
synchronized (lock) {
- info.forgetProgramBreakpoint(bookmark, c);
+ info.forgetProgramBreakpoint(bookmark, forChange, c);
}
}
}
@@ -644,7 +648,7 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
}
protected LogicalBreakpointInternal removeFromLogicalBreakpoint(Bookmark bookmark,
- RemoveCollector c) {
+ boolean forChange, RemoveCollector c) {
Address address = bookmark.getAddress();
Set<LogicalBreakpointInternal> set = breakpointsByAddress.get(address);
if (set == null) {
@@ -653,7 +657,7 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
}
for (LogicalBreakpointInternal lb : Set.copyOf(set)) {
if (lb.untrackBreakpoint(program, bookmark)) {
- if (lb.isEmpty()) {
+ if (lb.isEmpty() && !forChange) {
// If being disposed, this info may no longer be in the map
removeLogicalBreakpoint(address, lb);
removeLogicalBreakpointGlobally(lb);
@@ -696,7 +700,7 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
.getBookmarksIterator(LogicalBreakpoint.BREAKPOINT_DISABLED_BOOKMARK_TYPE)
.forEachRemaining(marks::add);
for (Bookmark bm : marks) {
- forgetProgramBreakpoint(bm, r);
+ forgetProgramBreakpoint(bm, false, r);
}
}
@@ -716,11 +720,11 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
continue;
}
if (bm != program.getBookmarkManager().getBookmark(bm.getId())) {
- forgetProgramBreakpoint(bm, r);
+ forgetProgramBreakpoint(bm, false, r);
continue;
}
if (!lb.getProgramLocation().getByteAddress().equals(bm.getAddress())) {
- forgetProgramBreakpoint(bm, r);
+ forgetProgramBreakpoint(bm, false, r);
continue;
}
}
@@ -751,13 +755,22 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
}
}
- protected void forgetProgramBreakpoint(Bookmark breakpoint, RemoveCollector c) {
- LogicalBreakpointInternal lb = removeFromLogicalBreakpoint(breakpoint, c);
+ protected void forgetProgramBreakpoint(Bookmark breakpoint, boolean forChange,
+ RemoveCollector c) {
+ LogicalBreakpointInternal lb = removeFromLogicalBreakpoint(breakpoint, forChange, c);
if (lb == null) {
return;
}
- assert lb.isEmpty() == (breakpointsByAddress.get(breakpoint.getAddress()) == null ||
- !breakpointsByAddress.get(breakpoint.getAddress()).contains(lb));
+ assert isConsistentAfterRemoval(breakpoint, lb, forChange);
+ }
+
+ private boolean isConsistentAfterRemoval(Bookmark breakpoint, LogicalBreakpointInternal lb,
+ boolean forChange) {
+ Set<LogicalBreakpointInternal> present =
+ breakpointsByAddress.get(breakpoint.getAddress());
+ boolean shouldBeAbsent = lb.isEmpty() && !forChange;
+ boolean isAbsent = present == null || !present.contains(lb);
+ return shouldBeAbsent == isAbsent;
}
}
@@ -994,7 +1007,7 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
@Override
public CompletableFuture<Void> placeBreakpointAt(Program program, Address address, long length,
- Collection<TraceBreakpointKind> kinds) {
+ Collection<TraceBreakpointKind> kinds, String name) {
/**
* TODO: This is quite a waste, but it gets the job done. The instance created here is
* dropped. It's just used for its breakpoint placement logic, part of which I had to
@@ -1010,7 +1023,7 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
lb.setTraceAddress(ti.recorder, loc.getAddress());
}
}
- return lb.enable();
+ return lb.enableWithName(name);
}
@Override
@@ -1029,9 +1042,9 @@ public class DebuggerLogicalBreakpointServicePlugin extends Plugin
@Override
public CompletableFuture<Void> placeBreakpointAt(ProgramLocation loc, long length,
- Collection<TraceBreakpointKind> kinds) {
+ Collection<TraceBreakpointKind> kinds, String name) {
return DebuggerLogicalBreakpointService.programOrTrace(loc,
- (p, a) -> placeBreakpointAt(p, a, length, kinds),
+ (p, a) -> placeBreakpointAt(p, a, length, kinds, name),
(t, a) -> placeBreakpointAt(t, a, length, kinds));
}
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java
index 7146335029..3e9ba8e360 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java
@@ -113,6 +113,27 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
return location;
}
+ public String getName() {
+ // TODO: Be prepared to use JSON or something, if more fields are needed
+ Bookmark bookmark = getBookmark();
+ if (bookmark == null) {
+ return "";
+ }
+ return bookmark.getComment();
+ }
+
+ public void setName(String name) {
+ Bookmark bookmark = getBookmark();
+ if (bookmark == null) {
+ throw new IllegalStateException("Must save breakpoint to program before naming it");
+ }
+ try (UndoableTransaction tid =
+ UndoableTransaction.start(program, "Rename breakpoint", false)) {
+ bookmark.set(bookmark.getCategory(), name);
+ tid.commit();
+ }
+ }
+
public ProgramEnablement computeEnablement() {
if (eBookmark != null) {
return ProgramEnablement.ENABLED;
@@ -206,6 +227,11 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
return dBookmark;
}
+ protected String getComment() {
+ Bookmark bookmark = getBookmark();
+ return bookmark == null ? "" : bookmark.getComment();
+ }
+
public boolean isEnabled() {
return computeEnablement() == ProgramEnablement.ENABLED;
}
@@ -218,15 +244,13 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
return TraceBreakpointKindSet.encode(kinds) + ";" + Long.toUnsignedString(length);
}
- public void enable() {
- if (isEnabled()) {
- return;
- }
+ public void enableWithComment(String comment) {
try (UndoableTransaction tid =
UndoableTransaction.start(program, "Enable breakpoint", false)) {
BookmarkManager manager = program.getBookmarkManager();
String catStr = computeCategory();
- manager.setBookmark(address, BREAKPOINT_ENABLED_BOOKMARK_TYPE, catStr, "");
+ manager.setBookmark(address, BREAKPOINT_ENABLED_BOOKMARK_TYPE, catStr,
+ comment);
manager.removeBookmarks(new AddressSet(address), BREAKPOINT_DISABLED_BOOKMARK_TYPE,
catStr, TaskMonitor.DUMMY);
tid.commit();
@@ -236,6 +260,13 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
}
}
+ public void enable() {
+ if (isEnabled()) {
+ return;
+ }
+ enableWithComment(getComment());
+ }
+
public void disable() {
if (isDisabled()) {
return;
@@ -244,7 +275,8 @@ public interface LogicalBreakpointInternal extends LogicalBreakpoint {
UndoableTransaction.start(program, "Disable breakpoint", false)) {
BookmarkManager manager = program.getBookmarkManager();
String catStr = computeCategory();
- manager.setBookmark(address, BREAKPOINT_DISABLED_BOOKMARK_TYPE, catStr, "");
+ manager.setBookmark(address, BREAKPOINT_DISABLED_BOOKMARK_TYPE, catStr,
+ getComment());
manager.removeBookmarks(new AddressSet(address), BREAKPOINT_ENABLED_BOOKMARK_TYPE,
catStr, TaskMonitor.DUMMY);
tid.commit();
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LoneLogicalBreakpoint.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LoneLogicalBreakpoint.java
index 95297fb7db..7c687c667d 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LoneLogicalBreakpoint.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LoneLogicalBreakpoint.java
@@ -74,6 +74,16 @@ public class LoneLogicalBreakpoint implements LogicalBreakpointInternal {
return null;
}
+ @Override
+ public String getName() {
+ return "";
+ }
+
+ @Override
+ public void setName(String name) {
+ throw new IllegalStateException("Breakpoint must be saved to a program before naming");
+ }
+
@Override
public void setTraceAddress(TraceRecorder recorder, Address address) {
throw new AssertionError();
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/MappedLogicalBreakpoint.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/MappedLogicalBreakpoint.java
index 4af14865de..8d693b3450 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/MappedLogicalBreakpoint.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/MappedLogicalBreakpoint.java
@@ -158,15 +158,25 @@ public class MappedLogicalBreakpoint implements LogicalBreakpointInternal {
}
}
- @Override
- public CompletableFuture<Void> enable() {
- progBreak.enable();
+ public CompletableFuture<Void> enableForTraces() {
BreakpointActionSet actions = new BreakpointActionSet();
planEnable(actions, null);
return actions.execute();
// NOTE: Recorder will cause appropriate updates
}
+ public CompletableFuture<Void> enableWithName(String name) {
+ // TODO: Consider more fields than name in comment
+ progBreak.enableWithComment(name);
+ return enableForTraces();
+ }
+
+ @Override
+ public CompletableFuture<Void> enable() {
+ progBreak.enable();
+ return enableForTraces();
+ }
+
@Override
public void planDisable(BreakpointActionSet actions, Trace trace) {
if (trace != null) {
@@ -220,6 +230,16 @@ public class MappedLogicalBreakpoint implements LogicalBreakpointInternal {
return progBreak.getBookmark();
}
+ @Override
+ public String getName() {
+ return progBreak.getName();
+ }
+
+ @Override
+ public void setName(String name) {
+ progBreak.setName(name);
+ }
+
@Override
public ProgramLocation getProgramLocation() {
return progBreak.getLocation();
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java
index a0a7f962df..89fe66231a 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/DebuggerLogicalBreakpointService.java
@@ -216,10 +216,11 @@ public interface DebuggerLogicalBreakpointService {
* @param address the address in the image
* @param length size of the breakpoint, may be ignored by debugger
* @param kinds the kinds of breakpoint
+ * @param name a name for the breakpoint. For no name, use the empty string
* @return a future which completes when all relevant breakpoints have been placed
*/
CompletableFuture<Void> placeBreakpointAt(Program program, Address address, long length,
- Collection<TraceBreakpointKind> kinds);
+ Collection<TraceBreakpointKind> kinds, String name);
/**
* Create an enabled breakpoint at the given trace location only.
@@ -250,15 +251,17 @@ public interface DebuggerLogicalBreakpointService {
* If the given location refers to a static image, this behaves as in
* {@link #placeBreakpointAt(Program, Address, TraceBreakpointKind)}. If it refers to a trace
* view, this behaves as in {@link #placeBreakpointAt(Trace, Address, TraceBreakpointKind)},
- * ignoring the view's current snapshot in favor of the present.
+ * ignoring the view's current snapshot in favor of the present. The name is only saved for a
+ * program breakpoint.
*
* @param loc the location
* @param length size of the breakpoint, may be ignored by debugger
* @param kinds the kinds of breakpoint
+ * @param name an optional name for the breakpoint (null becomes the empty string)
* @return a future which completes when the breakpoints have been placed
*/
CompletableFuture<Void> placeBreakpointAt(ProgramLocation loc, long length,
- Collection<TraceBreakpointKind> kinds);
+ Collection<TraceBreakpointKind> kinds, String name);
/**
* Enable a collection of logical breakpoints on target, if applicable
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/LogicalBreakpoint.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/LogicalBreakpoint.java
index 332fe8d5c1..7d90ff9dcf 100644
--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/LogicalBreakpoint.java
+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/services/LogicalBreakpoint.java
@@ -522,6 +522,21 @@ public interface LogicalBreakpoint {
*/
Bookmark getProgramBookmark();
+ /**
+ * If the logical breakpoint is present in a program, get its name.
+ *
+ * @return the name, or the empty string
+ */
+ String getName();
+
+ /**
+ * If the logical breakpoint is present in a program, set its name.
+ *
+ * @param name the name
+ * @throws IllegalStateException if the breakpoint is not present in a program
+ */
+ void setName(String name);
+
/**
* If the logical breakpoint has a mapped program location, get that location.
*
diff --git a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java
index 2acb848337..fee298ccfa 100644
--- a/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java
+++ b/Ghidra/Debug/Debugger/src/screen/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginScreenShots.java
@@ -70,7 +70,7 @@ public class DebuggerBreakpointMarkerPluginScreenShots extends GhidraScreenShotG
Msg.debug(this, "Placing breakpoint");
breakpointService.placeBreakpointAt(program, addr(program, 0x00401c60), 1,
- Set.of(TraceBreakpointKind.SW_EXECUTE));
+ Set.of(TraceBreakpointKind.SW_EXECUTE), "");
Msg.debug(this, "Disabling breakpoint");
LogicalBreakpoint lb = waitForValue(() -> Unique.assertAtMostOne(
@@ -79,7 +79,7 @@ public class DebuggerBreakpointMarkerPluginScreenShots extends GhidraScreenShotG
Msg.debug(this, "Placing another");
breakpointService.placeBreakpointAt(program, addr(program, 0x00401c63), 1,
- Set.of(TraceBreakpointKind.SW_EXECUTE));
+ Set.of(TraceBreakpointKind.SW_EXECUTE), "");
Msg.debug(this, "Saving program");
program.save("Placed breakpoints", TaskMonitor.DUMMY);
@@ -96,7 +96,10 @@ public class DebuggerBreakpointMarkerPluginScreenShots extends GhidraScreenShotG
public void testCaptureDebuggerPlaceBreakpointDialog() throws Throwable {
listing.goTo(program, new ProgramLocation(program, addr(program, 0x00401c63)));
performAction(breakpointMarkerPlugin.actionSetSoftwareBreakpoint, false);
+ DebuggerPlaceBreakpointDialog dialog =
+ waitForDialogComponent(DebuggerPlaceBreakpointDialog.class);
- captureDialog(DebuggerPlaceBreakpointDialog.class);
+ dialog.setName("After setup");
+ captureDialog(dialog);
}
}
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginTest.java
index 34092d421e..1c93f60da0 100644
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginTest.java
+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointMarkerPluginTest.java
@@ -507,6 +507,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
performAction(action, staticCtx(addr(program, 0x0400321)), false);
DebuggerPlaceBreakpointDialog dialog =
waitForDialogComponent(DebuggerPlaceBreakpointDialog.class);
+ dialog.setName("Test name");
dialog.okCallback();
waitForPass(() -> {
@@ -514,6 +515,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
breakpointService.getBreakpointsAt(program, addr(program, 0x00400321)));
assertEquals(expectedKinds, lb.getKinds());
assertEquals(Enablement.ENABLED, lb.computeEnablement());
+ assertEquals("Test name", lb.getName());
});
}
diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProviderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProviderTest.java
index 232b3e0607..0fe192c2bf 100644
--- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProviderTest.java
+++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/breakpoint/DebuggerBreakpointsProviderTest.java
@@ -256,6 +256,29 @@ public class DebuggerBreakpointsProviderTest extends AbstractGhidraHeadedDebugge
waitForPass(() -> assertEquals(Enablement.ENABLED, row.getEnablement()));
}
+ @Test
+ public void testRenameStaticViaTable() throws Exception {
+ createProgram();
+ programManager.openProgram(program);
+ addStaticMemoryAndBreakpoint();
+ waitForDomainObject(program);
+
+ LogicalBreakpointRow row =
+ Unique.assertOne(breakpointsProvider.breakpointTableModel.getModelData());
+ assertEquals("", row.getName());
+
+ row.setName("Test name");
+ waitForDomainObject(program);
+
+ assertEquals("Test name", row.getName());
+
+ // Check that name persists, since bookmark is swapped
+ row.setEnabled(false);
+ waitForDomainObject(program);
+
+ assertEquals("Test name", row.getName());
+ }
+
// TODO: Test a scenario where one spec manifests two breaks, select both, and perform actions
// TODO: Test a scenario where one spec manifests the same mapped breakpoint in two traces