From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oQ3zHel64mkZvR8AWB0awg (envelope-from ) for ; Fri, 17 Apr 2026 14:24:41 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=j97DTvGq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 763C41E04F; Fri, 17 Apr 2026 14:24:41 -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 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 EACD81E04F for ; Fri, 17 Apr 2026 14:24:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 8552B4D108DA for ; Fri, 17 Apr 2026 18:24:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8552B4D108DA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=j97DTvGq Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 027754BA23C3 for ; Fri, 17 Apr 2026 18:24:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 027754BA23C3 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 027754BA23C3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776450249; cv=none; b=Q7q9iC2B8gpTlQtkLXk5awdt4oU9HxMXh0jFBI51aLENhob84wPXqQTMbliwlVsheP7nPLb/w7ERcFi16jAqkoGAqctW/R0mCfq/MCAn7QTApx2avhQV2FgRWaeNYN5G0wmerQC4Vp6iCLwUCxVVXTbNQDpEz+iLuXL9bc5bCmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776450249; c=relaxed/simple; bh=sgj0nhs3OmLmSRzpXJzUUDZbYQH2Jf3s7m9H0Hxdz9c=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=LMk8bHs0gcDLT1+LYdUUcFnG5d1bKMa3zwLUHphse5ufvP0DPpl/ZGDoUsSxaFMu18dq1d3WjHwgLDjp9rlsjPeS5q4uDnoRh4OZj6sEq2YzyfA0nRRsv7zi1sLqWFll8zV9tVKcP6BkqkHPlrS47j8HN41tXXOIa+I5fu9MCKg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 027754BA23C3 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-7dca00c1591so122732a34.3 for ; Fri, 17 Apr 2026 11:24:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1776450248; x=1777055048; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=bKlCcmblEMRzs3M4m3MoGoPaouoAN8aMUWEhBSVSEcA=; b=j97DTvGqiisR/QWoLq2d3lQ68QLkDsdzGLVD3DSYzHwqqdetr2pkjcmaxnywIcYt2S wJ1SGjxG+eVpeAX5YesLxFQGDI4PIK5q6VLUElxhNtFrj+vGVJcyLeBBpqW+UGweiDpz VvkMXXOECTIgAKRDCPcFxJWP2Ss+u8BzciXQk2fkAJcIvO1HHGdBXgcOhbmtK6royeAM nVj84kjdtaH2B406lA0RhUbT5vkEiJVd7zMxrvjGSF2lzkAx6G5OwpvGQsZK7CDaSTKd c72tR0PR8iPa7YlzWbw8vZMm6cJFdsZvDhE4Rpe7ecHDgwXAwgyjCMKYmppSSiTKr8I8 l0YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776450248; x=1777055048; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=bKlCcmblEMRzs3M4m3MoGoPaouoAN8aMUWEhBSVSEcA=; b=oZRzbFBJxH3Zc5QlcEjLeJSVGLNWNDHEhRBSqbz8AIrHoOh43LdfTXQJGwA3cTrOLH aDTQgtbJ/hop6ZkrZmDNGC45xfiYOZDNOnw0mlGaU3gQYSFVJfwn/NI3vfamnTfaImfe NTycs9DcLXcL5vewwsYvgE50dIWGuqs9IyPZNhgIPeF920VUWaY6LtB+Vs5CmRRZr66P egtW0rOTpBexff/0ThsWps2c9+LHHdxlWqE0iu/Veopp5NywLIndG41akH39EKXY8FUw AXCgc8pxvJ7gDjRo69HeWNepDwNWUz5+Lq/nqGxepbEzBLCx7QT/Ra7TzQB/sPPRFL3u Xqug== X-Gm-Message-State: AOJu0YybwNX/7HNfziUXZXXUY6hrk1MwNm5cT7R+F7t/67Kco4m4Y8Ag aZD99MXa0BoyJvbFqxHJAO5jzB0rTbgQU8zSCvKzk5S4VhLDj15X4BiJJnRC7NNUbzAjRFTR06P +WJk= X-Gm-Gg: AeBDiesM32NB86zrwrNgRtQ2OVc6Zp8xFfZgoYBWOSJ7BJSlLsTtdyBJ9oIh4IDlgHa xFYAJjl+PEkyhBGnGsP4imajhOmm9hbqoX8cVf66mmyjeTpuJuIvpN1W3B6SmgRrdzvV3XnCa3w IQhHM5XijR3DA8urKRRUqn2rQ7prLeVfjqjZWCAnqm6k+cgIlhIpSveRiHGsUUW92Qz7OvmTU1E /0QefdRgKk6tEZgfyjKcpER5mmHZXuQqtUG1LCcCROx+thXlTN2b/hEDrPSYbGYj03GaTZkH4yg VpZ0Q/ieS5dFB50+GXbW/v3uQ+iErLKYAWSdI8VXXZSD72mSgE/+ZNTdOViNiIGii3/RwnivJ1H 5fi6H15AJGuMmOvQ5t+x6Bt1s4xIVhafH6NqgjmQ0vXVzuBbEIS342ISuk2cB5Y85lDmhRKahTg MrYseKRIKptW0IyM8EXl73JXxanLjBGgradzGEB/RgjvryEZvCAuRU0s9uvjxow1TM X-Received: by 2002:a05:6830:82eb:b0:7d7:d4ee:c02d with SMTP id 46e09a7af769-7dc951f20c7mr2443137a34.21.1776450248156; Fri, 17 Apr 2026 11:24:08 -0700 (PDT) Received: from [192.168.0.26] (75-166-225-82.hlrn.qwest.net. [75.166.225.82]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7dc9a7102b0sm1182475a34.0.2026.04.17.11.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 11:24:07 -0700 (PDT) From: Tom Tromey Date: Fri, 17 Apr 2026 12:24:06 -0600 Subject: [PATCH 4/6] Change pop_context to return a block MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260417-list-in-scope-v1-4-0deb050fc03d@adacore.com> References: <20260417-list-in-scope-v1-0-0deb050fc03d@adacore.com> In-Reply-To: <20260417-list-in-scope-v1-0-0deb050fc03d@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 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 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 (); + + 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; + return result; } diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 70d22229f53..d1199735abb 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -189,11 +189,6 @@ struct buildsym_compunit return &m_local_using_directives; } - void set_local_using_directives (struct using_direct *new_local) - { - m_local_using_directives = new_local; - } - struct using_direct **get_global_using_directives () { return &m_global_using_directives; @@ -243,7 +238,15 @@ struct buildsym_compunit context_stack &push_context (CORE_ADDR valu); - context_stack pop_context (); + /* Pop a context and create the corresponding block. Returns the + block. END_ADDR is the final address of the block. STATIC_LINK, + if provided, is the static link. REQUIRED controls whether the + block is required. When false, if the block does not contain any + variables or 'using' directives, this method will return + nullptr. */ + block *pop_context (CORE_ADDR end_addr, + const struct dynamic_prop *static_link = nullptr, + bool required = true); struct block *end_compunit_symtab_get_static_block (CORE_ADDR end_addr, bool expandable, bool required); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e1d70ea650d..4447923ae3e 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -7715,7 +7715,6 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) CORE_ADDR highpc; struct attribute *attr, *call_line, *call_file; const char *name; - struct block *block; int inlined_func = (die->tag == DW_TAG_inlined_subroutine); std::vector template_args; struct template_symbol *templ_func = NULL; @@ -7802,17 +7801,18 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) gdb_assert (cu->get_builder () != nullptr); context_stack &ctx = cu->get_builder ()->push_context (lowpc); - ctx.name = new_symbol (die, read_type_die (die, cu), cu, templ_func); + symbol *func_sym = new_symbol (die, read_type_die (die, cu), cu, templ_func); + ctx.name = func_sym; if (dwarf2_func_is_main_p (die, cu)) - set_objfile_main_name (objfile, ctx.name->linkage_name (), + set_objfile_main_name (objfile, func_sym->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, ctx.name, cu, 1); + dwarf2_symbol_mark_computed (attr, func_sym, cu, 1); /* If there is a location for the static link, record it. */ dynamic_prop *static_link = nullptr; @@ -7864,11 +7864,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) } } - struct context_stack cstk = cu->get_builder ()->pop_context (); - - /* Make a block for the local symbols within. */ - block = cu->get_builder ()->finish_block (cstk.name, cstk.old_blocks, - static_link, lowpc, highpc); + block *block = cu->get_builder ()->pop_context (highpc, static_link); /* For C++, set the block's scope. */ if ((cu->lang () == language_cplus @@ -7882,7 +7878,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) /* If we have address ranges, record them. */ dwarf2_record_block_ranges (die, block, cu); - gdbarch_make_symbol_special (gdbarch, cstk.name, objfile); + gdbarch_make_symbol_special (gdbarch, func_sym, objfile); /* Attach template arguments to function. */ if (!template_args.empty ()) @@ -7904,13 +7900,6 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) for (symbol *sym : template_args) sym->set_symtab (templ_func->symtab ()); } - - /* In C++, we can have functions nested inside functions (e.g., when - a function declares a class that has methods). This means that - when we finish processing a function scope, we may need to go - back to building a containing block's symbol lists. */ - cu->get_builder ()->get_local_symbols () = std::move (cstk.locals); - cu->get_builder ()->set_local_using_directives (cstk.local_using_directives); } /* Process all the DIES contained within a lexical block scope. Start @@ -7958,29 +7947,21 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) process_die (child_die, cu); inherit_abstract_dies (die, cu); - struct context_stack cstk = cu->get_builder ()->pop_context (); - if (!cu->get_builder ()->get_local_symbols ().empty () - || (*cu->get_builder ()->get_local_using_directives ()) != NULL) - { - struct block *block - = cu->get_builder ()->finish_block (0, cstk.old_blocks, NULL, - cstk.start_addr, highpc); + block *block = cu->get_builder ()->pop_context (highpc, nullptr, false); - /* Note that recording ranges after traversing children, as we - do here, means that recording a parent's ranges entails - walking across all its children's ranges as they appear in - the address map, which is quadratic behavior. + /* Note that recording ranges after traversing children, as we + do here, means that recording a parent's ranges entails + walking across all its children's ranges as they appear in + the address map, which is quadratic behavior. - It would be nicer to record the parent's ranges before - traversing its children, simply overriding whatever you find - there. But since we don't even decide whether to create a - block until after we've traversed its children, that's hard - to do. */ - dwarf2_record_block_ranges (die, block, cu); - } - cu->get_builder ()->get_local_symbols () = std::move (cstk.locals); - cu->get_builder ()->set_local_using_directives (cstk.local_using_directives); + It would be nicer to record the parent's ranges before + traversing its children, simply overriding whatever you find + there. But since we don't even decide whether to create a + block until after we've traversed its children, that's hard + to do. */ + if (block != nullptr) + dwarf2_record_block_ranges (die, block, cu); } static void dwarf2_ranges_read_low_addrs -- 2.53.0