From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oBpoOJmO5GmhdikAWB0awg (envelope-from ) for ; Sun, 19 Apr 2026 04:13:13 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sFUZZ0B9; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=lTLGobtk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=hxU1a4jz; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=HLR9ZrTc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AD31D1E0A2; Sun, 19 Apr 2026 04:13:13 -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 194801E0A2 for ; Sun, 19 Apr 2026 04:13:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id A589D4C515FA for ; Sun, 19 Apr 2026 08:13:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A589D4C515FA Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sFUZZ0B9; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=lTLGobtk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=hxU1a4jz; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=HLR9ZrTc Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 773384BA9000 for ; Sun, 19 Apr 2026 08:12:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 773384BA9000 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 773384BA9000 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776586366; cv=none; b=v4xXs0hBPef0l3J5cun3KtiKagb8QlvLc81wc87lxzvxO6zMPEN8FZxuhtM2S4HkgGwZFuXL4gRGSITvCbZXU3rggRDZW+NUSkXEr7zXAeriR6mpnmyIsivMD4R4hlrDHjjaKZY/r3kACNIFGns4Yv2EwqvVSdKeb+ebq8/HRKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776586366; c=relaxed/simple; bh=Jsp35Wvt1lAjB2ScL7i9ahfDr1PdCY3gy/ZuZQyKZiw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=wG1tbKJMbYqe523xiSlaQ7LunZqlEZdPMewApmkcW4bXpgFROhITSvp5h5lTivBmz8nfrhbi81kaPpbkCdcQxbX+eRe95ZDBqyM39fQQOYzUMyxypsnKwCvYkCthrnIw+G7J3aTxPB6MkearEkEPNX6+vjYNgmZzMVI9z6TPFOk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 773384BA9000 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 134336A945 for ; Sun, 19 Apr 2026 08:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776586358; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z3dXQmiHJsxYSTj0joLy+wEgEaIuZh1sc3PtbmkXKys=; b=sFUZZ0B9orDTz3hAiHrifQlozEnPpt2Cfy2KcJknMxkkHcZLD53/Zed5n8jQJppowcjUQc OOmgrH7mQC6/o8QLehHRkHoWtpcrdutarSgKw93K9BtfaAe+kX7ZtW98xLKSKiI5G8yBj2 Jw2Z0XDbqcY5ngwWsAIK9vBbLq9HUVU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776586358; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z3dXQmiHJsxYSTj0joLy+wEgEaIuZh1sc3PtbmkXKys=; b=lTLGobtkcyZuILAwZXjmG2YyBA3302v1b3jYWZr42ZH/Fa/kvRuXG45OU7PUgoPC8CNzYo uvV8UE6e/AHS+CDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=hxU1a4jz; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=HLR9ZrTc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1776586357; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z3dXQmiHJsxYSTj0joLy+wEgEaIuZh1sc3PtbmkXKys=; b=hxU1a4jzGYLPmJ7VKu1ckgbq/jpeHZ2u8IOn+U3s27UHQDUYgbn+z5lf1DGMfBQgrr9cGX 1TR5OmUhoqddsKaohVS1O/PwJBsPXhvO84/SXqazhUYfJzudL6Tj7r29CCo/Ybpc6mgHyH d/h0FKHnHfguJdc4vmjCG7VBpGu1S34= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1776586357; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z3dXQmiHJsxYSTj0joLy+wEgEaIuZh1sc3PtbmkXKys=; b=HLR9ZrTcRJEXW116OPpSvMdxcMTH5J7P4TXrsmmUtXTBY0jZVl0ORJCvPw6T5096FyeiUb 8rIF9twuNb/Zk4AA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E8DA5593B1 for ; Sun, 19 Apr 2026 08:12:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gIWzN3SO5GktUAAAD6G6ig (envelope-from ) for ; Sun, 19 Apr 2026 08:12:36 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v5 3/3] [gdb/exp] Handle recursive namespace import Date: Sun, 19 Apr 2026 10:12:36 +0200 Message-ID: <20260419081236.570600-4-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260419081236.570600-1-tdevries@suse.de> References: <20260419081236.570600-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,sourceware.org:url]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 134336A945 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 Consider test.c, compiled to a.out using "g++ -g test.c": ... 1 namespace mod_a { int xxx = 10; } 2 namespace mod_b { using namespace mod_a; 3 int yyy = 20; } 4 int main (void) { 5 using namespace mod_b; 6 void (xxx + yyy); 7 return 0; 8 } ... When trying to print the value of variable xxx we get: ... $ gdb -q -batch a.out -ex start -ex "print xxx" ... Temporary breakpoint 1, main () at test.c:7 7 return 0; No symbol "xxx" in current context. ... The symbol xxx is defined in namespace mod_a, so it's available as: ... (gdb) p mod_a::xxx $1 = 10 ... and namespace mod_b uses namespace mod_a, so it's available as: ... (gdb) p mod_b::xxx $2 = 10 ... Then main uses namespace mod_b so xxx should also be available in main, but it's not. The problem happens here in cp_lookup_symbol_via_imports: ... Thread 1 "gdb" hit Breakpoint 1, cp_lookup_symbol_via_imports (scope=0x5f43d0 "", name=0xfffffffface0 "xxx", block=0x2fba5a0, domain=..., search_scope_first=0, declaration_only=0, search_parents=1, found_symbols=...) at /home/vries/gdb/src/gdb/cp-namespace.c:505 505 cp_lookup_symbol_via_imports (current->import_src, name, ... We're about to follow the "using namespace mod_b" statement: ... (gdb) p *current $1 = {import_src = 0x2ed2140 "mod_b", import_dest = 0x66e910 "", alias = 0x0, declaration = 0x0, next = 0x0, decl_line = 5, searched = 1, excludes = {0x0}} ... But it does so using the current block, which is the function block for main: ... (gdb) p block->function ().m_name $7 = 0x2f8bc20 "main()" ... and the block containing the "using namespace mod_a" statement is the static block. Fix this by additionally iterating over the super blocks instead of only using the current block. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34034 --- gdb/cp-namespace.c | 8 +++++--- gdb/testsuite/gdb.cp/nsusing-2.exp | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index d7a960127dc..a0d86fd26f0 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -502,9 +502,11 @@ cp_lookup_symbol_via_imports (const char *scope, /* If this import statement creates no alias, pass current->inner as NAMESPACE to direct the search towards the imported namespace. */ - cp_lookup_symbol_via_imports (current->import_src, name, - block, domain, 1, 0, 0, - found_symbols); + for (const struct block *b = block; b != nullptr; + b = b->superblock ()) + cp_lookup_symbol_via_imports (current->import_src, name, + b, domain, 1, 0, 0, + found_symbols); } } diff --git a/gdb/testsuite/gdb.cp/nsusing-2.exp b/gdb/testsuite/gdb.cp/nsusing-2.exp index 65e685d0d32..5a2eac5ce67 100644 --- a/gdb/testsuite/gdb.cp/nsusing-2.exp +++ b/gdb/testsuite/gdb.cp/nsusing-2.exp @@ -66,7 +66,6 @@ foreach_with_prefix n {1 2 3 4} { # Function main is using namespace mod_b, and namespace mod_b is using # namespace mod_a, so mod_a::xxx is available as xxx. Regression test for # PR34034. - setup_kfail exp/34034 *-*-* gdb_test "print xxx" " = 10" # This used to print " $ = 20". Regression test for PR34051. -- 2.51.0