From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] Remove ALL_DICT_SYMBOLS
Date: Sun, 16 Apr 2023 10:28:29 -0600 [thread overview]
Message-ID: <20230416-remove-all-macros-v1-3-f118956faafe@tromey.com> (raw)
In-Reply-To: <20230416-remove-all-macros-v1-0-f118956faafe@tromey.com>
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<mdict_iterator_wrapper> multidict_symbols () const
+ { return iterator_range<mdict_iterator_wrapper> (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
{
--
2.39.2
next prev parent reply other threads:[~2023-04-16 16:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-16 16:28 [PATCH 0/4] Remove remaining ALL_ iterator macros Tom Tromey
2023-04-16 16:28 ` [PATCH 1/4] Rename objfile::sections Tom Tromey
2023-04-17 17:57 ` Keith Seitz
2023-05-07 18:43 ` Tom Tromey
2023-04-16 16:28 ` [PATCH 2/4] Remove ALL_OBJFILE_OSECTIONS Tom Tromey
2023-04-16 16:28 ` Tom Tromey [this message]
2023-04-16 16:28 ` [PATCH 4/4] Remove ALL_BREAKPOINTS_SAFE Tom Tromey
2023-05-08 2:24 ` Simon Marchi
2023-05-08 14:59 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230416-remove-all-macros-v1-3-f118956faafe@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).