Blame SOURCES/gdb-rhbz1186918-gdbserver-in-container-3of8.patch

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