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

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