From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway36.websitewelcome.com (gateway36.websitewelcome.com [192.185.185.36]) by sourceware.org (Postfix) with ESMTPS id 5268B3857808 for ; Sun, 27 Jun 2021 14:24:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5268B3857808 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway36.websitewelcome.com (Postfix) with ESMTP id B2637400CDB56 for ; Sun, 27 Jun 2021 09:24:32 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id xVi4loayrK61ixVi4lJJsT; Sun, 27 Jun 2021 09:24:32 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BaTirfxyLywKqzw4giE+zbt6kvUegMW/u5oocujDPJk=; b=JCn+rZV5aTmz3YHKaSyP59VCGN frTVSc7ntMWo1BN/ahDuxfYJuo49LasseoJftqBj+SJ9ndV8pPvrgAbVaQrbylpFKImwjgV+lkrWi UjAfTHm+6RzhhsVK2QR2UlWwu; Received: from 71-211-145-10.hlrn.qwest.net ([71.211.145.10]:37800 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lxVi4-000b1b-EH; Sun, 27 Jun 2021 08:24:32 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Document quick_symbol_functions::expand_symtabs_matching invariant Date: Sun, 27 Jun 2021 08:24:30 -0600 Message-Id: <20210627142430.993717-1-tom@tromey.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.145.10 X-Source-L: No X-Exim-ID: 1lxVi4-000b1b-EH X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-145-10.hlrn.qwest.net (localhost.localdomain) [71.211.145.10]:37800 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, 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: Sun, 27 Jun 2021 14:24:35 -0000 While working on my series to replace the DWARF psymbol reader, I noticed that the expand_symtabs_matching has an undocumented invariant. I think that, if this invariant is not followed, then GDB will crash. So, this patch documents this in the relevant spots and introduces some asserts to make it clear. Regression tested on x86-64 Fedora 32. gdb/ChangeLog 2021-06-27 Tom Tromey * symfile-debug.c (objfile::expand_symtabs_matching): Add assert. * quick-symbol.h (struct quick_symbol_functions) : Add comment. * psymtab.c (psymbol_functions::expand_symtabs_matching): Add assert, simplify. * dwarf2/read.c (dwarf2_gdb_index::expand_symtabs_matching) (dwarf2_debug_names_index::expand_symtabs_matching): Add assert, simplify. --- gdb/ChangeLog | 11 +++++++++++ gdb/dwarf2/read.c | 8 ++++++-- gdb/psymtab.c | 5 ++++- gdb/quick-symbol.h | 2 ++ gdb/symfile-debug.c | 3 +++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 760d4319c29..4f51470f151 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -4319,7 +4319,9 @@ dwarf2_gdb_index::expand_symtabs_matching dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher); - if (symbol_matcher == NULL && lookup_name == NULL) + /* This invariant is documented in quick-functions.h. */ + gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); + if (lookup_name == nullptr) { for (const auto &per_cu : per_objfile->per_bfd->all_comp_units) { @@ -5307,7 +5309,9 @@ dwarf2_debug_names_index::expand_symtabs_matching dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher); - if (symbol_matcher == NULL && lookup_name == NULL) + /* This invariant is documented in quick-functions.h. */ + gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); + if (lookup_name == nullptr) { for (const auto &per_cu : per_objfile->per_bfd->all_comp_units) { diff --git a/gdb/psymtab.c b/gdb/psymtab.c index 069052d712c..7c3017d36d2 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1130,6 +1130,9 @@ psymbol_functions::expand_symtabs_matching if (lookup_name != nullptr) psym_lookup_name = lookup_name->make_ignore_params (); + /* This invariant is documented in quick-functions.h. */ + gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); + for (partial_symtab *ps : m_partial_symtabs->range ()) { QUIT; @@ -1157,7 +1160,7 @@ psymbol_functions::expand_symtabs_matching continue; } - if ((symbol_matcher == NULL && lookup_name == NULL) + if (lookup_name == nullptr || recursively_search_psymtabs (ps, objfile, search_flags, domain, search, *psym_lookup_name, diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h index 7af0aebb9fe..5eb7c8423e2 100644 --- a/gdb/quick-symbol.h +++ b/gdb/quick-symbol.h @@ -167,6 +167,8 @@ struct quick_symbol_functions If the symbol name does not match LOOKUP_NAME, the symbol is skipped. If SYMBOL_MATCHER returns false, then the symbol is skipped. + Note that if SYMBOL_MATCHER is non-NULL, then LOOKUP_NAME must + also be provided. Otherwise, the symbol's symbol table is expanded and the notification function is called. If the notification function diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index a10af68f5b1..f3d5a68b72e 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -405,6 +405,9 @@ objfile::expand_symtabs_matching domain_enum domain, enum search_domain kind) { + /* This invariant is documented in quick-functions.h. */ + gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); + if (debug_symfile) fprintf_filtered (gdb_stdlog, "qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n", -- 2.26.3