[PATCH v2 19/47] gdb, gdbserver, ze: add library notification to U stop reply

Tankut Baris Aktemur
2024-12-13T16:24:53Z

From: Markus Metzger <markus.t.metzger@intel.com>

If libraries have changed, add a ";library" notification to a 'U' stop
reply packet and handle it at the GDB side.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
---
gdb/doc/gdb.texinfo | 5 +++++
gdb/remote.c | 11 +++++++++--
gdbserver/remote-utils.cc | 22 +++++++++++++++++++---
3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 1cf31d022843b41dfdc4014125438d5455dc0bb8..365f74a5817ae82f729f5491dd3fde8ed24dbc2c 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -43909,10 +43909,15 @@ or @samp{s} action is expected to be continued. @xref{File-I/O Remote
Protocol Extension}, for more details.

@item U @var{thread-id}
+@itemx U @var{thread-id};library
The program is currently unavailable. The remote target tried to stop
it but it would not respond. The thread designator @var{thread-id}
has the format and interpretation described in @ref{thread-id syntax}.

+If @samp{;library} is appended, the loaded libraries have changed.
+@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
+list of loaded libraries.
+
This packet should not be sent by default; older @value{GDBN} versions
did not support it. @value{GDBN} requests it, by supplying an
appropriate @samp{qSupported} feature (@pxref{qSupported}). The
diff --git a/gdb/remote.c b/gdb/remote.c
index e277370ab4f1783d781c9b3a9edd4f459397839e..d55ca04fc6fce91fc01fac049959a55bd0af85f4 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -8369,8 +8369,15 @@ Packet: '%s'\n"),
event->ptid = minus_one_ptid;
break;
case 'U':
- event->ws.set_unavailable ();
- event->ptid = read_ptid (&buf[1], NULL);
+ {
+ const char *opt = nullptr;
+
+ event->ws.set_unavailable ();
+ event->ptid = read_ptid (&buf[1], &opt);
+
+ if (strcmp (opt, ";library") == 0)
+ event->ws.set_loaded ();
+ }
break;
}
}
diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index bbf72146ee8d301a9540211ef636dc0f6c223ef6..153701ceb1ecaa60702d17c62528997154887676 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1285,9 +1285,25 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
sprintf (buf, "N");
break;
case TARGET_WAITKIND_UNAVAILABLE:
- sprintf (buf, "U");
- buf += strlen (buf);
- buf = write_ptid (buf, ptid);
+ {
+ sprintf (buf, "U");
+ buf += strlen (buf);
+ buf = write_ptid (buf, ptid);
+
+ process_info *proc = find_process_pid (ptid.pid ());
+ gdb_assert (proc != nullptr);
+ if (proc->dlls_changed)
+ {
+ strcpy (buf, ";library");
+ buf += strlen (buf);
+ proc->dlls_changed = false;
+ }
+
+ /* In non-stop, don't change the general thread behind
+ GDB's back. */
+ if (!non_stop)
+ cs.general_thread = ptid;
+ }
break;
default:
error ("unhandled waitkind");