Merge remote-tracking branch 'origin/GP-4393_ghidragon_add_hover_to_show_symbol_source--SQUASHED'

This commit is contained in:
Ryan Kurtz 2025-03-05 10:25:28 -05:00
commit 7bbbc20cdf
6 changed files with 63 additions and 64 deletions

View file

@ -86,7 +86,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
private ReferenceListingHover referenceHoverService; private ReferenceListingHover referenceHoverService;
private DataTypeListingHover dataTypeHoverService; private DataTypeListingHover dataTypeHoverService;
private TruncatedTextListingHover truncatedTextHoverService; private TruncatedTextListingHover truncatedTextHoverService;
private FunctionNameListingHover functionNameHoverService; private LabelListingHover labelListingHoverService;
private boolean showListingPanel; private boolean showListingPanel;
ExternalAddConflictPanel(MergeManager mergeManager, int totalConflicts, Program latestProgram, ExternalAddConflictPanel(MergeManager mergeManager, int totalConflicts, Program latestProgram,
@ -108,7 +108,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
referenceHoverService = new ReferenceListingHover(tool, this); referenceHoverService = new ReferenceListingHover(tool, this);
dataTypeHoverService = new DataTypeListingHover(tool); dataTypeHoverService = new DataTypeListingHover(tool);
truncatedTextHoverService = new TruncatedTextListingHover(tool); truncatedTextHoverService = new TruncatedTextListingHover(tool);
functionNameHoverService = new FunctionNameListingHover(tool); labelListingHoverService = new LabelListingHover(tool);
initializeListingHoverService(latestPanel); initializeListingHoverService(latestPanel);
initializeListingHoverService(myPanel); initializeListingHoverService(myPanel);
@ -118,7 +118,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
listingPanel.addHoverService(referenceHoverService); listingPanel.addHoverService(referenceHoverService);
listingPanel.addHoverService(dataTypeHoverService); listingPanel.addHoverService(dataTypeHoverService);
listingPanel.addHoverService(truncatedTextHoverService); listingPanel.addHoverService(truncatedTextHoverService);
listingPanel.addHoverService(functionNameHoverService); listingPanel.addHoverService(labelListingHoverService);
listingPanel.setHoverMode(true); listingPanel.setHoverMode(true);
} }

View file

@ -84,7 +84,7 @@ public class ListingMergePanel extends JPanel
private ReferenceListingHover referenceHoverService; private ReferenceListingHover referenceHoverService;
private DataTypeListingHover dataTypeHoverService; private DataTypeListingHover dataTypeHoverService;
private TruncatedTextListingHover truncatedTextHoverService; private TruncatedTextListingHover truncatedTextHoverService;
private FunctionNameListingHover functionNameHoverService; private LabelListingHover labelListingHoverService;
public ListingMergePanel(PluginTool tool, Program original, Program result, Program myChanges, public ListingMergePanel(PluginTool tool, Program original, Program result, Program myChanges,
Program latest, boolean showListings) { Program latest, boolean showListings) {
@ -133,7 +133,7 @@ public class ListingMergePanel extends JPanel
referenceHoverService = new ReferenceListingHover(tool, this); referenceHoverService = new ReferenceListingHover(tool, this);
dataTypeHoverService = new DataTypeListingHover(tool); dataTypeHoverService = new DataTypeListingHover(tool);
truncatedTextHoverService = new TruncatedTextListingHover(tool); truncatedTextHoverService = new TruncatedTextListingHover(tool);
functionNameHoverService = new FunctionNameListingHover(tool); labelListingHoverService = new LabelListingHover(tool);
initializeListingHoverService(listingPanels[RESULT]); initializeListingHoverService(listingPanels[RESULT]);
initializeListingHoverService(listingPanels[LATEST]); initializeListingHoverService(listingPanels[LATEST]);
@ -145,7 +145,7 @@ public class ListingMergePanel extends JPanel
listingPanel.addHoverService(referenceHoverService); listingPanel.addHoverService(referenceHoverService);
listingPanel.addHoverService(dataTypeHoverService); listingPanel.addHoverService(dataTypeHoverService);
listingPanel.addHoverService(truncatedTextHoverService); listingPanel.addHoverService(truncatedTextHoverService);
listingPanel.addHoverService(functionNameHoverService); listingPanel.addHoverService(labelListingHoverService);
listingPanel.setHoverMode(true); listingPanel.setHoverMode(true);
} }

View file

@ -15,6 +15,8 @@
*/ */
package ghidra.app.plugin.core.codebrowser.hover; package ghidra.app.plugin.core.codebrowser.hover;
import static ghidra.util.HTMLUtilities.*;
import javax.swing.JComponent; import javax.swing.JComponent;
import docking.widgets.fieldpanel.field.Field; import docking.widgets.fieldpanel.field.Field;
@ -22,27 +24,25 @@ import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.GhidraOptions; import ghidra.GhidraOptions;
import ghidra.app.plugin.core.hover.AbstractConfigurableHover; import ghidra.app.plugin.core.hover.AbstractConfigurableHover;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.*; import ghidra.program.model.symbol.Symbol;
import ghidra.program.util.LabelFieldLocation; import ghidra.program.util.LabelFieldLocation;
import ghidra.program.util.ProgramLocation; import ghidra.program.util.ProgramLocation;
/** /**
* A hover service to show tool tip text for hovering over a label. * A hover service to show the full namespace path of a symbol along with its symbol type and
* The tooltip shows the label along with its namespace information. * source type.
* This provides the hover capability for the FunctionNameHoverPlugin and can
* also be used to directly provide this hover capability to a listing.
*/ */
public class FunctionNameListingHover extends AbstractConfigurableHover public class LabelListingHover extends AbstractConfigurableHover
implements ListingHoverService { implements ListingHoverService {
private static final String NAME = "Function Name Display"; private static final String NAME = "Label Display";
private static final String DESCRIPTION = private static final String DESCRIPTION =
"Toggle whether the full symbol name is shown as a tooltip. This only applies " + "Toggle whether the full symbol name is shown as a tooltip. This only applies " +
"when displaying namespaces."; "when displaying namespaces.";
private static final int PRIORITY = 20; private static final int PRIORITY = 20;
public FunctionNameListingHover(PluginTool tool) { public LabelListingHover(PluginTool tool) {
super(tool, PRIORITY); super(tool, PRIORITY);
} }
@ -65,6 +65,14 @@ public class FunctionNameListingHover extends AbstractConfigurableHover
public JComponent getHoverComponent(Program program, ProgramLocation programLocation, public JComponent getHoverComponent(Program program, ProgramLocation programLocation,
FieldLocation fieldLocation, Field field) { FieldLocation fieldLocation, Field field) {
Symbol symbol = getLabelSymbol(programLocation);
if (symbol == null) {
return null;
}
return createTooltipComponent(getToolTipText(symbol));
}
private Symbol getLabelSymbol(ProgramLocation programLocation) {
if (!enabled || programLocation == null) { if (!enabled || programLocation == null) {
return null; return null;
} }
@ -73,37 +81,27 @@ public class FunctionNameListingHover extends AbstractConfigurableHover
return null; return null;
} }
// is the label local to the function
Symbol symbol = ((LabelFieldLocation) programLocation).getSymbol(); Symbol symbol = ((LabelFieldLocation) programLocation).getSymbol();
if (isLocalFunctionSymbol(program, symbol)) { if (symbol == null) {
return createTooltipComponent(symbol.getName(true));
}
return null; return null;
} }
private boolean isLocalFunctionSymbol(Program program, Symbol symbol) { return symbol;
if (symbol == null) {
return false;
} }
Namespace parentScope = symbol.getParentNamespace(); private String getToolTipText(Symbol symbol) {
SymbolType symbolType = symbol.getSymbolType(); StringBuilder buf = new StringBuilder(HTML);
buf.append(friendlyEncodeHTML(symbol.getName(true)));
buf.append(BR).append(BR);
buf.append("Type: ");
buf.append(HTML_SPACE).append(HTML_SPACE).append(HTML_SPACE).append(HTML_SPACE);
buf.append(symbol.getSymbolType());
buf.append(BR);
buf.append("Source: ");
buf.append(symbol.getSource().getDisplayString());
buf.append(BR);
return buf.toString();
if (symbolType != SymbolType.LABEL) {
return false;
}
if (parentScope.getID() == Namespace.GLOBAL_NAMESPACE_ID) {
return false;
}
FunctionManager functionManager = program.getFunctionManager();
Function function = functionManager.getFunctionContaining(symbol.getAddress());
if (function == null) {
return false;
}
return function.getName().equals(parentScope.getName());
} }
} }

View file

@ -21,32 +21,30 @@ import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus; import ghidra.framework.plugintool.util.PluginStatus;
/** /**
* A plugin to show tool tip text for hovering over function names in the listing. * A plugin to show tool tip text for hovering over labels in the listing.
*
*
*/ */
//@formatter:off //@formatter:off
@PluginInfo( @PluginInfo(
status = PluginStatus.RELEASED, status = PluginStatus.RELEASED,
packageName = CorePluginPackage.NAME, packageName = CorePluginPackage.NAME,
category = PluginCategoryNames.CODE_VIEWER, category = PluginCategoryNames.CODE_VIEWER,
shortDescription = "Function Name Hover", shortDescription = "Label Name Hover",
description = "Displays the function name of labels within functions in the Code Viewer.", description = "Displays the information about labels in the Code Viewer.",
servicesProvided = { ListingHoverService.class } servicesProvided = { ListingHoverService.class }
) )
//@formatter:on //@formatter:on
public class FunctionNameListingHoverPlugin extends Plugin { public class LabelListingHoverPlugin extends Plugin {
private FunctionNameListingHover functionNameHoverService; private LabelListingHover labelListingHoverService;
public FunctionNameListingHoverPlugin(PluginTool tool) { public LabelListingHoverPlugin(PluginTool tool) {
super(tool); super(tool);
functionNameHoverService = new FunctionNameListingHover(tool); labelListingHoverService = new LabelListingHover(tool);
registerServiceProvided(ListingHoverService.class, functionNameHoverService); registerServiceProvided(ListingHoverService.class, labelListingHoverService);
} }
@Override @Override
public void dispose() { public void dispose() {
functionNameHoverService.dispose(); labelListingHoverService.dispose();
} }
} }

View file

@ -29,7 +29,6 @@ import ghidra.app.util.viewer.field.ListingColors.FunctionColors;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum; import ghidra.program.model.data.Enum;
import ghidra.program.model.lang.PrototypeModel;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.ExternalLocation; import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.Symbol; import ghidra.program.model.symbol.Symbol;
@ -186,9 +185,13 @@ public class ToolTipUtils {
if (includeSymbolDetails) { if (includeSymbolDetails) {
buf.append("Function"); buf.append("Function");
buf.append(HTML_SPACE).append("-").append(HTML_SPACE); buf.append(HTML_SPACE).append("-").append(HTML_SPACE);
String functionName = function.getSymbol().getName(true); Symbol symbol = function.getSymbol();
String functionName = symbol.getName(true);
functionName = StringUtilities.trimMiddle(functionName, LINE_LENGTH); functionName = StringUtilities.trimMiddle(functionName, LINE_LENGTH);
buf.append(friendlyEncodeHTML(functionName)); buf.append(friendlyEncodeHTML(functionName));
buf.append("   <");
buf.append(friendlyEncodeHTML(symbol.getSource().getDisplayString()));
buf.append(">");
if (extLoc != null) { if (extLoc != null) {
Address addr = extLoc.getAddress(); Address addr = extLoc.getAddress();
if (addr != null) { if (addr != null) {

View file

@ -85,7 +85,7 @@ public class ListingDisplay implements ListingDiffChangeListener {
listingPanel.addHoverService(new ReferenceListingHover(tool, () -> formatManager)); listingPanel.addHoverService(new ReferenceListingHover(tool, () -> formatManager));
listingPanel.addHoverService(new DataTypeListingHover(tool)); listingPanel.addHoverService(new DataTypeListingHover(tool));
listingPanel.addHoverService(new TruncatedTextListingHover(tool)); listingPanel.addHoverService(new TruncatedTextListingHover(tool));
listingPanel.addHoverService(new FunctionNameListingHover(tool)); listingPanel.addHoverService(new LabelListingHover(tool));
listingDiff.addListingDiffChangeListener(this); listingDiff.addListingDiffChangeListener(this);
setHoverMode(true); setHoverMode(true);