aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLancelot SIX <lsix@lancelotsix.com>2021-02-25 00:30:49 +0000
committerLancelot SIX <lsix@lancelotsix.com>2021-02-27 14:29:39 +0000
commitbb3a4efe13c0bd9a7b15ecd02ddb966870a03bd0 (patch)
tree2fba83defaddb1b33723dd84e7c3276a5c3c2603
parent573dc0cc43f2c3ce4d28ec1aa1bf05fc43810cda (diff)
downloadgdb-bb3a4efe13c0bd9a7b15ecd02ddb966870a03bd0.zip
gdb-bb3a4efe13c0bd9a7b15ecd02ddb966870a03bd0.tar.gz
gdb-bb3a4efe13c0bd9a7b15ecd02ddb966870a03bd0.tar.bz2
[PR gdb/27393] set directories: handle empty dirs.
As reported in gdb/27393, the 'directory' and 'set directories' commands fail when parsing an empty dir name: (gdb) set directories "" /home/lsix/dev/gnu/binutils-gdb/gdbsupport/pathstuff.cc:132: internal-error: gdb::unique_xmalloc_ptr<char> gdb_abspath(const char*): Assertion `path != NULL && path[0] != '\0'' failed. or (gdb) dir : /home/lsix/dev/gnu/binutils-gdb/gdbsupport/pathstuff.cc:132: internal-error: gdb::unique_xmalloc_ptr<char> gdb_abspath(const char*): Assertion `path != NULL && path[0] != '\0'' failed. This patch fixes this issue by ignoring any attempt to add an empty name to the source directories list. 'set dir ""' will reset the directories list the same way 'set dir' would do it. Tested on x86_64.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/source.c2
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/source-dir.exp41
4 files changed, 54 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8a27253..bb7b2de 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2021-02-27 Lancelot Six <lsix@lancelotsix.com>
+
+ PR gdb/27393
+ * source.c (add_path): Skip empty dirnames.
+
2021-02-25 Kevin Buettner <kevinb@redhat.com>
* nat/aarch64-sve-linux-ptrace.h: Add comment regarding
diff --git a/gdb/source.c b/gdb/source.c
index dc30dac..3a8f829 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -572,6 +572,8 @@ add_path (const char *dirname, char **which_path, int parse_separators)
break;
}
+ if (name[0] == '\0')
+ goto skip_dup;
if (name[0] == '~')
new_name_holder.reset (tilde_expand (name));
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 625c4ec..b92e67c 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2021-02-27 Lancelot Six <lsix@lancelotix.com>
+
+ PR gdb/27393
+ * gdb.base/source-dir.exp: Test that empty dirnames are skipped.
+
+
2021-02-26 Tom Tromey <tom@tromey.com>
* lib/gdb.exp (skip_ctf_tests): Use expr on result.
diff --git a/gdb/testsuite/gdb.base/source-dir.exp b/gdb/testsuite/gdb.base/source-dir.exp
index 988ea59..eff6831 100644
--- a/gdb/testsuite/gdb.base/source-dir.exp
+++ b/gdb/testsuite/gdb.base/source-dir.exp
@@ -163,5 +163,46 @@ proc test_truncated_comp_dir {} {
"info source after setting directory search list"
}
+proc test_change_search_directory_with_empty_dirname {} {
+ gdb_start
+
+ # Add 3 entries to the source directories list:
+ # - ""
+ # - "/foo"
+ # - "/bar"
+ # Since /foo and /bar probably do not exist, ignore the warnings printed by
+ # GDB.
+ if { [ishost *-*-mingw*] } {
+ gdb_test "set directories ;/foo;/bar" ".*"
+ } else {
+ gdb_test "set directories :/foo:/bar" ".*"
+ }
+
+ # The first entry added ("") should be ignored, only /foo and /bar are
+ # effectively added.
+ with_test_prefix "initial_directory_state" {
+ gdb_test "show directories" \
+ [search_dir_list [list \
+ "/foo" \
+ "/bar" \
+ "\\\$cdir" \
+ "\\\$cwd"]]
+ }
+
+ # Arguments can be quoted. Check a empty string has the same effect as
+ # 'set directory' (i.e. reset to $cdir:$cwd)
+ gdb_test_no_output "set directories \"\""
+
+ with_test_prefix "directory_after_reset" {
+ gdb_test "show directories" \
+ [search_dir_list [list \
+ "\\\$cdir" \
+ "\\\$cwd"]]
+ }
+
+ gdb_exit
+}
+
test_changing_search_directory
+test_change_search_directory_with_empty_dirname
test_truncated_comp_dir