You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.2 KiB

Locate executables on remote stubs without multiprocess extensions
From: Gary Benson <gbenson@redhat.com>
This commit allows GDB to determine filenames of main executables
when debugging using remote stubs without multiprocess extensions.
The qXfer:exec-file:read packet is extended to allow an empty
annex, with the meaning that the remote stub should supply the
filename of whatever it thinks is the current process.
gdb/ChangeLog:
* remote.c (remote_add_inferior): Call exec_file_locate_attach
for fake PIDs as well as real ones.
(remote_pid_to_exec_file): Send empty annex if PID is fake.
gdb/doc/ChangeLog:
* gdb.texinfo (General Query Packets): Document
qXfer:exec-file:read with empty annex.
gdb/gdbserver/ChangeLog:
* server.c (handle_qxfer_exec_file): Use current process
if annex is empty.
---
gdb/gdbserver/server.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 78cf155..c1719da 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -29,6 +29,7 @@
#endif
#include "gdb_wait.h"
#include "btrace-common.h"
+#include "linux-low.h"
/* The thread set with an `Hc' packet. `Hc' is deprecated in favor of
`vCont'. Note the multi-process extensions made `vCont' a
@@ -1012,17 +1013,32 @@ handle_qxfer_exec_file (const char *const_annex,
gdb_byte *readbuf, const gdb_byte *writebuf,
ULONGEST offset, LONGEST len)
{
- char *annex, *file;
+ char *file;
ULONGEST pid;
int total_len;
if (the_target->pid_to_exec_file == NULL || writebuf != NULL)
return -2;
- annex = alloca (strlen (const_annex) + 1);
- strcpy (annex, const_annex);
- annex = unpack_varlen_hex (annex, &pid);
- if (annex[0] != '\0' || pid == 0)
+ if (const_annex[0] == '\0')
+ {
+ if (current_inferior == NULL)
+ return -1;
+
+ pid = ptid_get_pid (current_inferior->entry.id);
+ }
+ else
+ {
+ char *annex = alloca (strlen (const_annex) + 1);
+
+ strcpy (annex, const_annex);
+ annex = unpack_varlen_hex (annex, &pid);
+
+ if (annex[0] != '\0')
+ return -1;
+ }
+
+ if (pid <= 0)
return -1;
file = (*the_target->pid_to_exec_file) (pid);