public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2]     remote.c: Allow inferior to reply with an error
@ 2023-01-13 11:59 
  2023-01-13 13:16 ` Eli Zaretskii
  2023-01-17 16:30 ` Andrew Burgess
  0 siblings, 2 replies; 7+ messages in thread
From:  @ 2023-01-13 11:59 UTC (permalink / raw)
  To: gdb-patches

From: Alexandra Hájková <ahajkova@redhat.com>

    When gdb communicates with some kind of gdbserver or gdbserver
    stub over the remote protocol, the only possible response to
    the QSetWorkingDir packet is "OK".  If the remote will reply
    with anything else, gdb will complain about the unexpected reply.

    [remote] Sending packet: $QSetWorkingDir:2f746d70#bb
    [remote] Packet received: E00
    Remote replied unexpectedly while setting the inferior's working
    directory: E00
    (gdb)

    Allow remote to send an error message over as a QSetWorkingDir
    packet reply.

    [remote] Sending packet: $QSetWorkingDir:2f746d70#bb
    [remote] Packet received: E.directory does not exist
    Remote failed to set working directory: directory does not exist.

---
V2 does not change the behaviour of gdb in a case it wasn't possible to
set the inferior's working directory. It just allows to pass the error
message to gdb.

 gdb/doc/gdb.texinfo |  3 +++
 gdb/remote.c        | 12 +++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 9c0018ea5c1..5df9a5a9178 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -42517,6 +42517,9 @@ Reply:
 @table @samp
 @item OK
 The request succeeded.
+
+@item E.errtext
+An error occurred.  Reply with an error message.
 @end table
 
 @item qfThreadInfo
diff --git a/gdb/remote.c b/gdb/remote.c
index 218bca30d04..ea89759e85a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -10397,8 +10397,10 @@ remote_target::extended_remote_set_inferior_cwd ()
   if (packet_support (PACKET_QSetWorkingDir) != PACKET_DISABLE)
     {
       const std::string &inferior_cwd = current_inferior ()->cwd ();
+      char *buf;
       remote_state *rs = get_remote_state ();
 
+      buf = rs->buf.data ();
       if (!inferior_cwd.empty ())
 	{
 	  std::string hexpath
@@ -10420,11 +10422,15 @@ remote_target::extended_remote_set_inferior_cwd ()
       getpkt (&rs->buf, 0);
       if (packet_ok (rs->buf,
 		     &remote_protocol_packets[PACKET_QSetWorkingDir])
-	  != PACKET_OK)
-	error (_("\
+	  != PACKET_OK) {
+          if (buf[0] == 'E' && buf[1] == '.')
+	    error (_("Remote failed to set working directory: %s"), buf + 2);
+          else
+              error (_("\
 Remote replied unexpectedly while setting the inferior's working\n\
-directory: %s"),
+directory: %s."),
 	       rs->buf.data ());
+      }
 
     }
 }
-- 
2.39.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-18 18:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 11:59 [PATCH v2] remote.c: Allow inferior to reply with an error 
2023-01-13 13:16 ` Eli Zaretskii
2023-01-17 16:30 ` Andrew Burgess
2023-01-18  9:48   ` Mark Wielaard
2023-01-18 18:10     ` Andrew Burgess
2023-01-18 13:37   ` Alexandra Petlanova Hajkova
2023-01-18 18:19     ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).