Skip to content

Commit 5720a79

Browse files
authored
[lldb-dap] Waiting for the test binary to exit prior to dumping logs. (llvm#131917)
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.
1 parent 2c41a8e commit 5720a79

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def packet_type_is(packet, packet_type):
8888

8989

9090
def dump_dap_log(log_file):
91-
print("========= DEBUG ADAPTER PROTOCOL LOGS =========")
91+
print("========= DEBUG ADAPTER PROTOCOL LOGS =========", file=sys.stderr)
9292
if log_file is None:
93-
print("no log file available")
93+
print("no log file available", file=sys.stderr)
9494
else:
9595
with open(log_file, "r") as file:
96-
print(file.read())
97-
print("========= END =========")
96+
print(file.read(), file=sys.stderr)
97+
print("========= END =========", file=sys.stderr)
9898

9999

100100
def read_packet_thread(vs_comm, log_file):
@@ -107,6 +107,14 @@ def read_packet_thread(vs_comm, log_file):
107107
# termination of lldb-dap and stop waiting for new packets.
108108
done = not vs_comm.handle_recv_packet(packet)
109109
finally:
110+
# Wait for the process to fully exit before dumping the log file to
111+
# ensure we have the entire log contents.
112+
if vs_comm.process is not None:
113+
try:
114+
# Do not wait forever, some logs are better than none.
115+
vs_comm.process.wait(timeout=20)
116+
except subprocess.TimeoutExpired:
117+
pass
110118
dump_dap_log(log_file)
111119

112120

@@ -1274,7 +1282,11 @@ def terminate(self):
12741282
super(DebugAdapterServer, self).terminate()
12751283
if self.process is not None:
12761284
self.process.terminate()
1277-
self.process.wait()
1285+
try:
1286+
self.process.wait(timeout=20)
1287+
except subprocess.TimeoutExpired:
1288+
self.process.kill()
1289+
self.process.wait()
12781290
self.process = None
12791291

12801292

0 commit comments

Comments
 (0)