[binutils-gdb] Remove OBJSTAT and OBJSTATS macros

Tom Tromey via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9b9cbb09d85e40adb9a22f3c97de74b6c9c5e205

commit 9b9cbb09d85e40adb9a22f3c97de74b6c9c5e205
Author: Tom Tromey <[email protected]>
Date:   Fri Apr 17 12:34:20 2026 -0600

    Remove OBJSTAT and OBJSTATS macros
    
    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 <[email protected]>

Diff:
---
 gdb/ctfread.c     | 12 ++++--------
 gdb/dwarf2/read.c |  7 +++----
 gdb/gdbtypes.c    |  2 +-
 gdb/objfiles.h    | 36 +++++++++++++++---------------------
 gdb/symmisc.c     | 11 ++++-------
 5 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 0ddb2325344..5f8c54a34df 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -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);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0c95a582e7f..375e8a75db4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 07a8c7065ea..2f566583509 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -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
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 58c4ff81008..c8b989911e5 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -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
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index b586f8fdb00..89374bd8a2f 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -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)));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.