From patchwork Fri May 24 09:16:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ijaz, Abdul B" X-Patchwork-Id: 90797 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7F2E3858C66 for ; Fri, 24 May 2024 09:22:09 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by sourceware.org (Postfix) with ESMTPS id 3CB46385ED71 for ; Fri, 24 May 2024 09:17:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CB46385ED71 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 3CB46385ED71 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716542256; cv=none; b=nTTy1jKl8hlmzSTq0TFuQtzVjvAAIrSKSE3ia4U14CgCRJnxLQEsULdTfUzmI/9swb+LHuTBB5snZ49arFA+EIksFosGwgBMEyTGMtS/81aeArr9GLpwpN4rZZuvKXJq/CrE3eDHDnPoq0q7QY2SfPDbinhDiRuex02O1y7D8KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716542256; c=relaxed/simple; bh=yxpFh2pMrxNGQ4baBcsB8eAK/hN2VeIIqvP16uSO7Us=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=UzcsWhzUFkBkN8TT6CTYzDA9RYjzo2gQfJFp0FqO3aZg8ZUPjwrZdjYIHB01s7MN6+mMYalwFOGT4G9CYqV2P1VPCvutpH5v9ujjNuQaI8tPZ06X1sx6wKpoNypNSQa7nby1rzDw6aI6rjujKU038yPd3dbhoYbSdBjESduRE1g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716542251; x=1748078251; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yxpFh2pMrxNGQ4baBcsB8eAK/hN2VeIIqvP16uSO7Us=; b=Skd7fHznrRHcZdt2HtvnLW8bETvN+y05w7VPOgavlbw+JQJNrRndte+2 37/KBqvE5SLlgQNDDZTvf+N5ybPtjd3GRbJ9ZdE5TIjsnh1lrunnxOsWP ZLwwkJnUKG0k71BarPxJuBqliwqivKzlVEjFlmZxxcbLcW7HvONXAGzgc cv1bPXpyoodTqLVHAmsA3FklMD7isVj0zxCarzag5S3INiErZf3BKWxeB ultcJyEuf0c/8snxAeHqWB3bzr3dq2fBkZ6GF0uLSgucVHVQzDR8hEVjH pzHUArBZ20ol5ASErYO0I2ZzJ+WV/DsfHPrK4EXVkLQUq/QvvsB7t92UD g==; X-CSE-ConnectionGUID: vw2eli6YTEqRWz0BQCR/Yw== X-CSE-MsgGUID: 1AVAXACjTKmwum4gcdjsKw== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="24321669" X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="24321669" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2024 02:17:30 -0700 X-CSE-ConnectionGUID: K7Gw1YSaQ+eaZq1q1iiRSA== X-CSE-MsgGUID: IE7ozIjDSsiw4bv+20F2Sw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="33945490" Received: from abijaz-mobl2.ger.corp.intel.com (HELO localhost) ([10.94.253.168]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2024 02:17:29 -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 v7 10/10] gdb: Filter trampoline frames in backtrace when using Python frame-filters. Date: Fri, 24 May 2024 11:16:13 +0200 Message-Id: <20240524091613.11377-11-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524091613.11377-1-abdul.b.ijaz@intel.com> References: <20240524091613.11377-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org From: "Ijaz, Abdul B" 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. 2024-05-24 Ijaz, Abdul B --- 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 bbb42afb2ed..5c07ba58b23 100644 --- a/gdb/python/py-frame.c +++ b/gdb/python/py-frame.c @@ -70,6 +70,17 @@ frame_object_to_frame_info (PyObject *obj) if (frame_obj->frame_id_is_next) frame = get_prev_frame (frame); + 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..76dbdaa970a --- /dev/null +++ b/gdb/testsuite/gdb.python/py-framefilter-trampoline.exp @@ -0,0 +1,77 @@ +# Copyright (C) 2024 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 -1 +} + +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 -1 +} + +# 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..0e9dfd7af2a --- /dev/null +++ b/gdb/testsuite/gdb.python/py-framefilter-trampoline.py @@ -0,0 +1,31 @@ +# Copyright (C) 2024 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()