Ghidra is a software reverse engineering (SRE) framework
GP-7211: LLDB tests fail because of update prompt and new ANSI sequences
d-millarba630691d8e3
diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/AnsiBufferedInputStream.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/AnsiBufferedInputStream.javaindex 4f2a715dda..56d750c37b 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/AnsiBufferedInputStream.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/AnsiBufferedInputStream.java@@ -15,9 +15,7 @@*/package ghidra.pty.windows;-import java.io.BufferedInputStream;-import java.io.IOException;-import java.io.InputStream;+import java.io.*;import java.nio.ByteBuffer;import java.nio.charset.Charset;import java.util.Arrays;@@ -121,7 +119,7 @@ public class AnsiBufferedInputStream extends InputStream {return -1;}byte c = (byte) ci;-// printDebugChar(c);+ //printDebugChar(c);switch (mode) {case CHARS -> processChars(c);case ESC -> processEsc(c);@@ -189,7 +187,10 @@ public class AnsiBufferedInputStream extends InputStream {switch (c) {case '[' -> mode = Mode.CSI;case ']' -> mode = Mode.OSC;- default -> throw new AssertionError("Saw 'ESC " + c + "' at " + countIn);+ default -> {+ mode = Mode.CHARS;+ Msg.debug(this, "Saw 'ESC " + c + "' at " + countIn);+ }}}@@ -251,6 +252,10 @@ public class AnsiBufferedInputStream extends InputStream {execPrivateSequence(false);mode = Mode.CHARS;}+ case 'r' -> {+ Msg.debug(this, "TODO: r (scroll region)");+ mode = Mode.CHARS;+ }}}@@ -352,11 +357,11 @@ public class AnsiBufferedInputStream extends InputStream {}protected void execCursorUp() {- throw new UnsupportedOperationException("Cursor Up");+ //throw new UnsupportedOperationException("Cursor Up");}protected void execCursorDown() {- throw new UnsupportedOperationException("Cursor Down");+ //throw new UnsupportedOperationException("Cursor Down");}protected void setPosition(int newPosition) {@@ -377,8 +382,9 @@ public class AnsiBufferedInputStream extends InputStream {}protected void execCursorCharAbsolute() {- int abs = parseNumericBuffer();- lineBuf.position(abs - 1);+ int[] abset = parseNumericListBuffer();+ int abs = Math.min(abset[0] - 1, lineBuf.limit());+ lineBuf.position(abs);}protected void execCursorPosition() {@@ -442,7 +448,9 @@ public class AnsiBufferedInputStream extends InputStream {}protected void execEraseInLine() {- switch (parseNumericBuffer()) {+ int[] abset = parseNumericListBuffer();+ int abs = abset[0];+ switch (abs) {case 0 -> Arrays.fill(lineBuf.array(), lineBuf.position(), lineBuf.capacity(),(byte) 0);case 1 -> Arrays.fill(lineBuf.array(), 0, lineBuf.position() + 1, (byte) 0);diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbStackUnwindTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbStackUnwindTest.javaindex b9e52bb939..67bd681314 100644--- a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbStackUnwindTest.java+++ b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/lldb/rmi/LldbStackUnwindTest.java@@ -59,15 +59,18 @@ import ghidra.app.util.viewer.listingpanel.ListingPanel;import ghidra.debug.api.tracemgr.DebuggerCoordinates;import ghidra.framework.model.DomainFile;import ghidra.framework.model.DomainFolder;+import ghidra.program.database.ProgramDB;import ghidra.program.model.address.Address;import ghidra.program.model.listing.*;import ghidra.program.util.*;+import ghidra.test.TestProgramManager;import ghidra.trace.database.ToyDBTraceBuilder;import ghidra.trace.database.module.DBTraceStaticMappingManager;import ghidra.trace.model.Trace;import ghidra.trace.model.modules.TraceStaticMapping;import ghidra.util.*;import ghidra.util.exception.CancelledException;+import ghidra.util.exception.VersionException;import junit.framework.AssertionFailedError;@Category(NightlyCategory.class) // this may actually be an @PortSensitive test@@ -140,19 +143,11 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Testpublic void testBasicUnwind() throws Throwable {- List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe", "ntdll.dll");-addPlugins();- DomainFile[] dfs = getDomainFiles(files);- tool.acceptDomainFiles(dfs);-- DomainFile traceDF = getDomainFile("expSpin_lldb");- ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);- resyncMappings(mdo.get());- tool.acceptDomainFiles(new DomainFile[] { traceDF });-- programs = openPrograms(dfs);+ List<String> files =+ Arrays.asList("kernel32.dll", "expSpin.exe", "ntdll.dll");+ ManagedDomainObject<Trace> mdo = initPrograms("expSpin_lldb", files);try (LldbAndTrace conn = startAndSyncLldb(mdo)) {traceManager.activateSnap(2);@@ -170,19 +165,10 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Testpublic void testUnwindActivateMidStack() throws Throwable {- List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe", "ntdll.dll");-addPlugins();- DomainFile[] dfs = getDomainFiles(files);- tool.acceptDomainFiles(dfs);-- DomainFile traceDF = getDomainFile("expSpin_lldb");- ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);- resyncMappings(mdo.get());- tool.acceptDomainFiles(new DomainFile[] { traceDF });-- programs = openPrograms(dfs);+ List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe", "ntdll.dll");+ ManagedDomainObject<Trace> mdo = initPrograms("expSpin_lldb", files);try (LldbAndTrace conn = startAndSyncLldb(mdo)) {traceManager.activateSnap(2);@@ -202,19 +188,10 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Testpublic void testUnwindActivateHighFrame() throws Throwable {- List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe", "ntdll.dll");-addPlugins();- DomainFile[] dfs = getDomainFiles(files);- tool.acceptDomainFiles(dfs);-- DomainFile traceDF = getDomainFile("expSpin_lldb");- ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);- resyncMappings(mdo.get());- tool.acceptDomainFiles(new DomainFile[] { traceDF });-- programs = openPrograms(dfs);+ List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe", "ntdll.dll");+ ManagedDomainObject<Trace> mdo = initPrograms("expSpin_lldb", files);try (LldbAndTrace conn = startAndSyncLldb(mdo)) {traceManager.activateSnap(2);@@ -234,19 +211,10 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Testpublic void testBasicUnwindMissingLowFrame() throws Throwable {- List<String> files = Arrays.asList("expSpin.exe", "ntdll.dll");-addPlugins();- DomainFile[] dfs = getDomainFiles(files);- tool.acceptDomainFiles(dfs);-- DomainFile traceDF = getDomainFile("expSpin_lldb");- ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);- resyncMappings(mdo.get());- tool.acceptDomainFiles(new DomainFile[] { traceDF });-- programs = openPrograms(dfs);+ List<String> files = Arrays.asList("expSpin.exe", "ntdll.dll");+ ManagedDomainObject<Trace> mdo = initPrograms("expSpin_lldb", files);try (LldbAndTrace conn = startAndSyncLldb(mdo)) {traceManager.activateSnap(2);@@ -263,19 +231,10 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Testpublic void testBasicUnwindMissingMedFrame() throws Throwable {- List<String> files = Arrays.asList("kernel32.dll", "ntdll.dll");-addPlugins();- DomainFile[] dfs = getDomainFiles(files);- tool.acceptDomainFiles(dfs);-- DomainFile traceDF = getDomainFile("expSpin_lldb");- ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);- resyncMappings(mdo.get());- tool.acceptDomainFiles(new DomainFile[] { traceDF });-- programs = openPrograms(dfs);+ List<String> files = Arrays.asList("kernel32.dll", "ntdll.dll");+ ManagedDomainObject<Trace> mdo = initPrograms("expSpin_lldb", files);try (LldbAndTrace conn = startAndSyncLldb(mdo)) {traceManager.activateSnap(2);@@ -292,19 +251,10 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Testpublic void testBasicUnwindMissingHighFrame() throws Throwable {- List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe");-addPlugins();- DomainFile[] dfs = getDomainFiles(files);- tool.acceptDomainFiles(dfs);-- DomainFile traceDF = getDomainFile("expSpin_lldb");- ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);- resyncMappings(mdo.get());- tool.acceptDomainFiles(new DomainFile[] { traceDF });-- programs = openPrograms(dfs);+ List<String> files = Arrays.asList("kernel32.dll", "expSpin.exe");+ ManagedDomainObject<Trace> mdo = initPrograms("expSpin_lldb", files);try (LldbAndTrace conn = startAndSyncLldb(mdo)) {traceManager.activateSnap(2);@@ -345,11 +295,11 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {RowKey.FRAME,"Frame: 1 FUN_140001000 pc=7ff6bd611040 sp=f900000000 base=f900000078",RowKey.STORAGE, "Storage: Stack[-0x58]:4",- RowKey.TYPE, "Type: int",+ RowKey.TYPE, "Type: int", // undefined4RowKey.LOCATION, "Location: f900000020:4",RowKey.BYTES, "Bytes: (UNKNOWN) 00 00 00 00",RowKey.INTEGER, "Integer: (UNKNOWN) 0",- RowKey.VALUE, "Value: (UNKNOWN) 0h",+ RowKey.VALUE, "Value: (UNKNOWN) 0h", // 00000000hRowKey.WARNINGS, "IGNORED"), table);}@@ -395,31 +345,47 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {return getVariableValueTable(loc.pLoc, traceManager.getCurrent(), loc.fLoc, loc.field);}- private DomainFile[] getDomainFiles(List<String> files)- throws InvalidNameException, CancelledException, IOException {- DomainFile[] dfs = new DomainFile[files.size()];- int i = 0;- for (String fname : files) {- dfs[i++] = getDomainFile(fname);- }- return dfs;+ protected void addPlugins() throws Throwable {+ codeBrowserPlugin = addPlugin(tool, CodeBrowserPlugin.class);+ staticListing = codeBrowserPlugin.getProvider().getListingPanel();+ listingPlugin = addPlugin(tool, DebuggerListingPlugin.class);+ valuesPlugin = addPlugin(tool, VariableValueHoverPlugin.class);+ mappingService = addPlugin(tool, DebuggerStaticMappingServicePlugin.class);+ dynamicListing = listingPlugin.getProvider().getListingPanel();+ //addPlugin(tool, DebuggerControlPlugin.class);+ //addPlugin(tool, DebuggerStaticMappingPlugin.class);+ //addPlugin(tool, DebuggerModelPlugin.class);+ addPlugin(tool, DisassemblerPlugin.class);+ addPlugin(tool, DecompilePlugin.class);+ valuesService = valuesPlugin.getHoverService();++ decompilerProvider = waitForComponentProvider(DecompilerProvider.class);+ decompilerPanel = decompilerProvider.getDecompilerPanel();+ tool.showComponentProvider(decompilerProvider, true);}- private DomainFile getDomainFile(String fname)- throws InvalidNameException, CancelledException, IOException {+ private ManagedDomainObject<Trace> initPrograms(String trace, List<String> files)+ throws InvalidNameException, IOException, CancelledException, VersionException,+ MalformedURLException, URISyntaxException {+ TestProgramManager manager = new TestProgramManager();DomainFolder rootFolder = tool.getProject().getProjectData().getRootFolder();- File f = getTestDataFile(fname + ".gzf");- return rootFolder.createFile(fname, f, monitor);- }- private List<Program> openPrograms(DomainFile[] files) {- List<Program> progs = new ArrayList<>();- for (int i = 0; i < files.length; i++) {- progs.add(programManager.openProgram(files[i]));+ programs = new ArrayList<>();+ for (String fname : files) {+ ProgramDB pgm = manager.getProgram(fname);+ DomainFile df = rootFolder.createFile(fname, pgm, monitor);+ programs.add(programManager.openProgram(df));+ manager.release(pgm);}- return progs;++ File f = getTestDataFile(trace + ".gzt");+ DomainFile traceDF = rootFolder.createFile(trace, f, monitor);+ ManagedDomainObject<Trace> mdo = new ManagedDomainObject<>(traceDF, Trace.class, monitor);+ resyncMappings(mdo.get());+ tool.acceptDomainFiles(new DomainFile[] { traceDF });+ return mdo;}private void resyncMappings(Trace trace)@@ -450,25 +416,6 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {}}- protected void addPlugins() throws Throwable {- codeBrowserPlugin = addPlugin(tool, CodeBrowserPlugin.class);- staticListing = codeBrowserPlugin.getProvider().getListingPanel();- listingPlugin = addPlugin(tool, DebuggerListingPlugin.class);- valuesPlugin = addPlugin(tool, VariableValueHoverPlugin.class);- mappingService = addPlugin(tool, DebuggerStaticMappingServicePlugin.class);- dynamicListing = listingPlugin.getProvider().getListingPanel();- //addPlugin(tool, DebuggerControlPlugin.class);- //addPlugin(tool, DebuggerStaticMappingPlugin.class);- //addPlugin(tool, DebuggerModelPlugin.class);- addPlugin(tool, DisassemblerPlugin.class);- addPlugin(tool, DecompilePlugin.class);- valuesService = valuesPlugin.getHoverService();-- decompilerProvider = waitForComponentProvider(DecompilerProvider.class);- decompilerPanel = decompilerProvider.getDecompilerPanel();- tool.showComponentProvider(decompilerProvider, true);- }-public record HoverLocation(ProgramLocation pLoc, FieldLocation fLoc, Field field,ClangToken token) {}@@ -601,6 +548,7 @@ public class LldbStackUnwindTest extends AbstractLldbTraceRmiTest {@Overridepublic void dataChanged(BigInteger start, BigInteger end) {+ // Ignore}});tool.showComponentProvider(decompilerProvider, true);