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

[lldb-dap] Waiting for the test binary to exit prior to dumping logs. #131917

Merged
merged 2 commits into from
Mar 19, 2025

Conversation

ashgti
Copy link
Contributor

@ashgti ashgti commented Mar 18, 2025

This should ensure we have the full logs prior to dumping the logs. Additionally, printing log dumps to stderr so they are adjacent to assertion failures.

This should ensure we have the full logs prior to dumping the logs. Additionally, printing log dumps to stderr so they are interspersed with assertion failures.
@ashgti ashgti requested a review from JDevlieghere as a code owner March 18, 2025 21:13
@llvmbot llvmbot added the lldb label Mar 18, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

Changes

This should ensure we have the full logs prior to dumping the logs. Additionally, printing log dumps to stderr so they are adjacent to assertion failures.


Full diff: https://github.com/llvm/llvm-project/pull/131917.diff

1 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py (+8-4)
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
index 0fea3419d9725..a9a47e281e829 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py
@@ -88,13 +88,13 @@ def packet_type_is(packet, packet_type):
 
 
 def dump_dap_log(log_file):
-    print("========= DEBUG ADAPTER PROTOCOL LOGS =========")
+    print("========= DEBUG ADAPTER PROTOCOL LOGS =========", file=sys.stderr)
     if log_file is None:
-        print("no log file available")
+        print("no log file available", file=sys.stderr)
     else:
         with open(log_file, "r") as file:
-            print(file.read())
-    print("========= END =========")
+            print(file.read(), file=sys.stderr)
+    print("========= END =========", file=sys.stderr)
 
 
 def read_packet_thread(vs_comm, log_file):
@@ -107,6 +107,10 @@ def read_packet_thread(vs_comm, log_file):
             # termination of lldb-dap and stop waiting for new packets.
             done = not vs_comm.handle_recv_packet(packet)
     finally:
+        # Wait for the process to fully exit before dumping the log file to
+        # ensure we have the entire log contents.
+        if vs_comm.process is not None:
+            vs_comm.process.wait()
         dump_dap_log(log_file)
 
 

# Wait for the process to fully exit before dumping the log file to
# ensure we have the entire log contents.
if vs_comm.process is not None:
vs_comm.process.wait()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we provide a reasonable timeout (e.g. 5 seconds) so that if the process hangs, we still dump the logs? Maybe even send a kill?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say 20 seconds. Some build bots make every test run very slowly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with 20 (or really anything below 600, which is the individual lit timeout).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test itself usually handles this with the call to terminate in

called from:

But the read_packet_thread thread is never joined or waited on so it tends to write the DAP logs whenever it thinks its done with the connection, not when the process has exited.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so the main thread is going to send a SIGTERM asking the process to terminate gracefully. I think the timeout still makes sense (at least here) in case it doesn't, but if we wanted to send a SIGKILL, I agree we should do it where we currently call terminate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated both of the waits to have a timeout of 20s.

For the read_packet_thread, we'll just print whatever logs we find after the timeout.

For the terminate call, we upgrade to a kill().

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@ashgti ashgti merged commit 5720a79 into llvm:main Mar 19, 2025
10 checks passed
@ashgti ashgti deleted the lldb-dap-test-logs branch March 19, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants