From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id H73+NXJfIWrnKTQAWB0awg (envelope-from ) for ; Thu, 04 Jun 2026 07:20:18 -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=lY41wyJP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ncVfyniP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=R/oBhmQ2; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SU0tA9EF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C8BF41E062; Thu, 04 Jun 2026 07:20:18 -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 A39871E062 for ; Thu, 04 Jun 2026 07:20:17 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2318A4BA5436 for ; Thu, 4 Jun 2026 11:20:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2318A4BA5436 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=lY41wyJP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ncVfyniP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=R/oBhmQ2; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SU0tA9EF Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 72F7B4BA540B for ; Thu, 4 Jun 2026 11:19:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72F7B4BA540B 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 72F7B4BA540B 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=1780571986; cv=none; b=WitE8vFttIYxBw3t1RgUHLt0HwKoONBaZo/7yW5f5iJh9g+ysVVwaA6rndiWB0j5K8Lp/Am9NPs+xxgqQi/ue48Oq/XVBz902P4U5j60nElrQPNPhc6cZZcobvv6DojDY4/nK1YQiKHfE4ZBKCGQ4bTBsg3VktJDhYJjehJQDiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780571986; c=relaxed/simple; bh=S5wOfHU8vfz7x6vobm69MQyqlC+6DeVsHX+6kQMuNO8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=pw9dD+Q19sX7yT8sdHnudArgNwSv1oaaCreDghIOuvafIh3O+lx8cUjDPVGN2HB5p/lRBgJqNw521/KWEZYg4fxETcHJ+rgUhgLsTcLcEpoBkCc8k0ZqkHo4gFowKq86ZpVmesXm1A7duiJ7zh7XOAUKU3hUfUS4cepKdbu1mr0= 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=lY41wyJP; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ncVfyniP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=R/oBhmQ2; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SU0tA9EF DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72F7B4BA540B 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 0F0806ADD5 for ; Thu, 4 Jun 2026 11:19:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1780571985; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Ddpe8FZmtXQIBmAa5R2mj0mSzxy+FDm7PRTJy6io3N0=; b=lY41wyJPAW+mqtPbPWMiubtFiJZ+ApQ7KZ6dxi4/K/o3wjc+o1PwHqzStHZVvQBdRXj5QW Q59CGhKLzKAPX9SEdgBBQIsgHYMICmdC7UXfVWL4xGUr9fjoMbTnnpPCSe+GhmpcJt2Bnm Yqniv03Enc7nAaytd94jTmFhBSnXFRg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1780571985; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Ddpe8FZmtXQIBmAa5R2mj0mSzxy+FDm7PRTJy6io3N0=; b=ncVfyniPQB+x94Vf4NGrHbGHS5SuPepaMRo6h/AFCADgVXPYRZ0Rowp4bwwPGtAvvZ0tZD gFfwAvCPyqIawCAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1780571984; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Ddpe8FZmtXQIBmAa5R2mj0mSzxy+FDm7PRTJy6io3N0=; b=R/oBhmQ2GUZd2vr3eVVyuqG0aMIws4yxgflMnJiTx0o9QnLMhXXwvD0bcjVTN2xqZyvTGr XATRvKcDSZSdOON9DK/rV2ykqvmQhI+CzD/6CCncWlmW6dBUgm93N6rLxSNlmVvTO6w4Os jMS3IllD3B9EIR5bUzSNV+0JX4r24GM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1780571984; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Ddpe8FZmtXQIBmAa5R2mj0mSzxy+FDm7PRTJy6io3N0=; b=SU0tA9EFYVeJSWgDVvPdbeT3pnsYB7J6ys6fCm03SQQV8mnDyZZIHoN0Obn5lGQZvVoTWz ZZ4uwy7wFvtoeiDA== 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 EDD2D779A8 for ; Thu, 4 Jun 2026 11:19:43 +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 ApqNOE9fIWrXNQAAD6G6ig (envelope-from ) for ; Thu, 04 Jun 2026 11:19:43 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/exp] Fix ns var lookup when stopped at inlined fn call Date: Thu, 4 Jun 2026 13:19:43 +0200 Message-ID: <20260604111943.84104-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 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)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[sourceware.org:url, suse.de:mid, gnu.org:url, imap1.dmz-prg2.suse.org:helo] 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: ... 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. 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 -- 2.51.0