From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EVUCL2SkM2r3CQ0AWB0awg (envelope-from ) for ; Thu, 18 Jun 2026 03:55:16 -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=KOlYsX0T; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AgtaOAm2; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KOlYsX0T; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AgtaOAm2; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B7DC91E098; Thu, 18 Jun 2026 03:55:16 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,TRACKER_ID 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 344A61E024 for ; Thu, 18 Jun 2026 03:55:15 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE7324BA2E3E for ; Thu, 18 Jun 2026 07:55:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE7324BA2E3E 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=KOlYsX0T; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AgtaOAm2; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KOlYsX0T; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AgtaOAm2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 8E0FA4BA2E18 for ; Thu, 18 Jun 2026 07:54:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E0FA4BA2E18 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 8E0FA4BA2E18 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781769285; cv=none; b=Y03U6NSJaXseHD6FpXg6bB8vLrjTjKADRqwJGZ08agVHnbGeYr9iEsisprRzNmGIxReTNzqrgCm7F8N3hzob0MV3S0DiqTn/A28Sy2FGIKXMuEW3vbsjFsNL9149F3Cn3J/qBIEd6kDWpTmDm87x/4OKfF25F7DTOd8Ox7Kk4t4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781769285; c=relaxed/simple; bh=hFKy7+k0r/No1Szotk6Xf+MUZi+GwOEjkVbgF921Wbk=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=WQm8kPEgYL2++g2qiqRlPdr9U73jcn7jupFHBmVWx3Oq/Vht7SdrBQKIbydAEiP5y80CIadbuGsd3TCAWqSitNCqMH8IouwoZMQFeIjjNJosBD6pz8x9zdTptTIbL4e1u0hgjUg6LM4YrXxn4WoBDe0E0fhnNHMjlA35mSwiCJM= ARC-Authentication-Results: i=1; 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=KOlYsX0T; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AgtaOAm2; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=KOlYsX0T; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=AgtaOAm2 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E0FA4BA2E18 Received: from imap1.dmz-prg2.suse.org (unknown [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 AE5E46D1A9 for ; Thu, 18 Jun 2026 07:54:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1781769284; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DmVMKojo7ohp0PUnc6aqhh7mQuqAC+2kf1eMwc1VuII=; b=KOlYsX0TFBM09yrGwpZ5tPYg2FCGmdQRhtILFdf4/65HvlnRWdXZ+aLo0wrT2jW12VVqdr ljciPK0ly+DTXRlg4yVTJhtsUJYaCsddWFqVR7lhvxDv21nH39SRcVOMRgBzEy4YXsdZ5Q eF3poo63MdWSw2TQv7GsbT7T4kurydU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1781769284; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DmVMKojo7ohp0PUnc6aqhh7mQuqAC+2kf1eMwc1VuII=; b=AgtaOAm2R/xqX0yKEgD/9teRSsxbbqICKaXF0whC3+Vo2e9pPZ6FoinoHVSdxmuoMoYMO4 V6RtUJmata67TeDQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1781769284; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DmVMKojo7ohp0PUnc6aqhh7mQuqAC+2kf1eMwc1VuII=; b=KOlYsX0TFBM09yrGwpZ5tPYg2FCGmdQRhtILFdf4/65HvlnRWdXZ+aLo0wrT2jW12VVqdr ljciPK0ly+DTXRlg4yVTJhtsUJYaCsddWFqVR7lhvxDv21nH39SRcVOMRgBzEy4YXsdZ5Q eF3poo63MdWSw2TQv7GsbT7T4kurydU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1781769284; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DmVMKojo7ohp0PUnc6aqhh7mQuqAC+2kf1eMwc1VuII=; b=AgtaOAm2R/xqX0yKEgD/9teRSsxbbqICKaXF0whC3+Vo2e9pPZ6FoinoHVSdxmuoMoYMO4 V6RtUJmata67TeDQ== 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 9EEFE779A8 for ; Thu, 18 Jun 2026 07:54:44 +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 /dCdJUSkM2qrDwAAD6G6ig (envelope-from ) for ; Thu, 18 Jun 2026 07:54:44 +0000 Message-ID: <155fd32b-ce9f-4c46-958b-b9ff89e749bf@suse.de> Date: Thu, 18 Jun 2026 09:54:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING][PATCH] [gdb/exp] Fix ns var lookup when stopped at inlined fn call From: Tom de Vries To: gdb-patches@sourceware.org References: <20260604111943.84104-1-tdevries@suse.de> Content-Language: en-US In-Reply-To: <20260604111943.84104-1-tdevries@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid, imap1.dmz-prg2.suse.org:helo, gnu.org:url, sourceware.org:url] 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 6/4/26 1:19 PM, Tom de Vries wrote: > Consider test.c: > ... > 1 namespace mod_a { > 2 int xxx = 10; > 3 } > 4 > 5 static inline int __attribute__((always_inline)) > 6 inlined () { > 7 return 0; > 8 } > 9 > 10 int main () { > 11 using namespace mod_a; > 12 int res = inlined (); > 13 return res + xxx; > 14 } > ... > compiled with "g++ test.c -g". > > Trying to print variable xxx at line 12 fails: > ... > $ gdb -q -batch a.out -ex start -ex "p xxx" > ... > Temporary breakpoint 1, main () at test.c:12 > 12 int res = inlined (); > No symbol "xxx" in current context. > ... > > The problem is here in function using_direct::valid_line: > ... > CORE_ADDR curr_pc = get_frame_pc (get_selected_frame (nullptr)); > symtab_and_line curr_sal = find_sal_for_pc (curr_pc, 0); > return (decl_line <= curr_sal.line) > || (decl_line >= boundary); > ... > where we're trying to decide whether "using namespace mod_a" is applicable. > > The decl_line is 11, as expected. > > If curr_sal.line were 12, decl_line <= curr_sal.line would be true, and > using_direct::valid_line would return true. > > But instead, curr_sal.line is 7. > > This is sort of correct, the current PC maps to that line. It's just that gdb > steps into inlined functions in two steps, each with identical PC: > - once stopping at the call site (line 12 in this case) > - once stopping at the PC line (line 7 in this case) > > The function using_direct::valid_line doesn't apply this logic, and > consequently line 7 is used for both cases. > > Fix this by using find_frame_sal instead. > Ping. Thanks, - Tom > Tested on x86_64-linux. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34201 > --- > gdb/namespace.c | 4 +-- > gdb/testsuite/gdb.cp/ns-inlined.c | 41 +++++++++++++++++++++++ > gdb/testsuite/gdb.cp/ns-inlined.exp | 52 +++++++++++++++++++++++++++++ > 3 files changed, 95 insertions(+), 2 deletions(-) > create mode 100644 gdb/testsuite/gdb.cp/ns-inlined.c > create mode 100644 gdb/testsuite/gdb.cp/ns-inlined.exp > > diff --git a/gdb/namespace.c b/gdb/namespace.c > index 5b5749369ee..fec5e5cf67d 100644 > --- a/gdb/namespace.c > +++ b/gdb/namespace.c > @@ -111,8 +111,8 @@ using_direct::valid_line (unsigned int boundary) const > { > try > { > - CORE_ADDR curr_pc = get_frame_pc (get_selected_frame (nullptr)); > - symtab_and_line curr_sal = find_sal_for_pc (curr_pc, 0); > + frame_info_ptr frame = get_selected_frame (); > + symtab_and_line curr_sal = find_frame_sal (frame); > return (decl_line <= curr_sal.line) > || (decl_line >= boundary); > } > diff --git a/gdb/testsuite/gdb.cp/ns-inlined.c b/gdb/testsuite/gdb.cp/ns-inlined.c > new file mode 100644 > index 00000000000..26e72f6ba3f > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/ns-inlined.c > @@ -0,0 +1,41 @@ > +/* 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 . */ > + > +namespace mod_a > +{ > + int xxx = 10; > +} > + > +static inline int __attribute__((always_inline)) > +inlined () > +{ > + return 0; > +} > + > +static void > +foo () > +{ > +} > + > +int > +main () > +{ > + foo (); /* stop 1. */ > + using namespace mod_a; > + int res = inlined (); /* stop 2. */ > + return res + xxx; /* stop 3. */ > +} > diff --git a/gdb/testsuite/gdb.cp/ns-inlined.exp b/gdb/testsuite/gdb.cp/ns-inlined.exp > new file mode 100644 > index 00000000000..90cfbc0ff23 > --- /dev/null > +++ b/gdb/testsuite/gdb.cp/ns-inlined.exp > @@ -0,0 +1,52 @@ > +# 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 . > + > +standard_testfile .c > + > +set stop2_line [gdb_get_line_number "stop 2"] > +set stop3_line [gdb_get_line_number "stop 3"] > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ > + {debug c++}]} { > + return > +} > + > +if {![runto_main]} { > + return > +} > + > +with_test_prefix "stop 1" { > + gdb_test "print xxx" \ > + [string_to_regexp {No symbol "xxx" in current context.}] > +} > + > +gdb_test "next" \ > + "\r\n$stop2_line\t\[^\r\n\]+" \ > + "next to stop 2" > + > +with_test_prefix "stop 2" { > + # Regression test for PR exp/34201. > + gdb_test "print xxx" \ > + "$valnum_re = 10" > +} > + > +gdb_test "next" \ > + "\r\n$stop3_line\t\[^\r\n\]+" \ > + "next to stop 3" > + > +with_test_prefix "stop 3" { > + gdb_test "print xxx" \ > + "$valnum_re = 10" > +} > > base-commit: 48997323b0f929d3255a4845f8a3800c6c00a53a