[5/5] Explicitly quit gdb from DAP server thread

Message ID 20240223-final-cleanups-v1-5-84d5271e9979@adacore.com
State New
Headers
Series Restore DAP 'quit' request |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Tom Tromey Feb. 23, 2024, 9:11 p.m. UTC
  This changes the DAP code to explicitly request that gdb exit.
Previously this could cause crashes, but with the previous cleanups,
this should no longer happen.

This also adds a tests that ensures that gdb exits with status 0.
---
 gdb/python/lib/gdb/dap/server.py  | 1 +
 gdb/testsuite/lib/dap-support.exp | 9 +++++++++
 2 files changed, 10 insertions(+)
  

Patch

diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index 6757f2921bf..19840f4028d 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -230,6 +230,7 @@  class Server:
         # responses are flushed to the client before exiting.
         self.write_queue.put(None)
         json_writer.join()
+        send_gdb("quit")
 
     @in_dap_thread
     def send_event_later(self, event, body=None):
diff --git a/gdb/testsuite/lib/dap-support.exp b/gdb/testsuite/lib/dap-support.exp
index 72c22d00711..54795a34e39 100644
--- a/gdb/testsuite/lib/dap-support.exp
+++ b/gdb/testsuite/lib/dap-support.exp
@@ -400,6 +400,15 @@  proc dap_check_log_file_re { re } {
 proc dap_shutdown {{terminate false}} {
     dap_check_request_and_response "shutdown" disconnect \
 	[format {o terminateDebuggee [l %s]} $terminate]
+
+    # Check gdb's exit status.
+    global gdb_spawn_id
+    set result [wait -i $gdb_spawn_id]
+    gdb_assert {[lindex $result 2] == 0}
+    gdb_assert {[lindex $result 3] == 0}
+
+    clear_gdb_spawn_id
+
     dap_check_log_file
 }