Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-0: Fix missing custom reg initialization in p-code tests.

Dan6c5b87c04986
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.java
index d7728544f6..dcdc13149f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/EmulatorTestRunner.java
@@ -379,7 +379,7 @@ public class EmulatorTestRunner {
}
else {
Address aligned = alignAddress(testGroup.functionEntryPtr, alignment);
- EmulatorUtilities.initializeRegisters(emuThread, program, aligned);
+ emuThread.overrideCounter(aligned);
success = runToBreakpoint();
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java
index 7d1cc493f8..caa5bec67c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java
@@ -38,6 +38,7 @@ import ghidra.app.util.opinion.Loader;
import ghidra.framework.*;
import ghidra.framework.options.Options;
import ghidra.framework.store.LockException;
+import ghidra.pcode.emu.EmulatorUtilities;
import ghidra.pcode.floatformat.FloatFormat;
import ghidra.pcode.floatformat.FloatFormatFactory;
import ghidra.program.database.ProgramDB;
@@ -1493,20 +1494,7 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements E
throws Exception {
Address addr = testRunner.getTestGroup().functionEntryPtr;
addr = PseudoDisassembler.getNormalizedDisassemblyAddress(program, addr);
- ProgramContext programContext = program.getProgramContext();
- for (Register reg : programContext.getRegisters()) {
- if (reg.isProcessorContext() || reg.isProgramCounter()) {
- continue;
- }
- RegisterValue value = programContext.getRegisterValue(reg, addr);
- if (value != null && value.hasValue()) {
- log(testRunner.getTestGroup(),
- "Initialized register " + reg.getName() + "=0x" +
- value.getUnsignedValue().toString(16) + " using context at " +
- addr.toString(true));
- testRunner.setRegister(reg.getName(), value.getUnsignedValue());
- }
- }
+ EmulatorUtilities.initializeRegisters(testRunner.getEmulatorThread(), program, addr);
}
/**
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java
index 5a8097b2dc..2186c6ba95 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_31_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java
index c3d7af73bc..38bd08420b 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_31_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java
index 91ec6b5d42..772771569e 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_51_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java
index 78f0d47400..e9090a9767 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_51_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java
index 81b7fef79d..1f3cec52c7 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_6_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java
index 4ff0d21932..fc2f3d219d 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_6_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O0_EmulatorTest.java
index c759239ebb..8af4ae7050 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O0_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O0_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_xmega_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O3_EmulatorTest.java
index cda349e5c0..1f71cc04ad 100644
--- a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O3_EmulatorTest.java
+++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_xmega_GCC_O3_EmulatorTest.java
@@ -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.
@@ -40,6 +40,7 @@ public class AVR8_xmega_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program)
throws Exception {
+ super.initializeState(testRunner, program);
// These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems.
testRunner.setRegister("SP", 0x0);
testRunner.setRegister("R1", 0x0);
diff --git a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O0_EmulatorTest.java b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O0_EmulatorTest.java
index bceef7a812..01b1f543b6 100644
--- a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O0_EmulatorTest.java
+++ b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O0_EmulatorTest.java
@@ -38,6 +38,7 @@ public class SparcV9_32_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception {
+ super.initializeState(testRunner, program);
testRunner.setRegister("DECOMPILE_MODE", 0x0); // turn decompile mode off
}
diff --git a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O3_EmulatorTest.java b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O3_EmulatorTest.java
index 1654b0ccfb..d66b97f0a6 100644
--- a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O3_EmulatorTest.java
+++ b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_32_O3_EmulatorTest.java
@@ -38,6 +38,7 @@ public class SparcV9_32_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception {
+ super.initializeState(testRunner, program);
testRunner.setRegister("DECOMPILE_MODE", 0x0); // turn decompile mode off
}
diff --git a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O0_EmulatorTest.java b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O0_EmulatorTest.java
index 06b4ec4edb..55aa4308d3 100644
--- a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O0_EmulatorTest.java
+++ b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O0_EmulatorTest.java
@@ -38,6 +38,7 @@ public class SparcV9_64_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception {
+ super.initializeState(testRunner, program);
testRunner.setRegister("DECOMPILE_MODE", 0x0); // turn decompile mode off
}
diff --git a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O3_EmulatorTest.java b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O3_EmulatorTest.java
index 7b5f3d36aa..820f8bc9f6 100644
--- a/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O3_EmulatorTest.java
+++ b/Ghidra/Processors/Sparc/src/test.processors/java/ghidra/test/processors/SparcV9_64_O3_EmulatorTest.java
@@ -38,6 +38,7 @@ public class SparcV9_64_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception {
+ super.initializeState(testRunner, program);
testRunner.setRegister("DECOMPILE_MODE", 0x0); // turn decompile mode off
}
diff --git a/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O0_EmulatorTest.java b/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O0_EmulatorTest.java
index 995d33ecd5..bfb2658a8d 100644
--- a/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O0_EmulatorTest.java
+++ b/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O0_EmulatorTest.java
@@ -35,6 +35,7 @@ public class TRICORE_BE_O0_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception {
+ super.initializeState(testRunner, program);
testRunner.setRegister("a10", 0x40000000L); // stack, unused location
testRunner.setRegister("FCX", 0x00020000L); // free context list start, unused location
testRunner.setRegister("LCX", 0x00030000L); // free context list max
diff --git a/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O3_EmulatorTest.java b/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O3_EmulatorTest.java
index 0e1010294b..b5e7a12b04 100644
--- a/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O3_EmulatorTest.java
+++ b/Ghidra/Processors/tricore/src/test.processors/java/ghidra/test/processors/TRICORE_BE_O3_EmulatorTest.java
@@ -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.
@@ -39,6 +39,7 @@ public class TRICORE_BE_O3_EmulatorTest extends ProcessorEmulatorTestAdapter {
@Override
protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception {
+ super.initializeState(testRunner, program);
testRunner.setRegister("a10", 0x40000000L); // stack, unused location
testRunner.setRegister("FCX", 0x00020000L); // free context list start, unused location