]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove OBJSTAT and OBJSTATS macros master
authorTom Tromey <tromey@adacore.com>
Fri, 17 Apr 2026 18:34:20 +0000 (12:34 -0600)
committerTom Tromey <tromey@adacore.com>
Mon, 20 Apr 2026 14:26:27 +0000 (08:26 -0600)
The OBJSTATS macro seems pretty pointless, so I removed it.  Then when
looking at the OBJSTAT macro as well, I decided to remove it and also
struct objstats.

After this patch, symbols are allocated using a template method that
automatically updates the n_syms member.  This cleans up the code a
little.

Also, nothing ever set objstats::sz_strtab, so this is removed.

Regression tested on x86-64 Fedora 43.

Approved-by: Kevin Buettner <kevinb@redhat.com>
gdb/ctfread.c
gdb/dwarf2/read.c
gdb/gdbtypes.c
gdb/objfiles.h
gdb/symmisc.c

index 0ddb23253442eed291387c4d5ecc97b02ad9e3f3..5f8c54a34dfdf334bf449a63eb831128f197268b 100644 (file)
@@ -416,8 +416,7 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
   if (name != nullptr && *name != '\0')
     {
       objfile *objfile = ccp->per_objfile->objfile;
-      struct symbol *sym = new (&objfile->objfile_obstack) symbol;
-      OBJSTAT (objfile, n_syms++);
+      symbol *sym = objfile->new_symbol<symbol> ();
 
       sym->set_language (language_c, &objfile->objfile_obstack);
       sym->compute_and_set_names (name, false, objfile->per_bfd);
@@ -444,8 +443,7 @@ new_type_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
   if (name != nullptr && *name != '\0')
     {
       objfile *objfile = ccp->per_objfile->objfile;
-      struct symbol *sym = new (&objfile->objfile_obstack) symbol;
-      OBJSTAT (objfile, n_syms++);
+      symbol *sym = objfile->new_symbol<symbol> ();
 
       sym->set_language (language_c, &objfile->objfile_obstack);
       sym->compute_and_set_names (name, false, objfile->per_bfd);
@@ -1131,8 +1129,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
       complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id);
       type = builtin_type (objfile)->builtin_error;
     }
-  sym = new (&objfile->objfile_obstack) symbol;
-  OBJSTAT (objfile, n_syms++);
+  sym = objfile->new_symbol<symbol> ();
   sym->set_type (type);
   sym->set_loc_class_index (LOC_OPTIMIZED_OUT);
   sym->compute_and_set_names (name, false, objfile->per_bfd);
@@ -1178,8 +1175,7 @@ add_stt_entries (struct ctf_context *ccp, int functions)
       ctf_debug_printf ("adding %s '%s' tid=0x%lx",
                        functions ? "function" : "object", tname, tid);
 
-      sym = new (&objfile->objfile_obstack) symbol;
-      OBJSTAT (objfile, n_syms++);
+      sym = objfile->new_symbol<symbol> ();
       sym->set_type (type);
       sym->set_domain (functions ? FUNCTION_DOMAIN : VAR_DOMAIN);
       sym->set_loc_class_index (LOC_STATIC);
index 0c95a582e7ffc9b95a04375740b8a81aebb2348c..375e8a75db49bfc7e465316e6888f138e0444ef0 100644 (file)
@@ -7795,7 +7795,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       if (child_die->tag == DW_TAG_template_type_param
          || child_die->tag == DW_TAG_template_value_param)
        {
-         templ_func = new (&objfile->objfile_obstack) template_symbol;
+         templ_func = objfile->new_symbol<template_symbol> ();
          templ_func->subclass = SYMBOL_TEMPLATE;
          break;
        }
@@ -8329,7 +8329,7 @@ read_variable (struct die_info *die, struct dwarf2_cu *cu)
        {
          struct objfile *objfile = cu->per_objfile->objfile;
 
-         storage = new (&objfile->objfile_obstack) rust_vtable_symbol;
+         storage = objfile->new_symbol<rust_vtable_symbol> ();
          storage->concrete_type = containing_type;
          storage->subclass = SYMBOL_RUST_VTABLE;
        }
@@ -15461,8 +15461,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       if (space)
        sym = space;
       else
-       sym = new (&objfile->objfile_obstack) symbol;
-      OBJSTAT (objfile, n_syms++);
+       sym = objfile->new_symbol<symbol> ();
 
       /* Cache this symbol's name and the name's demangled form (if any).  */
       sym->set_language (cu->lang (), &objfile->objfile_obstack);
index 07a8c7065ea81f2f91a134bbfdc071165b24a07b..2f566583509ed4637868c154542b2ffb83ab3181 100644 (file)
@@ -222,7 +222,7 @@ type_allocator::new_type ()
 
   if (m_is_objfile)
     {
-      OBJSTAT (m_data.objfile, n_types++);
+      ++m_data.objfile->n_types;
       type->set_owner (m_data.objfile);
     }
   else
index 58c4ff810088dbcef6f206965b563a4afa5166b5..c8b989911e5f4d64ef00d6fbc997512217f36c27 100644 (file)
@@ -142,25 +142,6 @@ struct entry_info
    uninitialized section index.  */
 #define SECT_OFF_BSS(objfile) (objfile)->sect_index_bss
 
-/* The "objstats" structure provides a place for gdb to record some
-   interesting information about its internal state at runtime, on a
-   per objfile basis, such as information about the number of symbols
-   read, size of string table (if any), etc.  */
-
-struct objstats
-{
-  /* Number of full symbols read.  */
-  int n_syms = 0;
-
-  /* Number of types.  */
-  int n_types = 0;
-
-  /* Size of stringtable, (if applicable).  */
-  int sz_strtab = 0;
-};
-
-#define OBJSTAT(objfile, expr) (objfile -> stats.expr)
-#define OBJSTATS struct objstats stats
 extern void print_objfile_statistics (void);
 
 /* Number of entries in the minimal symbol hash table.  */
@@ -689,6 +670,17 @@ public:
             section_iterator (sections_end, sections_end)));
   }
 
+  /* Allocate a new symbol on this objfile's obstack.  Normally a
+     symbol is made, but other subtypes (e.g., template_symbol) can
+     also be created.  */
+  template<typename T>
+  T *new_symbol ()
+  {
+    T *result = new (&objfile_obstack) T;
+    ++n_syms;
+    return result;
+  }
+
 public:
 
   /* The object file's original name as specified by the user,
@@ -818,9 +810,11 @@ public:
 
   struct objfile *separate_debug_objfile_link = nullptr;
 
-  /* Place to stash various statistics about this objfile.  */
+  /* Number of full symbols read.  */
+  int n_syms = 0;
 
-  OBJSTATS;
+  /* Number of types.  */
+  int n_types = 0;
 
   /* A linked list of symbols created when reading template types or
      function templates.  These symbols are not stored in any symbol
index b586f8fdb004670c8940ea70195cd497a46e7464..89374bd8a2ffe256249caedd91e84c631bded4c7 100644 (file)
@@ -63,12 +63,12 @@ print_objfile_statistics (void)
        if (objfile.per_bfd->n_minsyms > 0)
          gdb_printf (_("  Number of \"minimal\" symbols read: %d\n"),
                      objfile.per_bfd->n_minsyms);
-       if (OBJSTAT ((&objfile), n_syms) > 0)
+       if (objfile.n_syms > 0)
          gdb_printf (_("  Number of \"full\" symbols read: %d\n"),
-                     OBJSTAT ((&objfile), n_syms));
-       if (OBJSTAT ((&objfile), n_types) > 0)
+                     objfile.n_syms);
+       if (objfile.n_types > 0)
          gdb_printf (_("  Number of \"types\" defined: %d\n"),
-                     OBJSTAT ((&objfile), n_types));
+                     objfile.n_types);
 
        i = linetables = 0;
        for (compunit_symtab &cu : objfile.compunits ())
@@ -90,9 +90,6 @@ print_objfile_statistics (void)
 
        objfile.print_stats (false);
 
-       if (OBJSTAT ((&objfile), sz_strtab) > 0)
-         gdb_printf (_("  Space used by string tables: %d\n"),
-                     OBJSTAT ((&objfile), sz_strtab));
        gdb_printf (_("  Total memory used for objfile obstack: %s\n"),
                    pulongest (obstack_memory_used (&objfile
                                                    .objfile_obstack)));