Add thread exited event
authorSimon Farre <simon.farre.cx@gmail.com>
Mon, 5 Jun 2023 12:56:54 +0000 (14:56 +0200)
committerSimon Farre <simon.farre.cx@gmail.com>
Tue, 1 Aug 2023 16:14:59 +0000 (18:14 +0200)
Reports a thread exit according to the DAP spec:
https://microsoft.github.io/debug-adapter-protocol/specification#Events_Thread

This patch requires the ThreadExitedEvent to be checked in,
in order to work. That patch is found here https://sourceware.org/pipermail/gdb-patches/2023-June/200071.html

Formatted correctly using black

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30474

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/lib/gdb/dap/events.py

index c16314427462de08f640b28ed40e3798c53697aa..ab36dc559b2382cc49bcc90143fa83f9a5024708 100644 (file)
@@ -58,23 +58,33 @@ def _bp_created(event):
 
 
 @in_gdb_thread
-def _bp_deleted(event):
+def thread_event(event, reason):
     send_event(
-        "breakpoint",
+        "thread",
         {
-            "reason": "removed",
-            "breakpoint": breakpoint_descriptor(event),
+            "reason": reason,
+            "threadId": event.inferior_thread.global_num,
         },
     )
 
 
 @in_gdb_thread
 def _new_thread(event):
+    thread_event(event, "started")
+
+
+@in_gdb_thread
+def _thread_exited(event):
+    thread_event(event, "exited")
+
+
+@in_gdb_thread
+def _bp_deleted(event):
     send_event(
-        "thread",
+        "breakpoint",
         {
-            "reason": "started",
-            "threadId": event.inferior_thread.global_num,
+            "reason": "removed",
+            "breakpoint": breakpoint_descriptor(event),
         },
     )
 
@@ -173,5 +183,6 @@ gdb.events.breakpoint_created.connect(_bp_created)
 gdb.events.breakpoint_modified.connect(_bp_modified)
 gdb.events.breakpoint_deleted.connect(_bp_deleted)
 gdb.events.new_thread.connect(_new_thread)
+gdb.events.thread_exited.connect(_thread_exited)
 gdb.events.cont.connect(_cont)
 gdb.events.new_objfile.connect(_new_objfile)