diff options
author | Pedro Alves <pedro@palves.net> | 2024-04-17 19:26:32 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2024-04-26 21:22:47 +0100 |
commit | f1fc8dc2dccb4a224cdd1c3973c7a09a752aa95b (patch) | |
tree | 5be0cbe6b8ae44b06b82dfbefa7e729a66ddf943 /gdbserver | |
parent | 33befefc3d6bf643af9b521e85feaeff0b06ee7b (diff) | |
download | binutils-f1fc8dc2dccb4a224cdd1c3973c7a09a752aa95b.zip binutils-f1fc8dc2dccb4a224cdd1c3973c7a09a752aa95b.tar.gz binutils-f1fc8dc2dccb4a224cdd1c3973c7a09a752aa95b.tar.bz2 |
Fix "attach" failure handling with GDBserver
This fixes the same issue as the previous patch, but for "attach"
instead of "run".
If attaching to a process with "attach" (vAttach packet) fails,
GDBserver throws an error that escapes all the way to the top level.
When an error escapes all the way like that, GDBserver interprets it
as a disconnection, and either goes back to waiting for a new GDB
connection, or exits, if --once was specified.
Here's an example:
On the GDB side:
...
(gdb) tar extended-remote :9999
...
Remote debugging using :9999
(gdb) attach 1
Attaching to process 1
Attaching to process 1 failed
(gdb)
On the GDBserver side:
$ gdbserver --once --multi :9999
Listening on port 9999
Remote debugging from host 127.0.0.1, port 37464
gdbserver: Cannot attach to process 1: Operation not permitted (1)
$ # gdbserver exited
This is wrong, as we've connected with extended-remote/--multi.
GDBserver should just report an error to vAttach, and continue
connected to GDB, waiting for other commands.
This commit fixes GDBserver by catching the error locally in
handle_v_attach.
Note we now let pid == 0 pass down to attach_inferior. That is so we
get a useful textual error message to report to GDB.
This fixes a couple KFAILs in gdb.base/attach.exp. Still, I thought
it would be useful to add a new testcase specifically for this
scenario, in case gdb.base/attach.exp is ever split and stops trying
to attach again after a failed attach, with the same GDB session.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19558
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31554
Change-Id: I25314c7e5f1435eff69cb84d57ecac13d8de3393
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdbserver')
-rw-r--r-- | gdbserver/server.cc | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/gdbserver/server.cc b/gdbserver/server.cc index b170da4..2633df0 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3294,29 +3294,36 @@ static void handle_v_attach (char *own_buf) { client_state &cs = get_client_state (); - int pid; - pid = strtol (own_buf + 8, NULL, 16); - if (pid != 0 && attach_inferior (pid) == 0) - { - /* Don't report shared library events after attaching, even if - some libraries are preloaded. GDB will always poll the - library list. Avoids the "stopped by shared library event" - notice on the GDB side. */ - current_process ()->dlls_changed = false; + int pid = strtol (own_buf + 8, NULL, 16); - if (non_stop) + try + { + if (attach_inferior (pid) == 0) { - /* In non-stop, we don't send a resume reply. Stop events - will follow up using the normal notification - mechanism. */ - write_ok (own_buf); + /* Don't report shared library events after attaching, even if + some libraries are preloaded. GDB will always poll the + library list. Avoids the "stopped by shared library event" + notice on the GDB side. */ + current_process ()->dlls_changed = false; + + if (non_stop) + { + /* In non-stop, we don't send a resume reply. Stop events + will follow up using the normal notification + mechanism. */ + write_ok (own_buf); + } + else + prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status); } else - prepare_resume_reply (own_buf, cs.last_ptid, cs.last_status); + write_enn (own_buf); + } + catch (const gdb_exception_error &exception) + { + sprintf (own_buf, "E.%s", exception.what ()); } - else - write_enn (own_buf); } /* Decode an argument from the vRun packet buffer. PTR points to the |