gdb: remove COMPUNIT_FILETABS macro
authorSimon Marchi <simon.marchi@efficios.com>
Sat, 20 Nov 2021 02:35:17 +0000 (21:35 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sun, 6 Feb 2022 20:48:18 +0000 (15:48 -0500)
I think that most remaining uses of COMPUNIT_FILETABS intend to get the
primary filetab of the compunit_symtab specifically (and not to iterate
over all filetabs, for example, those cases would use compunit_filetabs,
which has been converted to compunit_symtab::filetabs), so replace mosts
uses with compunit_symtab::primary_filetab.

In jit.c, function finalize_symtab, we can save the symtab object
returned by allocate_symtab and use it, it makes things simpler.

Change-Id: I4e51d6d4b40759de8768b61292e5e13c8eae2e38

gdb/buildsym.c
gdb/dwarf2/read.c
gdb/jit.c
gdb/linespec.c
gdb/mdebugread.c
gdb/symmisc.c
gdb/symtab.h

index 914834f8e51f0a09d791fd18c76cb4a729e5fe88..855d84bd27a62e08864fd41aa2e84b3710e6e118 100644 (file)
@@ -1031,7 +1031,7 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
     int block_i;
 
     /* The main source file's symtab.  */
-    struct symtab *symtab = COMPUNIT_FILETABS (cu);
+    struct symtab *symtab = cu->primary_filetab ();
 
     for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
       {
@@ -1150,7 +1150,7 @@ set_missing_symtab (struct pending *pending_list,
       for (i = 0; i < pending->nsyms; ++i)
        {
          if (symbol_symtab (pending->symbol[i]) == NULL)
-           symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
+           symbol_set_symtab (pending->symbol[i], cu->primary_filetab ());
        }
     }
 }
index 84877e6c7fe0d39487a1d349f80a771f3e61b0d2..7e62d11aa2cc71be999126cc4a0f46de76ad2965 100644 (file)
@@ -9477,8 +9477,8 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
         compilation is from a C file generated by language preprocessors, do
         not set the language if it was already deduced by start_subfile.  */
       if (!(cu->per_cu->lang == language_c
-           && COMPUNIT_FILETABS (cust)->language != language_unknown))
-       COMPUNIT_FILETABS (cust)->language = cu->per_cu->lang;
+           && cust->primary_filetab ()->language != language_unknown))
+       cust->primary_filetab ()->language = cu->per_cu->lang;
 
       /* GCC-4.0 has started to support -fvar-tracking.  GCC-3.x still can
         produce DW_AT_location with location lists but it can be possibly
@@ -9562,8 +9562,8 @@ process_full_type_unit (dwarf2_cu *cu,
             do not set the language if it was already deduced by
             start_subfile.  */
          if (!(cu->per_cu->lang == language_c
-               && COMPUNIT_FILETABS (cust)->language != language_c))
-           COMPUNIT_FILETABS (cust)->language = cu->per_cu->lang;
+               && cust->primary_filetab ()->language != language_c))
+           cust->primary_filetab ()->language = cu->per_cu->lang;
        }
     }
   else
index 356525443cb246f9ca172d00f3fc52389387e60e..6366c7511e6b8e2b8bf33ca6d484f9a8d3d8cacb 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -509,7 +509,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
     });
 
   cust = allocate_compunit_symtab (objfile, stab->file_name.c_str ());
-  allocate_symtab (cust, stab->file_name.c_str ());
+  symtab *filetab = allocate_symtab (cust, stab->file_name.c_str ());
   add_compunit_symtab_to_objfile (cust);
 
   /* JIT compilers compile in memory.  */
@@ -521,9 +521,9 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       size_t size = ((stab->linetable->nitems - 1)
                     * sizeof (struct linetable_entry)
                     + sizeof (struct linetable));
-      SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust))
+      SYMTAB_LINETABLE (filetab)
        = (struct linetable *) obstack_alloc (&objfile->objfile_obstack, size);
-      memcpy (SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust)),
+      memcpy (SYMTAB_LINETABLE (filetab),
              stab->linetable.get (), size);
     }
 
@@ -562,7 +562,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       /* The name.  */
       SYMBOL_DOMAIN (block_name) = VAR_DOMAIN;
       SYMBOL_ACLASS_INDEX (block_name) = LOC_BLOCK;
-      symbol_set_symtab (block_name, COMPUNIT_FILETABS (cust));
+      symbol_set_symtab (block_name, filetab);
       SYMBOL_TYPE (block_name) = lookup_function_type (block_type);
       SYMBOL_BLOCK_VALUE (block_name) = new_block;
 
index 27ceaa41adbda021aadec6b0b91a288aa407752e..d50251578338a48d303a459dc9a02edd2986418c 100644 (file)
@@ -1179,7 +1179,7 @@ iterate_over_all_matching_symtabs
 
          for (compunit_symtab *cu : objfile->compunits ())
            {
-             struct symtab *symtab = COMPUNIT_FILETABS (cu);
+             struct symtab *symtab = cu->primary_filetab ();
 
              iterate_over_file_blocks (symtab, lookup_name, name_domain,
                                        callback);
index 1b327ad61153b167601f9cb2aaa5d8d91c80425f..836da8a3b8caa7360a40c5fbe32a2ff4738a737a 100644 (file)
@@ -4084,17 +4084,17 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 
          /* The proper language was already determined when building
             the psymtab, use it.  */
-         COMPUNIT_FILETABS (cust)->language = PST_PRIVATE (pst)->pst_language;
+         cust->primary_filetab ()->language = PST_PRIVATE (pst)->pst_language;
        }
 
-      psymtab_language = COMPUNIT_FILETABS (cust)->language;
+      psymtab_language = cust->primary_filetab ()->language;
 
-      lines = SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust));
+      lines = SYMTAB_LINETABLE (cust->primary_filetab ());
 
       /* Get a new lexical context.  */
 
       push_parse_stack ();
-      top_stack->cur_st = COMPUNIT_FILETABS (cust);
+      top_stack->cur_st = cust->primary_filetab ();
       top_stack->cur_block
        = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
       BLOCK_START (top_stack->cur_block) = pst->text_low (objfile);
@@ -4173,7 +4173,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
       size = lines->nitems;
       if (size > 1)
        --size;
-      SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust))
+      SYMTAB_LINETABLE (cust->primary_filetab ())
        = ((struct linetable *)
           obstack_copy (&mdebugread_objfile->objfile_obstack,
                         lines, (sizeof (struct linetable)
@@ -4183,7 +4183,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
       /* .. and our share of externals.
         XXX use the global list to speed up things here.  How?
         FIXME, Maybe quit once we have found the right number of ext's?  */
-      top_stack->cur_st = COMPUNIT_FILETABS (cust);
+      top_stack->cur_st = cust->primary_filetab ();
       top_stack->cur_block
        = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (top_stack->cur_st),
                             GLOBAL_BLOCK);
@@ -4201,7 +4201,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
        {
          printf_filtered (_("File %s contains %d unresolved references:"),
                           symtab_to_filename_for_display
-                            (COMPUNIT_FILETABS (cust)),
+                            (cust->primary_filetab ()),
                           n_undef_symbols);
          printf_filtered ("\n\t%4d variables\n\t%4d "
                           "procedures\n\t%4d labels\n",
@@ -4211,7 +4211,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
        }
       pop_parse_stack ();
 
-      sort_blocks (COMPUNIT_FILETABS (cust));
+      sort_blocks (cust->primary_filetab ());
     }
 
   /* Now link the psymtab and the symtab.  */
index b4b58f6e0f51081acadfa799700276e51ab6169d..61e3eff562e50378555e0d63c3569a4e693e329b 100644 (file)
@@ -329,8 +329,9 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
     }
   else
     {
+      compunit_symtab *compunit = SYMTAB_COMPUNIT (symtab);
       const char *compunit_filename
-       = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab)));
+       = symtab_to_filename_for_display (compunit->primary_filetab ());
 
       fprintf_filtered (outfile,
                        "\nBlockvector same as owning compunit: %s\n\n",
@@ -346,7 +347,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
       if (cust->user != nullptr)
        {
          const char *addr
-           = host_address_to_string (COMPUNIT_FILETABS (cust->user));
+           = host_address_to_string (cust->user->primary_filetab ());
          fprintf_filtered (outfile, "Compunit user: %s\n", addr);
        }
       if (cust->includes != nullptr)
@@ -356,7 +357,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
            if (include == nullptr)
              break;
            const char *addr
-             = host_address_to_string (COMPUNIT_FILETABS (include));
+             = host_address_to_string (include->primary_filetab ());
            fprintf_filtered (outfile, "Compunit include: %s\n", addr);
          }
     }
index 670826dd183256dcf9f123528eb9641b14d780a6..45d4bc4dc2998b3c2be74431cde0029fb365e9ce 100644 (file)
@@ -1577,7 +1577,6 @@ struct compunit_symtab
 
 using compunit_symtab_range = next_range<compunit_symtab>;
 
-#define COMPUNIT_FILETABS(cust) (*(cust)->filetabs ().begin ())
 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
 #define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
@@ -1596,7 +1595,7 @@ extern enum language compunit_language (const struct compunit_symtab *cust);
 static inline bool
 is_main_symtab_of_compunit_symtab (struct symtab *symtab)
 {
-  return symtab == COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab));
+  return symtab == SYMTAB_COMPUNIT (symtab)->primary_filetab ();
 }
 \f