]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Locate executables on remote stubs without multiprocess extensions
authorGary Benson <gbenson@redhat.com>
Tue, 12 May 2015 10:57:52 +0000 (11:57 +0100)
committerGary Benson <gbenson@redhat.com>
Tue, 12 May 2015 10:57:52 +0000 (11:57 +0100)
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/ChangeLog
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/gdbserver/ChangeLog
gdb/gdbserver/server.c
gdb/remote.c

index b58f04ab5e4c9e9e73b84158972ac6600af8af80..7f4b45724db3bd005d0079f9842f2671348ff8ed 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-12  Gary Benson <gbenson@redhat.com>
+
+       * 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.
+
 2015-05-09  Siva Chandra Reddy  <sivachandra@google.com>
 
        * NEWS (Python Scripting): Mention the new gdb.Value methods.
index 727d0ad05ed83d176e8479f8be4de0e43c5d2496..05aeab788c21bf30f2cb9905308a0f3208826160 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-12  Gary Benson <gbenson@redhat.com>
+
+       * gdb.texinfo (General Query Packets): Document
+       qXfer:exec-file:read with empty annex.
+
 2015-05-09  Siva Chandra Reddy  <sivachandra@google.com>
 
        * python.texi (Values From Inferior): Add descriptions of new
index 19d8bb3893aedf6b48283aaafa20d2684d0b793b..5461356bd8f2003857e7fc8f1f21c8c99e5a5dda 100644 (file)
@@ -36558,7 +36558,8 @@ by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
 Return the full absolute name of the file that was executed to create
 a process running on the remote system.  The annex specifies the
 numeric process ID of the process to query, encoded as a hexadecimal
-number.
+number.  If the annex part is empty the remote stub should return the
+filename corresponding to the currently executing process.
 
 This packet is not probed by default; the remote stub must request it,
 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
index c33f90a10c3ec14ab6673c0931c0c51a1ac9f8b6..94146b8f48b4a20a6528551dba8ad5957d08cb19 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-12  Gary Benson <gbenson@redhat.com>
+
+       * server.c (handle_qxfer_exec_file): Use current process
+       if annex is empty.
+
 2015-05-08  Sandra Loosemore  <sandra@codesourcery.com>
 
        * linux-nios2-low.c: Include elf/common.h.  Adjust comments.
index 3f9bb8938d6131c5f5724e2164853f393dafe190..174ab398b0b4c15f283ca56c77b1e7311adc88fe 100644 (file)
@@ -1146,17 +1146,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_thread == NULL)
+       return -1;
+
+      pid = pid_of (current_thread);
+    }
+  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);
index 3b2325f86155e12809f434c494c545e6c9a00055..02c83711b6fde1625384e612f72e9b69d5dfdc7d 100644 (file)
@@ -1558,7 +1558,7 @@ remote_add_inferior (int fake_pid_p, int pid, int attached,
 
   /* If no main executable is currently open then attempt to
      open the file that was executed to create this inferior.  */
-  if (try_open_exec && !fake_pid_p && get_exec_file (0) == NULL)
+  if (try_open_exec && get_exec_file (0) == NULL)
     exec_file_locate_attach (pid, 1);
 
   return inf;
@@ -11666,7 +11666,8 @@ static char *
 remote_pid_to_exec_file (struct target_ops *self, int pid)
 {
   static char *filename = NULL;
-  char annex[9];
+  struct inferior *inf;
+  char *annex = NULL;
 
   if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE)
     return NULL;
@@ -11674,7 +11675,19 @@ remote_pid_to_exec_file (struct target_ops *self, int pid)
   if (filename != NULL)
     xfree (filename);
 
-  xsnprintf (annex, sizeof (annex), "%x", pid);
+  inf = find_inferior_pid (pid);
+  if (inf == NULL)
+    internal_error (__FILE__, __LINE__,
+                   _("not currently attached to process %d"), pid);
+
+  if (!inf->fake_pid_p)
+    {
+      const int annex_size = 9;
+
+      annex = alloca (annex_size);
+      xsnprintf (annex, annex_size, "%x", pid);
+    }
+
   filename = target_read_stralloc (&current_target,
                                   TARGET_OBJECT_EXEC_FILE, annex);