From patchwork Wed Jul 31 20:14:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 33877 Received: (qmail 96204 invoked by alias); 31 Jul 2019 20:14:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 96103 invoked by uid 89); 31 Jul 2019 20:14:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:tromey, sk:tromey@, U*tromey, tromeyadacorecom X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 Jul 2019 20:14:17 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id A1553116EA8; Wed, 31 Jul 2019 16:14:15 -0400 (EDT) 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 uhdI8X69zESn; Wed, 31 Jul 2019 16:14:15 -0400 (EDT) Received: from murgatroyd.Home (97-122-178-82.hlrn.qwest.net [97.122.178.82]) (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 4B0DD116BDB; Wed, 31 Jul 2019 16:14:15 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/8] Simplify psym_map_matching_symbols Date: Wed, 31 Jul 2019 14:14:06 -0600 Message-Id: <20190731201411.8044-4-tromey@adacore.com> In-Reply-To: <20190731201411.8044-1-tromey@adacore.com> References: <20190731201411.8044-1-tromey@adacore.com> MIME-Version: 1.0 This introduces a new helper function, iterate_over_symbols_terminated, and changes psym_map_matching_symbols to use it. A subsequent patch will introduce a new user of this function in the DWARF reader. gdb/ChangeLog 2019-07-31 Tom Tromey * psymtab.c (map_block): Remove. (psym_map_matching_symbols): Use iterate_over_symbols_terminated. * symtab.c (iterate_over_symbols_terminated): New function. * symtab.c (iterate_over_symbols_terminated): Declare. --- gdb/ChangeLog | 7 +++++++ gdb/psymtab.c | 40 ++++------------------------------------ gdb/symtab.c | 15 +++++++++++++++ gdb/symtab.h | 10 ++++++++++ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/gdb/psymtab.c b/gdb/psymtab.c index c667a6273c2..daaa608d5d1 100644 --- a/gdb/psymtab.c +++ b/gdb/psymtab.c @@ -1162,38 +1162,6 @@ psymtab_to_fullname (struct partial_symtab *ps) return ps->fullname; } -/* For all symbols, s, in BLOCK that are in DOMAIN and match NAME - according to the function MATCH, call CALLBACK(BLOCK, s, DATA). - BLOCK is assumed to come from OBJFILE. Returns false iff CALLBACK - ever returns false, and otherwise returns true. */ - -static bool -map_block (const char *name, domain_enum domain, struct objfile *objfile, - const struct block *block, - gdb::function_view callback, - symbol_name_match_type match) -{ - struct block_iterator iter; - struct symbol *sym; - - lookup_name_info lookup_name (name, match); - - for (sym = block_iter_match_first (block, lookup_name, &iter); - sym != NULL; - sym = block_iter_match_next (lookup_name, &iter)) - { - if (symbol_matches_domain (SYMBOL_LANGUAGE (sym), - SYMBOL_DOMAIN (sym), domain)) - { - struct block_symbol block_sym = {sym, block}; - if (!callback (&block_sym)) - return false; - } - } - - return true; -} - /* Psymtab version of map_matching_symbols. See its definition in the definition of quick_symbol_functions in symfile.h. */ @@ -1208,6 +1176,8 @@ psym_map_matching_symbols { const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK; + lookup_name_info lookup_name (name, match); + for (partial_symtab *ps : require_partial_symbols (objfile, 1)) { QUIT; @@ -1221,10 +1191,8 @@ psym_map_matching_symbols if (cust == NULL) continue; block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind); - if (!map_block (name, domain, objfile, block, callback, match)) - return; - struct block_symbol block_sym = {nullptr, block}; - if (!callback (&block_sym)) + if (!iterate_over_symbols_terminated (block, lookup_name, + domain, callback)) return; } } diff --git a/gdb/symtab.c b/gdb/symtab.c index ba348f01bbf..f6d05c2fd06 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2857,6 +2857,21 @@ iterate_over_symbols (const struct block *block, return true; } +/* See symtab.h. */ + +bool +iterate_over_symbols_terminated + (const struct block *block, + const lookup_name_info &name, + const domain_enum domain, + gdb::function_view callback) +{ + if (!iterate_over_symbols (block, name, domain, callback)) + return false; + struct block_symbol block_sym = {nullptr, block}; + return callback (&block_sym); +} + /* Find the compunit symtab associated with PC and SECTION. This will read in debug info as necessary. */ diff --git a/gdb/symtab.h b/gdb/symtab.h index e62dd2b0ab3..50cf84ad929 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2115,6 +2115,16 @@ bool iterate_over_symbols (const struct block *block, const domain_enum domain, gdb::function_view callback); +/* Like iterate_over_symbols, but if all calls to CALLBACK return + true, then calls CALLBACK one additional time with a block_symbol + that has a valid block but a NULL symbol. */ + +bool iterate_over_symbols_terminated + (const struct block *block, + const lookup_name_info &name, + const domain_enum domain, + gdb::function_view callback); + /* Storage type used by demangle_for_lookup. demangle_for_lookup either returns a const char * pointer that points to either of the fields of this type, or a pointer to the input NAME. This is done