This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/9] Add macro ALL_BLOCK_SYMBOLS_WITH_NAME.


Doug Evans <xdje42@gmail.com> writes:
> On Sun, Oct 26, 2014 at 9:26 PM, Doug Evans <xdje42@gmail.com> wrote:
>> Hi.
>>
>> This patch adds macro ALL_BLOCK_SYMBOLS_WITH_NAME to go with
>> the ALL_BLOCK_SYMBOLS macro already in block.h.
>>
>> 2014-10-26  Doug Evans  <xdje42@gmail.com>
>>
>>         * block.h (ALL_BLOCK_SYMBOLS_WITH_NAME): New macro.
>>         * cp-support.c (make_symbol_overload_list_block): Use it.
>>         * symtab.c (iterate_over_symbols): Use it.
>
> Heh.  block_lookup_symbol in 1/9 of this series could use this macro.
> https://sourceware.org/ml/gdb-patches/2014-10/msg00720.html
> I'll add that to this patch.

Here's what I committed.

 2014-11-06  Doug Evans  <xdje42@gmail.com>
 
	* block.h (ALL_BLOCK_SYMBOLS_WITH_NAME): New macro.
	* block.c (block_lookup_symbol): Use it.
	* cp-support.c (make_symbol_overload_list_block): Use it.
	* symtab.c (iterate_over_symbols): Use it.

diff --git a/gdb/block.c b/gdb/block.c
index 3bb9de0..1cb9875 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -706,9 +706,7 @@ block_lookup_symbol (const struct block *block, const char *name,
 
   if (!BLOCK_FUNCTION (block))
     {
-      for (sym = block_iter_name_first (block, name, &iter);
-	   sym != NULL;
-	   sym = block_iter_name_next (name, &iter))
+      ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
 	{
 	  if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
 				     SYMBOL_DOMAIN (sym), domain))
@@ -726,9 +724,7 @@ block_lookup_symbol (const struct block *block, const char *name,
 
       struct symbol *sym_found = NULL;
 
-      for (sym = block_iter_name_first (block, name, &iter);
-	   sym != NULL;
-	   sym = block_iter_name_next (name, &iter))
+      ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
 	{
 	  if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
 				     SYMBOL_DOMAIN (sym), domain))
diff --git a/gdb/block.h b/gdb/block.h
index e8d3452..50a7919 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -286,4 +286,13 @@ extern struct symbol *block_lookup_symbol (const struct block *block,
        (sym);						\
        (sym) = block_iterator_next (&(iter)))
 
+/* Macro to loop through all symbols with name NAME in BLOCK,
+   in no particular order.  ITER helps keep track of the iteration, and
+   must be a struct block_iterator.  SYM points to the current symbol.  */
+
+#define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym)		\
+  for ((sym) = block_iter_name_first ((block), (name), &(iter));	\
+       (sym) != NULL;							\
+       (sym) = block_iter_name_next ((name), &(iter)))
+
 #endif /* BLOCK_H */
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index d35920c..72ffb52 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1218,9 +1218,7 @@ make_symbol_overload_list_block (const char *name,
   struct block_iterator iter;
   struct symbol *sym;
 
-  for (sym = block_iter_name_first (block, name, &iter);
-       sym != NULL;
-       sym = block_iter_name_next (name, &iter))
+  ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
     overload_list_add_symbol (sym, name);
 }
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 482a23d..9add71f 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2031,9 +2031,7 @@ iterate_over_symbols (const struct block *block, const char *name,
   struct block_iterator iter;
   struct symbol *sym;
 
-  for (sym = block_iter_name_first (block, name, &iter);
-       sym != NULL;
-       sym = block_iter_name_next (name, &iter))
+  ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
     {
       if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
 				 SYMBOL_DOMAIN (sym), domain))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]