public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/9] Strip "target:" prefix in solib_find if accessing local files
Date: Fri, 20 Mar 2015 16:48:00 -0000	[thread overview]
Message-ID: <1426870087-32654-7-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1426870087-32654-1-git-send-email-gbenson@redhat.com>

This commit updates solib_find to strip the "target:" prefix from
gdb_sysroot when accessing local files.  This ensures that the same
search algorithm is used for local files regardless of whether a
"target:" prefix was used or not.  It also avoids cluttering GDB's
output with unnecessary "target:" prefixes on paths.

gdb/ChangeLog:

	* solib.c (solib_find): Strip "target:" prefix from sysroot
	if accessing local files.
---
 gdb/ChangeLog |    5 +++++
 gdb/solib.c   |   51 +++++++++++++++++++++++++++++++++++----------------
 2 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/gdb/solib.c b/gdb/solib.c
index 039f529..359a208 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -119,24 +119,30 @@ show_solib_search_path (struct ui_file *file, int from_tty,
 
    Global variable GDB_SYSROOT is used as a prefix directory
    to search for shared libraries if they have an absolute path.
+   If GDB_SYSROOT starts with "target:" and target filesystem
+   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.
 
    Global variable SOLIB_SEARCH_PATH is used as a prefix directory
    (or set of directories, as in LD_LIBRARY_PATH) to search for all
-   shared libraries if not found in GDB_SYSROOT.
+   shared libraries if not found in either the sysroot (if set) or
+   the local filesystem.
 
    Search algorithm:
-   * If there is a gdb_sysroot and path is absolute:
-   *   Search for gdb_sysroot/path.
+   * If a sysroot is set and path is absolute:
+   *   Search for sysroot/path.
    * else
    *   Look for it literally (unmodified).
    * Look in SOLIB_SEARCH_PATH.
    * If available, use target defined search function.
-   * If gdb_sysroot is NOT set, perform the following two searches:
+   * If NO sysroot is set, perform the following two searches:
    *   Look in inferior's $PATH.
    *   Look in inferior's $LD_LIBRARY_PATH.
    *
    * The last check avoids doing this search when targetting remote
-   * machines since gdb_sysroot will almost always be set.
+   * machines since a sysroot will almost always be set.
 */
 
 char *
@@ -145,12 +151,11 @@ solib_find (char *in_pathname, int *fd)
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
   int found_file = -1;
   char *temp_pathname = NULL;
-  int gdb_sysroot_is_empty;
   const char *solib_symbols_extension
     = gdbarch_solib_symbols_extension (target_gdbarch ());
   const char *fskind = effective_target_file_system_kind ();
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  char *sysroot = NULL;
+  char *sysroot = gdb_sysroot;
 
   /* If solib_symbols_extension is set, replace the file's
      extension.  */
@@ -175,18 +180,32 @@ solib_find (char *in_pathname, int *fd)
 	}
     }
 
-  gdb_sysroot_is_empty = (gdb_sysroot == NULL || *gdb_sysroot == 0);
+  if (sysroot != NULL)
+    {
+      /* 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_SYSROOT_PREFIX);
+
+      if (*sysroot == '\0')
+	sysroot = NULL;
+    }
 
-  if (!gdb_sysroot_is_empty)
+  if (sysroot != NULL)
     {
-      int prefix_len = strlen (gdb_sysroot);
+      int prefix_len = strlen (sysroot);
 
       /* Remove trailing slashes from absolute prefix.  */
       while (prefix_len > 0
-	     && IS_DIR_SEPARATOR (gdb_sysroot[prefix_len - 1]))
+	     && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
 	prefix_len--;
 
-      sysroot = savestring (gdb_sysroot, prefix_len);
+      sysroot = savestring (sysroot, prefix_len);
       make_cleanup (xfree, sysroot);
     }
 
@@ -222,7 +241,7 @@ solib_find (char *in_pathname, int *fd)
        3rd attempt, c:/foo/bar.dll ==> /sysroot/foo/bar.dll
   */
 
-  if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || gdb_sysroot_is_empty)
+  if (!IS_TARGET_ABSOLUTE_PATH (fskind, in_pathname) || sysroot == NULL)
     temp_pathname = xstrdup (in_pathname);
   else
     {
@@ -273,7 +292,7 @@ solib_find (char *in_pathname, int *fd)
        c:/foo/bar.dll ==> /sysroot/c/foo/bar.dll.  */
 
   if (found_file < 0
-      && !gdb_sysroot_is_empty
+      && sysroot != NULL
       && HAS_TARGET_DRIVE_SPEC (fskind, in_pathname))
     {
       int need_dir_separator = !IS_DIR_SEPARATOR (in_pathname[2]);
@@ -353,7 +372,7 @@ solib_find (char *in_pathname, int *fd)
 					   &temp_pathname);
 
   /* If not found, next search the inferior's $PATH environment variable.  */
-  if (found_file < 0 && gdb_sysroot_is_empty)
+  if (found_file < 0 && sysroot == NULL)
     found_file = openp (get_in_environ (current_inferior ()->environment,
 					"PATH"),
 			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
@@ -361,7 +380,7 @@ solib_find (char *in_pathname, int *fd)
 
   /* If not found, next search the inferior's $LD_LIBRARY_PATH
      environment variable.  */
-  if (found_file < 0 && gdb_sysroot_is_empty)
+  if (found_file < 0 && sysroot == NULL)
     found_file = openp (get_in_environ (current_inferior ()->environment,
 					"LD_LIBRARY_PATH"),
 			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
-- 
1.7.1

  parent reply	other threads:[~2015-03-20 16:48 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 16:48 [PATCH 0/9] New default sysroot "target:" Gary Benson
2015-03-20 16:48 ` [PATCH 1/9] Introduce target_fileio_fstat Gary Benson
2015-04-01 12:11   ` Pedro Alves
2015-03-20 16:48 ` [PATCH 4/9] Convert "remote:" sysroots to "target:" and remove "remote:" Gary Benson
2015-04-01 12:13   ` Pedro Alves
2015-04-01 13:48     ` Gary Benson
2015-03-20 16:48 ` Gary Benson [this message]
2015-04-01 12:14   ` [PATCH 6/9] Strip "target:" prefix in solib_find if accessing local files Pedro Alves
2015-03-20 16:57 ` [PATCH 9/9] Document "target:" sysroot changes Gary Benson
2015-03-20 17:51   ` Eli Zaretskii
2015-04-01 12:15   ` Pedro Alves
2015-03-20 16:57 ` [PATCH 8/9] Make the default sysroot be "target:" Gary Benson
2015-04-01 12:15   ` Pedro Alves
2015-04-01 14:12     ` Gary Benson
2015-04-01 14:18       ` Pedro Alves
2015-03-20 17:18 ` [PATCH 7/9] Update exec_file_attach to cope with "target:" filenames Gary Benson
2015-04-01 12:14   ` Pedro Alves
2015-04-01 13:55     ` Gary Benson
2015-04-01 14:16       ` Pedro Alves
2015-04-01 15:59         ` Gary Benson
2015-03-20 17:32 ` [PATCH 2/9] Introduce target_filesystem_is_local Gary Benson
2015-04-01 12:11   ` Pedro Alves
2015-03-20 17:46 ` [PATCH 5/9] Rearrange symfile_bfd_open Gary Benson
2015-04-01 12:13   ` Pedro Alves
2015-04-01 15:50     ` Gary Benson
2015-04-01 16:03       ` Pedro Alves
2015-03-20 17:47 ` [PATCH 3/9] Make gdb_bfd_open able to open BFDs using target fileio Gary Benson
2015-04-01 12:13   ` Pedro Alves
2015-04-01 12:17 ` [PATCH 0/9] New default sysroot "target:" Pedro Alves
2015-04-02 13:00   ` Gary Benson
2015-04-01 12:22 ` [PING][PATCH " Gary Benson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426870087-32654-7-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).