From patchwork Fri May 24 15:40:28 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: 90830 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 A0DA03858CD9 for ; Fri, 24 May 2024 15:42:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by sourceware.org (Postfix) with ESMTPS id 57FF53860740 for ; Fri, 24 May 2024 15:41:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57FF53860740 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 57FF53860740 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716565312; cv=none; b=r7wr7Naeu9cNgrT/a9tbrkljb+mekp/5vP5VqyzqSWvWTkETkjW4G2dp5z7EwQN61hbP+dUY1PavWG92ugwzWLNrIPKajWfhFFa0jPtmgwCYhe+j5OzeuqJTw0sF4cLV9N41BL4AGhiYpELjLfQYgIewJLITUEFjjScxWAoK/tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716565312; c=relaxed/simple; bh=LW4Xen/X9uZE/wzcsHtLvYZQUzXQoExvNnhEUjLg3cQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=p5I1M5oi1wJYPKgJCJUfJPtgRNYZqAi4JT14IRKGGu+NLW1Z+qKbGEfoA7mavgYYBBhILIcwWbjB8wk0kezm6H20uyLETuBuF1DLfy4+ehH+WgtTKxVsNKm/QuJ4dzQx4EaMj3hVu15nDd++hZUhwZPnW0pkdbLXkGfs78eO+qY= 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=1716565306; x=1748101306; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LW4Xen/X9uZE/wzcsHtLvYZQUzXQoExvNnhEUjLg3cQ=; b=aV2KWJpXuS+Jw9oEqxax+7y0486vnHshuImD2M0WroZ3SI0opSoMBNTy BYnBW8SHwOiMOJG53uPbQt8F9hLDKTcjsYtUtWKThJMe166s64gNTeuiI PyDVId8Lj4jcET8B/7f4U0XARpuNIc7beW4jnYJXgWd4aZig/ufy3i94Q qXSaOUpOUwjm1wd/fKSiYtzvl+T+MyJ6GLoPEqNNBZdoCU7dm6u0EVfMm Kri2o43pYJVcSvA/Bx4kmEjsqv+8wW7FSl/ZTC2+UeFCtV8C3JVTFPjn1 07kh0IyRelZjwXsmzBxdJ5N5fyO5OlPjc8ov2D4D/aIg6KhCzb/56S+me g==; X-CSE-ConnectionGUID: 9GC+lyPDQQSI67rNTs7mgw== X-CSE-MsgGUID: rT0JR1I6TKS760sVwVUGiw== X-IronPort-AV: E=McAfee;i="6600,9927,11082"; a="23554268" X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="23554268" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2024 08:41:46 -0700 X-CSE-ConnectionGUID: OgA0fIWFS06wNtF07QNpWg== X-CSE-MsgGUID: XV0RT++yRtW14Yn6h9RM2Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="65279072" Received: from abijaz-mobl2.ger.corp.intel.com (HELO localhost) ([10.94.253.168]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 May 2024 08:41:44 -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 v8 06/10] gdb: Skip trampoline functions for the up command. Date: Fri, 24 May 2024 17:40:28 +0200 Message-Id: <20240524154032.12652-7-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524154032.12652-1-abdul.b.ijaz@intel.com> References: <20240524154032.12652-1-abdul.b.ijaz@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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" This change skips trampoline functions when the option 'skip-trampoline-functions' is set to 'on' for the up command. Before this change, GDB processes trampoline functions indicated by the compiler with DIE "DW_AT_trampoline" and stops at the trampoline function for the 'up' command. For better user experience, all such frames can be skipped and 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-up 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 'up' command output looks like: ''' (gdb) up \#1 0x0000000000405209 in second_.t74p.t75p () at test.f90:12 12 end function first ''' After this change: ''' (gdb) up \#2 0x00000000004051e3 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 this change. 2024-05-24 Ijaz, Abdul B --- gdb/doc/gdb.texinfo | 2 +- gdb/stack.c | 7 +++++++ gdb/testsuite/gdb.fortran/func-trampoline.exp | 12 ++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 807cedcd91e..d04f3c718d2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -6538,7 +6538,7 @@ 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 +When issuing a @code{finish}, @code{reverse-finish} or @code{up}, if @code{skip-trampoline-functions} is set, @value{GDBN} will skip trampoline frames while returning from the target function. diff --git a/gdb/stack.c b/gdb/stack.c index de8b404365f..5dad1fe503a 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2635,6 +2635,13 @@ up_silently_base (const char *count_exp) frame = find_relative_frame (get_selected_frame ("No stack."), &count); if (count != 0 && count_exp == NULL) error (_("Initial frame selected; you cannot go up.")); + + if (skip_trampoline_functions) + { + for (int i = 0; (SAFE_TRAMPOLINE_CHAIN (i, frame) + && in_trampoline_frame (frame)); ++i) + frame = get_prev_frame (frame); + } select_frame (frame); } diff --git a/gdb/testsuite/gdb.fortran/func-trampoline.exp b/gdb/testsuite/gdb.fortran/func-trampoline.exp index 4cb9e4f4919..e7e4c8ae7b0 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", "backtrace -n" and "finish" commands for functions with -# trampoline calls. +# Test "backtrace", "backtrace -n", "finish" and "up" commands for +# functions with trampoline calls. require allow_fortran_tests @@ -84,3 +84,11 @@ with_test_prefix "finish" { "${fill}first \\(num1=16, num2=3\\)${fill}" \ "${fill}(\r\nValue returned is $valnum_re = 180)"] } + +with_test_prefix "up" { + init_test + + gdb_test "up" [multi_line \ + "#$decimal.* $middle_desc" \ + "${fill}first = second \\(num1 \\+ 4, num2 \\* 3\\).*${fill}"] +}