diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java index f7f7185206..0e6b40ca8b 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java @@ -120,6 +120,10 @@ public abstract class AddressBasedGraphDisplayListener return null; } String id = getVertexId(address); + if (id == null) { + return null; + } + return graphDisplay.getGraph().getVertex(id); } @@ -202,6 +206,9 @@ public abstract class AddressBasedGraphDisplayListener private void handleSymbolAddedOrRenamed(Address address, Symbol symbol) { AttributedVertex vertex = getVertex(address); + if (vertex == null) { + return; + } graphDisplay.updateVertexName(vertex, symbol.getName()); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java index 83e08c570e..00ce20c00f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/test/ToyProgramBuilder.java @@ -15,14 +15,14 @@ */ package ghidra.test; +import java.util.ArrayList; +import java.util.List; + import ghidra.program.database.ProgramBuilder; import ghidra.program.model.address.*; import ghidra.program.model.listing.Program; import ghidra.program.model.mem.MemoryAccessException; -import java.util.ArrayList; -import java.util.List; - public class ToyProgramBuilder extends ProgramBuilder { private static final String TOY_LANGUAGE_ID_BE = "Toy:BE:32:builder"; @@ -106,7 +106,7 @@ public class ToyProgramBuilder extends ProgramBuilder { /** * Get address in default ram space * @param offset address offset - * @return address + * @return the address */ public Address getAddress(long offset) { return defaultSpace.getAddress(offset); diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java index 2ed6c445fe..f034c1faeb 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java @@ -123,13 +123,7 @@ public class ASTGraphTask extends Task { graphType == GraphType.DATA_FLOW_GRAPH ? "AST Data Flow" : "AST Control Flow"; description = description + " for " + hfunction.getFunction().getName(); display.setGraph(graph, description, false, monitor); - // set the graph location - if (location != null) { - AttributedVertex vertex = displayListener.getVertex(location); - // update graph location, but don't have it send out event - display.setFocusedVertex(vertex, EventTrigger.INTERNAL_ONLY); - } - + setGraphLocation(display, displayListener); } catch (GraphException e) { Msg.showError(this, null, "Graph Error", e.getMessage()); @@ -140,6 +134,20 @@ public class ASTGraphTask extends Task { } + private void setGraphLocation(GraphDisplay display, ASTGraphDisplayListener displayListener) { + if (location == null) { + return; + } + + AttributedVertex vertex = displayListener.getVertex(location); + if (vertex == null) { + return; // location not in graph + } + + // update graph location, but don't have it send out event + display.setFocusedVertex(vertex, EventTrigger.INTERNAL_ONLY); + } + protected void createDataFlowGraph(AttributedGraph graph, TaskMonitor monitor) throws CancelledException { Iterator opIter = hfunction.getPcodeOps(); diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java index c3938b79c3..853c1cca6e 100644 --- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java +++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java @@ -770,7 +770,6 @@ public class DefaultGraphDisplay implements GraphDisplay { } } - /** * set the {@link AttributedGraph} for visualization * @param attributedGraph the {@link AttributedGraph} to visualize @@ -784,7 +783,7 @@ public class DefaultGraphDisplay implements GraphDisplay { configureViewerPreferredSize(); Swing.runNow(() -> { - // set the graph but defer the layoutalgorithm setting + // set the graph but defer the layout algorithm setting viewer.getVisualizationModel().setGraph(graph, false); configureFilters(); LayoutAlgorithm initialLayoutAlgorithm = @@ -795,8 +794,8 @@ public class DefaultGraphDisplay implements GraphDisplay { } /** - * Determines if a vertex is a root. For our purpose, a root either has no incomming edges - * or has at least one outgoing "favored" edge and no incomming "favored" edge + * Determines if a vertex is a root. For our purpose, a root either has no incoming edges + * or has at least one outgoing "favored" edge and no incoming "favored" edge * @param vertex the vertex to test if it is a root * @return true if the vertex is a root */ @@ -1208,7 +1207,6 @@ public class DefaultGraphDisplay implements GraphDisplay { } - /** * Use the hide selected action states to determine what vertices are shown: *