From patchwork Wed Apr 8 07:02:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 132789 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 8F2F04BA2E14 for ; Wed, 8 Apr 2026 07:02:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F2F04BA2E14 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=dcZvP4A+; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Br91zqKX; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=YFBEWWaw; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=zpzrW84V X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 681144BA2E07 for ; Wed, 8 Apr 2026 07:02:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 681144BA2E07 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 681144BA2E07 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=1775631733; cv=none; b=ksS1MZbShOzJD5532PYoR2iKOGH1vNtI8nyrlZay/nYYZNj7os8L2N3gKQdvqDA1ZFzeSwUaIT64PLmo2gMbZTP5lmyAO0GLNZ8LST147wISRT4+zKHh4GHS4Lxhq8FqTzU70zVByazvvvYhuauprLA0vNP1L8RRQ6FKvGJZBzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775631733; c=relaxed/simple; bh=8zEu5zJ1V4wobvFcva+TYgX2LvRdI9Ex6eahxvaDwGc=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=Gqiw4u6807SYhAcdPe/lpkRjGILt5xNIzwhlZ7bfst6/7a0q2gCcjWstgng2Mhflf42d3CF2lUBGgOIc0LLllnnJvjeBAxRrtqR+UQrJaeMZAuH7mJEo2rHKCNpYh+Ln1Ht21M/qBYBAprCgG89ZhCx4MzaAAVwbvUNEsA2md74= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 681144BA2E07 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 F1EF84E887 for ; Wed, 8 Apr 2026 07:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775631732; 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=EVqPrZB0dqZLzQDp/cmbE2slQH9WWJ0xYqRpUlfa2BU=; b=dcZvP4A+7pakjFK6G7ZXC4cC7IDyiJKfGZlvqC0NN38CD2Ifec1qemDLS5i9nE3v4Yjfo+ gSxIsXr0sDryZhVozA8fnOw2QcDxD2AbaA+1x/comSPwQ2AzeZrAar+sLvwFUtLpORE7ud nMjYOwn8/P9p8hlb4lGfLWCZc3fs5rs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775631732; 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=EVqPrZB0dqZLzQDp/cmbE2slQH9WWJ0xYqRpUlfa2BU=; b=Br91zqKXqRNYzP8rsrU9Mj+J6CvE+mEWus0MNyHROQTwHiGeZaemZXVQtIOEzwmI39NGkB AJfEljuFV/wXuFCQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=YFBEWWaw; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=zpzrW84V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775631731; 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=EVqPrZB0dqZLzQDp/cmbE2slQH9WWJ0xYqRpUlfa2BU=; b=YFBEWWawg64s1SaLnmLYqSkn4YerMfYA4Ccni9Yttb4GApgfMvtYiL6Z3W2s1hqsVKqmCv 3KE5BPEklI2ZOujPmBAF34/heF+Dr5sJa38lytN4rpwQcqv+NvupND+lMo36rVABpA3HhJ VRqz4QrAsaEs9ykw5jfWjGoSNf0P4NA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775631731; 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=EVqPrZB0dqZLzQDp/cmbE2slQH9WWJ0xYqRpUlfa2BU=; b=zpzrW84Vz1Ev/c2Hip5NelFGxrAEZhPX8mGBuJ4InVwtCQsp2SGZ4jGYMlH9lu/TiGXap5 GhZvuP5I3EX9RzBQ== 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 D762F4A0B4 for ; Wed, 8 Apr 2026 07:02:11 +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 qPEtM3P91Wl3GQAAD6G6ig (envelope-from ) for ; Wed, 08 Apr 2026 07:02:11 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 1/2] [gdb] Break up complex assignment in cp_lookup_symbol_via_imports Date: Wed, 8 Apr 2026 09:02:10 +0200 Message-ID: <20260408070211.124957-2-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260408070211.124957-1-tdevries@suse.de> References: <20260408070211.124957-1-tdevries@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; 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)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_NONE(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:rdns, suse.de:dkim, suse.de:mid] X-Rspamd-Queue-Id: F1EF84E887 X-Spam-Score: -3.01 X-Spam-Level: X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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 In cp_lookup_symbol_via_imports, we have a complex assignment: ... directive_match = (search_parents ? (startswith (scope, current->import_dest) && (len == 0 || scope[len] == ':' || scope[len] == '\0')) : streq (scope, current->import_dest)); ... Writing it like this makes it: - harder to comment on parts of the expression, and also - harder to understand and modify it. Also, len == 0 makes the startswith redundant, so that part of the expression can be hoisted. Doing so makes it clear that scope is not compared against in all cases. Fix this by breaking this up into three separate assignments: ... if (search_parents) { if (len == 0) directive_match = 1; else directive_match = (startswith (scope, current->import_dest) && (scope[len] == ':' || scope[len] == '\0')); } else directive_match = streq (scope, current->import_dest); ... --- gdb/cp-namespace.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index c8cd5c245aa..f8b71be3ff1 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -394,7 +394,6 @@ cp_lookup_symbol_via_imports (const char *scope, { struct block_symbol sym = {}; int len; - int directive_match; /* All the symbols we found will be kept in this relational map between the mangled name and the block_symbol found. We do this so that GDB @@ -425,13 +424,21 @@ cp_lookup_symbol_via_imports (const char *scope, do not use this directive. */ if (!current->valid_line (boundary_sal.line)) continue; + len = strlen (current->import_dest); - directive_match = (search_parents - ? (startswith (scope, current->import_dest) - && (len == 0 - || scope[len] == ':' - || scope[len] == '\0')) - : streq (scope, current->import_dest)); + + bool directive_match; + if (search_parents) + { + if (len == 0) + directive_match = 1; + else + directive_match = (startswith (scope, current->import_dest) + && (scope[len] == ':' + || scope[len] == '\0')); + } + else + directive_match = streq (scope, current->import_dest); /* If the import destination is the current scope or one of its ancestors then it is applicable. */ From patchwork Wed Apr 8 07:02:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 132790 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 332C04BA2E2D for ; Wed, 8 Apr 2026 07:02:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 332C04BA2E2D 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=fvgckmuT; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1Ct5KcJ9; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=RBU/JZOD; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=y2Ft4bOw X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 2EF884BA2E0F for ; Wed, 8 Apr 2026 07:02:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EF884BA2E0F 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 2EF884BA2E0F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775631736; cv=none; b=uQdxq3Fbj5174a5wmKhGH7V4xYKcONpUR0ctIzqfelc34X2rm5JlvSwzaEYfrMhJTFjnds9gxrFDOhkPydvdvdor9H8pHgmswoN4GtIeFe6xwfnCeZUTm3+zifsZi4GvYWZx96Gt3q8Zr9sD5JLkw0Ytag473yLm+wE5XtqJT38= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775631736; c=relaxed/simple; bh=Q25kJCFcqK0UOqOQrSS+FFXFAu9aHSU3/5kGkzhE7UA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=Fmn2OuNWw9LSQJnPQXdr7hkOFM1qUNkBk0vxbQQu1Nv0eNIJyK0uE2rwyfDiAhYHoq+jl75saCLSq5/HylUlrO4oRagwY/31q1/e3c9rO/Xp1vjklCdSQfiqiXhO6clTmDEEgtm9j3yqBgymwjVp2lh0hjQElR5VD6tgTetUnoc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EF884BA2E0F 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-out2.suse.de (Postfix) with ESMTPS id 1A9895BD96 for ; Wed, 8 Apr 2026 07:02:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775631735; 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=Q2StniHcrQzPKN9rEBf+CgxVYZl/iXxTyzwran5ZRjo=; b=fvgckmuTuBEcPOyqfJUPc+1a1ISz0Ep7TO5trIFKPYktqsxtIqTD3b3v8H2OQC4A+C8J84 S+UcfJFQDrbGVR21hWB+bxNaWSzgnhEwzqzowog2wKE69EcIbzWPWYIiR6rhzqvf+07XTI 7Gpb3EPitATusIRcd8ehpj99OPiZLrI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775631735; 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=Q2StniHcrQzPKN9rEBf+CgxVYZl/iXxTyzwran5ZRjo=; b=1Ct5KcJ99U4YF5LMZsMvVNDS6E0d26GOPAgtrBOrxsx7I5gn6Ds19s3ui2aKskSKe0BwKl GRush1ZwCGj6zaBQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="RBU/JZOD"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=y2Ft4bOw DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1775631732; 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=Q2StniHcrQzPKN9rEBf+CgxVYZl/iXxTyzwran5ZRjo=; b=RBU/JZODe0pc2n7DPryB4krfisLxYZ8CPQexeaYRF/vAt85UJ5kt3rbw5nW80gj9ChWeIO nngvtGyA71md/p5Tll7I/AfRQtvR+rp7AHkTN136kffFMx34Tmx/fmZVWc7oZC+Lgu5Thl OE0v8pWdPGmClWM4yAu8Kqb0P3YoWpE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1775631732; 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=Q2StniHcrQzPKN9rEBf+CgxVYZl/iXxTyzwran5ZRjo=; b=y2Ft4bOwI3zddVBhONbdRysbLdjleEyblNyfaRvl4OJ81F69RM8ie2OxnW/h6YIo1gWhR+ vZ/uaMi+Jg2eR2CQ== 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 F41824A0B5 for ; Wed, 8 Apr 2026 07:02:11 +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 SOZGOnP91Wl3GQAAD6G6ig (envelope-from ) for ; Wed, 08 Apr 2026 07:02:11 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 2/2] [gdb/exp] Fix ignoring of incorrect namespace prefix Date: Wed, 8 Apr 2026 09:02:11 +0200 Message-ID: <20260408070211.124957-3-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260408070211.124957-1-tdevries@suse.de> References: <20260408070211.124957-1-tdevries@suse.de> MIME-Version: 1.0 X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; 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)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FUZZY_RATELIMITED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_NONE(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(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, gnu.org:url] X-Rspamd-Queue-Id: 1A9895BD96 X-Spam-Score: -3.01 X-Spam-Level: X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP 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 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 non-existent variable mod_a::yyy, we get: ... $ gdb -q -batch a.out -ex start -ex "print mod_a::yyy" ... Temporary breakpoint 1, main () at test.c:7 7 return 0; $1 = 20 ... The problem is in cp_lookup_symbol_via_imports, where we decide that the "using namespace mod_b" from main is applicable in scope mod_a. Fix this by being more strict in the calculation of directive_match: ... if (len == 0) - directive_match = 1; + { + const char *current_scope = (block->function () != nullptr + ? block->scope () + : nullptr /* Don't know. */); + directive_match = (current_scope != nullptr + ? streq (scope, current_scope) + : 1 /* Assume there's a match. */); + } ... As is clear from the code, in case we don't know the current scope, we assume there's a match. This may be harmless, or this may describe a cornercase we haven't run into yet. If so, it's a pre-existing issue. The new test-case contains regression tests for: - PR34051, and - PR34034 for which it contains a kfail. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34051 --- gdb/cp-namespace.c | 9 +++- gdb/testsuite/gdb.cp/nsusing-2.cc | 39 ++++++++++++++++ gdb/testsuite/gdb.cp/nsusing-2.exp | 75 ++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.cp/nsusing-2.cc create mode 100644 gdb/testsuite/gdb.cp/nsusing-2.exp diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index f8b71be3ff1..45cde597674 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -431,7 +431,14 @@ cp_lookup_symbol_via_imports (const char *scope, if (search_parents) { if (len == 0) - directive_match = 1; + { + const char *current_scope = (block->function () != nullptr + ? block->scope () + : nullptr /* Don't know. */); + directive_match = (current_scope != nullptr + ? streq (scope, current_scope) + : 1 /* Assume there's a match. */); + } else directive_match = (startswith (scope, current->import_dest) && (scope[len] == ':' diff --git a/gdb/testsuite/gdb.cp/nsusing-2.cc b/gdb/testsuite/gdb.cp/nsusing-2.cc new file mode 100644 index 00000000000..72f98add1b9 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsusing-2.cc @@ -0,0 +1,39 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* C++ variant of the Fortran example from PR34034. */ + +namespace mod_a { + int xxx = 10; +} + +namespace mod_b { + using namespace mod_a; + int yyy = 20; +} + +static void foo () {} + +int +main (void) +{ + foo (); /* main-entry. */ + using namespace mod_b; + (void)xxx; + (void)yyy; + return 0; /* main-return. */ +} diff --git a/gdb/testsuite/gdb.cp/nsusing-2.exp b/gdb/testsuite/gdb.cp/nsusing-2.exp new file mode 100644 index 00000000000..9653616f7f4 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsusing-2.exp @@ -0,0 +1,75 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test recursive "using namespace". Regression test for PR34034 and PR34051. + +standard_testfile .cc + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ + {debug c++}]} { + return -1 +} + +with_test_prefix pre-main { + gdb_test "print mod_a::xxx" " = 10" + gdb_test "print mod_b::yyy" " = 20" + + # Namespace mod_b is using namespace mod_a, so mod_a::xxx is available as + # mod_b::xxx. This is not available here though, but later, at + # start-of-main. I wonder if this should also be availabe here. + gdb_test "print mod_b::xxx" \ + [string_to_regexp {No symbol "xxx" in namespace "mod_b".}] +} + +set line_main_entry [gdb_get_line_number main-entry] +if {![runto $srcfile:$line_main_entry]} { + return +} + +# Start of main. Function main is not yet using namespace mod_b. +with_test_prefix start-of-main { + # Namespace mod_b is using namespace mod_a, so mod_a::xxx is available as + # mod_b::xxx. See also the note at the identical command in pre-main. + gdb_test "print mod_b::xxx" " = 10" + + # Same command as in end-of-main, but not a regression test for PR34034. + gdb_test "print xxx" \ + [string_to_regexp {No symbol "xxx" in current context.}] + + # Same test as in end-of-main, but not a regression test for PR34051. + gdb_test "print mod_a::yyy" \ + [string_to_regexp {No symbol "yyy" in namespace "mod_a".}] +} + +set line_main_return [gdb_get_line_number "main-return"] +gdb_test "next" \ + [subst_vars {$line_main_return\t[^\r\n]+}] + +# End of main. Function main is using namespace mod_b. +with_test_prefix end-of-main { + # Function main is using namespace mod_b, so mod_b::yyy is available as + # yyy. + gdb_test "print yyy" " = 20" + + # 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. + gdb_test "print mod_a::yyy" \ + [string_to_regexp {No symbol "yyy" in namespace "mod_a".}] +}