public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [PR gdb/27393] set directories: handle empty dirs.
@ 2021-02-25  0:50 Lancelot SIX
  2021-02-25 14:26 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Lancelot SIX @ 2021-02-25  0:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Lancelot SIX

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.

gdb/ChangeLog:

	PR gdb/27393
	* source.c (add_path): Skip empty dirnames.

gdb/testsuite/ChangeLog:

	PR gdb/27393
	* gdb.base/source-dir.exp: Test that empty dirnames are skipped.
---
 gdb/source.c                          |  2 ++
 gdb/testsuite/gdb.base/source-dir.exp | 41 +++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/gdb/source.c b/gdb/source.c
index dc30dac6d78..3a8f829759b 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/gdb.base/source-dir.exp b/gdb/testsuite/gdb.base/source-dir.exp
index 988ea59afb5..eff683199be 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
-- 
2.30.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [PR gdb/27393] set directories: handle empty dirs.
  2021-02-25  0:50 [PATCH] [PR gdb/27393] set directories: handle empty dirs Lancelot SIX
@ 2021-02-25 14:26 ` Tom Tromey
  2021-02-27 18:49   ` Lancelot SIX
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2021-02-25 14:26 UTC (permalink / raw)
  To: Lancelot SIX via Gdb-patches; +Cc: Lancelot SIX

>>>>> "Lancelot" == Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org> writes:

Lancelot> gdb/ChangeLog:

Lancelot> 	PR gdb/27393
Lancelot> 	* source.c (add_path): Skip empty dirnames.

Lancelot> gdb/testsuite/ChangeLog:

Lancelot> 	PR gdb/27393
Lancelot> 	* gdb.base/source-dir.exp: Test that empty dirnames are skipped.

Thank you.  This is ok.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [PR gdb/27393] set directories: handle empty dirs.
  2021-02-25 14:26 ` Tom Tromey
@ 2021-02-27 18:49   ` Lancelot SIX
  0 siblings, 0 replies; 3+ messages in thread
From: Lancelot SIX @ 2021-02-27 18:49 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Lancelot SIX via Gdb-patches

Le Thu, Feb 25, 2021 at 07:26:08AM -0700, Tom Tromey a écrit :
> >>>>> "Lancelot" == Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Lancelot> gdb/ChangeLog:
> 
> Lancelot> 	PR gdb/27393
> Lancelot> 	* source.c (add_path): Skip empty dirnames.
> 
> Lancelot> gdb/testsuite/ChangeLog:
> 
> Lancelot> 	PR gdb/27393
> Lancelot> 	* gdb.base/source-dir.exp: Test that empty dirnames are skipped.
> 
> Thank you.  This is ok.
> 
> Tom

Hi,

Thanks. I pushed it.

Lancelot.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-27 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-25  0:50 [PATCH] [PR gdb/27393] set directories: handle empty dirs Lancelot SIX
2021-02-25 14:26 ` Tom Tromey
2021-02-27 18:49   ` Lancelot SIX

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).