diff --git a/gdb/NEWS b/gdb/NEWS
index b435553d23a..58c81203a7e 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -917,8 +917,9 @@ show skip-trampoline-functions
   This setting is 'on' by default.  When 'on' it controls whether GDB will
   recognize function calls that have been marked as trampolines in the debug
   info.  It improves stepping behavior in that it steps over the trampoline
-  code and hides it from the user.  Currently, only DWARF trampolines are
-  supported.
+  code and hides it from the user.  It improves the printing of the stack by
+  hiding trampoline functions from the backtrace.  Currently, only DWARF
+  trampolines are supported.
 
   If this is turned off, GDB will handle @dfn{trampoline functions} the same
   as any other function.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4da796c99ae..8fa35fa7b5e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -6535,6 +6535,12 @@ execution until leaving the trampoline region.  The @code{stepi} command
 is not affected by the setting which is enabled by default.  Currently, only
 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.
+
+Currently, only DWARF trampolines marked via DW_AT_trampoline are supported by
+this.
+
 @item set skip-trampoline-functions off
 Causes @value{GDBN} to completely ignore any trampoline information a compiler
 might have emitted in its debug info.  Trampolines will be treated like any
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 0e79aa7201e..fab98a96ba6 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -191,7 +191,7 @@ static bool detach_fork = true;
    DW_AT_trampoline by the compiler.  If false, GDB will ignore the
    attribute.  */
 
-static bool skip_trampoline_functions = true;
+bool skip_trampoline_functions = true;
 
 bool debug_infrun = false;
 static void
@@ -10793,8 +10793,8 @@ Options are 'forward' or 'reverse'."),
 			  &skip_trampoline_functions, _("\
 Set whether gdb attempts to hide trampolines marked in the debug info."), _("\
 Show whether gdb attempts to hide trampolines marked in the debug info."), _("\
-If on, while stepping gdb will skip through functions and inlined functions\n\
-marked as trampolines by the compiler.  If off, gdb will treat trampolines as\n\
+If on, gdb will skip through functions and inlined functions marked as\n\
+trampolines by the compiler.  If off, gdb will treat trampolines as\n\
 normal functions."),
 			  nullptr, show_skip_trampoline_functions, &setlist,
 			  &showlist);
diff --git a/gdb/infrun.h b/gdb/infrun.h
index ea1ec134c7c..fbe88ad4595 100644
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -107,6 +107,12 @@ extern bool non_stop;
    starting an inferior.  */
 extern bool disable_randomization;
 
+/* If set (default) GDB will step through functions/inlined subroutines marked
+   DW_AT_trampoline by the compiler.  If false, GDB will ignore the
+   attribute.  */
+
+extern bool skip_trampoline_functions;
+
 /* Returns a unique identifier for the current stop.  This can be used
    to tell whether a command has proceeded the inferior past the
    current location.  */
diff --git a/gdb/stack.c b/gdb/stack.c
index c2323e1726d..de8b404365f 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2060,6 +2060,14 @@ backtrace_command_1 (const frame_print_options &fp_opts,
 	{
 	  QUIT;
 
+	  if (skip_trampoline_functions && in_trampoline_frame (fi))
+	    {
+	      /* Trampoline frames are not printed so they are not counted in
+		 the backtrace limit.  */
+	      count++;
+	      continue;
+	    }
+
 	  /* Don't use print_stack_frame; if an error() occurs it probably
 	     means further attempts to backtrace would fail (on the other
 	     hand, perhaps the code does or could be fixed to make sure
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 5eac2ee8535..1027143a110 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4301,6 +4301,18 @@ in_trampoline_function (CORE_ADDR pc)
 
 /* See symtab.h.  */
 
+bool
+in_trampoline_frame (frame_info_ptr fi)
+{
+  CORE_ADDR pc;
+  if (get_frame_pc_if_available (fi, &pc))
+    return in_trampoline_function (pc);
+
+  return false;
+}
+
+/* See symtab.h.  */
+
 CORE_ADDR
 find_function_trampoline_target (CORE_ADDR pc)
 {
diff --git a/gdb/symtab.h b/gdb/symtab.h
index c60485dc6d3..234171ed404 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2359,6 +2359,11 @@ extern CORE_ADDR find_solib_trampoline_target (const frame_info_ptr &, CORE_ADDR
 
 extern bool in_trampoline_function (CORE_ADDR pc);
 
+/* Return whether or not the pc of the current frame is within a block that
+   belongs to a function that is marked as a trampoline by the compiler.  */
+
+extern bool in_trampoline_frame (frame_info_ptr);
+
 /* Find the target of a trampoline function marked via the DW_AT_trampoline
    attribute and return its address.  Returns 0 if the pc is not contained
    in a trampoline function (inlined or not).  If DW_AT_trampoline
diff --git a/gdb/testsuite/gdb.fortran/func-trampoline.exp b/gdb/testsuite/gdb.fortran/func-trampoline.exp
new file mode 100644
index 00000000000..bfa0002cf0e
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/func-trampoline.exp
@@ -0,0 +1,77 @@
+# Copyright 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 <http://www.gnu.org/licenses/> .
+
+# Test "backtrace" and "backtrace -n" commands for functions with trampoline
+# calls.
+
+require 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
+}
+
+standard_testfile ".f90"
+load_lib fortran.exp
+
+# Initialize the test by running the program to the innermost
+# function name "second".
+
+proc init_test {} {
+    global binfile srcfile inner_loc
+
+    clean_restart ${binfile}
+    if {![fortran_runto_main]} {
+	return -1
+    }
+
+    # Set breakpoint inside the innermost function 'second'.
+    gdb_breakpoint "$srcfile:$inner_loc"
+    gdb_continue_to_breakpoint "innermost-body" ".*$srcfile:$inner_loc.*"
+}
+
+if {[build_executable "failed to prepare" ${testfile} ${srcfile} \
+    {debug f90}]} {
+    return -1
+}
+
+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"
+
+with_test_prefix "backtrace" {
+    init_test
+
+    # Limit the backtrace to 3 frames and ensure both frames for first
+    # and second function are shown only and trampoline frames are filtered.
+    gdb_test "backtrace 3" [multi_line \
+	"#$decimal.* $inner_desc" \
+	"#$decimal.* $middle_desc" \
+	"#$decimal.* $outer_desc.*"]
+}
+
+with_test_prefix "backtrace outerframes" {
+    init_test
+
+    gdb_test "backtrace -3" [multi_line \
+	"#$decimal.* $middle_desc" \
+	"#$decimal.* $outer_desc.*"]
+}
diff --git a/gdb/testsuite/gdb.fortran/func-trampoline.f90 b/gdb/testsuite/gdb.fortran/func-trampoline.f90
new file mode 100644
index 00000000000..10eb3f5188f
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/func-trampoline.f90
@@ -0,0 +1,39 @@
+! Copyright 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 <http://www.gnu.org/licenses/> .
+
+! Source code for func-trampoline.exp.
+
+integer(kind=4) function second(x, y)
+  integer(kind=4), intent(in) :: x
+  integer(kind=4), intent(in) :: y
+
+  second = x * y ! second-breakpt
+end function
+
+integer(kind=4) function first(num1, num2)
+  integer(kind=4), intent(in) :: num1
+  integer(kind=4), intent(in) :: num2
+
+  first = second (num1 + 4, num2 * 3) ! first-breakpt
+end function
+
+program func_trampoline
+  integer(kind=4) :: total
+
+  total = first(16, 3) ! main-outer-loc
+
+  write(*,*)  "Result is ", total, "\n"
+  ! Expected: 180
+end program func_trampoline
diff --git a/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp b/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp
index eef84da0e44..4591880ca7b 100644
--- a/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp
+++ b/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp
@@ -41,7 +41,7 @@ set have_index [exec_has_index_section $binfile]
 # value to pass to GDB's 'set language ...' command.
 proc run_tests { lang } {
     with_test_prefix "lang=${lang}" {
-	global binfile hex have_index
+	global binfile hex have_index decimal
 
 	clean_restart ${binfile}
 
@@ -63,6 +63,10 @@ proc run_tests { lang } {
 	set e_arg "\['\"\]abcdef\['\"\]"
 	set 1b_args "\[^\r\n\]+$e_arg\[^\r\n\]+"
 	set 1g_args "obj=\[^\r\n\]+"
+	# Generic decimal number is checked in regex for Frame #8 and #9 to
+	# handle filtered trampoline frames.  Since Frame#8 and Frame#10 are
+	# set to trampoline in DWARF by Intel® Fortran Compiler (ifx), they
+	# are not shown by the backtrace command.
 	set bt_stack \
 	    [multi_line \
 		 "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \
@@ -73,8 +77,8 @@ proc run_tests { lang } {
 		 "#5\\s+$hex in mixed_func_1d \\(\[^\r\n\]+\\) at \[^\r\n\]+" \
 		 "#6\\s+$hex in mixed_func_1c \\(\[^\r\n\]+\\) at \[^\r\n\]+" \
 		 "#7\\s+$hex in mixed_func_1b \\($1b_args\\) at \[^\r\n\]+" \
-		 "#8\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \
-		 "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" ]
+		 "#$decimal\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \
+		 "#$decimal\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" ]
 	set main_args "argc=1, argv=${hex}( \[^\r\n\]+)?"
 	set bt_stack_kfail \
 	    [multi_line \
