diff options
author | Tom Tromey <tromey@adacore.com> | 2025-06-12 10:48:25 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2025-06-24 08:38:09 -0600 |
commit | 744dabeb29d6fb07f3fe7d91031adc5c85b7f865 (patch) | |
tree | 6b556869cf50921f9d1593ed72d0b55570f553ba /gdb/python | |
parent | baba7c9a2ae10eb19c8eff6f5c981268b1f3831e (diff) | |
download | gdb-744dabeb29d6fb07f3fe7d91031adc5c85b7f865.zip gdb-744dabeb29d6fb07f3fe7d91031adc5c85b7f865.tar.gz gdb-744dabeb29d6fb07f3fe7d91031adc5c85b7f865.tar.bz2 |
Allow DAP "threads" request when inferior is running
A user pointed out that DAP allows the "threads" request to work when
the inferior is running. This is documented in the overview, not the
specification.
While looking into this, I found a few other issues:
* The _thread_name function was not marked @in_gdb_thread.
This isn't very important but is still an oversight.
* DAP requires all threads to have a name -- the field is not optional
in the "Thread" type.
* There was no test examining events resulting from the inferior
printing to stdout.
This patch fixes all these problems.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33080
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/dap/threads.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/gdb/python/lib/gdb/dap/threads.py b/gdb/python/lib/gdb/dap/threads.py index c271961..89046a8 100644 --- a/gdb/python/lib/gdb/dap/threads.py +++ b/gdb/python/lib/gdb/dap/threads.py @@ -16,27 +16,32 @@ import gdb from .server import request +from .startup import in_gdb_thread +@in_gdb_thread def _thread_name(thr): if thr.name is not None: return thr.name if thr.details is not None: return thr.details - return None + # Always return a name, as the protocol doesn't allow for nameless + # threads. Use the local thread number here... it doesn't matter + # without multi-inferior but in that case it might make more + # sense. + return f"Thread #{thr.num}" -@request("threads") +@request("threads", expect_stopped=False) def threads(**args): result = [] for thr in gdb.selected_inferior().threads(): - one_result = { - "id": thr.global_num, - } - name = _thread_name(thr) - if name is not None: - one_result["name"] = name - result.append(one_result) + result.append( + { + "id": thr.global_num, + "name": _thread_name(thr), + } + ) return { "threads": result, } |