From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qaZyOwWU4mliKiAAWB0awg (envelope-from ) for ; Fri, 17 Apr 2026 16:11:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1776456709; bh=4Za6XeJqlqDSko8NHa48Mz3OHogDQ0DWzdglntlIYHI=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gBsU/DwpQ/PP5SGfnGcLghCoEZZL1mkGu7iCF/hkIyL5aHx852ADiMj62viF7lcnM Je2GbK1HIsPoLKZeV9gqj0DTSQsOyeNobNY2rHV/9Wx3suw9YQMPyl4y8oJYEHXxEl Y9CyeheWJ7hthY56h91hB7wkuiYTNOOmjDEd06B0= Received: by simark.ca (Postfix, from userid 112) id DCBD91E04F; Fri, 17 Apr 2026 16:11:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=sX+1a28X; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9F4EF1E04F for ; Fri, 17 Apr 2026 16:11:48 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5A10B4D8D1F6 for ; Fri, 17 Apr 2026 20:11:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A10B4D8D1F6 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=sX+1a28X Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5F2BE4D108E7 for ; Fri, 17 Apr 2026 20:11:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F2BE4D108E7 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F2BE4D108E7 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=1776456683; cv=none; b=FqjlqYL4+Gr7dJnlzhRcuUrWH0CauXf8a47GjnVjqRq/zR+W36Lc/m1zb7We+ZX/yBfGZ04/Z+fmu94UDkYi63IErpvhdNO4tadrNjHjfxMcC89lEa3YL1MTanjjty1Hcsslh5cstg4lPnJ/QmXPGykGRkcygLCbkEZl3Ym8kXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776456683; c=relaxed/simple; bh=4Za6XeJqlqDSko8NHa48Mz3OHogDQ0DWzdglntlIYHI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=F18FOvNx/Mk+kZlX8oI7HxjpRbfPAzjLfT1XlakzDeoYRD9wPdRJqtzT66nDK1dymzbQ58UaBZxv8oL38t34UmjgE/STRu/1+Ig9jcC34poRK8L7uzvGADGuDljemcfYxNlrLh6SkNsiC2KSG8G4bANJizY0p05kSoxfBRBg1go= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F2BE4D108E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1776456682; bh=4Za6XeJqlqDSko8NHa48Mz3OHogDQ0DWzdglntlIYHI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=sX+1a28XAdOYd/0b1J+P88RZCJPwAgzBBMD5YPotwADIhgZ5lDbXc9MpL41OKW4ZD vG9bbql/2IsWJ+9CUukYA1QwO1FqjCFKmiZ2Jrl2bvgztcjhwl+m8hoikE0JmDwNKf JTYuBWnBVcvl+isyX78QeLVuVp4OO6AYwGb7AK6Y= Received: by simark.ca (Postfix) id A04241E04F; Fri, 17 Apr 2026 16:11:21 -0400 (EDT) Message-ID: Date: Fri, 17 Apr 2026 16:11:21 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/6] Change pop_context to return a block To: Tom Tromey , gdb-patches@sourceware.org References: <20260417-list-in-scope-v1-0-0deb050fc03d@adacore.com> <20260417-list-in-scope-v1-4-0deb050fc03d@adacore.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20260417-list-in-scope-v1-4-0deb050fc03d@adacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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~public-inbox=simark.ca@sourceware.org On 4/17/26 2:24 PM, Tom Tromey wrote: > This changes buildsym_compunit::pop_context to create and return the > block, if needed. It also arranges to reset some fields in the > buildsym_compunit object to their saved values. > > This also enables the removal of the set_local_using_directives > method. > --- > gdb/buildsym.c | 29 +++++++++++++++++------------ > gdb/buildsym.h | 15 +++++++++------ > gdb/dwarf2/read.c | 55 ++++++++++++++++++------------------------------------- > 3 files changed, 44 insertions(+), 55 deletions(-) > > diff --git a/gdb/buildsym.c b/gdb/buildsym.c > index 6d719cb25a0..592bcf8bcf0 100644 > --- a/gdb/buildsym.c > +++ b/gdb/buildsym.c > @@ -629,13 +629,7 @@ buildsym_compunit::end_compunit_symtab_get_static_block (CORE_ADDR end_addr, > the context stack. */ > > if (!m_context_stack.empty ()) > - { > - struct context_stack cstk = pop_context (); > - > - /* Make a block for the local symbols within. */ > - finish_block (cstk.name, cstk.old_blocks, NULL, > - cstk.start_addr, end_addr); > - } > + pop_context (end_addr); > gdb_assert (m_context_stack.empty ()); > > /* Executables may have out of order pending blocks; sort the > @@ -949,14 +943,25 @@ buildsym_compunit::push_context (CORE_ADDR valu) > return ctx; > } > > -/* Pop a context block. Returns the address of the context block just > - popped. */ > +/* See buildsym.h. */ > > -context_stack > -buildsym_compunit::pop_context () > +block * > +buildsym_compunit::pop_context (CORE_ADDR end_addr, > + const struct dynamic_prop *static_link, > + bool required) > { > gdb_assert (!m_context_stack.empty ()); > - context_stack result = m_context_stack.back (); > + context_stack cstk = m_context_stack.back (); > m_context_stack.pop_back (); A nit about pre-existing code, but I think that we could std::move the result of `.back ()`: context_stack cstk = std::move (m_context_stack.back ()); > + block *result = nullptr; > + if (required || !m_local_symbols.empty () > + || m_local_using_directives != nullptr) > + result = finish_block (cstk.name, cstk.old_blocks, static_link, > + cstk.start_addr, end_addr); > + > + m_local_symbols = std::move (cstk.locals); > + m_local_using_directives = cstk.local_using_directives; My understanding is that the "current" locals and local_using_directives vectors are not held in m_context_stack, they are held in these m_local_symbols and m_local_using_directives fields. An entry in m_context_stack is a saved context, to be restored later. I wonder if it would simplify the code if we removed m_local_symbols and m_local_using_directives, and said that the topmost m_context_stack entry holds the current locals and local_using_directives. That would mean pushing an initial context_stack entry for the global scope, I guess? We wouldn't need moving in and out of m_local_symbols and m_local_using_directives anymore. I don't think it would simplify that much in terms of number of lines, but it might make the code a bit easier to follow. Just something to explore, I think this patch is good. Simon