Skip to content

Commit 8ebfd61

Browse files
committed
GT-3446 - Review fixes
1 parent 142ed19 commit 8ebfd61

File tree

5 files changed

+13
-43
lines changed

5 files changed

+13
-43
lines changed

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

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

2625
import javax.swing.ImageIcon;
2726
import javax.swing.JComponent;
@@ -970,7 +969,7 @@ private void showXrefs(ActionContext context) {
970969
return; // not sure if this can happen
971970
}
972971

973-
Supplier<Set<Reference>> refs = () -> XReferenceUtil.getAllXrefs(location);
972+
Set<Reference> refs = XReferenceUtil.getAllXrefs(location);
974973
XReferenceUtil.showAllXrefs(connectedProvider, tool, service, location, refs);
975974
}
976975

Ghidra/Features/Base/src/main/java/ghidra/app/util/XReferenceUtil.java

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package ghidra.app.util;
1717

1818
import java.util.*;
19-
import java.util.function.Supplier;
2019

2120
import org.apache.commons.collections4.CollectionUtils;
2221

@@ -25,6 +24,7 @@
2524
import ghidra.app.util.query.TableService;
2625
import ghidra.framework.plugintool.ServiceProvider;
2726
import ghidra.program.model.address.*;
27+
import ghidra.program.model.data.DataUtilities;
2828
import ghidra.program.model.listing.*;
2929
import ghidra.program.model.symbol.*;
3030
import ghidra.program.util.ProgramLocation;
@@ -307,15 +307,13 @@ public static Set<Reference> getVariableRefs(Variable var) {
307307
* @param serviceProvider the service provider needed to wire navigation
308308
* @param service the service needed to show the table
309309
* @param location the location for which to find references
310-
* @param xrefs the supplier of xrefs to show
310+
* @param xrefs the xrefs to show
311311
*/
312312
public static void showAllXrefs(Navigatable navigatable, ServiceProvider serviceProvider,
313-
TableService service, ProgramLocation location, Supplier<Set<Reference>> xrefs) {
314-
315-
Set<Reference> refs = xrefs.get();
313+
TableService service, ProgramLocation location, Set<Reference> xrefs) {
316314

317315
ReferencesFromTableModel model =
318-
new ReferencesFromTableModel(new ArrayList<>(refs), serviceProvider,
316+
new ReferencesFromTableModel(new ArrayList<>(xrefs), serviceProvider,
319317
location.getProgram());
320318
TableComponentProvider<ReferenceEndpoint> provider = service.showTable(
321319
"XRefs to " + location.getAddress().toString(), "XRefs", model, "XRefs", navigatable);
@@ -332,7 +330,7 @@ public static void showAllXrefs(Navigatable navigatable, ServiceProvider service
332330
*/
333331
public static Set<Reference> getAllXrefs(ProgramLocation location) {
334332

335-
CodeUnit cu = getImmediateDataContaining(location);
333+
CodeUnit cu = DataUtilities.getDataAtLocation(location);
336334
if (cu == null) {
337335
Address toAddress = location.getAddress();
338336
Listing listing = location.getProgram().getListing();
@@ -348,22 +346,4 @@ public static Set<Reference> getAllXrefs(ProgramLocation location) {
348346
CollectionUtils.addAll(set, offcuts);
349347
return set;
350348
}
351-
352-
/**
353-
* Returns the nearest {@link Data} object containing a given address.
354-
*
355-
* @param location the program location within the data object
356-
* @return the Data object
357-
*/
358-
private static Data getImmediateDataContaining(ProgramLocation location) {
359-
Address addr = location.getAddress();
360-
Listing listing = location.getProgram().getListing();
361-
Data dataContaining = listing.getDataContaining(addr);
362-
if (dataContaining == null) {
363-
return null;
364-
}
365-
366-
Data dataAtAddr = dataContaining.getComponent(location.getComponentPath());
367-
return dataAtAddr;
368-
}
369349
}

Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/VariableXRefFieldMouseHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package ghidra.app.util.viewer.field;
1717

1818
import java.util.Set;
19-
import java.util.function.Supplier;
2019

2120
import ghidra.app.nav.Navigatable;
2221
import ghidra.app.util.XReferenceUtil;
@@ -80,7 +79,7 @@ protected void showXRefDialog(Navigatable navigatable, ProgramLocation location,
8079
VariableLocation variableLocation = (VariableLocation) location;
8180
Variable variable = variableLocation.getVariable();
8281

83-
Supplier<Set<Reference>> refs = () -> XReferenceUtil.getVariableRefs(variable);
82+
Set<Reference> refs = XReferenceUtil.getVariableRefs(variable);
8483
XReferenceUtil.showAllXrefs(navigatable, serviceProvider, service, location, refs);
8584
}
8685
}

Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/XRefFieldMouseHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.awt.event.MouseEvent;
1919
import java.util.Set;
20-
import java.util.function.Supplier;
2120

2221
import docking.widgets.fieldpanel.field.FieldElement;
2322
import docking.widgets.fieldpanel.field.TextField;
@@ -106,7 +105,7 @@ private void showXRefDialog(Navigatable navigatable, ProgramLocation location,
106105
return;
107106
}
108107

109-
Supplier<Set<Reference>> refs = () -> XReferenceUtil.getAllXrefs(location);
108+
Set<Reference> refs = XReferenceUtil.getAllXrefs(location);
110109
XReferenceUtil.showAllXrefs(navigatable, serviceProvider, service, location, refs);
111110
}
112111

Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/DataUtilities.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,20 +326,13 @@ public static Data getDataAtLocation(ProgramLocation loc) {
326326

327327
Address addr = loc.getAddress();
328328
Listing listing = loc.getProgram().getListing();
329-
CodeUnit cu = listing.getCodeUnitAt(addr);
330-
if (cu == null) {
331-
cu = listing.getCodeUnitContaining(addr);
329+
Data dataContaining = listing.getDataContaining(addr);
330+
if (dataContaining == null) {
331+
return null;
332332
}
333333

334-
if (cu instanceof Data) {
335-
Data d = (Data) cu;
336-
int[] compPath = loc.getComponentPath();
337-
if (compPath != null) {
338-
d = d.getComponent(compPath);
339-
}
340-
return d;
341-
}
342-
return null;
334+
Data dataAtAddr = dataContaining.getComponent(loc.getComponentPath());
335+
return dataAtAddr;
343336
}
344337

345338
/**

0 commit comments

Comments
 (0)