From patchwork Fri Dec 19 18:43:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 126898 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 6D5584BA2E33 for ; Fri, 19 Dec 2025 18:45:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D5584BA2E33 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 57A404BA2E31 for ; Fri, 19 Dec 2025 18:44:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57A404BA2E31 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 57A404BA2E31 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766169872; cv=none; b=ayIRXf+sZUYN3hfxdkBC7ZLYnaeHaJk6i4+LNgDtmroRBdzfKzLlkqeiDUJghLsqaYaiT2+203SactYg+/v3yhSUSKW2Jse5CYk9GN8v27vUYMUDDCOVYsvKFabipQMP0TI4fazC8dhzAq9cidsKLchW+deaROTwiIzdpc98XRQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766169872; c=relaxed/simple; bh=Iu1oF4eQJtSN3Y4yKbjK67r7MCbHYFnc8oqUazXvAZU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LIk9rMr3DChUXYxAO5KZs04h2mb/4UWKDP4/8axosabHYOv/22GzS+FjXLdrwWBTCxkPNpX3akuNXI8zKgNfzvuWo8xQD7+rWjpO40lfwm0FEa4YJjs9dT9lLvpxLQvMk3VVi9+vLmvdZP8m9yO1aqCNxFuSh4ZsVFEJcifZ9Eg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57A404BA2E31 Received: by simark.ca (Postfix) id E76451E0B6; Fri, 19 Dec 2025 13:44:31 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 4/6] gdb/buildsym: make buildsym_compunit return a reference Date: Fri, 19 Dec 2025 13:43:42 -0500 Message-ID: <20251219184426.406228-4-simon.marchi@efficios.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251219184426.406228-1-simon.marchi@efficios.com> References: <20251219184426.406228-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1166.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, LOCAL_AUTHENTICATION_FAIL_DMARC, LOCAL_AUTHENTICATION_FAIL_SPF, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org 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 --- gdb/buildsym-legacy.c | 4 ++-- gdb/buildsym-legacy.h | 4 ++-- gdb/buildsym.c | 22 +++++++++++----------- gdb/buildsym.h | 4 ++-- gdb/coffread.c | 11 +++++------ gdb/dwarf2/read.c | 15 +++++++-------- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/gdb/buildsym-legacy.c b/gdb/buildsym-legacy.c index 5e9e0422d1b7..ee7fa4c828b8 100644 --- a/gdb/buildsym-legacy.c +++ b/gdb/buildsym-legacy.c @@ -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); diff --git a/gdb/buildsym-legacy.h b/gdb/buildsym-legacy.h index 006be225d241..f1178defeca4 100644 --- a/gdb/buildsym-legacy.h +++ b/gdb/buildsym-legacy.h @@ -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); diff --git a/gdb/buildsym.c b/gdb/buildsym.c index e6bb86a6404c..2259caad6ad6 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -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; } diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 8446377c5a6c..c2b61b3f9fac 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -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); diff --git a/gdb/coffread.c b/gdb/coffread.c index cdb2bcfb98db..bbb1598bcbc9 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -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"), diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 12f3e5f0e3dd..64cb22348e17 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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 ()); }