From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AQDzFuztcGo/awMAWB0awg (envelope-from ) for ; Mon, 03 Aug 2026 15:37:16 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=VtU5GoBc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 5740D1E099; Mon, 03 Aug 2026 15:37: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=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 65E7F1E099 for ; Mon, 03 Aug 2026 15:37:15 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7648C4BB24F3 for ; Mon, 3 Aug 2026 19:37:14 +0000 (GMT) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by sourceware.org (Postfix) with ESMTPS id 067094BB1C35 for ; Mon, 3 Aug 2026 19:35:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 067094BB1C35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 067094BB1C35 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785785753; cv=none; b=uhF8RLo70SGS3hTZj9+jE7arJZmxi3xVm2NFaIcY71VAmaicdJn2QFR9pNYjxdTUf+iC+B56jqDcgf++yNAE8j/T1EAL3TSTWpLMnBEsu2xTo2Gko6dVolTUotiBSRglzTC8pYcUUrP4jH38uwWjv/yGFfnG6KrSWv7hB5oqY74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785785753; c=relaxed/simple; bh=0PbwzrTc7pJKRjfglYsfG38PIukh4IY487cePyAWk+c=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mBQRTAZwNhanfiYjH1GAtvk0CNw2DQ9nw/wmsQVV/6Ff7XBabrn58h3xeCQHtoD3hP60VTItWy+V1JgADimXra3vTFp3BGq++UQIabp01ubNIQhhVgqoUVwWcQj3Z+g6qq32Rp0THofBtvX6LClVar/62J2eD3He0tfdG983Kgk= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=VtU5GoBc DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 067094BB1C35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=VtU5GoBc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785785753; x=1817321753; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0PbwzrTc7pJKRjfglYsfG38PIukh4IY487cePyAWk+c=; b=VtU5GoBcVMHJIY+xHNHHG4vk1XmXWZ6TQqg1UihrVxs1Tb1h7MtL8MjA XCyTrBK6UiOz06edLcTdINmwhhOl6Jh1IC1Unj3Icjf/j0teOvXVE8MJb KdE8XLl2zdPqPB0cVI8VoBUsHyji5kCI1DtHCdRgDXvTVEiq0r7dqF21w I5XJSKnymgxXjNZtHZabKjK7mWjIESK6KXtWXuEeJmCDRnzN87oDcISac nD5KD9nU96UVrxdbNR0lpU8fl5pu/y+2a0wWxngJMp3ck3BkJ15BO1MZE 5/ICiG/LDXP9yLx/st4qwekbKYPev+TLqqHA+aUo1is+T85Em3ChA7/ef w==; X-CSE-ConnectionGUID: sH4mN1IvRCai042hR13obA== X-CSE-MsgGUID: MB+9cTZqT3aO8yB+NAGdBQ== X-IronPort-AV: E=McAfee;i="6800,10657,11864"; a="85462647" X-IronPort-AV: E=Sophos;i="6.25,203,1779174000"; d="scan'208";a="85462647" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 12:35:47 -0700 X-CSE-ConnectionGUID: cPgbcL00TceiRV3gtkdVmw== X-CSE-MsgGUID: XCPGfm/sQ9+YJIx+OrNa+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,203,1779174000"; d="scan'208";a="265139722" Received: from fdaddami-mobl1.amr.corp.intel.com (HELO localhost) ([10.245.115.173]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 12:35:46 -0700 From: Abdul Basit Ijaz To: gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com, JiniSusan.George@amd.com, tom@tromey.com, eliz@gnu.org Subject: [PATCH v11 05/10] gdb: Skip trampoline functions for the finish and reverse-finish commands. Date: Mon, 3 Aug 2026 21:34:44 +0200 Message-Id: <20260803193449.33375-6-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260803193449.33375-1-abdul.b.ijaz@intel.com> References: <20260803193449.33375-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 This change skips trampoline functions when the option 'skip-trampoline-functions' is set to 'on' for the finish or reverse-finish command. Before this change, for these commands GDB returns to the trampoline function indicated by the compiler with DIE "DW_AT_trampoline". For better user experience, all such frames can be hidden from the user. In this example the IFX compiler emits "DW_AT_trampoline" tag for the 'first' and 'second' trampoline functions like following: function second (x, y) result(z) integer, intent(in) :: x, y integer :: z z = x * y ! breakpt-finish end function second function first (num1, num2) result(total) integer, intent(in) :: num1, num2 integer :: total total = second (num1 + 4, num2 * 3) ! first-breakpt total = total + 30 end function first Related Dwarf: 0x0000013f: DW_TAG_subprogram DW_AT_low_pc (0x0000000000404350) DW_AT_high_pc (0x000000000040435f) DW_AT_frame_base (DW_OP_reg6 RBP) DW_AT_linkage_name ("second_.t74p.t75p") DW_AT_name ("second_.t74p.t75p") DW_AT_trampoline ("second_") 0x0000015a: DW_TAG_subprogram DW_AT_low_pc (0x00000000004044a0) DW_AT_high_pc (0x00000000004044af) DW_AT_frame_base (DW_OP_reg6 RBP) DW_AT_linkage_name ("first_.t104p.t105p") DW_AT_name ("first_.t104p.t105p") DW_AT_trampoline ("first_") Before this change, the finish command output looks like: ''' (gdb) finish Run till exit from #0 second (x=20, y=9) at test.f90:4 0x0000000000405209 in second_.t74p.t75p () at test.f90:12 12 end function first Value returned is $1 = 180 ''' The reverse-finish command output in this test before the change: ''' (gdb) reverse-finish Run back to call of #0 second (x=20, y=9) at test.f90:4 0x0000000000405204 in second_.t74p.t75p () at test.f90:12 12 end function first ''' After this change: ''' (gdb) finish Run till exit from #0 second (x=20, y=9) at test.f90:4 0x00000000004051e3 in first (num1=16, num2=3) at test.f90:10 10 total = second (num1 + 4, num2 * 3) ! first-breakpt Value returned is $1 = 180 (gdb) reverse-finish Run back to call of #0 second (x=20, y=9) at test.f90:4 0x00000000004051de in first (num1=16, num2=3) at test.f90:10 10 total = second (num1 + 4, num2 * 3) ! first-breakpt ''' The test gdb.fortran/func-trampoline.exp is updated for testing the finish command. The test gdb.reverse/finish-reverse-trampoline.exp is added for testing the reverse-finish command. --- gdb/NEWS | 5 +- gdb/doc/gdb.texinfo | 4 ++ gdb/infcmd.c | 12 ++++ gdb/infrun.c | 9 +++ gdb/infrun.h | 5 ++ gdb/testsuite/gdb.fortran/func-trampoline.exp | 17 +++++- .../gdb.reverse/finish-reverse-trampoline.exp | 56 +++++++++++++++++++ 7 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 gdb/testsuite/gdb.reverse/finish-reverse-trampoline.exp diff --git a/gdb/NEWS b/gdb/NEWS index 8100f7cd7b4..ed035f25303 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -1774,8 +1774,9 @@ show skip-trampoline-functions recognize function calls that have been marked as trampolines in the debug info. It improves stepping behavior in that it steps over the trampoline code and hides it from the user. It improves the printing of the stack by - hiding trampoline functions from the backtrace. Currently, only DWARF - trampolines are supported. + hiding the trampoline frames from the backtrace and skips trampoline + functions while returning from the target function of a trampoline call. + Currently, only DWARF trampolines are supported. If this is turned off, GDB will handle @dfn{trampoline functions} the same as any other function. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index af57610ddc3..b9dd6c14809 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -6772,6 +6772,10 @@ DWARF trampolines marked via DW_AT_trampoline are supported by this. When issuing a @code{backtrace}, if @code{skip-trampoline-functions} is set, @value{GDBN} will skip trampoline frames while printing the stack. +When issuing a @code{finish} or @code{reverse-finish}, if +@code{skip-trampoline-functions} is set, @value{GDBN} will skip trampoline +frames while returning from the target function. + Currently, only DWARF trampolines marked via DW_AT_trampoline are supported by this. diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 3e943123519..451777e3087 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -1952,6 +1952,18 @@ finish_command (const char *arg, int from_tty) error (_("\"%ps\" not meaningful in the outermost frame."), styled_string (command_style.style (), "finish")); + if (skip_trampoline_functions) + { + for (int i = 0; (SAFE_TRAMPOLINE_CHAIN (i, frame) + && in_trampoline_frame (frame)); ++i) + frame = get_prev_frame (frame); + + if (frame == nullptr) + error (_("\"finish\" not meaningful in the outermost non-trampoline \ +frame. Consider running \"set skip-trampoline-functions off\", to stop in \ +trampoline frames for the \"finish\" command.")); + } + clear_proceed_status (0); tp = inferior_thread (); diff --git a/gdb/infrun.c b/gdb/infrun.c index 9d1b85e9d1f..024bf30aced 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -8211,6 +8211,15 @@ process_event_stop_test (struct execution_control_state *ecs) keep_going (ecs); return; } + else if (skip_trampoline_functions && in_trampoline_code (stop_pc)) + { + /* While reverse stepping if we are in trampoline code + we will just continue single step in the hope of leaving the + trampoline again soon. Uses in_trampoline_code() to detect + both inline and concrete trampolines. */ + keep_going (ecs); + return; + } } /* This always returns the sal for the inner-most frame when we are in a diff --git a/gdb/infrun.h b/gdb/infrun.h index a5c6f317193..019ea86c43f 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -80,6 +80,11 @@ infrun_debug_show_threads (const char *title, ThreadRange threads) information. */ #define MAX_TRAMPOLINE_CHAIN_SIZE 10 +/* True if the trampoline index "i" is less then the maximum allowed size + of a trampoline chain. */ +#define SAFE_TRAMPOLINE_CHAIN(i, frame) \ + (i < MAX_TRAMPOLINE_CHAIN_SIZE && (frame != nullptr)) + /* Nonzero if we want to give control to the user when we're notified of shared library events by the dynamic linker. */ extern int stop_on_solib_events; diff --git a/gdb/testsuite/gdb.fortran/func-trampoline.exp b/gdb/testsuite/gdb.fortran/func-trampoline.exp index 5216de25a45..f330ac54ef2 100644 --- a/gdb/testsuite/gdb.fortran/func-trampoline.exp +++ b/gdb/testsuite/gdb.fortran/func-trampoline.exp @@ -13,8 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Test "backtrace" and "backtrace -n" commands for functions with trampoline -# calls. +# Test "backtrace", "backtrace -n" and "finish" commands for functions with +# trampoline calls. require allow_fortran_tests @@ -84,4 +84,17 @@ foreach_with_prefix opt_level {O0 O2} { "#$decimal.* $middle_desc" \ "#$decimal.* $outer_desc.*"] } + + if {[string match -nocase "O2" $opt_level]} { + continue + } + + with_test_prefix "finish" { + init_test $opt_level + + gdb_test "finish" [multi_line \ + "Run till exit from #0 $fill second \\(x=20, y=9\\) $fill" \ + "${fill}first \\(num1=16, num2=3\\)${fill}" \ + "${fill}(\r\nValue returned is $valnum_re = 180)"] + } } diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-trampoline.exp b/gdb/testsuite/gdb.reverse/finish-reverse-trampoline.exp new file mode 100644 index 00000000000..fb342eca030 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/finish-reverse-trampoline.exp @@ -0,0 +1,56 @@ +# 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 "reverse-finish" command for functions with trampoline. + +require supports_reverse allow_fortran_tests + +if {![test_compiler_info {ifx-*} f90]} { + untested "This test is only applicable for IFX, which emits the\ + trampoline DIE in Dwarf." + return +} + +load_lib fortran.exp + +set testfile finish-reverse-trampoline +set srcfile "${srcdir}/gdb.fortran/func-trampoline.f90" +set binfile [standard_output_file $testfile] + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug f90}]} { + return +} + +if {![fortran_runto_main]} { + return +} + +set inner_loc [gdb_get_line_number "second-breakpt"] + +if [supports_process_record] { + # Activate process record/replay + gdb_test_no_output "record" "turn on process record" +} + +# Set breakpoint inside the innermost function 'second'. +gdb_breakpoint "$srcfile:$inner_loc" +gdb_continue_to_breakpoint "innermost-body" ".*$srcfile:$inner_loc.*" + +gdb_test "reverse-finish" [multi_line \ + "Run back to call of #0 second \\(x=20, y=9\\).*" \ + ".*in first \\(num1=16, num2=3\\).*"] + +gdb_test "frame" "#0.*first.*" "Frame 0 shows first function" -- 2.34.1 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.