Re: qXfer:exec-file:read and non multiprocess target

Gary Benson
2015-05-05T11:02:20Z

Philippe Waroquiers wrote:
> I am busy adding qXfer:exec-file:read to the Valgrind gdbserver.
>
> Even if Valgrind reports it supports qXfer:exec-file, GDB does
> not query it. This is due to the fact that GDB does not query
> the exec-file when the pid is a fake pid, which is the case for
> Valgrind, as the target command to use is:
> target remote | vgdb
>
> The following change in remote.c ensures GDB queries the
> remote exec-file:
> 1561,1562c1561,1562
> < if (try_open_exec && !fake_pid_p && get_exec_file (0) == NULL)
> < exec_file_locate_attach (pid, 1);
> ---
> > if (try_open_exec && get_exec_file (0) == NULL)
> > exec_file_locate_attach (fake_pid_p ? 0 : pid, 1);
>
> With that change, GDB can use a Valgrind target without having
> to specify the exec file. The idea is that when the stub gets
> a pid 0 in this request, it replies with the exec file of the
> current process.

The PID is fake because vgdb does not support multiprocess extensions.
I don't like sending a fake/zero PID over the wire, but how about I
change qXfer:exec-file:read to send a NULL annex if the remote does
not have multiprocess extensions? Can you make your side work with
the patch inlined below? If so I'll tidy and document it and submit
it for review.

Thanks,
Gary

--
diff --git a/gdb/remote.c b/gdb/remote.c
index 099ddbb..42d990a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1558,7 +1558,7 @@

/* 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;
@@ -11710,7 +11710,7 @@
remote_pid_to_exec_file (struct target_ops *self, int pid)
{
static char *filename = NULL;
- char annex[9];
+ char *annex = NULL;

if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE)
return NULL;
@@ -11718,7 +11718,14 @@
if (filename != NULL)
xfree (filename);

- xsnprintf (annex, sizeof (annex), "%x", pid);
+ if (remote_multi_process_p (get_remote_state ()))
+ {
+ 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);