Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH] Remove OBJSTAT and OBJSTATS macros
Date: Fri, 17 Apr 2026 13:20:39 -0600	[thread overview]
Message-ID: <20260417192039.2758461-1-tromey@adacore.com> (raw)

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.
---
 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 4035bba6e45..9eedfe2794c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7797,7 +7797,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;
 	}
@@ -8351,7 +8351,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;
 	}
@@ -15479,8 +15479,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 89ac559ce81..fc6d9d97c83 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.  */
@@ -694,6 +675,17 @@ struct objfile : intrusive_list_node<objfile>
 	     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,
@@ -823,9 +815,11 @@ struct objfile : intrusive_list_node<objfile>
 
   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)));

base-commit: bfd118583ed69db365265915d1a48eb719e997f5
-- 
2.53.0


             reply	other threads:[~2026-04-17 19:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-17 19:20 Tom Tromey [this message]
2026-04-17 22:01 ` Kevin Buettner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260417192039.2758461-1-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox