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

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -86,7 +86,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
private ReferenceListingHover referenceHoverService;
private DataTypeListingHover dataTypeHoverService;
private TruncatedTextListingHover truncatedTextHoverService;
private FunctionNameListingHover functionNameHoverService;
private LabelListingHover labelListingHoverService;
private boolean showListingPanel;
ExternalAddConflictPanel(MergeManager mergeManager, int totalConflicts, Program latestProgram,
@ -108,7 +108,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
referenceHoverService = new ReferenceListingHover(tool, this);
dataTypeHoverService = new DataTypeListingHover(tool);
truncatedTextHoverService = new TruncatedTextListingHover(tool);
functionNameHoverService = new FunctionNameListingHover(tool);
labelListingHoverService = new LabelListingHover(tool);
initializeListingHoverService(latestPanel);
initializeListingHoverService(myPanel);
@ -118,7 +118,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
listingPanel.addHoverService(referenceHoverService);
listingPanel.addHoverService(dataTypeHoverService);
listingPanel.addHoverService(truncatedTextHoverService);
listingPanel.addHoverService(functionNameHoverService);
listingPanel.addHoverService(labelListingHoverService);
listingPanel.setHoverMode(true);
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -84,7 +84,7 @@ public class ListingMergePanel extends JPanel
private ReferenceListingHover referenceHoverService;
private DataTypeListingHover dataTypeHoverService;
private TruncatedTextListingHover truncatedTextHoverService;
private FunctionNameListingHover functionNameHoverService;
private LabelListingHover labelListingHoverService;
public ListingMergePanel(PluginTool tool, Program original, Program result, Program myChanges,
Program latest, boolean showListings) {
@ -133,7 +133,7 @@ public class ListingMergePanel extends JPanel
referenceHoverService = new ReferenceListingHover(tool, this);
dataTypeHoverService = new DataTypeListingHover(tool);
truncatedTextHoverService = new TruncatedTextListingHover(tool);
functionNameHoverService = new FunctionNameListingHover(tool);
labelListingHoverService = new LabelListingHover(tool);
initializeListingHoverService(listingPanels[RESULT]);
initializeListingHoverService(listingPanels[LATEST]);
@ -145,7 +145,7 @@ public class ListingMergePanel extends JPanel
listingPanel.addHoverService(referenceHoverService);
listingPanel.addHoverService(dataTypeHoverService);
listingPanel.addHoverService(truncatedTextHoverService);
listingPanel.addHoverService(functionNameHoverService);
listingPanel.addHoverService(labelListingHoverService);
listingPanel.setHoverMode(true);
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,6 +15,8 @@
*/
package ghidra.app.plugin.core.codebrowser.hover;
import static ghidra.util.HTMLUtilities.*;
import javax.swing.JComponent;
import docking.widgets.fieldpanel.field.Field;
@ -22,27 +24,25 @@ import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.GhidraOptions;
import ghidra.app.plugin.core.hover.AbstractConfigurableHover;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.Symbol;
import ghidra.program.util.LabelFieldLocation;
import ghidra.program.util.ProgramLocation;
/**
* A hover service to show tool tip text for hovering over a label.
* The tooltip shows the label along with its namespace information.
* This provides the hover capability for the FunctionNameHoverPlugin and can
* also be used to directly provide this hover capability to a listing.
* A hover service to show the full namespace path of a symbol along with its symbol type and
* source type.
*/
public class FunctionNameListingHover extends AbstractConfigurableHover
public class LabelListingHover extends AbstractConfigurableHover
implements ListingHoverService {
private static final String NAME = "Function Name Display";
private static final String NAME = "Label Display";
private static final String DESCRIPTION =
"Toggle whether the full symbol name is shown as a tooltip. This only applies " +
"when displaying namespaces.";
private static final int PRIORITY = 20;
public FunctionNameListingHover(PluginTool tool) {
public LabelListingHover(PluginTool tool) {
super(tool, PRIORITY);
}
@ -65,6 +65,14 @@ public class FunctionNameListingHover extends AbstractConfigurableHover
public JComponent getHoverComponent(Program program, ProgramLocation programLocation,
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) {
return null;
}
@ -73,37 +81,27 @@ public class FunctionNameListingHover extends AbstractConfigurableHover
return null;
}
// is the label local to the function
Symbol symbol = ((LabelFieldLocation) programLocation).getSymbol();
if (isLocalFunctionSymbol(program, symbol)) {
return createTooltipComponent(symbol.getName(true));
if (symbol == null) {
return null;
}
return null;
return symbol;
}
private boolean isLocalFunctionSymbol(Program program, Symbol symbol) {
if (symbol == null) {
return false;
}
private String getToolTipText(Symbol symbol) {
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();
Namespace parentScope = symbol.getParentNamespace();
SymbolType symbolType = symbol.getSymbolType();
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

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -21,32 +21,30 @@ import ghidra.framework.plugintool.*;
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
@PluginInfo(
status = PluginStatus.RELEASED,
packageName = CorePluginPackage.NAME,
category = PluginCategoryNames.CODE_VIEWER,
shortDescription = "Function Name Hover",
description = "Displays the function name of labels within functions in the Code Viewer.",
shortDescription = "Label Name Hover",
description = "Displays the information about labels in the Code Viewer.",
servicesProvided = { ListingHoverService.class }
)
//@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);
functionNameHoverService = new FunctionNameListingHover(tool);
registerServiceProvided(ListingHoverService.class, functionNameHoverService);
labelListingHoverService = new LabelListingHover(tool);
registerServiceProvided(ListingHoverService.class, labelListingHoverService);
}
@Override
public void dispose() {
functionNameHoverService.dispose();
labelListingHoverService.dispose();
}
}

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -29,7 +29,6 @@ import ghidra.app.util.viewer.field.ListingColors.FunctionColors;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.program.model.lang.PrototypeModel;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.Symbol;
@ -186,9 +185,13 @@ public class ToolTipUtils {
if (includeSymbolDetails) {
buf.append("Function");
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);
buf.append(friendlyEncodeHTML(functionName));
buf.append("   <");
buf.append(friendlyEncodeHTML(symbol.getSource().getDisplayString()));
buf.append(">");
if (extLoc != null) {
Address addr = extLoc.getAddress();
if (addr != null) {

View file

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