Implement remote_pid_to_exec_file using qXfer:exec-file:read

This commit adds a new packet "qXfer:exec-file:read" to the remote
protocol that can be used to obtain the pathname of the file that
was executed to create a process on the remote system.  Support for
this packet is added to GDB and remote_ops.to_pid_to_exec_file is
implemented using it.

gdb/ChangeLog:

	* target.h (TARGET_OBJECT_EXEC_FILE): New enum value.
	* remote.c (PACKET_qXfer_exec_file): Likewise.
	(remote_protocol_features): Register the
	"qXfer:exec-file:read" feature.
	(remote_xfer_partial): Handle TARGET_OBJECT_EXEC_FILE.
	(remote_pid_to_exec_file): New function.
	(init_remote_ops): Initialize to_pid_to_exec_file.
	(_initialize_remote): Register new "set/show remote
	pid-to-exec-file-packet" command.
	* NEWS: Announce new qXfer:exec-file:read packet.

gdb/doc/ChangeLog:

	* gdb.texinfo (Remote Configuration): Document the "set/show
	remote pid-to-exec-file-packet" command.
	(General Query Packets): Document the qXfer:exec-file:read
	qSupported features.  Document the qXfer:exec-file:read packet.
This commit is contained in:
Gary Benson
2015-04-17 09:47:30 +01:00
parent e0d86d2cbd
commit c78fa86a21
6 changed files with 88 additions and 1 deletions

View File

@ -1,3 +1,16 @@
2015-04-17 Gary Benson <gbenson@redhat.com>
* target.h (TARGET_OBJECT_EXEC_FILE): New enum value.
* remote.c (PACKET_qXfer_exec_file): Likewise.
(remote_protocol_features): Register the
"qXfer:exec-file:read" feature.
(remote_xfer_partial): Handle TARGET_OBJECT_EXEC_FILE.
(remote_pid_to_exec_file): New function.
(init_remote_ops): Initialize to_pid_to_exec_file.
(_initialize_remote): Register new "set/show remote
pid-to-exec-file-packet" command.
* NEWS: Announce new qXfer:exec-file:read packet.
2015-04-17 Gary Benson <gbenson@redhat.com> 2015-04-17 Gary Benson <gbenson@redhat.com>
* nat/linux-procfs.h (linux_proc_pid_to_exec_file): * nat/linux-procfs.h (linux_proc_pid_to_exec_file):

View File

@ -106,6 +106,10 @@ hwbreak stop reason
vFile:fstat: vFile:fstat:
Return information about files on the remote system. Return information about files on the remote system.
qXfer:exec-file:read
Return the full absolute name of the file that was executed to
create a process running on the remote system.
* The info record command now shows the recording format and the * The info record command now shows the recording format and the
branch tracing configuration for the current thread when using branch tracing configuration for the current thread when using
the btrace record target. the btrace record target.

View File

@ -1,3 +1,10 @@
2015-04-17 Gary Benson <gbenson@redhat.com>
* gdb.texinfo (Remote Configuration): Document the "set/show
remote pid-to-exec-file-packet" command.
(General Query Packets): Document the qXfer:exec-file:read
qSupported features. Document the qXfer:exec-file:read packet.
2015-04-17 Gary Benson <gbenson@redhat.com> 2015-04-17 Gary Benson <gbenson@redhat.com>
* gdb.texinfo (set sysroot): Document that "set sysroot" also * gdb.texinfo (set sysroot): Document that "set sysroot" also

View File

@ -19791,6 +19791,10 @@ are:
@tab @code{Z4} @tab @code{Z4}
@tab @code{awatch} @tab @code{awatch}
@item @code{pid-to-exec-file}
@tab @code{qXfer:exec-file:read}
@tab @code{attach}, @code{run}
@item @code{target-features} @item @code{target-features}
@tab @code{qXfer:features:read} @tab @code{qXfer:features:read}
@tab @code{set architecture} @tab @code{set architecture}
@ -36016,6 +36020,11 @@ These are the currently defined stub features and their properties:
@tab @samp{-} @tab @samp{-}
@tab Yes @tab Yes
@item @samp{qXfer:exec-file:read}
@tab No
@tab @samp{-}
@tab Yes
@item @samp{qXfer:features:read} @item @samp{qXfer:features:read}
@tab No @tab No
@tab @samp{-} @tab @samp{-}
@ -36219,6 +36228,10 @@ packet (@pxref{qXfer btrace read}).
The remote stub understands the @samp{qXfer:btrace-conf:read} The remote stub understands the @samp{qXfer:btrace-conf:read}
packet (@pxref{qXfer btrace-conf read}). packet (@pxref{qXfer btrace-conf read}).
@item qXfer:exec-file:read
The remote stub understands the @samp{qXfer:exec-file:read} packet
(@pxref{qXfer executable filename read}).
@item qXfer:features:read @item qXfer:features:read
The remote stub understands the @samp{qXfer:features:read} packet The remote stub understands the @samp{qXfer:features:read} packet
(@pxref{qXfer target description read}). (@pxref{qXfer target description read}).
@ -36533,6 +36546,16 @@ Return a description of the current branch trace configuration.
This packet is not probed by default; the remote stub must request it This packet is not probed by default; the remote stub must request it
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}). by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
@anchor{qXfer executable filename read}
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.
This packet is not probed by default; the remote stub must request it,
by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
@item qXfer:features:read:@var{annex}:@var{offset},@var{length} @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
@anchor{qXfer target description read} @anchor{qXfer target description read}
Access the @dfn{target description}. @xref{Target Descriptions}. The Access the @dfn{target description}. @xref{Target Descriptions}. The

View File

@ -1252,6 +1252,7 @@ enum {
PACKET_vFile_fstat, PACKET_vFile_fstat,
PACKET_qXfer_auxv, PACKET_qXfer_auxv,
PACKET_qXfer_features, PACKET_qXfer_features,
PACKET_qXfer_exec_file,
PACKET_qXfer_libraries, PACKET_qXfer_libraries,
PACKET_qXfer_libraries_svr4, PACKET_qXfer_libraries_svr4,
PACKET_qXfer_memory_map, PACKET_qXfer_memory_map,
@ -3963,6 +3964,8 @@ static const struct protocol_feature remote_protocol_features[] = {
{ "PacketSize", PACKET_DISABLE, remote_packet_size, -1 }, { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
{ "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet, { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
PACKET_qXfer_auxv }, PACKET_qXfer_auxv },
{ "qXfer:exec-file:read", PACKET_DISABLE, remote_supported_packet,
PACKET_qXfer_exec_file },
{ "qXfer:features:read", PACKET_DISABLE, remote_supported_packet, { "qXfer:features:read", PACKET_DISABLE, remote_supported_packet,
PACKET_qXfer_features }, PACKET_qXfer_features },
{ "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet, { "qXfer:libraries:read", PACKET_DISABLE, remote_supported_packet,
@ -9035,6 +9038,11 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
len, xfered_len, len, xfered_len,
&remote_protocol_packets[PACKET_qXfer_btrace_conf]); &remote_protocol_packets[PACKET_qXfer_btrace_conf]);
case TARGET_OBJECT_EXEC_FILE:
return remote_read_qxfer (ops, "exec-file", annex, readbuf, offset,
len, xfered_len,
&remote_protocol_packets[PACKET_qXfer_exec_file]);
default: default:
return TARGET_XFER_E_IO; return TARGET_XFER_E_IO;
} }
@ -11642,6 +11650,29 @@ remote_load (struct target_ops *self, const char *name, int from_tty)
generic_load (name, from_tty); generic_load (name, from_tty);
} }
/* Accepts an integer PID; returns a string representing a file that
can be opened on the remote side to get the symbols for the child
process. Returns NULL if the operation is not supported. */
static char *
remote_pid_to_exec_file (struct target_ops *self, int pid)
{
static char *filename = NULL;
char annex[9];
if (packet_support (PACKET_qXfer_exec_file) != PACKET_ENABLE)
return NULL;
if (filename != NULL)
xfree (filename);
xsnprintf (annex, sizeof (annex), "%x", pid);
filename = target_read_stralloc (&current_target,
TARGET_OBJECT_EXEC_FILE, annex);
return filename;
}
static void static void
init_remote_ops (void) init_remote_ops (void)
{ {
@ -11691,6 +11722,7 @@ Specify the serial device it is connected to\n\
remote_ops.to_stop = remote_stop; remote_ops.to_stop = remote_stop;
remote_ops.to_xfer_partial = remote_xfer_partial; remote_ops.to_xfer_partial = remote_xfer_partial;
remote_ops.to_rcmd = remote_rcmd; remote_ops.to_rcmd = remote_rcmd;
remote_ops.to_pid_to_exec_file = remote_pid_to_exec_file;
remote_ops.to_log_command = serial_log_command; remote_ops.to_log_command = serial_log_command;
remote_ops.to_get_thread_local_address = remote_get_thread_local_address; remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
remote_ops.to_stratum = process_stratum; remote_ops.to_stratum = process_stratum;
@ -12219,6 +12251,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_auxv], add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_auxv],
"qXfer:auxv:read", "read-aux-vector", 0); "qXfer:auxv:read", "read-aux-vector", 0);
add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_exec_file],
"qXfer:exec-file:read", "pid-to-exec-file", 0);
add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_features], add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_features],
"qXfer:features:read", "target-features", 0); "qXfer:features:read", "target-features", 0);

View File

@ -204,7 +204,12 @@ enum target_object
/* Branch trace data, in XML format. */ /* Branch trace data, in XML format. */
TARGET_OBJECT_BTRACE, TARGET_OBJECT_BTRACE,
/* Branch trace configuration, in XML format. */ /* Branch trace configuration, in XML format. */
TARGET_OBJECT_BTRACE_CONF TARGET_OBJECT_BTRACE_CONF,
/* The pathname of the executable file that was run to create
a specified process. ANNEX should be a string representation
of the process ID of the process in question, in hexadecimal
format. */
TARGET_OBJECT_EXEC_FILE,
/* Possible future objects: TARGET_OBJECT_FILE, ... */ /* Possible future objects: TARGET_OBJECT_FILE, ... */
}; };