This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb] Correctly notice empty sysroots in solib_find_1
- From: Gary Benson <gary at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 25 Jun 2015 10:31:21 -0000
- Subject: [binutils-gdb] Correctly notice empty sysroots in solib_find_1
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f8773be1be076f828b93ac3bebeab3f782e191e4
commit f8773be1be076f828b93ac3bebeab3f782e191e4
Author: Gary Benson <gbenson@redhat.com>
Date: Thu Jun 25 09:54:12 2015 +0100
Correctly notice empty sysroots in solib_find_1
Some parts of solib_find_1 should only operate if the sysroot
is nonempty after processing, but the logic that checked this
happened before trailing slashes were stripped so empty but
non-NULL sysroots were possible. This commit moves the logic
so it correctly notices all empty sysroots.
gdb/ChangeLog:
* solib.c (solib_find_1): Set local variable sysroot to NULL if
it is the empty string after trailing slashes have been stripped.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/solib.c | 18 +++++++++---------
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4ff683d..659f9b7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2015-06-25 Gary Benson <gbenson@redhat.com>
+ * solib.c (solib_find_1): Set local variable sysroot to NULL if
+ it is the empty string after trailing slashes have been stripped.
+
+2015-06-25 Gary Benson <gbenson@redhat.com>
+
* exec.c (exec_file_locate_attach): Remove gdb_sysroot NULL check.
* infrun.c (follow_exec): Likewise.
* remote.c (remote_filesystem_is_local): Likewise.
diff --git a/gdb/solib.c b/gdb/solib.c
index ed1bc25..eb933c0 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -158,6 +158,7 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
const char *fskind = effective_target_file_system_kind ();
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
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
@@ -168,17 +169,16 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib)
if (is_target_filename (sysroot) && target_filesystem_is_local ())
sysroot += strlen (TARGET_SYSROOT_PREFIX);
- if (*sysroot == '\0')
- sysroot = NULL;
- else
- {
- int prefix_len = strlen (sysroot);
+ /* Strip any trailing slashes from the absolute prefix. */
+ prefix_len = orig_prefix_len = strlen (sysroot);
- /* Remove trailing slashes from absolute prefix. */
- while (prefix_len > 0
- && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
- prefix_len--;
+ while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
+ prefix_len--;
+ if (prefix_len == 0)
+ sysroot = NULL;
+ else if (prefix_len != orig_prefix_len)
+ {
sysroot = savestring (sysroot, prefix_len);
make_cleanup (xfree, sysroot);
}