Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance gdb commands logging #172

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ public void debugSymbolsSmokeGDB(TestInfo testInfo) throws IOException, Interrup
esvc.submit(reader);

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()))) {
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", processBuilder.command()));
Logs.appendln(report, stringBuffer.toString());
assertTrue(waitForBufferToMatch(stringBuffer,
Pattern.compile(".*Reading symbols from.*", Pattern.DOTALL),
3000, 500, TimeUnit.MILLISECONDS),
Logs.appendlnSection(report, appDir.getAbsolutePath());
Logs.appendln(report, String.join(" ", processBuilder.command()));
boolean result = waitForBufferToMatch(report, stringBuffer,
Pattern.compile(".*Reading symbols from.*", Pattern.DOTALL),
3000, 500, TimeUnit.MILLISECONDS);
Logs.appendlnSection(report, stringBuffer.toString());
assertTrue(result,
"GDB session did not start well. Check the names, paths... Content was: " + stringBuffer.toString());

carryOutGDBSession(stringBuffer, GDBSession.DEBUG_SYMBOLS_SMOKE, esvc, writer, report, false);
Expand Down Expand Up @@ -226,15 +227,16 @@ public void debugSymbolsQuarkus(TestInfo testInfo) throws IOException, Interrupt
};
esvc.submit(reader);

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()))) {
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", processBuilder.command()));
Logs.appendln(report, stringBuffer.toString());
assertTrue(waitForBufferToMatch(stringBuffer,
Pattern.compile(".*Reading symbols from.*", Pattern.DOTALL),
60000, 500, TimeUnit.MILLISECONDS),
"GDB session did not start well. Check the names, paths... Content was: " + stringBuffer.toString());
Logs.appendlnSection(report, appDir.getAbsolutePath());
Logs.appendln(report, String.join(" ", processBuilder.command()));
boolean result = waitForBufferToMatch(report, stringBuffer,
Pattern.compile(".*Reading symbols from.*", Pattern.DOTALL),
60000, 500, TimeUnit.MILLISECONDS);
Logs.appendlnSection(report, stringBuffer.toString());
assertTrue(result,
"GDB session did not start well. Check the names, paths... Content was: " + stringBuffer);

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()))) {
writer.write("set confirm off\n");
writer.flush();

Expand Down Expand Up @@ -335,14 +337,16 @@ public void debugSymbolsQuarkusContainer(TestInfo testInfo) throws IOException,
esvc.submit(reader);

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(gdbProcess.getOutputStream()))) {
Logs.appendln(report, appDir.getAbsolutePath());
Logs.appendlnSection(report, String.join(" ", processBuilder.command()));
Logs.appendln(report, stringBuffer.toString());
assertTrue(waitForBufferToMatch(stringBuffer,
Pattern.compile(".*Reading symbols from.*", Pattern.DOTALL),
3000, 500, TimeUnit.MILLISECONDS),
Logs.appendlnSection(report, appDir.getAbsolutePath());
Logs.appendln(report, String.join(" ", processBuilder.command()));
boolean result = waitForBufferToMatch(report, stringBuffer,
Pattern.compile(".*Reading symbols from.*", Pattern.DOTALL),
3000, 500, TimeUnit.MILLISECONDS);
Logs.appendlnSection(report, stringBuffer.toString());
assertTrue(result,
"GDB session did not start well. Check the names, paths... Content was: " + stringBuffer.toString());


writer.write("set confirm off\n");
writer.flush();

Expand Down Expand Up @@ -403,9 +407,9 @@ public static void carryOutGDBSession(StringBuffer stringBuffer, GDBSession gdbS
} else {
writer.write(cp.c);
writer.flush();
boolean m = waitForBufferToMatch(stringBuffer, cp.p, cp.timeoutSeconds, 1, TimeUnit.SECONDS);
Logs.appendlnSection(report, cp.c);
Logs.appendln(report, stringBuffer.toString());
Logs.appendln(report, cp.c);
boolean m = waitForBufferToMatch(report, stringBuffer, cp.p, cp.timeoutSeconds, 1, TimeUnit.SECONDS);
Logs.appendlnSection(report, stringBuffer.toString());
if (!m) {
errorQueue.add("Command '" + cp.c.trim() + "' did not match the expected pattern '" +
cp.p.pattern() + "'.\nOutput was:\n" + stringBuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ public static int waitForFileToMatch(Pattern lineMatchRegexp, Path path, int ski
return -1;
}

public static boolean waitForBufferToMatch(StringBuffer stringBuffer, Pattern pattern, long timeout, long sleep, TimeUnit unit) {
public static boolean waitForBufferToMatch(StringBuilder report, StringBuffer stringBuffer, Pattern pattern, long timeout, long sleep, TimeUnit unit) {
long timeoutMillis = unit.toMillis(timeout);
long sleepMillis = unit.toMillis(sleep);
long startMillis = System.currentTimeMillis();
Expand All @@ -909,6 +909,7 @@ public static boolean waitForBufferToMatch(StringBuffer stringBuffer, Pattern pa
// 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()) {
Logs.appendln(report, "Command took " + (System.currentTimeMillis() - startMillis) + " ms to complete");
return pattern.matcher(stringBuffer.toString()).matches();
}
try {
Expand All @@ -918,6 +919,7 @@ public static boolean waitForBufferToMatch(StringBuffer stringBuffer, Pattern pa
Thread.currentThread().interrupt();
}
}
Logs.appendln(report, "Command timed out after " + (System.currentTimeMillis() - startMillis) + " ms");
return false;
}

Expand Down
Loading