Skip to content

Commit

Permalink
Improve handling of gdb commands
Browse files Browse the repository at this point in the history
Instead of waiting till the gdb output matches the expected command or
timeouts, wait for the command to complete (or timeout), i.e. for the
prompt to appear. This way if a command prints the expected output but
doesn't complete, it's execution time is not being counted by the next
`waitForBufferToMatch` invocation, additionally if the command completes
but doesn't return the expected result we don't have to wait for the
timeout. Furthermore, we can enhance the logging to see if the command
timed out or completed but without matching the expected output.

To ensure the prompt appears consistently across gdb versions after
every command we use the GDB/MI mode, i.e. the "--interpreter=mi"
option.

Closes Karm#173
  • Loading branch information
zakkak committed Jul 26, 2023
1 parent 5eace8d commit 4e9aa59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void debugSymbolsSmokeGDB(TestInfo testInfo) throws IOException, Interrup
// We should somehow capture this semantically in an Enum or something. This is fragile...
builderRoutine(app.buildAndRunCmds.cmds.length - 2, app, report, cn, mn, appDir, processLog, null, switches);

final ProcessBuilder processBuilder = new ProcessBuilder(getRunCommand("gdb", "./target/debug-symbols-smoke"));
final ProcessBuilder processBuilder = new ProcessBuilder(getRunCommand("gdb", "--interpreter=mi", "./target/debug-symbols-smoke"));
final Map<String, String> envA = processBuilder.environment();
envA.put("PATH", System.getenv("PATH"));
processBuilder.directory(appDir)
Expand Down Expand Up @@ -206,7 +206,7 @@ public void debugSymbolsQuarkus(TestInfo testInfo) throws IOException, Interrupt
processLog = Path.of(appDir.getAbsolutePath(), "logs", "build-and-run.log").toFile();
builderRoutine(app.buildAndRunCmds.cmds.length - 1, app, report, cn, mn, appDir, processLog);

final ProcessBuilder processBuilder = new ProcessBuilder(getRunCommand("gdb", "./target/quarkus-runner"));
final ProcessBuilder processBuilder = new ProcessBuilder(getRunCommand("gdb", "--interpreter=mi", "./target/quarkus-runner"));
final Map<String, String> envA = processBuilder.environment();
envA.put("PATH", System.getenv("PATH"));
processBuilder.directory(appDir)
Expand Down Expand Up @@ -315,7 +315,7 @@ public void debugSymbolsQuarkusContainer(TestInfo testInfo) throws IOException,
// Q 1.11.7.Final and Mandrel 20.3.2 needs work/application.debug
// Is Q 2.x baking debug symbols to the main executable too?
final ProcessBuilder processBuilder = new ProcessBuilder(getRunCommand(
CONTAINER_RUNTIME, "exec", "-i", ContainerNames.QUARKUS_BUILDER_IMAGE_ENCODING.name, "/usr/bin/gdb", "/work/application.debug", "1"))
CONTAINER_RUNTIME, "exec", "-i", ContainerNames.QUARKUS_BUILDER_IMAGE_ENCODING.name, "/usr/bin/gdb", "--interpreter=mi", "/work/application.debug", "1"))
.directory(appDir)
.redirectErrorStream(true);
final Map<String, String> envA = processBuilder.environment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,11 @@ public static boolean waitForBufferToMatch(StringBuffer stringBuffer, Pattern pa
long sleepMillis = unit.toMillis(sleep);
long startMillis = System.currentTimeMillis();
while (System.currentTimeMillis() - startMillis < timeoutMillis) {
if (pattern.matcher(stringBuffer.toString()).matches()) {
return true;
// Wait for command to complete, i.e. for the prompt to appear.
// To ensure the prompt appears consistently across gdb versions after every command we use the GDB/MI mode, i.e. the "--interpreter=mi" option.
// See https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Output-Syntax.html#GDB_002fMI-Output-Syntax
if (Pattern.compile(".*\\(gdb\\).*", Pattern.DOTALL).matcher(stringBuffer.toString()).matches()) {
return pattern.matcher(stringBuffer.toString()).matches();
}
try {
Thread.sleep(sleepMillis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public CP[] get(boolean inContainer) {
new CP("bt\n",
Pattern.compile(".*at.*com/example/quarkus/config/ConfigTestController.java:33.*", Pattern.DOTALL)),
new CP("list\n",
Pattern.compile(".*String value = config.getValue\\(\"value\", String.class\\);.*", Pattern.DOTALL)),
Pattern.compile(".*String value = config.getValue\\(\\\\\"value\\\\\", String.class\\);.*", Pattern.DOTALL)),
new CP("c&\n",
Pattern.compile(".*Continuing.*", Pattern.DOTALL)),
};
Expand All @@ -266,7 +266,7 @@ public CP[] get(boolean inContainer) {
new CP("bt\n",
Pattern.compile(".*at org/acme/vertx/Fruit.java:48.*", Pattern.DOTALL)),
new CP("list\n",
Pattern.compile(".*48.*return client.query\\(\"SELECT id, name FROM fruits ORDER BY name ASC.*", Pattern.DOTALL)),
Pattern.compile(".*48.*return client.query\\(\\\\\"SELECT id, name FROM fruits ORDER BY name ASC.*", Pattern.DOTALL)),
new CP("c&\n",
Pattern.compile(".*", Pattern.DOTALL)),
};
Expand Down

0 comments on commit 4e9aa59

Please sign in to comment.