GP-2467: Change SleighProgramCompiler to use String (text block) instead of List<String>

This commit is contained in:
Dan 2022-09-12 09:03:54 -04:00
parent 6a2cd80550
commit 9d6f278f39
48 changed files with 730 additions and 613 deletions

View file

@ -69,8 +69,10 @@ public class DebuggerPcodeStepperPluginScreenShots extends GhidraScreenShotGener
PcodeExecutor<byte[]> exe =
TraceSleighUtils.buildByteExecutor(tb.trace, snap0, thread, 0);
exe.executeSleighLine("RIP = 0x00400000");
exe.executeSleighLine("RSP = 0x0010fff8");
exe.executeSleigh("""
RIP = 0x00400000;
RSP = 0x0010fff8;
""");
Assembler asm = Assemblers.getAssembler(tb.trace.getFixedProgramView(snap0));
asm.assemble(tb.addr(0x00400000), "SUB RSP,0x40");

View file

@ -69,14 +69,18 @@ public class DebuggerWatchesPluginScreenShots extends GhidraScreenShotGenerator
PcodeExecutor<byte[]> executor0 =
TraceSleighUtils.buildByteExecutor(tb.trace, snap0, thread, 0);
executor0.executeSleighLine("RSP = 0x7ffefff8");
executor0.executeSleighLine("*:4 (RSP+8) = 0x4030201");
executor0.executeSleigh("""
RSP = 0x7ffefff8;
*:4 (RSP+8) = 0x4030201;
""");
PcodeExecutor<byte[]> executor1 =
TraceSleighUtils.buildByteExecutor(tb.trace, snap1, thread, 0);
executor1.executeSleighLine("RSP = 0x7ffefff8");
executor1.executeSleighLine("*:4 (RSP+8) = 0x1020304");
executor1.executeSleighLine("*:4 0x7fff0004:8 = 0x4A9A70C8");
executor1.executeSleigh("""
RSP = 0x7ffefff8;
*:4 (RSP+8) = 0x1020304;
*:4 0x7fff0004:8 = 0x4A9A70C8;
""");
}
watchesProvider.addWatch("RSP");

View file

@ -134,11 +134,12 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
});
}
protected TraceRecorder addMappedBreakpointOpenAndWait() throws Exception {
protected TraceRecorder addMappedBreakpointOpenAndWait() throws Throwable {
createTestModel();
mb.createTestProcessesAndThreads();
TraceRecorder recorder = modelService.recordTarget(mb.testProcess1,
createTargetTraceMapper(mb.testProcess1), ActionSource.AUTOMATIC);
waitRecorder(recorder);
Trace trace = recorder.getTrace();
createProgramFromTrace(trace);
intoProject(trace);
@ -260,7 +261,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
Set.of("SW_EXECUTE", "HW_EXECUTE", "READ,WRITE", "READ", "WRITE");
@Test
public void testProgramNoBreakPopupMenus() throws Exception {
public void testProgramNoBreakPopupMenus() throws Throwable {
// NOTE: Need a target to have any breakpoint actions, even on programs
addMappedBreakpointOpenAndWait();
@ -276,7 +277,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testTraceNoBreakPopupMenus() throws Exception {
public void testTraceNoBreakPopupMenus() throws Throwable {
TraceRecorder recorder = addMappedBreakpointOpenAndWait();
Trace trace = recorder.getTrace();
traceManager.activateTrace(trace);
@ -414,7 +415,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
@Test
public void testActionToggleBreakpointProgramWithNoCurrentBreakpointOnInstruction()
throws Exception {
throws Throwable {
addMappedBreakpointOpenAndWait(); // wasteful, but whatever
for (LogicalBreakpoint lb : List.copyOf(breakpointService.getAllBreakpoints())) {
lb.delete();
@ -442,7 +443,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionToggleBreakpointProgramWithNoCurrentBreakpointOnData() throws Exception {
public void testActionToggleBreakpointProgramWithNoCurrentBreakpointOnData() throws Throwable {
addMappedBreakpointOpenAndWait(); // wasteful, but whatever
for (LogicalBreakpoint lb : List.copyOf(breakpointService.getAllBreakpoints())) {
lb.delete();
@ -470,7 +471,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionToggleBreakpointProgram() throws Exception {
public void testActionToggleBreakpointProgram() throws Throwable {
addMappedBreakpointOpenAndWait();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());
@ -486,7 +487,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionToggleBreakpointTrace() throws Exception {
public void testActionToggleBreakpointTrace() throws Throwable {
TraceRecorder recorder = addMappedBreakpointOpenAndWait();
Trace trace = recorder.getTrace();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());
@ -527,14 +528,16 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
protected void testActionSetBreakpointProgram(DockingAction action,
Set<TraceBreakpointKind> expectedKinds) throws Exception {
Set<TraceBreakpointKind> expectedKinds) throws Throwable {
addMappedBreakpointOpenAndWait(); // Adds an unneeded breakpoint. Aw well.
performAction(action, staticCtx(addr(program, 0x0400321)), false);
DebuggerPlaceBreakpointDialog dialog =
waitForDialogComponent(DebuggerPlaceBreakpointDialog.class);
dialog.setName("Test name");
runSwing(() -> dialog.okCallback());
runSwing(() -> {
dialog.setName("Test name");
dialog.okCallback();
});
waitForPass(() -> {
LogicalBreakpoint lb = Unique.assertOne(
@ -546,7 +549,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
protected void testActionSetBreakpointTrace(DockingAction action,
Set<TraceBreakpointKind> expectedKinds) throws Exception {
Set<TraceBreakpointKind> expectedKinds) throws Throwable {
TraceRecorder recorder = addMappedBreakpointOpenAndWait(); // Adds an unneeded breakpoint. Aw well.
Trace trace = recorder.getTrace();
@ -568,67 +571,67 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionSetSoftwareBreakpointProgram() throws Exception {
public void testActionSetSoftwareBreakpointProgram() throws Throwable {
testActionSetBreakpointProgram(breakpointMarkerPlugin.actionSetSoftwareBreakpoint,
Set.of(TraceBreakpointKind.SW_EXECUTE));
}
@Test
public void testActionSetSoftwareBreakpointTrace() throws Exception {
public void testActionSetSoftwareBreakpointTrace() throws Throwable {
testActionSetBreakpointTrace(breakpointMarkerPlugin.actionSetSoftwareBreakpoint,
Set.of(TraceBreakpointKind.SW_EXECUTE));
}
@Test
public void testActionSetExecuteBreakpointProgram() throws Exception {
public void testActionSetExecuteBreakpointProgram() throws Throwable {
testActionSetBreakpointProgram(breakpointMarkerPlugin.actionSetExecuteBreakpoint,
Set.of(TraceBreakpointKind.HW_EXECUTE));
}
@Test
public void testActionSetExecuteBreakpointTrace() throws Exception {
public void testActionSetExecuteBreakpointTrace() throws Throwable {
testActionSetBreakpointTrace(breakpointMarkerPlugin.actionSetExecuteBreakpoint,
Set.of(TraceBreakpointKind.HW_EXECUTE));
}
@Test
public void testActionSetReadWriteBreakpointProgram() throws Exception {
public void testActionSetReadWriteBreakpointProgram() throws Throwable {
testActionSetBreakpointProgram(breakpointMarkerPlugin.actionSetReadWriteBreakpoint,
Set.of(TraceBreakpointKind.READ, TraceBreakpointKind.WRITE));
}
@Test
public void testActionSetReadWriteBreakpointTrace() throws Exception {
public void testActionSetReadWriteBreakpointTrace() throws Throwable {
testActionSetBreakpointTrace(breakpointMarkerPlugin.actionSetReadWriteBreakpoint,
Set.of(TraceBreakpointKind.READ, TraceBreakpointKind.WRITE));
}
@Test
public void testActionSetReadBreakpointProgram() throws Exception {
public void testActionSetReadBreakpointProgram() throws Throwable {
testActionSetBreakpointProgram(breakpointMarkerPlugin.actionSetReadBreakpoint,
Set.of(TraceBreakpointKind.READ));
}
@Test
public void testActionSetReadBreakpointTrace() throws Exception {
public void testActionSetReadBreakpointTrace() throws Throwable {
testActionSetBreakpointTrace(breakpointMarkerPlugin.actionSetReadBreakpoint,
Set.of(TraceBreakpointKind.READ));
}
@Test
public void testActionSetWriteBreakpointProgram() throws Exception {
public void testActionSetWriteBreakpointProgram() throws Throwable {
testActionSetBreakpointProgram(breakpointMarkerPlugin.actionSetWriteBreakpoint,
Set.of(TraceBreakpointKind.WRITE));
}
@Test
public void testActionSetWriteBreakpointTrace() throws Exception {
public void testActionSetWriteBreakpointTrace() throws Throwable {
testActionSetBreakpointTrace(breakpointMarkerPlugin.actionSetWriteBreakpoint,
Set.of(TraceBreakpointKind.WRITE));
}
@Test
public void testActionEnableBreakpointProgram() throws Exception {
public void testActionEnableBreakpointProgram() throws Throwable {
addMappedBreakpointOpenAndWait();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());
lb.disable();
@ -641,7 +644,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionEnableBreakpointTrace() throws Exception {
public void testActionEnableBreakpointTrace() throws Throwable {
TraceRecorder recorder = addMappedBreakpointOpenAndWait();
Trace trace = recorder.getTrace();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());
@ -656,7 +659,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionDisableBreakpointProgram() throws Exception {
public void testActionDisableBreakpointProgram() throws Throwable {
addMappedBreakpointOpenAndWait();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());
@ -667,7 +670,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionDisableBreakpointTrace() throws Exception {
public void testActionDisableBreakpointTrace() throws Throwable {
TraceRecorder recorder = addMappedBreakpointOpenAndWait();
Trace trace = recorder.getTrace();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());
@ -680,7 +683,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionClearBreakpointProgram() throws Exception {
public void testActionClearBreakpointProgram() throws Throwable {
addMappedBreakpointOpenAndWait();
performAction(breakpointMarkerPlugin.actionClearBreakpoint,
@ -690,7 +693,7 @@ public class DebuggerBreakpointMarkerPluginTest extends AbstractGhidraHeadedDebu
}
@Test
public void testActionClearBreakpointTrace() throws Exception {
public void testActionClearBreakpointTrace() throws Throwable {
TraceRecorder recorder = addMappedBreakpointOpenAndWait();
Trace trace = recorder.getTrace();
LogicalBreakpoint lb = Unique.assertOne(breakpointService.getAllBreakpoints());

View file

@ -1269,7 +1269,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerGUI
.createRegion(".text", 0, tb.range(0x00400000, 0x0040ffff),
TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);
thread1 = tb.getOrAddThread("Thread1", 0);
tb.exec(0, 0, thread1, java.util.List.of("RIP = 0x00400000;"));
tb.exec(0, 0, thread1, "RIP = 0x00400000;");
}
TraceThread thread2;
@ -1279,7 +1279,7 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerGUI
.createRegion(".text", 0, tb2.range(0x200, 0x3ff), TraceMemoryFlag.READ,
TraceMemoryFlag.EXECUTE);
thread2 = tb2.getOrAddThread("Thread2", 0);
tb2.exec(0, 0, thread2, java.util.List.of("PC = 0x100;"));
tb2.exec(0, 0, thread2, "PC = 0x100;");
}
traceManager.openTrace(tb.trace);

View file

@ -82,7 +82,7 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
thread = tb.getOrAddThread("1", 0);
PcodeExecutor<byte[]> init = TraceSleighUtils.buildByteExecutor(tb.trace, 0, thread, 0);
init.executeSleighLine("pc = 0x00400000");
init.executeSleigh("pc = 0x00400000;");
Assembler asm = Assemblers.getAssembler(tb.trace.getFixedProgramView(0));
iit = asm.assemble(start,
@ -166,7 +166,7 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
.anyMatch(r -> r.getCode().contains("emu_swi"))));
}
protected List<PcodeRow> format(List<String> sleigh) {
protected List<PcodeRow> format(String sleigh) {
SleighLanguage language = (SleighLanguage) getToyBE64Language();
PcodeProgram prog = SleighProgramCompiler.compileProgram(language, "test", sleigh,
PcodeUseropLibrary.nil());
@ -179,7 +179,7 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
@Test
public void testPcodeFormatterSimple() {
List<PcodeRow> rows = format(List.of("r0 = 1;"));
List<PcodeRow> rows = format("r0 = 1;");
assertEquals(2, rows.size());
assertEquals("<html></html>", rows.get(0).getLabel());
assertEquals(FallthroughPcodeRow.class, rows.get(1).getClass());
@ -187,9 +187,10 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
@Test
public void testPcodeFormatterStartsLabel() {
List<PcodeRow> rows = format(List.of(
"<L0> r0 = 1;",
"goto <L0>;"));
List<PcodeRow> rows = format("""
<L0> r0 = 1;
goto <L0>;
""");
assertEquals(3, rows.size());
assertEquals("<html><span class=\"lab\">&lt;0&gt;</span></html>", rows.get(0).getLabel());
assertEquals("<html></html>", rows.get(1).getLabel());
@ -198,10 +199,11 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
@Test
public void testPcodeFormatterMiddleLabel() {
List<PcodeRow> rows = format(List.of(
"if 1:1 goto <SKIP>;",
"r0 = 1;",
"<SKIP> r1 = 2;"));
List<PcodeRow> rows = format("""
if 1:1 goto <SKIP>;
r0 = 1;
<SKIP> r1 = 2;
""");
assertEquals(4, rows.size());
assertEquals("<html></html>", rows.get(0).getLabel());
assertEquals("<html></html>", rows.get(1).getLabel());
@ -211,10 +213,11 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
@Test
public void testPcodeFormatterFallthroughLabel() {
List<PcodeRow> rows = format(List.of(
"if 1:1 goto <SKIP>;",
"r0 = 1;",
"<SKIP>"));
List<PcodeRow> rows = format("""
if 1:1 goto <SKIP>;
r0 = 1;
<SKIP>
""");
assertEquals(3, rows.size());
assertEquals("<html></html>", rows.get(0).getLabel());
assertEquals("<html></html>", rows.get(1).getLabel());
@ -224,12 +227,13 @@ public class DebuggerPcodeStepperProviderTest extends AbstractGhidraHeadedDebugg
@Test
public void testPcodeFormatterManyLabel() {
List<PcodeRow> rows = format(List.of(
"<L0> goto <L1>;",
"<L1> goto <L2>;",
"<L2> goto <L3>;",
"goto <L0>;",
"<L3>"));
List<PcodeRow> rows = format("""
<L0> goto <L1>;
<L1> goto <L2>;
<L2> goto <L3>;
goto <L0>;
<L3>
""");
assertEquals(5, rows.size());
// NB. templates number labels in order of appearance in BRANCHes
assertEquals("<html><span class=\"lab\">&lt;3&gt;</span></html>", rows.get(0).getLabel());

View file

@ -469,7 +469,7 @@ public class DebuggerRegistersProviderTest extends AbstractGhidraHeadedDebuggerG
TraceThread thread = addThread();
try (UndoableTransaction tid = tb.startTransaction()) {
tb.exec(0, 0, thread, List.of("pc = 100;"));
tb.exec(0, 0, thread, "pc = 100;");
}
traceManager.activateThread(thread);
waitForSwing();
@ -800,10 +800,11 @@ public class DebuggerRegistersProviderTest extends AbstractGhidraHeadedDebuggerG
modelData.stream().filter(r -> r.getRegister() == pc).findFirst().orElse(null);
assertNotNull(pcAvail);
pcAvail.setSelected(false);
dialog.availableTableModel.fireTableDataChanged();
dialog.okCallback();
waitForSwing();
runSwing(() -> {
pcAvail.setSelected(false);
dialog.availableTableModel.fireTableDataChanged();
dialog.okCallback();
});
assertNull(getRegisterRow(pc));
assertTrue(registersProvider.actionSelectRegisters.isEnabled());

View file

@ -148,7 +148,7 @@ public class DebuggerStateEditingServiceTest extends AbstractGhidraHeadedDebugge
Assembler asm = Assemblers.getAssembler(tb.trace.getFixedProgramView(0));
asm.assemble(tb.addr(0x00400000), "imm r0,#123");
executor.executeSleighLine("pc = 0x00400000");
executor.executeSleigh("pc = 0x00400000;");
}
traceManager.activateTrace(tb.trace);
editingService.setCurrentMode(tb.trace, StateEditingMode.WRITE_EMULATOR);
@ -186,7 +186,7 @@ public class DebuggerStateEditingServiceTest extends AbstractGhidraHeadedDebugge
Assembler asm = Assemblers.getAssembler(tb.trace.getFixedProgramView(0));
asm.assemble(tb.addr(0x00400000), "imm r0,#123");
executor.executeSleighLine("pc = 0x00400000");
executor.executeSleigh("pc = 0x00400000;");
}
traceManager.activateTrace(tb.trace);
editingService.setCurrentMode(tb.trace, StateEditingMode.WRITE_EMULATOR);

View file

@ -337,7 +337,7 @@ public class DebuggerTraceManagerServiceTest extends AbstractGhidraHeadedDebugge
}
@Test
public void testAutoActivatePresent() throws Exception {
public void testAutoActivatePresent() throws Throwable {
assertTrue(traceManager.isAutoActivatePresent());
createTestModel();
@ -345,6 +345,7 @@ public class DebuggerTraceManagerServiceTest extends AbstractGhidraHeadedDebugge
TraceRecorder recorder = modelService.recordTarget(mb.testProcess1,
createTargetTraceMapper(mb.testProcess1), ActionSource.AUTOMATIC);
waitRecorder(recorder);
Trace trace = recorder.getTrace();
traceManager.openTrace(trace);

View file

@ -18,7 +18,6 @@ package ghidra.pcode.exec;
import static org.junit.Assert.*;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import org.junit.Test;
@ -29,7 +28,6 @@ import ghidra.app.plugin.processors.sleigh.SleighLanguage;
import ghidra.app.services.ActionSource;
import ghidra.app.services.TraceRecorder;
import ghidra.dbg.model.TestTargetRegisterBankInThread;
import ghidra.pcode.exec.*;
import ghidra.pcode.utils.Utils;
import ghidra.program.model.lang.Register;
import ghidra.trace.model.Trace;
@ -100,7 +98,7 @@ public class TraceRecorderAsyncPcodeExecTest extends AbstractGhidraHeadedDebugge
SleighLanguage language = (SleighLanguage) trace.getBaseLanguage();
PcodeProgram prog = SleighProgramCompiler.compileProgram(language, "test",
List.of("r2 = r0 + r1;"), PcodeUseropLibrary.NIL);
"r2 = r0 + r1;", PcodeUseropLibrary.NIL);
Register r0 = language.getRegister("r0");
Register r1 = language.getRegister("r1");