[08/12] gdbserver: Fix vAttach response when attaching is not supported

Message ID 20240419151342.1592474-9-pedro@palves.net
State New
Headers
Series Fix attach/run failure handling - gdbserver & Windows, document "E.MESSAGE" RSP errors, more |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Pedro Alves April 19, 2024, 3:13 p.m. UTC
  handle_v_attach calls attach_inferior, which says:

  "return -1 if attaching is unsupported, 0 if it succeeded, and call
  error() otherwise."

So if attach_inferior return != 0, we have the unsupported case,
meaning we should return the empty packet instead of an error.

In practice, this shouldn't trigger, as vAttach support is supposed to
be reported via qSupported.  But it doesn't hurt to be pedantic here.

Change-Id: I99cce6fa678f2370571e6bca0657451300956127
---
 gdbserver/server.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Tom Tromey April 19, 2024, 6:48 p.m. UTC | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> In practice, this shouldn't trigger, as vAttach support is supposed to
Pedro> be reported via qSupported.  But it doesn't hurt to be pedantic here.

Makes sense, thanks.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 2633df08ddb..789af36d9a4 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -3318,7 +3318,10 @@  handle_v_attach (char *own_buf)
 	    prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status);
 	}
       else
-	write_enn (own_buf);
+	{
+	  /* Not supported.  */
+	  own_buf[0] = 0;
+	}
     }
   catch (const gdb_exception_error &exception)
     {