From patchwork Fri May 24 09:16:10 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: 90793 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 A30AD385E83F for ; Fri, 24 May 2024 09:20:08 +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 D225F385ED72 for ; Fri, 24 May 2024 09:17:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D225F385ED72 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 D225F385ED72 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=1716542237; cv=none; b=dIkjR2eoSxUhVEtpB7HbhMcOlAP3G0pe+W43wUs04cQYoGNJ+jrCsMlOuojExmmoIvyzywR4mlNs0t5Y0uR1zRj9ZbDIfs+ovFGuRX65e4SDWE29SXGB+TrA4uHFT7O0CBEfktt69/K9WfbFkffbAySQMb0LGMYsWPJGQ9jMKH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716542237; c=relaxed/simple; bh=EaLfQYO44X8kBiN29Q7WS968dF+8QR22ZwET4TUYWfg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GIoBsS6NeXWxPTC7yklFwFVXkr8DHKU/ZcH9w4WOPujav7KJ62KG2ODPQdXfqg/17EORMMf5T3XdRZEgy4Jv8NpisC8abKi7CaHYY8CYuBD14LFfDlDv0ejezpkS8LSHq3dARX0qBck4RsXAGYvCD7SM3Q9EJb/SvMXkGqQT4Q8= 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=1716542233; x=1748078233; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EaLfQYO44X8kBiN29Q7WS968dF+8QR22ZwET4TUYWfg=; b=A6s0ThSJwH6qsGFb0BN0LqnEZ1flDk/tu8gUNvwcpAXY5OYrPN9rwSGK e8ER9WvzFqmarVCNyR0RaopNWMoWtt3Ihk5a8sAIVheUQ6pzUGC5SJ81b pF18vWJRzAZQXGyJhdhft8qqlF6r5WDf8EcjJTlqaHds3egp8ZZ4oZGZe T8Emsdj5QgE7tPO35l+HFdK46HW9jxXAJI6bkjODcoGIGQXPkCAVTI3X+ iozu6RJXpl6GOCxfCqEiUmnbwQpZoR1ER1jjZrGpcHX1IXBQvc0MrFZNZ 5boM1lb/gjyBDhukZMfS2rneHDw9/0zYZ0XxmShdDGQ5oLW0UNzWaqJ9F A==; X-CSE-ConnectionGUID: KDIi/oyeRo+r7y7hViCNng== X-CSE-MsgGUID: 60p7sIdKT/6asyl0SpttbQ== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="24321610" X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="24321610" 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:12 -0700 X-CSE-ConnectionGUID: Lm1glZoZQBG4pDXsvsXLGw== X-CSE-MsgGUID: yboRnfG4QUyTXFKJfkDUUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,185,1712646000"; d="scan'208";a="33945421" 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:10 -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 07/10] gdb: Skip trampoline functions for the return command. Date: Fri, 24 May 2024 11:16:10 +0200 Message-Id: <20240524091613.11377-8-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 for the return command when the option 'skip-trampoline-functions' is set to 'on'. Before this change, GDB processes trampoline functions indicated by the compiler with DIE "DW_AT_trampoline" for the return command and stops at the trampoline functions. 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-return 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 return command output looks like: ''' (gdb) return Make second return now? (y or n) y \#0 0x0000000000405209 in second_.t74p.t75p () at test.f90:12 12 end function first ''' After this change: ''' (gdb) return Make second return now? (y or n) y \#0 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 | 6 +++--- gdb/stack.c | 11 +++++++++++ gdb/testsuite/gdb.fortran/func-trampoline.exp | 10 +++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e5f3dd26002..6d2628ae2c8 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -6538,9 +6538,9 @@ 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}, @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. +When issuing a @code{finish}, @code{reverse-finish}, @code{up} or +@code{return}, 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/stack.c b/gdb/stack.c index 5dad1fe503a..bb390cdffb4 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2831,6 +2831,17 @@ return_command (const char *retval_exp, int from_tty) if (get_frame_type (get_current_frame ()) == DUMMY_FRAME) frame_pop (get_current_frame ()); + if (skip_trampoline_functions) + { + frame_info_ptr ret_frame = get_current_frame (); + for (int i = 0; (SAFE_TRAMPOLINE_CHAIN (i, ret_frame) + && in_trampoline_frame (ret_frame)); ++i) + { + frame_pop (ret_frame); + ret_frame = get_current_frame (); + } + } + select_frame (get_current_frame ()); /* If interactive, print the frame that is now current. */ if (from_tty) diff --git a/gdb/testsuite/gdb.fortran/func-trampoline.exp b/gdb/testsuite/gdb.fortran/func-trampoline.exp index e7e4c8ae7b0..dd26e5ab035 100644 --- a/gdb/testsuite/gdb.fortran/func-trampoline.exp +++ b/gdb/testsuite/gdb.fortran/func-trampoline.exp @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Test "backtrace", "backtrace -n", "finish" and "up" commands for +# Test "backtrace", "backtrace -n", "finish", "up" and "return" commands for # functions with trampoline calls. require allow_fortran_tests @@ -92,3 +92,11 @@ with_test_prefix "up" { "#$decimal.* $middle_desc" \ "${fill}first = second \\(num1 \\+ 4, num2 \\* 3\\).*${fill}"] } + +with_test_prefix "return" { + init_test + + gdb_test "return" \ + ".*first = second \\(num1 \\+ 4, num2 \\* 3\\) \\! first-breakpt" \ + "" "Make second return now.*y or n. $" "y" +}