diff options
author | Pedro Alves <pedro@palves.net> | 2021-11-23 20:35:12 +0000 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2023-11-13 14:16:09 +0000 |
commit | 65c459abebf70bd5a64dcee11d4d7d4a8498465f (patch) | |
tree | 7079c882404567cd9a235a4c52280548837cfb81 /gdb/target | |
parent | 26f047ce788b42b7b5f96515d119138a8ae43979 (diff) | |
download | binutils-65c459abebf70bd5a64dcee11d4d7d4a8498465f.zip binutils-65c459abebf70bd5a64dcee11d4d7d4a8498465f.tar.gz binutils-65c459abebf70bd5a64dcee11d4d7d4a8498465f.tar.bz2 |
Thread options & clone events (core + remote)
A previous patch taught GDB about a new TARGET_WAITKIND_THREAD_CLONED
event kind, and made the Linux target report clone events.
A following patch will teach Linux GDBserver to do the same thing.
However, for remote debugging, it wouldn't be ideal for GDBserver to
report every clone event to GDB, when GDB only cares about such events
in some specific situations. Reporting clone events all the time
would be potentially chatty. We don't enable thread create/exit
events all the time for the same reason. Instead we have the
QThreadEvents packet. QThreadEvents is target-wide, though.
This patch makes GDB instead explicitly request that the target
reports clone events or not, on a per-thread basis.
In order to be able to do that with GDBserver, we need a new remote
protocol feature. Since a following patch will want to enable thread
exit events on per-thread basis too, the packet introduced here is
more generic than just for clone events. It lets you enable/disable a
set of options at once, modelled on Linux ptrace's PTRACE_SETOPTIONS.
IOW, this commit introduces a new QThreadOptions packet, that lets you
specify a set of per-thread event options you want to enable. The
packet accepts a list of options/thread-id pairs, similarly to vCont,
processed left to right, with the options field being a number
interpreted as a bit mask of options. The only option defined in this
commit is GDB_THREAD_OPTION_CLONE (0x1), which ask the remote target
to report clone events. Another patch later in the series will
introduce another option.
For example, this packet sets option "1" (clone events) on thread
p1000.2345:
QThreadOptions;1:p1000.2345
and this clears options for all threads of process 1000, and then sets
option "1" (clone events) on thread p1000.2345:
QThreadOptions;0:p1000.-1;1:p1000.2345
This clears options of all threads of all processes:
QThreadOptions;0
The target reports the set of supported options by including
"QThreadOptions=<supported options>" in its qSupported response.
infrun is then tweaked to enable GDB_THREAD_OPTION_CLONE when stepping
over a breakpoint.
Unlike PTRACE_SETOPTIONS, fork/vfork/clone children do NOT inherit
their parent's thread options. This is so that GDB can send e.g.,
"QThreadOptions;0;1:TID" without worrying about threads it doesn't
know about yet.
Documentation for this new remote protocol feature is included in a
documentation patch later in the series.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19675
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=27830
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Change-Id: Ie41e5093b2573f14cf6ac41b0b5804eba75be37e
Diffstat (limited to 'gdb/target')
-rw-r--r-- | gdb/target/target.c | 11 | ||||
-rw-r--r-- | gdb/target/target.h | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/gdb/target/target.c b/gdb/target/target.c index 8089918..3af7d73 100644 --- a/gdb/target/target.c +++ b/gdb/target/target.c @@ -188,3 +188,14 @@ target_read_string (CORE_ADDR memaddr, int len, int *bytes_read) return gdb::unique_xmalloc_ptr<char> ((char *) buffer.release ()); } + +/* See target/target.h. */ + +std::string +to_string (gdb_thread_options options) +{ + static constexpr gdb_thread_options::string_mapping mapping[] = { + MAP_ENUM_FLAG (GDB_THREAD_OPTION_CLONE), + }; + return options.to_string (mapping); +} diff --git a/gdb/target/target.h b/gdb/target/target.h index d1a18ee..2691f92 100644 --- a/gdb/target/target.h +++ b/gdb/target/target.h @@ -22,9 +22,25 @@ #include "target/waitstatus.h" #include "target/wait.h" +#include "gdbsupport/enum-flags.h" /* This header is a stopgap until more code is shared. */ +/* Available thread options. Keep this in sync with to_string, in + target.c. */ + +enum gdb_thread_option : unsigned +{ + /* Tell the target to report TARGET_WAITKIND_THREAD_CLONED events + for the thread. */ + GDB_THREAD_OPTION_CLONE = 1 << 0, +}; + +DEF_ENUM_FLAGS_TYPE (enum gdb_thread_option, gdb_thread_options); + +/* Convert gdb_thread_option to a string. */ +extern std::string to_string (gdb_thread_options options); + /* Read LEN bytes of target memory at address MEMADDR, placing the results in GDB's memory at MYADDR. Return zero for success, nonzero if any error occurs. This function must be provided by |