From 835205d078aa3b78180da1512f8019ab064032e7 Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Tue, 12 May 2015 11:57:52 +0100 Subject: Locate executables on remote stubs without multiprocess extensions 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/remote.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'gdb/remote.c') diff --git a/gdb/remote.c b/gdb/remote.c index 3b2325f..02c8371 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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 (¤t_target, TARGET_OBJECT_EXEC_FILE, annex); -- cgit v1.1