[v6,06/10] gdb: Skip trampoline functions for the up command.

Message ID 20240328120528.30382-7-abdul.b.ijaz@intel.com
State New
Headers
Series GDB support for DW_AT_trampoline |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Ijaz, Abdul B March 28, 2024, 12:05 p.m. UTC
  From: "Ijaz, Abdul B" <abdul.b.ijaz@intel.com>

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-03-28 Ijaz, Abdul B <abdul.b.ijaz@intel.com>
---
 gdb/doc/gdb.texinfo                           |  2 +-
 gdb/stack.c                                   |  7 +++++++
 gdb/testsuite/gdb.fortran/func-trampoline.exp | 12 ++++++++++--
 3 files changed, 18 insertions(+), 3 deletions(-)
  

Comments

Eli Zaretskii March 28, 2024, 2:01 p.m. UTC | #1
> From: Abdul Basit Ijaz <abdul.b.ijaz@intel.com>
> Cc: abdul.b.ijaz@intel.com,
> 	JiniSusan.George@amd.com,
> 	tom@tromey.com,
> 	eliz@gnu.org
> Date: Thu, 28 Mar 2024 13:05:24 +0100
> 
>  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 5782e06b91d..222faba5da3 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -6475,7 +6475,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.

The gdb.texinfo part is okay, thanks.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 5782e06b91d..222faba5da3 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -6475,7 +6475,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 6a25054673f..2071d98ffe6 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2605,6 +2605,13 @@  find_relative_frame (frame_info_ptr frame, int *level_offset_ptr)
     {
       frame_info_ptr prev = get_prev_frame (frame);
 
+      if (skip_trampoline_functions)
+	{
+	  for (int i = 0; (SAFE_TRAMPOLINE_CHAIN (i, prev)
+			   && in_trampoline_frame (prev)); ++i)
+	    prev = get_prev_frame (prev);
+	}
+
       if (!prev)
 	break;
       (*level_offset_ptr)--;
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 <http://www.gnu.org/licenses/> .
 
-# 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}"]
+}