From ac324c9023a1323846d8ce26bd0742f79c0e194e Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Tue, 2 Jul 2024 08:54:39 -0400 Subject: [PATCH] GP-0: Fix gdb tests on Ubuntu 24.04 (gdb-15-git) --- .../gdb/rmi/AbstractGdbTraceRmiTest.java | 19 ++++++++++++------- .../java/agent/gdb/rmi/GdbCommandsTest.java | 4 ++-- .../java/agent/gdb/rmi/GdbMethodsTest.java | 13 +++++++------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/AbstractGdbTraceRmiTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/AbstractGdbTraceRmiTest.java index ca010d1856..b6c5905d58 100644 --- a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/AbstractGdbTraceRmiTest.java +++ b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/AbstractGdbTraceRmiTest.java @@ -23,11 +23,11 @@ import java.net.*; import java.nio.file.*; import java.util.*; import java.util.concurrent.*; -import java.util.function.Function; -import java.util.function.Supplier; +import java.util.function.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.commons.lang3.exception.ExceptionUtils; import org.junit.Before; @@ -157,16 +157,22 @@ public abstract class AbstractGdbTraceRmiTest extends AbstractGhidraHeadedDebugg } protected record GdbResult(boolean timedOut, int exitCode, String stdout, String stderr) { + String filterLines(String in, Predicate lineTest) { + return Stream.of(in.split("\n")).filter(lineTest).collect(Collectors.joining("\n")); + } + protected String handle() { - if (!"".equals(stderr) | 0 != exitCode) { + String filtErr = filterLines(stderr, line -> { + return !line.contains("warning: could not find '.gnu_debugaltlink' file"); + }); + if (!filtErr.isBlank() | 0 != exitCode) { throw new GdbError(exitCode, stdout, stderr); } return stdout; } } - protected record ExecInGdb(Process gdb, CompletableFuture future) { - } + protected record ExecInGdb(Process gdb, CompletableFuture future) {} @SuppressWarnings("resource") // Do not close stdin protected ExecInGdb execInGdb(String script) throws IOException { @@ -345,8 +351,7 @@ public abstract class AbstractGdbTraceRmiTest extends AbstractGhidraHeadedDebugg return out.split(head)[1].split("---")[0].replace("(gdb)", "").trim(); } - record MemDump(long address, byte[] data) { - } + record MemDump(long address, byte[] data) {} protected MemDump parseHexDump(String dump) throws IOException { // First, get the address. Assume contiguous, so only need top line. diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbCommandsTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbCommandsTest.java index f7b36c3e25..ddfc7d3b90 100644 --- a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbCommandsTest.java +++ b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbCommandsTest.java @@ -1020,7 +1020,7 @@ public class GdbCommandsTest extends AbstractGdbTraceRmiTest { starti ghidra trace start ghidra trace tx-start "Tx" - break main + break *main hbreak *main+10 watch -l *((char*)(&main+20)) rwatch -l *((char(*)[8])(&main+30)) @@ -1046,7 +1046,7 @@ public class GdbCommandsTest extends AbstractGdbTraceRmiTest { // NB. starti avoid use of temporary main breakpoint assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1, Set.of(TraceBreakpointKind.SW_EXECUTE), - "main"); + "*main"); assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1, Set.of(TraceBreakpointKind.HW_EXECUTE), "*main+10"); diff --git a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbMethodsTest.java b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbMethodsTest.java index d705dbe527..aff703f2d2 100644 --- a/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbMethodsTest.java +++ b/Ghidra/Test/DebuggerIntegrationTest/src/test.slow/java/agent/gdb/rmi/GdbMethodsTest.java @@ -116,7 +116,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest { waitStopped(); conn.execute(""" - break main + break *main hbreak *main+10 watch -l *((char*)(&main+20)) rwatch -l *((char(*)[8])(&main+30)) @@ -138,7 +138,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest { // NB. starti avoid use of temporary main breakpoint assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1, Set.of(TraceBreakpointKind.SW_EXECUTE), - "main"); + "*main"); assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1, Set.of(TraceBreakpointKind.HW_EXECUTE), "*main+10"); @@ -172,7 +172,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest { TraceObject locations = Objects.requireNonNull(tb.obj("Inferiors[1].Breakpoints")); conn.execute(""" - break main + break *main hbreak *main+10 watch -l *((char*)(&main+20)) rwatch -l *((char(*)[8])(&main+30)) @@ -193,7 +193,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest { // NB. starti avoid use of temporary main breakpoint assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1, Set.of(TraceBreakpointKind.SW_EXECUTE), - "main"); + "*main"); assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1, Set.of(TraceBreakpointKind.HW_EXECUTE), "*main+10"); @@ -935,7 +935,8 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest { tb = new ToyDBTraceBuilder((Trace) mdo.get()); waitStopped(); - breakSwExecuteExpression.invoke(Map.of("expression", "main")); + // Use *main instead of main, because some gdb will instead do + breakSwExecuteExpression.invoke(Map.of("expression", "*main")); String out = conn.executeCapture("info break"); assertThat(out, containsString("
")); @@ -982,7 +983,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest { tb = new ToyDBTraceBuilder((Trace) mdo.get()); waitStopped(); - breakHwExecuteExpression.invoke(Map.of("expression", "main")); + breakHwExecuteExpression.invoke(Map.of("expression", "*main")); String out = conn.executeCapture("info break"); assertThat(out, containsString("
"));