From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 58F94386F824 for ; Tue, 21 Apr 2020 15:23:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 58F94386F824 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 27639116269; Tue, 21 Apr 2020 11:23:41 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DWan95ZILdXv; Tue, 21 Apr 2020 11:23:41 -0400 (EDT) Received: from murgatroyd.Home (184-96-229-138.hlrn.qwest.net [184.96.229.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 61B7A1163F2; Tue, 21 Apr 2020 11:23:40 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix Ada crash with .debug_names Date: Tue, 21 Apr 2020 09:23:35 -0600 Message-Id: <20200421152335.21282-1-tromey@adacore.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-24.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Tue, 21 Apr 2020 15:23:42 -0000 PR ada/25837 points out a crash in the gdb testsuite when .debug_names is used. You can reproduce like: runtest --target_board=cc-with-debug-names \ gdb.ada/big_packed_array.exp The bug was introduced by commit e0802d599 ("Avoid copying in lookup_name_info"). The problem is that the return type of language_lookup_name changed, but in a way that didn't cause existing callers to trigger a compilation error. So, the matcher cache in dw2_expand_symtabs_matching_symbol, which stored a "const string &", would end up with invalid data. This patch fixes the problem by updating the callers to use the new type. Tested on x86-64 Fedora 30. gdb/ChangeLog 2020-04-21 Tom Tromey PR ada/25837: * dwarf2/read.c (dw2_expand_symtabs_matching_symbol): Store a "const char *", not a "const std::string &". : Update. * unittests/lookup_name_info-selftests.c: Change type of "result". --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2/read.c | 4 ++-- gdb/unittests/lookup_name_info-selftests.c | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 41db511c851..2e21e801380 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3911,11 +3911,11 @@ dw2_expand_symtabs_matching_symbol struct name_and_matcher { symbol_name_matcher_ftype *matcher; - const std::string &name; + const char *name; bool operator== (const name_and_matcher &other) const { - return matcher == other.matcher && name == other.name; + return matcher == other.matcher && strcmp (name, other.name) == 0; } }; diff --git a/gdb/unittests/lookup_name_info-selftests.c b/gdb/unittests/lookup_name_info-selftests.c index 002fc697955..6a617521cb4 100644 --- a/gdb/unittests/lookup_name_info-selftests.c +++ b/gdb/unittests/lookup_name_info-selftests.c @@ -37,14 +37,14 @@ check_make_paramless (const char *file, int line, { lookup_name_info lookup_name (name, symbol_name_match_type::FULL, completion_mode, true /* ignore_parameters */); - const std::string &result = lookup_name.language_lookup_name (lang); + const char *result = lookup_name.language_lookup_name (lang); - if (result != expected) + if (strcmp (result, expected) != 0) { error (_("%s:%d: make-paramless self-test failed: (completion=%d, lang=%d) " "\"%s\" -> \"%s\", expected \"%s\""), file, line, completion_mode, lang, name, - result.c_str (), expected); + result, expected); } } -- 2.21.1