From patchwork Sun Apr 16 16:28:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67797 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BC623858C2F for ; Sun, 16 Apr 2023 16:55:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from qproxy6-pub.mail.unifiedlayer.com (qproxy6-pub.mail.unifiedlayer.com [69.89.23.12]) by sourceware.org (Postfix) with ESMTPS id 139B83858D1E for ; Sun, 16 Apr 2023 16:55:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 139B83858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from outbound-ss-761.bluehost.com (outbound-ss-761.bluehost.com [74.220.211.250]) by qproxy6.mail.unifiedlayer.com (Postfix) with ESMTP id 59F22802F174 for ; Sun, 16 Apr 2023 16:55:25 +0000 (UTC) Received: from cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway8.mail.pro1.eigbox.com (Postfix) with ESMTP id 16353100425EF for ; Sun, 16 Apr 2023 16:28:30 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id o5ErpDzVK4NB1o5ErpltXU; Sun, 16 Apr 2023 16:28:30 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Ab90o1bG c=1 sm=1 tr=0 ts=643c222e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=dKHAf1wccvYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=-hz9eCq0NK3VfaeAgH8A:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=lDLkIlpq+nTxSEV547IAI2OuzfTW3Z1vZc96rr95ofQ=; b=miXi8PhA1kDauoMPmiaKcdvNaW xwxCIXBU7lpHmFXNHQcB/ihPXF0pzvx4ys9HZLKs/qsS6X1bF2bX5qLNUEZ/a+TcjYlUF09HsvAxb UoEId/DjMJfjgyvBW+1HoTd0m; Received: from 71-211-191-82.hlrn.qwest.net ([71.211.191.82]:48248 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1po5Er-002aa3-Ot for gdb-patches@sourceware.org; Sun, 16 Apr 2023 10:28:29 -0600 From: Tom Tromey Date: Sun, 16 Apr 2023 10:28:29 -0600 Subject: [PATCH 3/4] Remove ALL_DICT_SYMBOLS MIME-Version: 1.0 Message-Id: <20230416-remove-all-macros-v1-3-f118956faafe@tromey.com> References: <20230416-remove-all-macros-v1-0-f118956faafe@tromey.com> In-Reply-To: <20230416-remove-all-macros-v1-0-f118956faafe@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 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.191.82 X-Source-L: No X-Exim-ID: 1po5Er-002aa3-Ot X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-191-82.hlrn.qwest.net ([192.168.0.21]) [71.211.191.82]:48248 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This replaces ALL_DICT_SYMBOLS with an iterator so that for-each can be used. --- gdb/block.h | 4 ++++ gdb/buildsym.c | 15 ++++++--------- gdb/dictionary.h | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- gdb/objfiles.c | 9 ++------- gdb/symmisc.c | 4 +--- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/gdb/block.h b/gdb/block.h index cdcee0844ec..f132d351bb6 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -143,6 +143,10 @@ struct block : public allocate_on_obstack multidictionary *multidict () const { return m_multidict; } + /* Return an iterator range for this block's multidict. */ + iterator_range multidict_symbols () const + { return iterator_range (m_multidict); } + /* Set this block's multidict. */ void set_multidict (multidictionary *multidict) { m_multidict = multidict; } diff --git a/gdb/buildsym.c b/gdb/buildsym.c index f000233dafa..d12ad2187ab 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -244,7 +244,6 @@ buildsym_compunit::finish_block_internal if (symbol) { struct type *ftype = symbol->type (); - struct mdict_iterator miter; symbol->set_value_block (block); symbol->set_section_index (SECT_OFF_TEXT (m_objfile)); block->set_function (symbol); @@ -255,11 +254,10 @@ buildsym_compunit::finish_block_internal function's type. Set that from the type of the parameter symbols. */ int nparams = 0, iparams; - struct symbol *sym; /* Here we want to directly access the dictionary, because we haven't fully initialized the block yet. */ - ALL_DICT_SYMBOLS (block->multidict (), miter, sym) + for (struct symbol *sym : block->multidict_symbols ()) { if (sym->is_argument ()) nparams++; @@ -274,7 +272,7 @@ buildsym_compunit::finish_block_internal iparams = 0; /* Here we want to directly access the dictionary, because we haven't fully initialized the block yet. */ - ALL_DICT_SYMBOLS (block->multidict (), miter, sym) + for (struct symbol *sym : block->multidict_symbols ()) { if (iparams == nparams) break; @@ -975,8 +973,6 @@ buildsym_compunit::end_compunit_symtab_with_blockvector for (block_i = 0; block_i < blockvector->num_blocks (); block_i++) { struct block *block = blockvector->block (block_i); - struct symbol *sym; - struct mdict_iterator miter; /* Inlined functions may have symbols not in the global or static symbol lists. */ @@ -985,9 +981,10 @@ buildsym_compunit::end_compunit_symtab_with_blockvector block->function ()->set_symtab (symtab); /* Note that we only want to fix up symbols from the local - blocks, not blocks coming from included symtabs. That is why - we use ALL_DICT_SYMBOLS here and not a block iterator. */ - ALL_DICT_SYMBOLS (block->multidict (), miter, sym) + blocks, not blocks coming from included symtabs. That is + why we use an mdict iterator here and not a block + iterator. */ + for (struct symbol *sym : block->multidict_symbols ()) if (sym->symtab () == NULL) sym->set_symtab (symtab); } diff --git a/gdb/dictionary.h b/gdb/dictionary.h index 9dc02c91e04..d982396cb31 100644 --- a/gdb/dictionary.h +++ b/gdb/dictionary.h @@ -164,16 +164,49 @@ extern struct symbol *mdict_iter_match_next (const lookup_name_info &name, extern int mdict_size (const struct multidictionary *mdict); -/* Macro to loop through all symbols in a dictionary DICT, in no - particular order. ITER is a struct dict_iterator (NOTE: __not__ a - struct dict_iterator *), and SYM points to the current symbol. - - It's implemented as a single loop, so you can terminate the loop - early by a break if you desire. */ - -#define ALL_DICT_SYMBOLS(dict, iter, sym) \ - for ((sym) = mdict_iterator_first ((dict), &(iter)); \ - (sym); \ - (sym) = mdict_iterator_next (&(iter))) +/* An iterator that wraps an mdict_iterator. The naming here is + unfortunate, but mdict_iterator was named before gdb switched to + C++. */ +struct mdict_iterator_wrapper +{ + typedef mdict_iterator_wrapper self_type; + typedef struct symbol *value_type; + + explicit mdict_iterator_wrapper (const struct multidictionary *mdict) + : m_sym (mdict_iterator_first (mdict, &m_iter)) + { + } + + mdict_iterator_wrapper () + : m_sym (nullptr) + { + } + + value_type operator* () const + { + return m_sym; + } + + bool operator== (const self_type &other) const + { + return m_sym == other.m_sym; + } + + bool operator!= (const self_type &other) const + { + return m_sym != other.m_sym; + } + + self_type &operator++ () + { + m_sym = mdict_iterator_next (&m_iter); + return *this; + } + +private: + + struct symbol *m_sym; + struct mdict_iterator m_iter; +}; #endif /* DICTIONARY_H */ diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 3fefc4ad846..5ba5f0a616d 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -625,9 +625,6 @@ objfile_relocate1 (struct objfile *objfile, for (block *b : bv->blocks ()) { - struct symbol *sym; - struct mdict_iterator miter; - b->set_start (b->start () + delta[block_line_section]); b->set_end (b->end () + delta[block_line_section]); @@ -639,10 +636,8 @@ objfile_relocate1 (struct objfile *objfile, /* We only want to iterate over the local symbols, not any symbols in included symtabs. */ - ALL_DICT_SYMBOLS (b->multidict (), miter, sym) - { - relocate_one_symbol (sym, objfile, delta); - } + for (struct symbol *sym : b->multidict_symbols ()) + relocate_one_symbol (sym, objfile, delta); } } diff --git a/gdb/symmisc.c b/gdb/symmisc.c index fb8a3ebf602..1d838710a66 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -236,9 +236,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) { struct objfile *objfile = symtab->compunit ()->objfile (); struct gdbarch *gdbarch = objfile->arch (); - struct mdict_iterator miter; const struct linetable *l; - struct symbol *sym; int depth; gdb_printf (outfile, "\nSymtab for file %s at %s\n", @@ -307,7 +305,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) /* Now print each symbol in this block (in no particular order, if we're using a hashtable). Note that we only want this block, not any blocks from included symtabs. */ - ALL_DICT_SYMBOLS (b->multidict (), miter, sym) + for (struct symbol *sym : b->multidict_symbols ()) { try {