[v2] Fix DAP Stop & Continue event bugs

Message ID 20230531141258.222599-1-simon.farre.cx@gmail.com
State New
Headers
Series [v2] Fix DAP Stop & Continue event bugs |

Commit Message

Simon Farre May 31, 2023, 2:12 p.m. UTC
  Removed type annotation as it broke gdbpy.

Fixes a bug in the stop and continue event handlers in the DAP code.

Event handlers used the `gdb.selected_thread` which may or may not be
null at the time the event handler is called. It may also return the
wrong thread. The event parameter holds the necessary data.
---
 gdb/python/lib/gdb/dap/events.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Tom Tromey May 31, 2023, 2:39 p.m. UTC | #1
>>>>> "Simon" == Simon Farre via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Removed type annotation as it broke gdbpy.
Simon> Fixes a bug in the stop and continue event handlers in the DAP code.

Simon> Event handlers used the `gdb.selected_thread` which may or may not be
Simon> null at the time the event handler is called. It may also return the
Simon> wrong thread. The event parameter holds the necessary data.

Thank you.  This is ok.

Tom
  

Patch

diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py
index d9ae603dfa4..9dc2b58ca5a 100644
--- a/gdb/python/lib/gdb/dap/events.py
+++ b/gdb/python/lib/gdb/dap/events.py
@@ -91,7 +91,7 @@  def _cont(event):
         send_event(
             "continued",
             {
-                "threadId": gdb.selected_thread().global_num,
+                "threadId": event.inferior_thread.global_num,
                 "allThreadsContinued": True,
             },
         )
@@ -139,7 +139,7 @@  def _on_stop(event):
     log("entering _on_stop: " + repr(event))
     global _expected_stop
     obj = {
-        "threadId": gdb.selected_thread().global_num,
+        "threadId": event.inferior_thread.global_num,
         "allThreadsStopped": True,
     }
     if isinstance(event, gdb.BreakpointEvent):