Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mohamed Bouhaouel <mohamed.bouhaouel@intel.com>
To: gdb-patches@sourceware.org
Cc: stephan.rohr@intel.com, markus.t.metzger@intel.com,
	pedro@palves.net, aburgess@redhat.com
Subject: [PATCH v3 07/11] gdb, dap: fix DAP events if no thread is selected
Date: Mon,  6 Jul 2026 14:11:20 +0200	[thread overview]
Message-ID: <20260706121124.18784-8-mohamed.bouhaouel@intel.com> (raw)
In-Reply-To: <20260706121124.18784-1-mohamed.bouhaouel@intel.com>

From: "Rohr, Stephan" <stephan.rohr@intel.com>

The DAP protocol requires a thread-id for a continue event.  It is
optional for the stopped event.  If we force the remote target to run in
non-stop mode, i.e., "-iex maint set target-non-stop on", GDB does not
have a thread selected.  Default to '0' for continue events in this
case.  Omit the 'threadID' for stopped events if no thread is selected.

Reproducible when running gdb.dap/remote-dap.exp on unix with
target-non-stop enabled.

export GDBFLAGS="-iex \"maint set target-non-stop on\""
make check TESTS="gdb.dap/remote-dap.exp" \
    RUNTESTFLAGS="--target_board=unix GDBFLAGS='$GDBFLAGS'"
---
 gdb/python/lib/gdb/dap/events.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py
index 27e3b5ab8bc..85e672b4c9e 100644
--- a/gdb/python/lib/gdb/dap/events.py
+++ b/gdb/python/lib/gdb/dap/events.py
@@ -138,10 +138,14 @@ def _cont(event):
         log("_suppress_cont case")
         _suppress_cont = False
     else:
+        thread = gdb.selected_thread()
+
+        # We may not have a selected thread if the target is running in
+        # non-stop mode.  Default to '0' in this case.
         send_event(
             "continued",
             {
-                "threadId": gdb.selected_thread().global_num,
+                "threadId": thread.global_num if thread else 0,
                 "allThreadsContinued": True,
             },
         )
@@ -213,9 +217,11 @@ def _on_stop(event):
     if hasattr(event, "details"):
         log("   details: " + repr(event.details))
     obj = {
-        "threadId": gdb.selected_thread().global_num,
         "allThreadsStopped": True,
     }
+    # The thread-id parameter is optional for stopped events.
+    if gdb.selected_thread():
+        obj["threadId"] = gdb.selected_thread().global_num
     if isinstance(event, gdb.BreakpointEvent):
         obj["hitBreakpointIds"] = [x.number for x in event.breakpoints]
     if hasattr(event, "details") and "finish-value" in event.details:
@@ -266,11 +272,14 @@ def _on_inferior_call(event):
         if not _infcall_was_running and inferior_running:
             inferior_running = False
             obj = {
-                "threadId": gdb.selected_thread().global_num,
                 "allThreadsStopped": True,
                 # DAP says any string is ok.
                 "reason": "function call",
             }
+            # The thread-id parameter is optional for stopped events.
+            if gdb.selected_thread():
+                obj["threadId"] = gdb.selected_thread().global_num
+
             global _expected_pause
             _expected_pause = False
             send_event("stopped", obj)
-- 
2.43.0

Intel Deutschland GmbH

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2026-07-06 12:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 12:11 [PATCH v3 00/11] Add AlwaysNonStop remote protocol extension Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 01/11] gdb, record: fix assertion when remote target is set to non-stop Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 02/11] gdb, remote: fix assertion on reconnect to non-stop target Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 03/11] gdb, remote: fix async handler " Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 04/11] gdb, remote: fix "info program" after " Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 05/11] gdb, remote: fix crash when accessing removed events Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 06/11] gdb, remote: fix ptid matching for process-wide stop events Mohamed Bouhaouel
2026-07-06 12:11 ` Mohamed Bouhaouel [this message]
2026-07-06 12:11 ` [PATCH v3 08/11] gdb, testsuite: handle async close in monitor-exit-quit.exp Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 09/11] gdb, testsuite: update attach-deleted-exec.exp to handle async messages Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 10/11] gdb, testsuite: add kfails for step-over-process-exit.exp Mohamed Bouhaouel
2026-07-06 12:11 ` [PATCH v3 11/11] gdb, gdbserver: add AlwaysNonStop remote protocol extension Mohamed Bouhaouel
2026-07-06 12:41   ` Eli Zaretskii
2026-07-14  9:28     ` Bouhaouel, Mohamed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260706121124.18784-8-mohamed.bouhaouel@intel.com \
    --to=mohamed.bouhaouel@intel.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=markus.t.metzger@intel.com \
    --cc=pedro@palves.net \
    --cc=stephan.rohr@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox