Remove ALL_COMPUNITS
authorTom Tromey <tom@tromey.com>
Sat, 24 Nov 2018 16:20:18 +0000 (09:20 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 10 Jan 2019 01:28:15 +0000 (18:28 -0700)
This removes the ALL_COMPUNITS, replacing its uses with two nested
ranged for loops.

gdb/ChangeLog
2019-01-09  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
gdb/ada-lang.c
gdb/cp-support.c
gdb/maint.c
gdb/objfiles.h
gdb/symtab.c

index 13dca51..70c8497 100644 (file)
@@ -1,5 +1,18 @@
 2019-01-09  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.
+
+2019-01-09  Tom Tromey  <tom@tromey.com>
+
        * source.c (select_source_symtab)
        (forget_cached_source_info_for_objfile): Remove declaration.
        * mi/mi-cmd-file.c (mi_cmd_file_list_exec_source_files): Remove
index 69c368a..f552f13 100644 (file)
@@ -6465,41 +6465,46 @@ 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)
+  for (objfile *objfile : all_objfiles (current_program_space))
     {
-      if (completion_skip_symbol (mode, sym))
-       continue;
+      for (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 (objfile *objfile : all_objfiles (current_program_space))
+    {
+      for (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 */
@@ -13548,8 +13553,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.  */
@@ -13563,26 +13566,29 @@ ada_add_global_exceptions (compiled_regex *preg,
                           NULL,
                           VARIABLES_DOMAIN);
 
-  ALL_COMPUNITS (objfile, s)
+  for (objfile *objfile : all_objfiles (current_program_space))
     {
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
-      int i;
-
-      for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+      for (compunit_symtab *s : objfile_compunits (objfile))
        {
-         struct block *b = BLOCKVECTOR_BLOCK (bv, i);
-         struct block_iterator iter;
-         struct symbol *sym;
+         const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
+         int i;
 
-         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)};
+         for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+           {
+             struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+             struct block_iterator iter;
+             struct symbol *sym;
 
-               exceptions->push_back (info);
-             }
+             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);
+                 }
+           }
        }
     }
 }
index 7906702..16d8176 100644 (file)
@@ -1395,23 +1395,28 @@ add_symbol_overload_list_qualified (const char *func_name,
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  struct objfile *objfile;
-  ALL_COMPUNITS (objfile, cust)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
-    add_symbol_overload_list_block (func_name, b, overload_list);
-  }
+  for (objfile *objfile : all_objfiles (current_program_space))
+    {
+      for (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 (objfile *objfile : all_objfiles (current_program_space))
+    {
+      for (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.  */
index a4241cd..d969e79 100644 (file)
@@ -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,12 +772,15 @@ 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)
+      for (objfile *o : all_objfiles (current_program_space))
        {
-         ++nr_compunit_symtabs;
-         nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
-         ALL_COMPUNIT_FILETABS (cu, s)
-           ++nr_symtabs;
+         for (compunit_symtab *cu : objfile_compunits (o))
+           {
+             ++nr_compunit_symtabs;
+             nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
+             ALL_COMPUNIT_FILETABS (cu, s)
+               ++nr_symtabs;
+           }
        }
     }
 
index ba6be2d..ae6a779 100644 (file)
@@ -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 (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)                                        \
index 0cd5119..e6e001b 100644 (file)
@@ -2166,22 +2166,23 @@ 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 (objfile *obj : all_objfiles (current_program_space))
+    {
+      for (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 +2872,6 @@ struct compunit_symtab *
 find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 {
   struct compunit_symtab *best_cust = NULL;
-  struct objfile *obj_file;
   CORE_ADDR distance = 0;
   struct bound_minimal_symbol msymbol;
 
@@ -2904,57 +2904,62 @@ 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 (obj_file, cust)
-  {
-    struct block *b;
-    const struct blockvector *bv;
+  for (objfile *obj_file : all_objfiles (current_program_space))
+    {
+      for (compunit_symtab *cust : objfile_compunits (obj_file))
+       {
+         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 ((obj_file->flags & OBJF_REORDERED) && obj_file->sf)
-         {
-           struct compunit_symtab *result;
-
-           result
-             = obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file,
-                                                               msymbol,
-                                                               pc, section,
-                                                               0);
-           if (result != NULL)
-             return result;
-         }
-       if (section != 0)
-         {
-           struct block_iterator iter;
-           struct symbol *sym = NULL;
+         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 ((obj_file->flags & OBJF_REORDERED) && obj_file->sf)
+               {
+                 struct compunit_symtab *result;
+
+                 result
+                   = obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file,
+                                                                     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, obj_file);
-               if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file, sym),
-                                          section))
-                 break;
-             }
-           if (sym == NULL)
-             continue;         /* No symbol in this symtab matches
-                                  section.  */
-         }
-       distance = BLOCK_END (b) - BLOCK_START (b);
-       best_cust = cust;
-      }
-  }
+                 ALL_BLOCK_SYMBOLS (b, iter, sym)
+                   {
+                     fixup_symbol_section (sym, obj_file);
+                     if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file,
+                                                                    sym),
+                                                section))
+                       break;
+                   }
+                 if (sym == NULL)
+                   continue;           /* No symbol in this symtab matches
+                                          section.  */
+               }
+             distance = BLOCK_END (b) - BLOCK_START (b);
+             best_cust = cust;
+           }
+       }
+    }
 
   if (best_cust != NULL)
     return best_cust;
@@ -4465,7 +4470,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.  */
+                        the next loop on compunits.  */
                      if (kind == FUNCTIONS_DOMAIN
                          ? (find_pc_compunit_symtab
                             (MSYMBOL_VALUE_ADDRESS (objfile, msymbol))
@@ -4481,60 +4486,60 @@ search_symbols (const char *regexp, enum search_domain kind,
        }
     }
 
-  {
-    struct objfile *objfile;
-    ALL_COMPUNITS (objfile, cust)
-      {
-       bv = COMPUNIT_BLOCKVECTOR (cust);
-       for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
-         {
-           b = BLOCKVECTOR_BLOCK (bv, i);
-           ALL_BLOCK_SYMBOLS (b, iter, sym)
-             {
-               struct symtab *real_symtab = symbol_symtab (sym);
-
-               QUIT;
-
-               /* Check first sole REAL_SYMTAB->FILENAME.  It does
-                  not need to be a substring of symtab_to_fullname as
-                  it may contain "./" etc.  */
-               if ((file_matches (real_symtab->filename, files, nfiles, 0)
-                    || ((basenames_may_differ
-                         || file_matches (lbasename (real_symtab->filename),
-                                          files, nfiles, 1))
-                        && file_matches (symtab_to_fullname (real_symtab),
-                                         files, nfiles, 0)))
-                   && ((!preg.has_value ()
-                        || preg->exec (SYMBOL_NATURAL_NAME (sym), 0,
-                                       NULL, 0) == 0)
-                       && ((kind == VARIABLES_DOMAIN
-                            && SYMBOL_CLASS (sym) != LOC_TYPEDEF
-                            && SYMBOL_CLASS (sym) != LOC_UNRESOLVED
-                            && SYMBOL_CLASS (sym) != LOC_BLOCK
-                            /* LOC_CONST can be used for more than
-                               just enums, e.g., c++ static const
-                               members.  We only want to skip enums
-                               here.  */
-                            && !(SYMBOL_CLASS (sym) == LOC_CONST
-                                 && (TYPE_CODE (SYMBOL_TYPE (sym))
-                                     == TYPE_CODE_ENUM))
-                            && (!treg.has_value ()
-                                || treg_matches_sym_type_name (*treg, sym)))
-                           || (kind == FUNCTIONS_DOMAIN
-                               && SYMBOL_CLASS (sym) == LOC_BLOCK
-                               && (!treg.has_value ()
-                                   || treg_matches_sym_type_name (*treg,
-                                                                  sym)))
-                           || (kind == TYPES_DOMAIN
-                               && SYMBOL_CLASS (sym) == LOC_TYPEDEF))))
-                 {
-                   /* match */
-                   result.emplace_back (i, sym);
-                 }
-             }
-         }
-      }
-  }
+  for (objfile *objfile : all_objfiles (current_program_space))
+    {
+      for (compunit_symtab *cust : objfile_compunits (objfile))
+       {
+         bv = COMPUNIT_BLOCKVECTOR (cust);
+         for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+           {
+             b = BLOCKVECTOR_BLOCK (bv, i);
+             ALL_BLOCK_SYMBOLS (b, iter, sym)
+               {
+                 struct symtab *real_symtab = symbol_symtab (sym);
+
+                 QUIT;
+
+                 /* Check first sole REAL_SYMTAB->FILENAME.  It does
+                    not need to be a substring of symtab_to_fullname as
+                    it may contain "./" etc.  */
+                 if ((file_matches (real_symtab->filename, files, nfiles, 0)
+                      || ((basenames_may_differ
+                           || file_matches (lbasename (real_symtab->filename),
+                                            files, nfiles, 1))
+                          && file_matches (symtab_to_fullname (real_symtab),
+                                           files, nfiles, 0)))
+                     && ((!preg.has_value ()
+                          || preg->exec (SYMBOL_NATURAL_NAME (sym), 0,
+                                         NULL, 0) == 0)
+                         && ((kind == VARIABLES_DOMAIN
+                              && SYMBOL_CLASS (sym) != LOC_TYPEDEF
+                              && SYMBOL_CLASS (sym) != LOC_UNRESOLVED
+                              && SYMBOL_CLASS (sym) != LOC_BLOCK
+                              /* LOC_CONST can be used for more than
+                                 just enums, e.g., c++ static const
+                                 members.  We only want to skip enums
+                                 here.  */
+                              && !(SYMBOL_CLASS (sym) == LOC_CONST
+                                   && (TYPE_CODE (SYMBOL_TYPE (sym))
+                                       == TYPE_CODE_ENUM))
+                              && (!treg.has_value ()
+                                  || treg_matches_sym_type_name (*treg, sym)))
+                             || (kind == FUNCTIONS_DOMAIN
+                                 && SYMBOL_CLASS (sym) == LOC_BLOCK
+                                 && (!treg.has_value ()
+                                     || treg_matches_sym_type_name (*treg,
+                                                                    sym)))
+                             || (kind == TYPES_DOMAIN
+                                 && SYMBOL_CLASS (sym) == LOC_TYPEDEF))))
+                   {
+                     /* match */
+                     result.emplace_back (i, sym);
+                   }
+               }
+           }
+       }
+    }
 
   if (!result.empty ())
     sort_search_symbols_remove_dups (&result);
@@ -5282,10 +5287,12 @@ 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 (objfile *objfile : all_objfiles (current_program_space))
+    {
+      for (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.  */