Skip to content

Commit 142ed19

Browse files
committed
GT-3446 - Added key binding to trigger the Show Xrefs dialog
1 parent decb362 commit 142ed19

File tree

9 files changed

+237
-166
lines changed

9 files changed

+237
-166
lines changed

Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,27 @@ <H2><A name="Navigation"></A>Navigation</H2>
111111
"help/topics/Tool/ToolOptions_Dialog.htm">Edit Tool Options</A> dialog for control over
112112
certain Navigation behaviors.</P>
113113

114+
115+
<A name="Show_Xrefs"></A>
114116
<P>In the XRef field, sometimes there are too many addresses to display so the the field will
115117
display "[more]" to indicate that one or more cross-reference addresses are not shown.</P>
116118

117119
<BLOCKQUOTE>
118120
<P><IMG border="0" src="../../shared/tip.png" alt=""> Double-clicking on the "<FONT color=
119-
"green"><TT>[more]</TT></FONT>" text will cause a <A href=
120-
"help/topics/LocationReferencesPlugin/Location_References.html#LocationReferencesPlugin">Location
121-
References Dialog</A> to appear. Also, double-clicking on the XREF header text (<FONT
122-
color="green"><TT>XREF[n]:</TT></FONT>) will too show this dialog.</P>
121+
"green"><TT>XREF[n]:</TT></FONT> or <FONT><TT>[more]</TT></FONT>" text will cause a
122+
dialog containing all the Xrefs to appear.</P>
123+
<P>
124+
This differs from the <A href=
125+
"help/topics/LocationReferencesPlugin/Location_References.html#LocationReferencesPlugin">
126+
<B>Show References to ...</B></A> feature in that the Xrefs dialog is simply a display
127+
of what already exists in the database, whereas <B>Show References to ...</B> will
128+
perform a search to find references additional to what is in the database.
129+
</P>
123130
</BLOCKQUOTE>
124131

125132
<P align="left">This dialog lists all the Xref addresses, any labels that are at that address
126133
and a preview of the instruction at that address. Clicking on any row in the table will cause
127-
the browser to navigate to that address. Double-clicking will navigate and dismiss the
128-
dialog.</P>
134+
the browser to navigate to that address</P>
129135
</BLOCKQUOTE>
130136

131137
<H2><A NAME="Keyboard_Controls">Keyboard Controls</H2>

Ghidra/Features/Base/src/main/java/ghidra/app/context/ProgramLocationActionContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public Address getAddress() {
6969
}
7070

7171
/**
72-
* @return the code unit at the action's program location or null
72+
* Returns the code unit containing the action's program location or null
73+
* @return the code unit containing the action's program location or null
7374
*/
7475
public CodeUnit getCodeUnit() {
7576
if (!codeUnitInitialized) {

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.math.BigInteger;
2222
import java.util.*;
2323
import java.util.concurrent.atomic.AtomicBoolean;
24+
import java.util.function.Supplier;
2425

2526
import javax.swing.ImageIcon;
2627
import javax.swing.JComponent;
@@ -32,12 +33,14 @@
3233
import docking.ActionContext;
3334
import docking.action.DockingAction;
3435
import docking.action.MenuData;
36+
import docking.action.builder.ActionBuilder;
3537
import docking.tool.ToolConstants;
3638
import docking.widgets.fieldpanel.*;
3739
import docking.widgets.fieldpanel.field.Field;
3840
import docking.widgets.fieldpanel.support.*;
3941
import ghidra.GhidraOptions;
4042
import ghidra.app.CorePluginPackage;
43+
import ghidra.app.context.ListingActionContext;
4144
import ghidra.app.events.*;
4245
import ghidra.app.nav.Navigatable;
4346
import ghidra.app.plugin.PluginCategoryNames;
@@ -60,6 +63,7 @@
6063
import ghidra.framework.plugintool.util.PluginStatus;
6164
import ghidra.program.model.address.*;
6265
import ghidra.program.model.listing.*;
66+
import ghidra.program.model.symbol.Reference;
6367
import ghidra.program.util.ProgramLocation;
6468
import ghidra.program.util.ProgramSelection;
6569
import ghidra.util.*;
@@ -121,6 +125,8 @@ public class CodeBrowserPlugin extends Plugin
121125
private FocusingMouseListener focusingMouseListener = new FocusingMouseListener();
122126

123127
private DockingAction tableFromSelectionAction;
128+
private DockingAction showXrefsAction;
129+
124130
private Color cursorHighlightColor;
125131
private boolean isHighlightCursorLine;
126132
private ProgramDropProvider dndProvider;
@@ -440,6 +446,7 @@ void removeProvider(CodeViewerProvider provider) {
440446
public void serviceAdded(Class<?> interfaceClass, Object service) {
441447
if (interfaceClass == TableService.class) {
442448
tool.addAction(tableFromSelectionAction);
449+
tool.addAction(showXrefsAction);
443450
}
444451
if (interfaceClass == ViewManagerService.class && viewManager == null) {
445452
viewManager = (ViewManagerService) service;
@@ -471,6 +478,7 @@ public void serviceRemoved(Class<?> interfaceClass, Object service) {
471478
if (interfaceClass == TableService.class) {
472479
if (tool != null) {
473480
tool.removeAction(tableFromSelectionAction);
481+
tool.removeAction(showXrefsAction);
474482
}
475483
}
476484
if ((service == viewManager) && (currentProgram != null)) {
@@ -902,6 +910,9 @@ private void initMiscellaneousOptions() {
902910
}
903911

904912
public void initActions() {
913+
914+
// note: these actions gets added later when the TableService is added
915+
905916
tableFromSelectionAction = new DockingAction("Create Table From Selection", getName()) {
906917
ImageIcon markerIcon = ResourceManager.loadImage("images/searchm_obj.gif");
907918

@@ -932,13 +943,35 @@ public boolean isEnabledForContext(ActionContext context) {
932943
}
933944
};
934945

935-
// note: this action gets added later when the TableService is added
936946
tableFromSelectionAction.setEnabled(false);
937947
tableFromSelectionAction.setMenuBarData(new MenuData(
938948
new String[] { ToolConstants.MENU_SELECTION, "Create Table From Selection" }, null,
939949
"SelectUtils"));
940950
tableFromSelectionAction
941951
.setHelpLocation(new HelpLocation("CodeBrowserPlugin", "Selection_Table"));
952+
953+
showXrefsAction = new ActionBuilder("Show Xrefs", getName())
954+
.description("Show the Xrefs to the code unit containing the cursor")
955+
.validContextWhen(context -> context instanceof ListingActionContext)
956+
.onAction(context -> showXrefs(context))
957+
.build();
958+
}
959+
960+
private void showXrefs(ActionContext context) {
961+
962+
TableService service = tool.getService(TableService.class);
963+
if (service == null) {
964+
return;
965+
}
966+
967+
ListingActionContext lac = (ListingActionContext) context;
968+
ProgramLocation location = lac.getLocation();
969+
if (location == null) {
970+
return; // not sure if this can happen
971+
}
972+
973+
Supplier<Set<Reference>> refs = () -> XReferenceUtil.getAllXrefs(location);
974+
XReferenceUtil.showAllXrefs(connectedProvider, tool, service, location, refs);
942975
}
943976

944977
private GhidraProgramTableModel<Address> createTableModel(CodeUnitIterator iterator,

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeViewerProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ private void createActions() {
449449

450450
action = new GotoNextFunctionAction(tool, plugin.getName());
451451
tool.addAction(action);
452+
452453
}
453454

454455
void fieldOptionChanged(String fieldName, Object newValue) {

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/LocationReferencesPanel.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import javax.swing.JPanel;
2424
import javax.swing.ListSelectionModel;
25-
import javax.swing.border.TitledBorder;
2625
import javax.swing.event.TableModelListener;
2726

2827
import ghidra.app.services.GoToService;
@@ -57,7 +56,6 @@ private void buildPanel() {
5756
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
5857

5958
setLayout(new BorderLayout(10, 10));
60-
setBorder(new TitledBorder("Reference(s)"));
6159

6260
PluginTool tool = locationReferencesProvider.getTool();
6361
GoToService goToService = tool.getService(GoToService.class);

0 commit comments

Comments
 (0)