[5/6] gdb/buildsym: add constructor to context_stack

Message ID 20251219184426.406228-5-simon.marchi@efficios.com
State New
Headers
Series [1/6] gdb/buildsym: remove find_symbol_in_list |

Commit Message

Simon Marchi Dec. 19, 2025, 6:43 p.m. UTC
  This makes it clearer what is set up front vs what is set later by
callers.

Change-Id: I2ee8d053c068f2b9ca37d48834aa688aeb6c0560
---
 gdb/buildsym.c | 15 +++++----------
 gdb/buildsym.h | 13 +++++++++++--
 2 files changed, 16 insertions(+), 12 deletions(-)
  

Comments

Tom Tromey Jan. 5, 2026, 4:55 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> This makes it clearer what is set up front vs what is set later by
Simon> callers.

Looks great, thank you.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 2259caad6ad6..bf1698dba794 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -1064,17 +1064,12 @@  buildsym_compunit::augment_type_symtab ()
 context_stack &
 buildsym_compunit::push_context (int desc, CORE_ADDR valu)
 {
-  context_stack &ctx = m_context_stack.emplace_back ();
+  context_stack &ctx
+    = m_context_stack.emplace_back (m_local_symbols, m_local_using_directives,
+				    m_pending_blocks, valu, desc);
 
-  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;
+  m_local_symbols = nullptr;
+  m_local_using_directives = nullptr;
 
   return ctx;
 }
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index c2b61b3f9fac..96cee966cc82 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -86,6 +86,15 @@  struct pending
 
 struct context_stack
 {
+  context_stack (pending *locals, using_direct *local_using_directives,
+		 pending_block *old_blocks, CORE_ADDR start_addr, int depth)
+    : locals (locals),
+      local_using_directives (local_using_directives),
+      old_blocks (old_blocks),
+      start_addr (start_addr),
+      depth (depth)
+  {}
+
   /* Outer locals at the time we entered.  */
   pending *locals;
 
@@ -96,11 +105,11 @@  struct context_stack
   pending_block *old_blocks;
 
   /* Name of function, if any, defining context.  */
-  symbol *name;
+  symbol *name = nullptr;
 
   /* Expression that computes the frame base of the lexically enclosing
      function, if any.  NULL otherwise.  */
-  dynamic_prop *static_link;
+  dynamic_prop *static_link = nullptr;
 
   /* PC where this context starts.  */
   CORE_ADDR start_addr;