From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sbb2C/ntcGoPbAMAWB0awg (envelope-from ) for ; Mon, 03 Aug 2026 15:37:29 -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=lYEKOxBm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 10FA11E099; Mon, 03 Aug 2026 15:37:29 -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 [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 70B981E099 for ; Mon, 03 Aug 2026 15:37:27 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11A004BB24E1 for ; Mon, 3 Aug 2026 19:37:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11A004BB24E1 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=lYEKOxBm Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by sourceware.org (Postfix) with ESMTPS id 6911D4BA23E6 for ; Mon, 3 Aug 2026 19:36:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6911D4BA23E6 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 6911D4BA23E6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785785819; cv=none; b=ECNndDdjtXUlWgRG3bEjAndf2ORkoKjMK1Yp+0wIZe4o5WrxNbyksg2e5z96me1qqy0A0YQrPYvTQTTEJwZPVHteAHpflpSQB7hB2179fRrR/DKbOUzAB7usR869uiQkjY981rFcqooP6kyNr1//Ucyt13wa093oai6IkV/qeX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785785819; c=relaxed/simple; bh=kjFOYUHhhlyOnYE1LEUCqgm9k+u4EJg6IzdJRBKQhKc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GiKKdjm4Zy1Brvb4rmPxw/buSugb6GoNlt943B2BVbUtgKZ0GWJZk6y2QRLOEFaqu1Tjz9XXEi5M0MSR1T61463XrPIV38ktE8NjuAbgwisDw4zXEikRLNucUe4SVYNCKr8tGJ+upz9TRl5EqxAE8a0FRlxxDyC3Lr8Dob4WBjU= ARC-Authentication-Results: i=1; sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785785819; x=1817321819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kjFOYUHhhlyOnYE1LEUCqgm9k+u4EJg6IzdJRBKQhKc=; b=lYEKOxBmNgaTf/Cy3eOhy/WP+6217vqxaREGFyRMsDfeheLOviMGMVB6 mk23nw1pyEEkAge5jAivv/LlIjttncFMnvBUBzl+XFUpDgoTomgY7PsZ5 P8/6fXgNvewfQ09FPgBRntJpujcFLXOqfMC0iQTE2GH6cE7ZK/1N00IyH pPothFMq/1LgD5raslXSy68LB4HJl+w7g8EvEdGqq/ScuUYZq53f/iINP C723D2ew6HP4Rv5r/BEMnowZa1O4YTacos85DOpii6Ium5KsRk8Wfyfzp kncrrhCvIwONY2DL6o6HyjJGOUByrYzK0yI357C9sFw+L5cnsU5NCa3/r g==; X-CSE-ConnectionGUID: 2Bb3g2y1QNy8y1uG8Ou2hA== X-CSE-MsgGUID: k92WBOPuTCWptnQZfzHmSw== X-IronPort-AV: E=McAfee;i="6800,10657,11864"; a="85309496" X-IronPort-AV: E=Sophos;i="6.25,203,1779174000"; d="scan'208";a="85309496" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 12:36:27 -0700 X-CSE-ConnectionGUID: p8cr1+iNRk2jP8STdDiOsQ== X-CSE-MsgGUID: CZ+QBnepTkOZpBgigK0lOw== X-ExtLoop1: 1 Received: from fdaddami-mobl1.amr.corp.intel.com (HELO localhost) ([10.245.115.173]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2026 12:36:25 -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 10/10] gdb: Filter trampoline frames in backtrace when using Python frame-filters. Date: Mon, 3 Aug 2026 21:34:49 +0200 Message-Id: <20260803193449.33375-11-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 In case of the Python frame-filters, this change filters trampoline functions when the option 'skip-trampoline-functions' is set to 'on'. GDB recently added the option to hide frames that are marked by the compiler with "DW_AT_trampoline", see commit 'Skip trampoline frames for the backtrace command'. This implements the same functionality when python frame filters are in use. 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-framefilter 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_") Once frame filters are enabled the backtrace command output before this change looks like: ''' (gdb) info frame-filter global frame-filters: Priority Enabled Name 100 Yes TestTrampolineFrameFilter (gdb) backtrace 3 \#0 second (x=20, y=9) at test.f90:4 \#1 0x0000000000405209 in second_.t74p.t75p () at test.f90:12 \#2 0x00000000004051e3 in first (num1=16, num2=3) at test.f90:10 (gdb) backtrace -3 \#2 0x00000000004051e3 in first (num1=16, num2=3) at test.f90:10 \#3 0x0000000000405309 in first_.t95p.t96p () at test.f90:21 \#4 0x0000000000405234 in func_trampoline () at test.f90:17 ''' After this change: ''' (gdb) info frame-filter global frame-filters: Priority Enabled Name 100 Yes TestTrampolineFrameFilter (gdb) backtrace 3 \#0 second (x=20, y=9) at test.f90:4 \#2 0x00000000004051e3 in first (num1=16, num2=3) at test.f90:10 \#4 0x0000000000405234 in func_trampoline () at test.f90:17 (gdb) backtrace -3 \#2 0x00000000004051e3 in first (num1=16, num2=3) at test.f90:10 \#4 0x0000000000405234 in func_trampoline () at test.f90:17 ''' New test gdb.python/py-framefilter-trampoline.exp is added to test this change. --- gdb/python/py-frame.c | 11 +++ .../gdb.python/py-framefilter-trampoline.exp | 77 +++++++++++++++++++ .../gdb.python/py-framefilter-trampoline.py | 31 ++++++++ 3 files changed, 119 insertions(+) create mode 100644 gdb/testsuite/gdb.python/py-framefilter-trampoline.exp create mode 100644 gdb/testsuite/gdb.python/py-framefilter-trampoline.py diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c index afa89f0d112..098b37230e1 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -59,6 +59,17 @@ frame_object_to_frame_info (PyObject *obj) if (frame == NULL) return NULL; + 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) + return nullptr; + } + } + return frame; } diff --git a/gdb/testsuite/gdb.python/py-framefilter-trampoline.exp b/gdb/testsuite/gdb.python/py-framefilter-trampoline.exp new file mode 100644 index 00000000000..23fd22164ef --- /dev/null +++ b/gdb/testsuite/gdb.python/py-framefilter-trampoline.exp @@ -0,0 +1,77 @@ +# Copyright (C) 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 . + +# This file is part of the GDB testsuite. It tests skipping of trampolines +# in the backtrace command in case Python-based frame-filters are enabled. + +load_lib gdb-python.exp + +require allow_python_tests 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 py-framefilter-trampoline +set srcfile "${srcdir}/gdb.fortran/func-trampoline.f90" +set binfile [standard_output_file $testfile] + +if {[build_executable $testfile.exp $testfile $srcfile {debug f90}] == -1} { + return +} + +# Start with a fresh gdb. +gdb_exit +gdb_start + +gdb_test "info frame-filter" \ + "No frame filters\\." \ + "info frame filter before loading filters" + +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if {![runto_main]} { + return +} +gdb_test_no_output "set python print-stack full" \ + "set python print-stack to full" + +# Load frame-filters +set remote_python_file [gdb_remote_download host \ + ${srcdir}/${subdir}/${testfile}.py] +gdb_test_no_output "source ${remote_python_file}" "load python file" + +set inner_loc [gdb_get_line_number "second-breakpt"] +set middle_loc [gdb_get_line_number "first-breakpt"] +set outer_loc [gdb_get_line_number "main-outer-loc"] +set fill "\[^\r\n\]*" + +set inner_desc "second \\(x=20, y=9\\) at ${fill}$srcfile:$inner_loc" +set middle_desc "first \\(num1=16, num2=3\\) at ${fill}$srcfile:$middle_loc" +set outer_desc ".* at .*$srcfile:$outer_loc" + +# Set breakpoint inside the innermost function 'second'. +gdb_breakpoint "$srcfile:$inner_loc" +gdb_continue_to_breakpoint "innermost-body" ".*$srcfile:$inner_loc.*" + +# Test with frame filter. +gdb_test "bt" [multi_line \ + "#$decimal.* $middle_desc" \ + "#$decimal.* $outer_desc.*"] diff --git a/gdb/testsuite/gdb.python/py-framefilter-trampoline.py b/gdb/testsuite/gdb.python/py-framefilter-trampoline.py new file mode 100644 index 00000000000..0cdaf7bb4de --- /dev/null +++ b/gdb/testsuite/gdb.python/py-framefilter-trampoline.py @@ -0,0 +1,31 @@ +# Copyright (C) 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 . + +# This file is part of the GDB testsuite. It tests if trampolines are +# skipped when Python-based frame-filters are enabled. + +import gdb + +class TestTrampolineFrameFilter(): + def __init__(self): + self.name = "TestTrampolineFrameFilter" + self.priority = 100 + self.enabled = True + gdb.frame_filters[self.name] = self + + def filter(self, frame_iter): + return frame_iter + +TestTrampolineFrameFilter() -- 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.