]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/buildsym: make buildsym_compunit return a reference
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 19 Dec 2025 18:43:42 +0000 (13:43 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 5 Jan 2026 20:26:32 +0000 (15:26 -0500)
This is more C++-y.  Remove the struct keywords from pop_context just to
match.

Rename "newobj" to "ctx" in the users of context_stack, because I think
the "newobj" name is meaningless.

For a later task: I think we should find a better name for
context_stack, because it is not a stack (it is an entry in the context
stack).

Change-Id: Ibc66b910ab0f31b367b99812e0469311a99641c9
Approved-By: Tom Tromey <tom@tromey.com>
gdb/buildsym-legacy.c
gdb/buildsym-legacy.h
gdb/buildsym.c
gdb/buildsym.h
gdb/coffread.c
gdb/dwarf2/read.c

index 2a09a701767425825a22e310e486d287fa1fcd18..68a2e1ebafc6f31c51ef7e4525674913d9db8ade 100644 (file)
@@ -170,14 +170,14 @@ end_compunit_symtab (CORE_ADDR end_addr)
   return result;
 }
 
-struct context_stack *
+context_stack &
 push_context (int desc, CORE_ADDR valu)
 {
   gdb_assert (buildsym_compunit != nullptr);
   return buildsym_compunit->push_context (desc, valu);
 }
 
-struct context_stack
+context_stack
 pop_context ()
 {
   gdb_assert (buildsym_compunit != nullptr);
index 756c1ee1f88e264dadf7706cd5d6c527f2775c71..e13a0673fa9abce406ad5a0394e51048fe07ba2e 100644 (file)
@@ -82,9 +82,9 @@ extern const char *pop_subfile ();
 
 extern struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr);
 
-extern struct context_stack *push_context (int desc, CORE_ADDR valu);
+extern context_stack &push_context (int desc, CORE_ADDR valu);
 
-extern struct context_stack pop_context ();
+extern context_stack pop_context ();
 
 extern void record_line (struct subfile *subfile, int line,
                         unrelocated_addr pc);
index f8daaccac296f5eab96e2d9a0d37050dd4cf0c24..60fb5c7fd0ad4d1d8df13a849dfb36c6076c1d70 100644 (file)
@@ -1061,32 +1061,32 @@ buildsym_compunit::augment_type_symtab ()
    (checkable when you pop it), and the starting PC address of this
    context.  */
 
-struct context_stack *
+context_stack &
 buildsym_compunit::push_context (int desc, CORE_ADDR valu)
 {
-  struct context_stack *newobj = &m_context_stack.emplace_back ();
+  context_stack &ctx = m_context_stack.emplace_back ();
 
-  newobj->depth = desc;
-  newobj->locals = m_local_symbols;
-  newobj->old_blocks = m_pending_blocks;
-  newobj->start_addr = valu;
-  newobj->local_using_directives = m_local_using_directives;
-  newobj->name = NULL;
+  ctx.depth = desc;
+  ctx.locals = m_local_symbols;
+  ctx.old_blocks = m_pending_blocks;
+  ctx.start_addr = valu;
+  ctx.local_using_directives = m_local_using_directives;
+  ctx.name = NULL;
 
   m_local_symbols = NULL;
   m_local_using_directives = NULL;
 
-  return newobj;
+  return ctx;
 }
 
 /* Pop a context block.  Returns the address of the context block just
    popped.  */
 
-struct context_stack
+context_stack
 buildsym_compunit::pop_context ()
 {
   gdb_assert (!m_context_stack.empty ());
-  struct context_stack result = m_context_stack.back ();
+  context_stack result = m_context_stack.back ();
   m_context_stack.pop_back ();
   return result;
 }
index 456489f1b30906da2174229ecde4f911c8760015..4ab91bf9e9fa2ff1ae3477234c2006af7729ce4d 100644 (file)
@@ -306,9 +306,9 @@ struct buildsym_compunit
     m_producer = producer;
   }
 
-  struct context_stack *push_context (int desc, CORE_ADDR valu);
+  context_stack &push_context (int desc, CORE_ADDR valu);
 
-  struct context_stack pop_context ();
+  context_stack pop_context ();
 
   struct block *end_compunit_symtab_get_static_block
     (CORE_ADDR end_addr, bool expandable, bool required);
index 67a0271f9dcec3f70dd7d20aac2141b6ef75550b..d88fdd0926210f5e1706be3e8676415630230d2c 100644 (file)
@@ -745,7 +745,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
                  struct objfile *objfile)
 {
   struct gdbarch *gdbarch = objfile->arch ();
-  struct context_stack *newobj = nullptr;
+  context_stack *ctx = nullptr;
   struct coff_symbol coff_symbol;
   struct coff_symbol *cs = &coff_symbol;
   static struct internal_syment main_sym;
@@ -1029,11 +1029,10 @@ coff_symtab_read (minimal_symbol_reader &reader,
                 context_stack_depth is zero, and complain if not.  */
 
              depth = 0;
-             newobj = push_context (depth, fcn_start_addr);
+             ctx = &push_context (depth, fcn_start_addr);
              fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
-             newobj->name =
-               process_coff_symbol (&fcn_cs_saved,
-                                    &fcn_aux_saved, objfile);
+             ctx->name
+               = process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved, objfile);
            }
          else if (strcmp (cs->c_name, ".ef") == 0)
            {
@@ -1055,7 +1054,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
 
              struct context_stack cstk = pop_context ();
              /* Stack must be empty now.  */
-             if (!outermost_context_p () || newobj == NULL)
+             if (!outermost_context_p () || ctx == nullptr)
                {
                  complaint (_("Unmatched .ef symbol(s) ignored "
                               "starting at symnum %d"),
index 35081aa3a6989c958aede0e379433b5d3c659e32..4f7e1c889f4492d3f3cf5519a763ba3312516321 100644 (file)
@@ -8505,7 +8505,6 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
   struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
-  struct context_stack *newobj;
   CORE_ADDR lowpc;
   CORE_ADDR highpc;
   struct attribute *attr, *call_line, *call_file;
@@ -8596,27 +8595,27 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   gdb_assert (cu->get_builder () != nullptr);
-  newobj = cu->get_builder ()->push_context (0, lowpc);
-  newobj->name = new_symbol (die, read_type_die (die, cu), cu, templ_func);
+  context_stack &ctx = cu->get_builder ()->push_context (0, lowpc);
+  ctx.name = new_symbol (die, read_type_die (die, cu), cu, templ_func);
 
   if (dwarf2_func_is_main_p (die, cu))
-    set_objfile_main_name (objfile, newobj->name->linkage_name (),
+    set_objfile_main_name (objfile, ctx.name->linkage_name (),
                           cu->lang ());
 
   /* If there is a location expression for DW_AT_frame_base, record
      it.  */
   attr = dwarf2_attr (die, DW_AT_frame_base, cu);
   if (attr != nullptr)
-    dwarf2_symbol_mark_computed (attr, newobj->name, cu, 1);
+    dwarf2_symbol_mark_computed (attr, ctx.name, cu, 1);
 
   /* If there is a location for the static link, record it.  */
-  newobj->static_link = NULL;
+  ctx.static_link = NULL;
   attr = dwarf2_attr (die, DW_AT_static_link, cu);
   if (attr != nullptr)
     {
-      newobj->static_link
+      ctx.static_link
        = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
-      attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
+      attr_to_dynamic_prop (attr, die, cu, ctx.static_link,
                            cu->addr_type ());
     }