Skip to content

Commit cf905d6

Browse files
committed
GT-3212 - Function Graph - fixed exception when a function's entry point
vertex was not correctly marked as such
1 parent bb27721 commit cf905d6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/graph/FunctionGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public Set<FGVertex> getEntryPoints() {
479479
HashSet<FGVertex> result = new LinkedHashSet<>();
480480
for (FGVertex vertex : getVertices()) {
481481
FGVertexType vertexType = vertex.getVertexType();
482-
if (vertexType.isEntry()) {
482+
if (vertex.isEntry()) {
483483
result.add(vertex);
484484
}
485485
else if (vertexType == FGVertexType.GROUP) {
@@ -495,7 +495,7 @@ private boolean groupContainsEntry(GroupedFunctionGraphVertex vertex) {
495495
Set<FGVertex> groupVertices = vertex.getVertices();
496496
for (FGVertex groupedVertex : groupVertices) {
497497
FGVertexType vertexType = groupedVertex.getVertexType();
498-
if (vertexType.isEntry()) {
498+
if (vertex.isEntry()) {
499499
return true;
500500
}
501501
else if (vertexType == FGVertexType.GROUP) {

Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/graph/FunctionGraphFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import ghidra.app.plugin.core.functiongraph.graph.vertex.FGVertex;
2828
import ghidra.app.plugin.core.functiongraph.graph.vertex.ListingFunctionGraphVertex;
2929
import ghidra.app.plugin.core.functiongraph.mvc.*;
30+
import ghidra.program.model.address.Address;
3031
import ghidra.program.model.address.AddressSetView;
3132
import ghidra.program.model.block.*;
3233
import ghidra.program.model.listing.Function;
@@ -131,6 +132,7 @@ private static FunctionGraphVertexAttributes cloneSettings(FunctionGraph origina
131132
*
132133
* @param function the function to graph
133134
* @param controller the controller needed by the function graph
135+
* @param program the function's program
134136
* @param monitor the task monitor
135137
* @return the new graph
136138
* @throws CancelledException if the task is cancelled via the monitor
@@ -313,6 +315,10 @@ private static BidiMap<CodeBlock, FGVertex> createVertices(Function function,
313315

314316
FlowType flowType = codeBlock.getFlowType();
315317
boolean isEntry = isEntry(codeBlock);
318+
Address cbStart = codeBlock.getFirstStartAddress();
319+
if (cbStart.equals(function.getEntryPoint())) {
320+
isEntry = true;
321+
}
316322

317323
FGVertex vertex =
318324
new ListingFunctionGraphVertex(controller, codeBlock, flowType, isEntry);

Ghidra/Features/FunctionGraph/src/main/java/ghidra/app/plugin/core/functiongraph/graph/vertex/AbstractFunctionGraphVertex.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public abstract class AbstractFunctionGraphVertex implements FGVertex {
7474
this.location = new Point2D.Double();
7575
}
7676

77-
/** Copy constructor */
77+
/* Copy constructor */
7878
AbstractFunctionGraphVertex(FGController controller, AbstractFunctionGraphVertex vertex) {
7979
this.controller = controller;
8080
this.program = vertex.program;
@@ -154,8 +154,8 @@ public AddressSetView getAddresses() {
154154
}
155155

156156
@Override
157-
public boolean containsProgramLocation(ProgramLocation location) {
158-
return addressSet.contains(location.getAddress());
157+
public boolean containsProgramLocation(ProgramLocation pl) {
158+
return addressSet.contains(pl.getAddress());
159159
}
160160

161161
@Override
@@ -210,7 +210,9 @@ public void setVertexType(FGVertexType vertexType) {
210210

211211
@Override
212212
public boolean isEntry() {
213-
return isEntry;
213+
// note: not sure if we need the second check; this check will catch any case where
214+
// the vertex was manually marked as an entry
215+
return isEntry || (vertexType != null && vertexType.isEntry());
214216
}
215217

216218
@Override

0 commit comments

Comments
 (0)