From patchwork Tue Jul 28 15:36:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 7895 Received: (qmail 104073 invoked by alias); 28 Jul 2015 15:36:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 103841 invoked by uid 89); 28 Jul 2015 15:36:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 28 Jul 2015 15:36:18 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 986CD91DC1; Tue, 28 Jul 2015 15:36:16 +0000 (UTC) Received: from blade.nx (ovpn-116-19.ams2.redhat.com [10.36.116.19]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6SFaFTK031253; Tue, 28 Jul 2015 11:36:15 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 25A5A264F12; Tue, 28 Jul 2015 16:36:15 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves , Sandra Loosemore , Paul_Koning@Dell.com, Jan Kratochvil , Joel Brobecker Subject: [PATCH 4/5] Use TARGET_FILENAME_PREFIX as the system root in some cases Date: Tue, 28 Jul 2015 16:36:11 +0100 Message-Id: <1438097772-31480-5-git-send-email-gbenson@redhat.com> In-Reply-To: <1438097772-31480-1-git-send-email-gbenson@redhat.com> References: <1438097772-31480-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes This commit updates solib_find_1 to use TARGET_FILENAME_PREFIX as the system root if auto-target-prefix is enabled and gdb_sysroot is empty and the target filesystem is not the local filesystem. gdb/ChangeLog: * solib.c (auto_target_prefix): New static variable. (solib_find_1): Use TARGET_FILENAME_PREFIX as sysroot in some cases. (show_auto_target_prefix): New function. (_initialize_solib): New "set/show auto-target-prefix" commands. * NEWS: Mention that GDB will use "target:" as the system root in some cases. Mention new "set/show auto-target-prefix" commands. gdb/doc/ChangeLog: * gdb.texinfo (Commands to Specify Files): Document the "set/show auto-target-prefix" commands. --- gdb/ChangeLog | 12 ++++++++++ gdb/NEWS | 8 +++++- gdb/doc/ChangeLog | 5 ++++ gdb/doc/gdb.texinfo | 11 +++++++++ gdb/solib.c | 62 +++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 88 insertions(+), 10 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 7ecdf93..3e22b82 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -40,7 +40,9 @@ prefixed with "target:" to tell GDB to access shared libraries from the target system, be it local or remote. This replaces the prefix "remote:", which is automatically converted to "target:" for - backward compatibility. + backward compatibility. If the system root is unset, GDB will use + "target:" as the system root where necessary if auto-target-prefix + is enabled. See "New commands" below. * The system root specified by "set sysroot" will be prepended to the filename of the main executable (if reported to GDB as absolute by @@ -193,6 +195,10 @@ maint set|show btrace pt skip-pad Set and show whether PAD packets are skipped when computing the packet history. +set auto-target-prefix +show auto-target-prefix + Control automatic prefixing of binary filenames with "target:". + * The command 'thread apply all' can now support new option '-ascending' to call its specified command for all threads in ascending order. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 9e2ecd1..9ac6e2f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18091,6 +18091,17 @@ location. @item show sysroot Display the current executable and shared library prefix. +@kindex set auto-target-prefix +@item set solib-search-path @var{mode} +If @var{mode} is @code{on}, and the system root is empty, @value{GDBN} +will use @file{target:} as the system root if that is necessary for +@value{GDBN} to be able to access the target binaries. + +@kindex show auto-target-prefix +@item show auto-solib-add +Display the current target-prefixing mode. +@end table + @kindex set solib-search-path @item set solib-search-path @var{path} If this variable is set, @var{path} is a colon-separated list of diff --git a/gdb/solib.c b/gdb/solib.c index 32931da..4fdfba0 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -105,6 +105,11 @@ show_solib_search_path (struct ui_file *file, int from_tty, value); } +/* If nonzero, prefix executable and shared library filenames with + TARGET_FILENAME_PREFIX when attaching to processes whose filesystem + is not the local filesystem. */ +static int auto_target_prefix = 1; + /* Same as HAVE_DOS_BASED_FILE_SYSTEM, but useable as an rvalue. */ #if (HAVE_DOS_BASED_FILE_SYSTEM) # define DOS_BASED_FILE_SYSTEM 1 @@ -124,7 +129,10 @@ show_solib_search_path (struct ui_file *file, int from_tty, is the local filesystem then the "target:" prefix will be stripped before the search starts. This ensures that the same search algorithm is used for local files regardless of - whether a "target:" prefix was used. + whether a "target:" prefix was used. If the target filesystem + is not the local filesystem then "target:" will be used as the + prefix directory for binary files if GDB_SYSROOT is empty and + AUTO_TARGET_PREFIX is nonzero. Global variable SOLIB_SEARCH_PATH is used as a prefix directory (or set of directories, as in LD_LIBRARY_PATH) to search for all @@ -160,14 +168,30 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib) char *sysroot = gdb_sysroot; int prefix_len, orig_prefix_len; - /* If the absolute prefix starts with "target:" but the filesystem - accessed by the target_fileio_* methods is the local filesystem - then we strip the "target:" prefix now and work with the local - filesystem. This ensures that the same search algorithm is used - for all local files regardless of whether a "target:" prefix was - used. */ - if (is_target_filename (sysroot) && target_filesystem_is_local ()) - sysroot += strlen (TARGET_FILENAME_PREFIX); + if (target_filesystem_is_local ()) + { + /* If the absolute prefix starts with "target:" but the + filesystem accessed by the target_fileio_* methods is the + local filesystem then we strip the "target:" prefix now and + work with the local filesystem. This ensures that the same + search algorithm is used for all local files regardless of + whether a "target:" prefix was used. */ + if (is_target_filename (sysroot)) + sysroot += strlen (TARGET_FILENAME_PREFIX); + } + else if (auto_target_prefix && *gdb_sysroot == '\0') + { + /* Set the absolute prefix to "target:" for executable files + and for shared libraries whose executable filename has a + "target:"-prefix. */ + if (!is_solib + || (exec_filename != NULL + && is_target_filename (exec_filename))) + { + sysroot = xstrdup (TARGET_FILENAME_PREFIX); + make_cleanup (xfree, sysroot); + } + } /* Strip any trailing slashes from the absolute prefix. */ prefix_len = orig_prefix_len = strlen (sysroot); @@ -1507,6 +1531,15 @@ show_auto_solib_add (struct ui_file *file, int from_tty, value); } +static void +show_auto_target_prefix (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, + _("Automatic prefixing of binary filenames is %s.\n"), + value); +} + /* Handler for library-specific lookup of global symbol NAME in OBJFILE. Call the library-specific handler if it is installed for the current target. */ @@ -1714,4 +1747,15 @@ PATH and LD_LIBRARY_PATH."), reload_shared_libraries, show_solib_search_path, &setlist, &showlist); + + add_setshow_boolean_cmd ("auto-target-prefix", class_support, + &auto_target_prefix, _("\ +Set automatic prefixing of binary filenames."), _("\ +Show automatic prefixing of binary filenames."), _("\ +If \"on\", filenames of binaries will be prefixed with \"target:\"\n\ +when attaching to processes whose filesystems GDB cannot access\n\ +directly."), + NULL, + show_auto_target_prefix, + &setlist, &showlist); }