[07/12] Remove ALL_COMPUNITS

Message ID 20181125165439.13773-8-tom@tromey.com
State New
Headers show
Series
  • Remove some ALL_* iteration macros
Related show

Commit Message

Tom Tromey Nov. 25, 2018, 4:54 p.m.
This removes the ALL_COMPUNITS, replacing its uses with two nested
ranged for loops.

gdb/ChangeLog
2018-11-25  Tom Tromey  <tom@tromey.com>

	* symtab.c (lookup_objfile_from_block)
	(find_pc_sect_compunit_symtab, search_symbols)
	(default_collect_symbol_completion_matches_break_on): Use
	objfile_compunits.
	* objfiles.h (ALL_COMPUNITS): Remove.
	* maint.c (count_symtabs_and_blocks): Use objfile_compunits.
	* cp-support.c (add_symbol_overload_list_qualified): Use
	objfile_compunits.
	* ada-lang.c (ada_collect_symbol_completion_matches)
	(ada_add_global_exceptions): Use objfile_compunits.
---
 gdb/ChangeLog    |  13 +++++
 gdb/ada-lang.c   | 106 ++++++++++++++++++++--------------------
 gdb/cp-support.c |  33 +++++++------
 gdb/maint.c      |  16 +++---
 gdb/objfiles.h   |   6 ---
 gdb/symtab.c     | 125 +++++++++++++++++++++++------------------------
 6 files changed, 152 insertions(+), 147 deletions(-)

-- 
2.17.2

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 1a1db17421..64f3b53303 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -6461,41 +6461,42 @@  ada_collect_symbol_completion_matches (completion_tracker &tracker,
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  struct objfile *objfile;
-  ALL_COMPUNITS (objfile, s)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
-    ALL_BLOCK_SYMBOLS (b, iter, sym)
-    {
-      if (completion_skip_symbol (mode, sym))
-	continue;
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *s : objfile_compunits (objfile))
+      {
+	QUIT;
+	b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
+	ALL_BLOCK_SYMBOLS (b, iter, sym)
+	  {
+	    if (completion_skip_symbol (mode, sym))
+	      continue;
 
-      completion_list_add_name (tracker,
-				SYMBOL_LANGUAGE (sym),
-				SYMBOL_LINKAGE_NAME (sym),
-				lookup_name, text, word);
-    }
-  }
+	    completion_list_add_name (tracker,
+				      SYMBOL_LANGUAGE (sym),
+				      SYMBOL_LINKAGE_NAME (sym),
+				      lookup_name, text, word);
+	  }
+      }
 
-  ALL_COMPUNITS (objfile, s)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
-    /* Don't do this block twice.  */
-    if (b == surrounding_static_block)
-      continue;
-    ALL_BLOCK_SYMBOLS (b, iter, sym)
-    {
-      if (completion_skip_symbol (mode, sym))
-	continue;
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *s : objfile_compunits (objfile))
+      {
+	QUIT;
+	b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
+	/* Don't do this block twice.  */
+	if (b == surrounding_static_block)
+	  continue;
+	ALL_BLOCK_SYMBOLS (b, iter, sym)
+	  {
+	    if (completion_skip_symbol (mode, sym))
+	      continue;
 
-      completion_list_add_name (tracker,
-				SYMBOL_LANGUAGE (sym),
-				SYMBOL_LINKAGE_NAME (sym),
-				lookup_name, text, word);
-    }
-  }
+	    completion_list_add_name (tracker,
+				      SYMBOL_LANGUAGE (sym),
+				      SYMBOL_LINKAGE_NAME (sym),
+				      lookup_name, text, word);
+	  }
+      }
 }
 
                                 /* Field Access */
@@ -13544,8 +13545,6 @@  static void
 ada_add_global_exceptions (compiled_regex *preg,
 			   std::vector<ada_exc_info> *exceptions)
 {
-  struct objfile *objfile;
-
   /* In Ada, the symbol "search name" is a linkage name, whereas the
      regular expression used to do the matching refers to the natural
      name.  So match against the decoded name.  */
@@ -13559,28 +13558,29 @@  ada_add_global_exceptions (compiled_regex *preg,
 			   NULL,
 			   VARIABLES_DOMAIN);
 
-  ALL_COMPUNITS (objfile, s)
-    {
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
-      int i;
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *s : objfile_compunits (objfile))
+      {
+	const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
+	int i;
 
-      for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
-	{
-	  struct block *b = BLOCKVECTOR_BLOCK (bv, i);
-	  struct block_iterator iter;
-	  struct symbol *sym;
+	for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+	  {
+	    struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+	    struct block_iterator iter;
+	    struct symbol *sym;
 
-	  ALL_BLOCK_SYMBOLS (b, iter, sym)
-	    if (ada_is_non_standard_exception_sym (sym)
-		&& name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg))
-	      {
-		struct ada_exc_info info
-		  = {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
+	    ALL_BLOCK_SYMBOLS (b, iter, sym)
+	      if (ada_is_non_standard_exception_sym (sym)
+		  && name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg))
+		{
+		  struct ada_exc_info info
+		    = {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
 
-		exceptions->push_back (info);
-	      }
-	}
-    }
+		  exceptions->push_back (info);
+		}
+	  }
+      }
 }
 
 /* Implements ada_exceptions_list with the regular expression passed
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index e976354f1f..5b4119b67e 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -1374,7 +1374,6 @@  static void
 add_symbol_overload_list_qualified (const char *func_name,
 				    std::vector<symbol *> *overload_list)
 {
-  struct objfile *objfile;
   const struct block *b, *surrounding_static_block = 0;
 
   /* Look through the partial symtabs for all symbols which begin by
@@ -1397,22 +1396,24 @@  add_symbol_overload_list_qualified (const char *func_name,
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  ALL_COMPUNITS (objfile, cust)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
-    add_symbol_overload_list_block (func_name, b, overload_list);
-  }
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *cust : objfile_compunits (objfile))
+      {
+	QUIT;
+	b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
+	add_symbol_overload_list_block (func_name, b, overload_list);
+      }
 
-  ALL_COMPUNITS (objfile, cust)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
-    /* Don't do this block twice.  */
-    if (b == surrounding_static_block)
-      continue;
-    add_symbol_overload_list_block (func_name, b, overload_list);
-  }
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *cust : objfile_compunits (objfile))
+      {
+	QUIT;
+	b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
+	/* Don't do this block twice.  */
+	if (b == surrounding_static_block)
+	  continue;
+	add_symbol_overload_list_block (func_name, b, overload_list);
+      }
 }
 
 /* Lookup the rtti type for a class name.  */
diff --git a/gdb/maint.c b/gdb/maint.c
index 56fbf3cfba..5cd5b01936 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -762,7 +762,6 @@  static void
 count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
 			  int *nr_blocks_ptr)
 {
-  struct objfile *o;
   struct symtab *s;
   int nr_symtabs = 0;
   int nr_compunit_symtabs = 0;
@@ -773,13 +772,14 @@  count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
      current_program_space may be NULL.  */
   if (current_program_space != NULL)
     {
-      ALL_COMPUNITS (o, cu)
-	{
-	  ++nr_compunit_symtabs;
-	  nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
-	  ALL_COMPUNIT_FILETABS (cu, s)
-	    ++nr_symtabs;
-	}
+      for (struct objfile *o : all_objfiles (current_program_space))
+	for (struct compunit_symtab *cu : objfile_compunits (o))
+	  {
+	    ++nr_compunit_symtabs;
+	    nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
+	    ALL_COMPUNIT_FILETABS (cu, s)
+	      ++nr_symtabs;
+	  }
     }
 
   *nr_symtabs_ptr = nr_symtabs;
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 916d80f571..165a6e3cf1 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -718,12 +718,6 @@  private:
   ALL_OBJFILES (objfile)			\
     ALL_OBJFILE_FILETABS (objfile, ps, s)
 
-/* Traverse all compunits in all objfiles in the current program space.  */
-
-#define ALL_COMPUNITS(objfile, cu)	\
-  ALL_OBJFILES (objfile)		\
-    for (struct compunit_symtab *cu : objfile_compunits (objfile))
-
 #define ALL_OBJFILE_OSECTIONS(objfile, osect)	\
   for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
     if (osect->the_bfd_section == NULL)					\
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 49dd30235c..86fa99b057 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2166,22 +2166,21 @@  lookup_local_symbol (const char *name,
 struct objfile *
 lookup_objfile_from_block (const struct block *block)
 {
-  struct objfile *obj;
-
   if (block == NULL)
     return NULL;
 
   block = block_global_block (block);
   /* Look through all blockvectors.  */
-  ALL_COMPUNITS (obj, cust)
-    if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
-				    GLOBAL_BLOCK))
-      {
-	if (obj->separate_debug_objfile_backlink)
-	  obj = obj->separate_debug_objfile_backlink;
+  for (struct objfile *obj : all_objfiles (current_program_space))
+    for (struct compunit_symtab *cust : objfile_compunits (obj))
+      if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
+				      GLOBAL_BLOCK))
+	{
+	  if (obj->separate_debug_objfile_backlink)
+	    obj = obj->separate_debug_objfile_backlink;
 
-	return obj;
-      }
+	  return obj;
+	}
 
   return NULL;
 }
@@ -2871,7 +2870,6 @@  struct compunit_symtab *
 find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 {
   struct compunit_symtab *best_cust = NULL;
-  struct objfile *objfile;
   CORE_ADDR distance = 0;
   struct bound_minimal_symbol msymbol;
 
@@ -2904,57 +2902,58 @@  find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
      It also happens for objfiles that have their functions reordered.
      For these, the symtab we are looking for is not necessarily read in.  */
 
-  ALL_COMPUNITS (objfile, cust)
-  {
-    struct block *b;
-    const struct blockvector *bv;
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *cust : objfile_compunits (objfile))
+      {
+	struct block *b;
+	const struct blockvector *bv;
 
-    bv = COMPUNIT_BLOCKVECTOR (cust);
-    b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+	bv = COMPUNIT_BLOCKVECTOR (cust);
+	b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
 
-    if (BLOCK_START (b) <= pc
-	&& BLOCK_END (b) > pc
-	&& (distance == 0
-	    || BLOCK_END (b) - BLOCK_START (b) < distance))
-      {
-	/* For an objfile that has its functions reordered,
-	   find_pc_psymtab will find the proper partial symbol table
-	   and we simply return its corresponding symtab.  */
-	/* In order to better support objfiles that contain both
-	   stabs and coff debugging info, we continue on if a psymtab
-	   can't be found.  */
-	if ((objfile->flags & OBJF_REORDERED) && objfile->sf)
+	if (BLOCK_START (b) <= pc
+	    && BLOCK_END (b) > pc
+	    && (distance == 0
+		|| BLOCK_END (b) - BLOCK_START (b) < distance))
 	  {
-	    struct compunit_symtab *result;
-
-	    result
-	      = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile,
-							       msymbol,
-							       pc, section,
-							       0);
-	    if (result != NULL)
-	      return result;
-	  }
-	if (section != 0)
-	  {
-	    struct block_iterator iter;
-	    struct symbol *sym = NULL;
-
-	    ALL_BLOCK_SYMBOLS (b, iter, sym)
+	    /* For an objfile that has its functions reordered,
+	       find_pc_psymtab will find the proper partial symbol table
+	       and we simply return its corresponding symtab.  */
+	    /* In order to better support objfiles that contain both
+	       stabs and coff debugging info, we continue on if a psymtab
+	       can't be found.  */
+	    if ((objfile->flags & OBJF_REORDERED) && objfile->sf)
 	      {
-		fixup_symbol_section (sym, objfile);
-		if (matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, sym),
-					   section))
-		  break;
+		struct compunit_symtab *result;
+
+		result
+		  = objfile->sf->qf->find_pc_sect_compunit_symtab (objfile,
+								   msymbol,
+								   pc, section,
+								   0);
+		if (result != NULL)
+		  return result;
+	      }
+	    if (section != 0)
+	      {
+		struct block_iterator iter;
+		struct symbol *sym = NULL;
+
+		ALL_BLOCK_SYMBOLS (b, iter, sym)
+		  {
+		    fixup_symbol_section (sym, objfile);
+		    if (matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, sym),
+					       section))
+		      break;
+		  }
+		if (sym == NULL)
+		  continue;		/* No symbol in this symtab matches
+					   section.  */
 	      }
-	    if (sym == NULL)
-	      continue;		/* No symbol in this symtab matches
-				   section.  */
+	    distance = BLOCK_END (b) - BLOCK_START (b);
+	    best_cust = cust;
 	  }
-	distance = BLOCK_END (b) - BLOCK_START (b);
-	best_cust = cust;
       }
-  }
 
   if (best_cust != NULL)
     return best_cust;
@@ -4463,7 +4462,7 @@  search_symbols (const char *regexp, enum search_domain kind,
 		  {
 		    /* Note: An important side-effect of these lookup functions
 		       is to expand the symbol table if msymbol is found, for the
-		       benefit of the next loop on ALL_COMPUNITS.  */
+		       benefit of the next loop compunits.  */
 		    if (kind == FUNCTIONS_DOMAIN
 			? (find_pc_compunit_symtab
 			   (MSYMBOL_VALUE_ADDRESS (objfile, msymbol)) == NULL)
@@ -4477,9 +4476,8 @@  search_symbols (const char *regexp, enum search_domain kind,
 	  }
     }
 
-  {
-    struct objfile *objfile;
-    ALL_COMPUNITS (objfile, cust)
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *cust : objfile_compunits (objfile))
       {
 	bv = COMPUNIT_BLOCKVECTOR (cust);
 	for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
@@ -4530,7 +4528,6 @@  search_symbols (const char *regexp, enum search_domain kind,
 	      }
 	  }
       }
-  }
 
   if (!result.empty ())
     sort_search_symbols_remove_dups (&result);
@@ -5274,10 +5271,10 @@  default_collect_symbol_completion_matches_break_on
     }
 
   /* Add completions for all currently loaded symbol tables.  */
-  struct objfile *objfile;
-  ALL_COMPUNITS (objfile, cust)
-    add_symtab_completions (cust, tracker, mode, lookup_name,
-			    sym_text, word, code);
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    for (struct compunit_symtab *cust : objfile_compunits (objfile))
+      add_symtab_completions (cust, tracker, mode, lookup_name,
+			      sym_text, word, code);
 
   /* Look through the partial symtabs for all symbols which begin by
      matching SYM_TEXT.  Expand all CUs that you find to the list.  */