This is the mail archive of the
mailing list for the GDB project.
[PATCH 2/2] Use exec_file_find to locate executable on attach (sometimes)
- From: Gary Benson <gbenson at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 5 Mar 2015 11:37:41 +0000
- Subject: [PATCH 2/2] Use exec_file_find to locate executable on attach (sometimes)
- Authentication-results: sourceware.org; auth=none
- References: <1425555461-22093-1-git-send-email-gbenson at redhat dot com>
This commit updates attach_command_post_wait to use exec_file_find
to compute the full pathname of the main executable if the pathname
returned by target_pid_to_exec_file is absolute and if gdb_sysroot
is non-empty and not remote. The net effect of this is to prefix
the main executable's path with gdb_sysroot if gdb_sysroot is set;
this is useful for attaching to processes running in chroot jails
or containerized environments. This logic is skipped for remote
gdb_sysroots because the subsequent code does not support opening
the main executable remotely.
* infcmd.c (filenames.h): New include.
(attach_command_post_wait): Prefix absolute executable
paths with gdb_sysroot if set and not remote.
gdb/ChangeLog | 8 ++++++++
gdb/infcmd.c | 37 +++++++++++++++++++++++++++++--------
2 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 3737b8f..23c7a6c 100644
@@ -54,6 +54,9 @@
/* Local functions: */
@@ -2493,16 +2496,34 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
exec_file = target_pid_to_exec_file (ptid_get_pid (inferior_ptid));
- /* It's possible we don't have a full path, but rather just a
- filename. Some targets, such as HP-UX, don't provide the
- full path, sigh.
+ /* If there is a gdb_sysroot and exec_file is absolute we
+ prepend gdb_sysroot to exec_file. This is currently
+ disabled for remote sysroot as the subsequent code cannot
+ yet cope with these. */
+ if (IS_ABSOLUTE_PATH (exec_file)
+ && gdb_sysroot != NULL && *gdb_sysroot != '\0'
+ && !remote_filename_p (gdb_sysroot))
+ int fd = -1;
+ full_exec_path = exec_file_find (exec_file, &fd);
+ if (fd >= 0)
+ close (fd);
- Attempt to qualify the filename against the source path.
- (If that fails, we'll just fall back on the original
- filename. Not much more we can do...) */
+ if (full_exec_path == NULL)
+ /* It's possible we don't have a full path, but rather
+ just a filename. Some targets, such as HP-UX, don't
+ provide the full path, sigh.
+ Attempt to qualify the filename against the source
+ path. (If that fails, we'll just fall back on the
+ original filename. Not much more we can do...) */
- if (!source_full_path_of (exec_file, &full_exec_path))
- full_exec_path = xstrdup (exec_file);
+ if (!source_full_path_of (exec_file, &full_exec_path))
+ full_exec_path = xstrdup (exec_file);
exec_file_attach (full_exec_path, from_tty);
symbol_file_add_main (full_exec_path, from_tty);