aboutsummaryrefslogtreecommitdiff
path: root/gdb/solib.c
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2015-04-02 13:38:29 +0100
committerGary Benson <gbenson@redhat.com>2015-04-02 13:38:29 +0100
commitb57fbfba4b53434252fce55e323f08aeab556409 (patch)
treedb4f1e7c1078f63d65986db7b1bd3bd9c0a73d92 /gdb/solib.c
parent97a41605e2473c67e82ef5147b4866768bd5a566 (diff)
Strip "target:" prefix in solib_find if accessing local files
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.
Diffstat (limited to 'gdb/solib.c')
-rw-r--r--gdb/solib.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/gdb/solib.c b/gdb/solib.c
index 2ec265a9aa..31298a721b 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,