From patchwork Fri May 24 09:16:09 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: 90792 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 6F6F2385ED72 for ; Fri, 24 May 2024 09:19:34 +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 EAF72385EC2A for ; Fri, 24 May 2024 09:17:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAF72385EC2A 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 EAF72385EC2A 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=1716542232; cv=none; b=iG83+gCaWbiKHI1px5ZvcbTbZhsLEoBdBZ65Ok4cvvD6JkDTSwbP7nhEEyDfIdo2RQgrFYM8P+JoQf8zdJDlbWCHKjlfN/nabGszf+805wNZrugZa3yFw4Jp0ja42Zxk+mqnT/XP5kFhQST9ykX8oiqQU4UMF6xH/aDilbs2a5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716542232; c=relaxed/simple; bh=Hlj35o2cezOcTjRqyRi0orE2CwlWjNWrtTsTPIZfIMk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=H7RsfJw5CJoHjMz4XF5MuNr42qUSglMIffOCN2srDiIdr6VTYTn5HVX98hRggbAxayNBS8qqHoZHA6fpP9LyT3sPhtDDOnsSNTPQsMvUdFKIpuvC6UIPVgJsTyuj6lQT6BR60emrNlFTk6KgjihrtkASOp7TRq3yHghWHhuHhRA= 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=1716542227; x=1748078227; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Hlj35o2cezOcTjRqyRi0orE2CwlWjNWrtTsTPIZfIMk=; b=JeX9XSGOBS2BfAMpQcG+hNKggTz1yPtGPMPMVY/s78K62bRFyMOMejrf 647AuVnvJHPp0RZoFYBScTSjD0v0F9gjMBpzZEsMg+8bo9QBZ9w1yS5AP ka3WFv1ClDFu8s+Su3tLpvrsOH7DFTAOK+T5rS5shd5oFl3vHBw4NUkAh BfCyYZgxGxhR++6eTvfLVxwM1o0oW71foP5+ucu9Tp18S0R/MDqVUBHMG XrhSgFYJMzTNNn193AUfloqGu8idg0WVXGs/TMBEx1d+Vp5W7V1sAFKmt SJqoADfzwG9VbMvfQhGUgxm5pr07cXGiQdbPNO96Qyq/GsLI3d6wJC4bU Q==; X-CSE-ConnectionGUID: 2UlvP8hOQAaIUSM+2D7xRA== X-CSE-MsgGUID: eiUGt4BDQri7bYvdmVAeyA== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="24321605" X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="24321605" 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:05 -0700 X-CSE-ConnectionGUID: 2RJvXUn0T1uxZyi4Hb8wjw== X-CSE-MsgGUID: etj+ca/vRD6gFd+C1uWE7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="33945401" 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:04 -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 06/10] gdb: Skip trampoline functions for the up command. Date: Fri, 24 May 2024 11:16:09 +0200 Message-Id: <20240524091613.11377-7-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.6 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 Reviewed-By: Eli Zaretskii --- 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 2cd44fd71ec..e5f3dd26002 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}"] +}