mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-0: Fix gdb tests on Ubuntu 24.04 (gdb-15-git)
This commit is contained in:
parent
3b03d836ae
commit
ac324c9023
3 changed files with 21 additions and 15 deletions
|
@ -23,11 +23,11 @@ import java.net.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.*;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import org.junit.Before;
|
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) {
|
protected record GdbResult(boolean timedOut, int exitCode, String stdout, String stderr) {
|
||||||
|
String filterLines(String in, Predicate<String> lineTest) {
|
||||||
|
return Stream.of(in.split("\n")).filter(lineTest).collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
protected String handle() {
|
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);
|
throw new GdbError(exitCode, stdout, stderr);
|
||||||
}
|
}
|
||||||
return stdout;
|
return stdout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected record ExecInGdb(Process gdb, CompletableFuture<GdbResult> future) {
|
protected record ExecInGdb(Process gdb, CompletableFuture<GdbResult> future) {}
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("resource") // Do not close stdin
|
@SuppressWarnings("resource") // Do not close stdin
|
||||||
protected ExecInGdb execInGdb(String script) throws IOException {
|
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();
|
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 {
|
protected MemDump parseHexDump(String dump) throws IOException {
|
||||||
// First, get the address. Assume contiguous, so only need top line.
|
// First, get the address. Assume contiguous, so only need top line.
|
||||||
|
|
|
@ -1020,7 +1020,7 @@ public class GdbCommandsTest extends AbstractGdbTraceRmiTest {
|
||||||
starti
|
starti
|
||||||
ghidra trace start
|
ghidra trace start
|
||||||
ghidra trace tx-start "Tx"
|
ghidra trace tx-start "Tx"
|
||||||
break main
|
break *main
|
||||||
hbreak *main+10
|
hbreak *main+10
|
||||||
watch -l *((char*)(&main+20))
|
watch -l *((char*)(&main+20))
|
||||||
rwatch -l *((char(*)[8])(&main+30))
|
rwatch -l *((char(*)[8])(&main+30))
|
||||||
|
@ -1046,7 +1046,7 @@ public class GdbCommandsTest extends AbstractGdbTraceRmiTest {
|
||||||
// NB. starti avoid use of temporary main breakpoint
|
// NB. starti avoid use of temporary main breakpoint
|
||||||
assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1,
|
assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1,
|
||||||
Set.of(TraceBreakpointKind.SW_EXECUTE),
|
Set.of(TraceBreakpointKind.SW_EXECUTE),
|
||||||
"main");
|
"*main");
|
||||||
assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1,
|
assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1,
|
||||||
Set.of(TraceBreakpointKind.HW_EXECUTE),
|
Set.of(TraceBreakpointKind.HW_EXECUTE),
|
||||||
"*main+10");
|
"*main+10");
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest {
|
||||||
waitStopped();
|
waitStopped();
|
||||||
|
|
||||||
conn.execute("""
|
conn.execute("""
|
||||||
break main
|
break *main
|
||||||
hbreak *main+10
|
hbreak *main+10
|
||||||
watch -l *((char*)(&main+20))
|
watch -l *((char*)(&main+20))
|
||||||
rwatch -l *((char(*)[8])(&main+30))
|
rwatch -l *((char(*)[8])(&main+30))
|
||||||
|
@ -138,7 +138,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest {
|
||||||
// NB. starti avoid use of temporary main breakpoint
|
// NB. starti avoid use of temporary main breakpoint
|
||||||
assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1,
|
assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1,
|
||||||
Set.of(TraceBreakpointKind.SW_EXECUTE),
|
Set.of(TraceBreakpointKind.SW_EXECUTE),
|
||||||
"main");
|
"*main");
|
||||||
assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1,
|
assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1,
|
||||||
Set.of(TraceBreakpointKind.HW_EXECUTE),
|
Set.of(TraceBreakpointKind.HW_EXECUTE),
|
||||||
"*main+10");
|
"*main+10");
|
||||||
|
@ -172,7 +172,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest {
|
||||||
|
|
||||||
TraceObject locations = Objects.requireNonNull(tb.obj("Inferiors[1].Breakpoints"));
|
TraceObject locations = Objects.requireNonNull(tb.obj("Inferiors[1].Breakpoints"));
|
||||||
conn.execute("""
|
conn.execute("""
|
||||||
break main
|
break *main
|
||||||
hbreak *main+10
|
hbreak *main+10
|
||||||
watch -l *((char*)(&main+20))
|
watch -l *((char*)(&main+20))
|
||||||
rwatch -l *((char(*)[8])(&main+30))
|
rwatch -l *((char(*)[8])(&main+30))
|
||||||
|
@ -193,7 +193,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest {
|
||||||
// NB. starti avoid use of temporary main breakpoint
|
// NB. starti avoid use of temporary main breakpoint
|
||||||
assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1,
|
assertBreakLoc(infBreakLocVals.get(0), "[1.1]", main, 1,
|
||||||
Set.of(TraceBreakpointKind.SW_EXECUTE),
|
Set.of(TraceBreakpointKind.SW_EXECUTE),
|
||||||
"main");
|
"*main");
|
||||||
assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1,
|
assertBreakLoc(infBreakLocVals.get(1), "[2.1]", main.add(10), 1,
|
||||||
Set.of(TraceBreakpointKind.HW_EXECUTE),
|
Set.of(TraceBreakpointKind.HW_EXECUTE),
|
||||||
"*main+10");
|
"*main+10");
|
||||||
|
@ -935,7 +935,8 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest {
|
||||||
tb = new ToyDBTraceBuilder((Trace) mdo.get());
|
tb = new ToyDBTraceBuilder((Trace) mdo.get());
|
||||||
waitStopped();
|
waitStopped();
|
||||||
|
|
||||||
breakSwExecuteExpression.invoke(Map.of("expression", "main"));
|
// Use *main instead of main, because some gdb will instead do <main+8>
|
||||||
|
breakSwExecuteExpression.invoke(Map.of("expression", "*main"));
|
||||||
|
|
||||||
String out = conn.executeCapture("info break");
|
String out = conn.executeCapture("info break");
|
||||||
assertThat(out, containsString("<main>"));
|
assertThat(out, containsString("<main>"));
|
||||||
|
@ -982,7 +983,7 @@ public class GdbMethodsTest extends AbstractGdbTraceRmiTest {
|
||||||
tb = new ToyDBTraceBuilder((Trace) mdo.get());
|
tb = new ToyDBTraceBuilder((Trace) mdo.get());
|
||||||
waitStopped();
|
waitStopped();
|
||||||
|
|
||||||
breakHwExecuteExpression.invoke(Map.of("expression", "main"));
|
breakHwExecuteExpression.invoke(Map.of("expression", "*main"));
|
||||||
|
|
||||||
String out = conn.executeCapture("info break");
|
String out = conn.executeCapture("info break");
|
||||||
assertThat(out, containsString("<main>"));
|
assertThat(out, containsString("<main>"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue