Skip to content

Ghidra is a software reverse engineering (SRE) framework

Test fixes

dragonmacher41583d5eb97c
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java
index cbec0cf893..c2687dddcf 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerNavigationTest.java
@@ -17,6 +17,7 @@ package ghidra.app.plugin.core.decompile;
import static org.junit.Assert.*;
+import java.util.List;
import java.util.function.*;
import org.junit.Before;
@@ -24,7 +25,10 @@ import org.junit.Test;
import docking.ActionContext;
import docking.action.DockingAction;
+import docking.widgets.fieldpanel.field.Field;
import ghidra.app.cmd.function.CreateFunctionCmd;
+import ghidra.app.decompiler.component.ClangTextField;
+import ghidra.app.decompiler.component.DecompilerPanel;
import ghidra.app.nav.Navigatable;
import ghidra.app.plugin.core.codebrowser.CodeViewerProvider;
import ghidra.app.plugin.core.gotoquery.GoToHelper;
@@ -136,9 +140,8 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {
decompile("10059a3"); // function that calls 'ghidra'
- int line = 33;
int character = 1;
- assertToken("ghidra", line, character);
+ int line = getLineForFunctionCall("ghidra");
setDecompilerLocation(line, character);
doubleClick();
@@ -146,6 +149,21 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {
assertNotEquals(thunkAddress, codeBrowser.getCurrentAddress());
}
+ private int getLineForFunctionCall(String functionName) {
+
+ DecompilerPanel panel = provider.getDecompilerPanel();
+ List<Field> fields = panel.getFields();
+ for (Field field : fields) {
+ String text = field.getText();
+ if (text.trim().startsWith(functionName)) {
+ return ((ClangTextField) field).getLineNumber();
+ }
+ }
+
+ fail("Could not find function call to " + functionName);
+ return -1;
+ }
+
@Test
public void testFunctionNavigation_ExternalProgramFunction_OptionNavigateToLinkage()
throws Exception {
@@ -171,9 +189,8 @@ public class DecompilerNavigationTest extends AbstractDecompilerTest {
decompile("10059a3"); // function that calls 'ghidra'
- int line = 33;
+ int line = getLineForFunctionCall("ghidra");
int character = 1;
- assertToken("ghidra", line, character);
setDecompilerLocation(line, character);
doubleClick();
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/LoggingInitialization.java b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/LoggingInitialization.java
index 2913711479..63d75a2563 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/framework/LoggingInitialization.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/framework/LoggingInitialization.java
@@ -70,6 +70,7 @@ public class LoggingInitialization {
// Simply requesting the context will force the log system to initialize. Make the call
// so that it will pick up the config file property we just set.
+ // Note: this will not work if the log4j was initialized before this call
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
replaceDefaultAppenders(ctx);
@@ -298,8 +299,8 @@ public class LoggingInitialization {
Configuration config = ctx.getConfiguration();
LoggerConfig rootLoggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
- List<AppenderRef> refs = rootLoggerConfig.getAppenderRefs();
+ List<AppenderRef> refs = rootLoggerConfig.getAppenderRefs();
for (AppenderRef ref : refs) {
String appenderName = ref.getRef();
if (appenderName.equals(name)) {
@@ -308,7 +309,13 @@ public class LoggingInitialization {
}
}
- error("Unable to find '%' default appender".formatted(name));
+ // Some helpful debug when expected appenders are missing
+ if (config instanceof DefaultConfiguration) {
+ error("Log4j did not use our config file. " +
+ "Verify it was not initialized before calling LoggingInitialization");
+ }
+
+ error("Unable to find '%s' default appender".formatted(name));
return false;
}
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java
index 7f1ff52363..726ecb4dec 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/datatree/DataTreeNode.java
@@ -21,6 +21,7 @@ import javax.swing.Icon;
import docking.widgets.tree.GTreeNode;
import docking.widgets.tree.GTreeSlowLoadingNode;
+import docking.widgets.tree.internal.InProgressGTreeNode;
import ghidra.framework.data.LinkHandler;
import ghidra.framework.data.LinkHandler.LinkStatus;
import ghidra.framework.model.*;
@@ -179,8 +180,7 @@ public abstract class DataTreeNode extends GTreeSlowLoadingNode implements Cutta
static GTreeNode getChild(List<GTreeNode> children, String name, NodeType type) {
SearchNode key = new SearchNode(name, type);
- int index =
- Collections.binarySearch(children, key, DATA_NODE_COMPARATOR);
+ int index = Collections.binarySearch(children, key, DATA_NODE_COMPARATOR);
return index >= 0 ? children.get(index) : null;
}
@@ -263,6 +263,10 @@ public abstract class DataTreeNode extends GTreeSlowLoadingNode implements Cutta
@Override
public int compare(GTreeNode o1, GTreeNode o2) {
+ if (o1 instanceof InProgressGTreeNode) {
+ return -1; // loading
+ }
+
// We want folders appear before files except for folder-links which should be grouped
// with folders but come after a folder with the same name
DataTreeNode dtn1 = (DataTreeNode) o1;