Skip to content

Commit 87839a5

Browse files
committed
Merge remote-tracking branch 'origin/GT-3446-dragonmacher-refs-to-key-binding'
2 parents c21bfa2 + 8ebfd61 commit 87839a5

File tree

10 files changed

+219
-178
lines changed

10 files changed

+219
-178
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: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
import docking.ActionContext;
3333
import docking.action.DockingAction;
3434
import docking.action.MenuData;
35+
import docking.action.builder.ActionBuilder;
3536
import docking.tool.ToolConstants;
3637
import docking.widgets.fieldpanel.*;
3738
import docking.widgets.fieldpanel.field.Field;
3839
import docking.widgets.fieldpanel.support.*;
3940
import ghidra.GhidraOptions;
4041
import ghidra.app.CorePluginPackage;
42+
import ghidra.app.context.ListingActionContext;
4143
import ghidra.app.events.*;
4244
import ghidra.app.nav.Navigatable;
4345
import ghidra.app.plugin.PluginCategoryNames;
@@ -60,6 +62,7 @@
6062
import ghidra.framework.plugintool.util.PluginStatus;
6163
import ghidra.program.model.address.*;
6264
import ghidra.program.model.listing.*;
65+
import ghidra.program.model.symbol.Reference;
6366
import ghidra.program.util.ProgramLocation;
6467
import ghidra.program.util.ProgramSelection;
6568
import ghidra.util.*;
@@ -121,6 +124,8 @@ public class CodeBrowserPlugin extends Plugin
121124
private FocusingMouseListener focusingMouseListener = new FocusingMouseListener();
122125

123126
private DockingAction tableFromSelectionAction;
127+
private DockingAction showXrefsAction;
128+
124129
private Color cursorHighlightColor;
125130
private boolean isHighlightCursorLine;
126131
private ProgramDropProvider dndProvider;
@@ -440,6 +445,7 @@ void removeProvider(CodeViewerProvider provider) {
440445
public void serviceAdded(Class<?> interfaceClass, Object service) {
441446
if (interfaceClass == TableService.class) {
442447
tool.addAction(tableFromSelectionAction);
448+
tool.addAction(showXrefsAction);
443449
}
444450
if (interfaceClass == ViewManagerService.class && viewManager == null) {
445451
viewManager = (ViewManagerService) service;
@@ -471,6 +477,7 @@ public void serviceRemoved(Class<?> interfaceClass, Object service) {
471477
if (interfaceClass == TableService.class) {
472478
if (tool != null) {
473479
tool.removeAction(tableFromSelectionAction);
480+
tool.removeAction(showXrefsAction);
474481
}
475482
}
476483
if ((service == viewManager) && (currentProgram != null)) {
@@ -902,6 +909,9 @@ private void initMiscellaneousOptions() {
902909
}
903910

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

@@ -932,13 +942,35 @@ public boolean isEnabledForContext(ActionContext context) {
932942
}
933943
};
934944

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

944976
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)