From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id HfrQHnT0NmBrJQAAWB0awg (envelope-from ) for ; Wed, 24 Feb 2021 19:51:00 -0500 Received: by simark.ca (Postfix, from userid 112) id 6E5D21EF78; Wed, 24 Feb 2021 19:51:00 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A1BB41E590 for ; Wed, 24 Feb 2021 19:50:59 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 26A76395542C; Thu, 25 Feb 2021 00:50:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26A76395542C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614214259; bh=rqXDoVTLkF8n9Z+PyowIB2ME/VMJsVoO2gyhl3DKy8Q=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Wz0Nn84F+jR/leFrI2HzfxZFcwBDNp52CE9PZi6PxfaFNyVtX/hlnb96jKOuL+Hds XKiyGD8vy9iaq+qDDNIz/ss3eR9+NaGi9tlgUBiMITbcE0wBYoa0tIgaHlkKn3S4wa M1Sn0ug/CBh0AxPknpaQ7rxFRrbdjIBd/pJwRKVk= Received: from beryx.lancelotsix.com (beryx.lancelotsix.com [164.132.98.193]) by sourceware.org (Postfix) with ESMTPS id B3A88395542C for ; Thu, 25 Feb 2021 00:50:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B3A88395542C Received: from Plymouth.lan (unknown [IPv6:2a02:390:8443:0:d484:f8ae:3264:4dad]) by beryx.lancelotsix.com (Postfix) with ESMTPSA id C23F52E03B; Thu, 25 Feb 2021 01:50:53 +0100 (CET) To: gdb-patches@sourceware.org Subject: [PATCH] [PR gdb/27393] set directories: handle empty dirs. Date: Thu, 25 Feb 2021 00:50:43 +0000 Message-Id: <20210225005043.30663-1-lsix@lancelotsix.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (beryx.lancelotsix.com [0.0.0.0]); Thu, 25 Feb 2021 01:50:53 +0100 (CET) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Cc: Lancelot SIX Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 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 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