From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +RPJLxAcVWoxbwYAWB0awg (envelope-from ) for ; Mon, 13 Jul 2026 13:10:40 -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=SJ7U1DVa; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FQzboFzA; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iO9HWiQe; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=kN3iv82j; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BFA381E033; Mon, 13 Jul 2026 13:10:40 -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.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 86D2C1E033 for ; Mon, 13 Jul 2026 13:10:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2ABB74BA2E19 for ; Mon, 13 Jul 2026 17:10:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2ABB74BA2E19 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=SJ7U1DVa; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FQzboFzA; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iO9HWiQe; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=kN3iv82j Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id E4C314BA2E08 for ; Mon, 13 Jul 2026 17:10:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4C314BA2E08 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 E4C314BA2E08 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=1783962611; cv=none; b=pO4xHPqST6WkXl7uqcsAUCTRBpKsKDr0pr5sQn05Jht+IEhLPJfnegkZ2Vby4C0XU0GT5b5OvVLWVkWzn5h8Wl1+4R37WLtThNeqCGfwvPScqIbJo/DXlo0kbPpyTGjxNs5ZQhzt1Lb63gjpoAD0FYgDWD9visb+IBsXq18OdZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783962611; c=relaxed/simple; bh=w+mAwKpmcJ2PYoywwfiCRRD0dfxvC31RLDCX4yitZ/Q=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=SsVZMIs5LLjP1bIg06DUfYBhQce79CUDAVOK5BKhxtOAZlD3M0EUbvJlAxMZCQ8R9U5Iwu1KDRIfOeRKbi1Sf3X+hrfxXdGpTD/i+bX27vZNkodVdKdxMfpCkCTvCWWVktMCjn7PdanBWkRZojW4HnF8IcliF+PKzMjqua1tWn8= 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=SJ7U1DVa; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FQzboFzA; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iO9HWiQe; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=kN3iv82j DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4C314BA2E08 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 CB1AE77A0A for ; Mon, 13 Jul 2026 17:10:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1783962609; 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=9pzliLIe4WRL82yrT7bC2ZXi9mG6suspZO6R96cXcx0=; b=SJ7U1DVa5ouK7Pu8/Jee3GTIvyrypdZkznW1HVNAaI4ikKK7vIs8RjsQtlAI2xkWE8Zo8Q +YjCe8CL5mOQ8bb/w+1lemy4DaydWoE+/0MOqV04KoNyvjipoarSPFZbZ2SMSzBNY326Dn MfkqDNtKgnRB1qp8qrR6nFYjTgGVvGg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1783962609; 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=9pzliLIe4WRL82yrT7bC2ZXi9mG6suspZO6R96cXcx0=; b=FQzboFzAdJz//q7nqZVyS6n8U9DuF3p+3je5cRooAx01/MQHfuEes2orMTLgwXVOlbyXaY NHuYR2vtlyaFJQAQ== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=iO9HWiQe; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=kN3iv82j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1783962608; 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=9pzliLIe4WRL82yrT7bC2ZXi9mG6suspZO6R96cXcx0=; b=iO9HWiQeX/fNLbKEPAgbBZRqfLfe9EO5KnoYIScXZsplnoOD/QeqQxxH/MVFmV4X7e/6yv N3Kn++IXUg4MT4JdmqxQB5lPuko4gJ5I31ATEemzIOzRh+t3hXv6Y2WLq1buSSOEJ+OwTy G93OVBZCFF/CBjRN5iqU2efy7j4z7lI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1783962608; 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=9pzliLIe4WRL82yrT7bC2ZXi9mG6suspZO6R96cXcx0=; b=kN3iv82j8Forb94EdtS6DxysaT0FkMEAPDnmf0HzFfYOfay0zkZlqEzHpPa3xeVD6AgX1z AclHu0srgwfq5bDQ== 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 B919F779AE for ; Mon, 13 Jul 2026 17:10:08 +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 IuCEK/AbVWqcTgAAD6G6ig (envelope-from ) for ; Mon, 13 Jul 2026 17:10:08 +0000 Message-ID: <1e033cc7-06b6-4530-9b6b-1ba0a1df8d67@suse.de> Date: Mon, 13 Jul 2026 19:10:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [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> <155fd32b-ce9f-4c46-958b-b9ff89e749bf@suse.de> Content-Language: en-US In-Reply-To: <155fd32b-ce9f-4c46-958b-b9ff89e749bf@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Action: no action X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; MID_RHS_MATCH_FROM(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url,suse.de:mid,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,sourceware.org:url]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: CB1AE77A0A 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/18/26 9:54 AM, Tom de Vries wrote: > 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. > I've pushed this, with a trivial update to the test-case to add an xfail for GCC PR debug/108716. Thanks, - Tom > 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 > licenses/>.  */ >> + >> +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 >