[v6] Fix range end handling of inlined subroutines

Message ID HE1PR0602MB3417B82A6028274A529E6168E4D50@HE1PR0602MB3417.eurprd06.prod.outlook.com
State Superseded
Headers show
Series
  • [v6] Fix range end handling of inlined subroutines
Related show

Commit Message

Bernd Edlinger Jan. 1, 2021, 9:57 a.m.
Hi,

this is the main part of the patch, which fixes the range end handling,
and depends on the is_weak line table flag from the previous patch.

I moved the entry_pc handling fix to a follow-up patch, as the
test cases do not depend on it.


Thanks
Bernd.

Comments

Lancelot SIX via Gdb-patches Jan. 1, 2021, 7:41 p.m. | #1
On 2021-01-01 4:57 a.m., Bernd Edlinger wrote:
> Hi,

> 

> this is the main part of the patch, which fixes the range end handling,

> and depends on the is_weak line table flag from the previous patch.

> 

> I moved the entry_pc handling fix to a follow-up patch, as the

> test cases do not depend on it.

> 

> 

> Thanks

> Bernd.

> 


This patch depends on the other one ("Introduce a new line table flag is_weak"),
right?  Could you send it as a series?  Normally, that's easily done using
git-send-email, although you don't seem to use git-send-email.

Simon
Bernd Edlinger Jan. 2, 2021, 9:30 a.m. | #2
On 1/1/21 8:41 PM, Simon Marchi wrote:
> On 2021-01-01 4:57 a.m., Bernd Edlinger wrote:

>> Hi,

>>

>> this is the main part of the patch, which fixes the range end handling,

>> and depends on the is_weak line table flag from the previous patch.

>>

>> I moved the entry_pc handling fix to a follow-up patch, as the

>> test cases do not depend on it.

>>

>>

>> Thanks

>> Bernd.

>>

> 

> This patch depends on the other one ("Introduce a new line table flag is_weak"),

> right?  Could you send it as a series?  Normally, that's easily done using

> git-send-email, although you don't seem to use git-send-email.

> 


Yes.  Will do that next time.

> Simon

>

Patch

From 8778c88874cd7f109645fd21e4657cbf8eb4dcae Mon Sep 17 00:00:00 2001
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date: Tue, 3 Nov 2020 18:41:43 +0100
Subject: [PATCH] Fix range end handling of inlined subroutines

Currently there is a problem when debugging
optimized code when the inferior stops at an inline
sub-range end PC.  It is unclear if that location
is from the inline function or from the calling
function.  Therefore the call stack is often
wrong.

This patch detects the "weak" line table entries
which are likely part of the previous inline block,
and if we have such a location, it assumes the
location belongs to the previous block.

Additionally it may happen that the infrun machinery
steps from one inline range to another inline range
of the same inline function.  That can look like
jumping back and forth from the calling program
to the inline function, while really the inline
function just jumps from a hot to a cold section
of the code, i.e. error handling.

Additionally it may happen that one inline sub-range
is empty or the inline is completely empty.  But
filtering that information away is not the right
solution, since although there is no actual code
from the inline, it is still possible that variables
from an inline function can be inspected here.

Conceptually this patch uses a heuristic to work around
a deficiency in the dwarf-4 and dwarf-5 rnglists structure.
There should be a location view number for each inline
sub-range begin PC and end PC, similar to the DW_AT_GNU_entry_view
which is the location view for the inline entry point.

gdb:
2021-01-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* block.c (blockvector_for_pc_sect): For weak line table values,
	use the inline frame at PC - 1 if it is deeper.
	* dwarf2/read.c (dwarf2_rnglists_process,
	dwarf2_ranges_process): Don't ignore empty ranges here.
	(dwarf2_ranges_read): Ignore empty ranges here.
	(dwarf2_get_pc_bounds): Allow empty inlined subroutines.
	(partial_die_info::read): Likewise.
	(dwarf_finish_line): Add new parameter end_sequence.
	(lnp_state_machine::m_last_file, lnp_state_machine::m_last_address,
	lnp_state_machine::m_stmt_at_address): Remove data items.
	(lnp_state_machine::record_line): Do not filter line entries here,
	except for line == 0.  Pass end_sequence to dwarf_finish_line.
	* infrun.c (process_event_stop_test): Don't stop in !is_stmt lines
	when stepping into inlines.  Don't stop at the call site again, when
	stepping within inlined subroutines with multiple ranges.
	Don't refresh the step info the when executing !is_stmt lines of
	of a different inlined subroutine.
	* symtab.c (find_pc_sect_line): Handle is_weak.

gdb/testsuite:
2021-01-01  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* gdb.base/empty-inline.exp: New test.
	* gdb.base/empty-inline.c: New test.
	* gdb.cp/empty-inline.exp: New test.
	* gdb.cp/empty-inline.cc: New test.
	* gdb.cp/step-and-next-inline.exp: Remove KFAILs, enhance test.
	* gdb.cp/step-and-next-inline.cc: Work around failure with
	gcc-9.3.0 from ubuntu 20.04.
---
 gdb/block.c                                   | 15 ++++-
 gdb/dwarf2/read.c                             | 84 ++++++------------------
 gdb/infrun.c                                  | 33 +++++++++-
 gdb/symtab.c                                  | 18 +++---
 gdb/testsuite/gdb.base/empty-inline.c         | 42 ++++++++++++
 gdb/testsuite/gdb.base/empty-inline.exp       | 48 ++++++++++++++
 gdb/testsuite/gdb.cp/empty-inline.cc          | 33 ++++++++++
 gdb/testsuite/gdb.cp/empty-inline.exp         | 51 +++++++++++++++
 gdb/testsuite/gdb.cp/step-and-next-inline.cc  |  6 ++
 gdb/testsuite/gdb.cp/step-and-next-inline.exp | 93 +++++++++++++++++----------
 10 files changed, 312 insertions(+), 111 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/empty-inline.c
 create mode 100644 gdb/testsuite/gdb.base/empty-inline.exp
 create mode 100644 gdb/testsuite/gdb.cp/empty-inline.cc
 create mode 100644 gdb/testsuite/gdb.cp/empty-inline.exp

diff --git a/gdb/block.c b/gdb/block.c
index fc6bfb9..6f6044b 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -205,7 +205,20 @@  struct symbol *
     return NULL;
 
   if (pblock)
-    *pblock = b;
+    {
+      struct symtab_and_line sal = find_pc_sect_line (pc, section, 0);
+      if (sal.line != 0 && sal.pc == pc && sal.is_weak)
+	{
+	  const struct block *b2 = find_block_in_blockvector (bl, pc - 1);
+	  const struct block *b0 = b;
+	  while (BLOCK_SUPERBLOCK (b0) && !BLOCK_FUNCTION (b0))
+	    b0 = BLOCK_SUPERBLOCK (b0);
+	  if (contained_in (b2, b0))
+	    b = b2;
+	}
+      *pblock = b;
+    }
+
   return bl;
 }
 
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ed45d70..a48beab 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -14402,10 +14402,6 @@  class process_die_scope
 	  return false;
 	}
 
-      /* Empty range entries have no effect.  */
-      if (range_beginning == range_end)
-	continue;
-
       /* Only DW_RLE_offset_pair needs the base address added.  */
       if (rlet == DW_RLE_offset_pair)
 	{
@@ -14524,10 +14520,6 @@  class process_die_scope
 	  return 0;
 	}
 
-      /* Empty range entries have no effect.  */
-      if (range_beginning == range_end)
-	continue;
-
       range_beginning += *base;
       range_end += *base;
 
@@ -14567,6 +14559,10 @@  class process_die_scope
   retval = dwarf2_ranges_process (offset, cu, tag,
     [&] (CORE_ADDR range_beginning, CORE_ADDR range_end)
     {
+      /* Empty range entries have no effect.  */
+      if (range_beginning == range_end)
+	return;
+
       if (ranges_pst != NULL)
 	{
 	  CORE_ADDR lowpc;
@@ -14681,8 +14677,8 @@  class process_die_scope
 	return PC_BOUNDS_NOT_PRESENT;
     }
 
-  /* partial_die_info::read has also the strict LOW < HIGH requirement.  */
-  if (high <= low)
+  /* partial_die_info::read has also the same low < high requirement.  */
+  if (low > high || (low == high && die->tag != DW_TAG_inlined_subroutine))
     return PC_BOUNDS_INVALID;
 
   /* When using the GNU linker, .gnu.linkonce. sections are used to
@@ -19855,8 +19851,9 @@  struct type *
 		     sect_offset_str (sect_off),
 		     objfile_name (objfile));
 	}
-      /* dwarf2_get_pc_bounds has also the strict low < high requirement.  */
-      else if (lowpc >= highpc)
+      /* dwarf2_get_pc_bounds has also the same low < high requirement.  */
+      else if (lowpc > highpc
+	       || (lowpc == highpc && tag != DW_TAG_inlined_subroutine))
 	{
 	  struct objfile *objfile = per_objfile->objfile;
 	  struct gdbarch *gdbarch = objfile->arch ();
@@ -21264,21 +21261,9 @@  class lnp_state_machine
 
   /* Additional bits of state we need to track.  */
 
-  /* The last file that we called dwarf2_start_subfile for.
-     This is only used for TLLs.  */
-  unsigned int m_last_file = 0;
   /* The last file a line number was recorded for.  */
   struct subfile *m_last_subfile = NULL;
 
-  /* The address of the last line entry.  */
-  CORE_ADDR m_last_address;
-
-  /* Set to true when a previous line at the same address (using
-     m_last_address) had m_is_stmt true.  This is reset to false when a
-     line entry at a new address (m_address different to m_last_address) is
-     processed.  */
-  bool m_stmt_at_address = false;
-
   /* When true, record the lines we decode.  */
   bool m_currently_recording_lines = false;
 
@@ -21430,7 +21415,7 @@  class lnp_state_machine
 
 static void
 dwarf_finish_line (struct gdbarch *gdbarch, struct subfile *subfile,
-		   CORE_ADDR address, struct dwarf2_cu *cu)
+		   CORE_ADDR address, struct dwarf2_cu *cu, bool end_sequence)
 {
   if (subfile == NULL)
     return;
@@ -21443,7 +21428,8 @@  class lnp_state_machine
 			  paddress (gdbarch, address));
     }
 
-  dwarf_record_line_1 (gdbarch, subfile, 0, address, true, cu);
+  dwarf_record_line_1 (gdbarch, subfile, end_sequence ? 0 : -1, address,
+		       true, cu);
 }
 
 void
@@ -21470,37 +21456,17 @@  class lnp_state_machine
   else if (m_op_index == 0 || end_sequence)
     {
       fe->included_p = 1;
-      if (m_record_lines_p)
-	{
-	  /* When we switch files we insert an end maker in the first file,
-	     switch to the second file and add a new line entry.  The
-	     problem is that the end marker inserted in the first file will
-	     discard any previous line entries at the same address.  If the
-	     line entries in the first file are marked as is-stmt, while
-	     the new line in the second file is non-stmt, then this means
-	     the end marker will discard is-stmt lines so we can have a
-	     non-stmt line.  This means that there are less addresses at
-	     which the user can insert a breakpoint.
-
-	     To improve this we track the last address in m_last_address,
-	     and whether we have seen an is-stmt at this address.  Then
-	     when switching files, if we have seen a stmt at the current
-	     address, and we are switching to create a non-stmt line, then
-	     discard the new line.  */
-	  bool file_changed
-	    = m_last_subfile != m_cu->get_builder ()->get_current_subfile ();
-	  bool ignore_this_line
-	   = ((file_changed && !end_sequence && m_last_address == m_address
-	       && !m_is_stmt && m_stmt_at_address)
-	      || (!end_sequence && m_line == 0));
-
-	  if ((file_changed && !ignore_this_line) || end_sequence)
+      if (m_record_lines_p && (end_sequence || m_line != 0))
+	{
+	  if (m_last_subfile != m_cu->get_builder ()->get_current_subfile ()
+	      || end_sequence)
 	    {
 	      dwarf_finish_line (m_gdbarch, m_last_subfile, m_address,
-				 m_currently_recording_lines ? m_cu : nullptr);
+				 m_currently_recording_lines ? m_cu : nullptr,
+				 end_sequence || m_is_stmt);
 	    }
 
-	  if (!end_sequence && !ignore_this_line)
+	  if (!end_sequence)
 	    {
 	      bool is_stmt = producer_is_codewarrior (m_cu) || m_is_stmt;
 
@@ -21519,15 +21485,6 @@  class lnp_state_machine
 	    }
 	}
     }
-
-  /* Track whether we have seen any m_is_stmt true at m_address in case we
-     have multiple line table entries all at m_address.  */
-  if (m_last_address != m_address)
-    {
-      m_stmt_at_address = false;
-      m_last_address = m_address;
-    }
-  m_stmt_at_address |= m_is_stmt;
 }
 
 lnp_state_machine::lnp_state_machine (struct dwarf2_cu *cu, gdbarch *arch,
@@ -21547,9 +21504,6 @@  class lnp_state_machine
   m_address = gdbarch_adjust_dwarf2_line (arch, 0, 0);
   m_is_stmt = lh->default_is_stmt;
   m_discriminator = 0;
-
-  m_last_address = m_address;
-  m_stmt_at_address = false;
 }
 
 void
diff --git a/gdb/infrun.c b/gdb/infrun.c
index f509481..b160427 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -6932,6 +6932,31 @@  struct wait_one_event
       return;
     }
 
+  /* Handle the case when subroutines have multiple ranges.
+     When we step from one part to the next part of the same subroutine,
+     all subroutine levels are skipped again which begin here.
+     Compensate for this by removing all skipped subroutines,
+     which were already executing from the user's perspective.  */
+
+  if (frame_id_eq (get_stack_frame_id (get_current_frame ()),
+		   ecs->event_thread->control.step_stack_frame_id)
+      && inline_skipped_frames (ecs->event_thread)
+      && ecs->event_thread->control.step_frame_id.artificial_depth > 0
+      && ecs->event_thread->control.step_frame_id.code_addr_p)
+    {
+      const struct block *prev, *curr;
+      int depth = 0;
+      prev = block_for_pc (ecs->event_thread->control.step_frame_id.code_addr);
+      curr = block_for_pc (ecs->event_thread->suspend.stop_pc);
+      while (curr && block_inlined_p (curr) && !contained_in (prev, curr))
+	{
+	  depth ++;
+	  curr = BLOCK_SUPERBLOCK (curr);
+	}
+      while (inline_skipped_frames (ecs->event_thread) > depth)
+	step_into_inline_frame (ecs->event_thread);
+    }
+
   /* Look for "calls" to inlined functions, part one.  If the inline
      frame machinery detected some skipped call sites, we have entered
      a new inline function.  */
@@ -6993,6 +7018,8 @@  struct wait_one_event
       infrun_debug_printf ("stepping through inlined function");
 
       if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL
+	  || ecs->event_thread->suspend.stop_pc != stop_pc_sal.pc
+	  || !stop_pc_sal.is_stmt
 	  || inline_frame_is_marked_for_skip (false, ecs->event_thread))
 	keep_going (ecs);
       else
@@ -7015,8 +7042,8 @@  struct wait_one_event
 	  end_stepping_range (ecs);
 	  return;
 	}
-      else if (frame_id_eq (get_frame_id (get_current_frame ()),
-			    ecs->event_thread->control.step_frame_id))
+      else if (frame_id_eq (get_stack_frame_id (get_current_frame ()),
+			    ecs->event_thread->control.step_stack_frame_id))
 	{
 	  /* We are at the start of a different line, however, this line is
 	     not marked as a statement, and we have not changed frame.  We
@@ -7046,7 +7073,7 @@  struct wait_one_event
   ecs->event_thread->control.step_range_end = stop_pc_sal.end;
   ecs->event_thread->control.may_range_step = 1;
   if (refresh_step_info)
-    set_step_info (ecs->event_thread, frame, stop_pc_sal);
+    set_step_info (ecs->event_thread, get_current_frame (), stop_pc_sal);
 
   infrun_debug_printf ("keep going");
   keep_going (ecs);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0d3fa9b..7da1aa5 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3293,7 +3293,11 @@  struct symtab_and_line
 	 save prev if it represents the end of a function (i.e. line number
 	 0) instead of a real line.  */
 
-      if (prev && prev->line && (!best || prev->pc > best->pc))
+      if (prev && prev->line && (!best || prev->pc > best->pc
+				       || (prev->pc == best->pc
+					   && (best->pc == pc
+					       ? !best->is_stmt
+					       : best->is_weak))))
 	{
 	  best = prev;
 	  best_symtab = iter_s;
@@ -3311,7 +3315,7 @@  struct symtab_and_line
 	      while (tmp > first && (tmp - 1)->pc == tmp->pc
 		     && (tmp - 1)->line != 0 && !tmp->is_stmt)
 		--tmp;
-	      if (tmp->is_stmt)
+	      if (tmp->is_stmt && (tmp->pc == pc || !tmp->is_weak))
 		best = tmp;
 	    }
 
@@ -3334,18 +3338,14 @@  struct symtab_and_line
 	 We used to return alt->line - 1 here, but that could be
 	 anywhere; if we don't have line number info for this PC,
 	 don't make some up.  */
-      val.pc = pc;
-    }
-  else if (best->line == 0)
-    {
-      /* If our best fit is in a range of PC's for which no line
-	 number info is available (line number is zero) then we didn't
-	 find any valid line information.  */
+      if (notcurrent)
+	pc++;
       val.pc = pc;
     }
   else
     {
       val.is_stmt = best->is_stmt;
+      val.is_weak = best->is_weak;
       val.symtab = best_symtab;
       val.line = best->line;
       val.pc = best->pc;
diff --git a/gdb/testsuite/gdb.base/empty-inline.c b/gdb/testsuite/gdb.base/empty-inline.c
new file mode 100644
index 0000000..923adee
--- /dev/null
+++ b/gdb/testsuite/gdb.base/empty-inline.c
@@ -0,0 +1,42 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020-2021 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/>.  */
+
+static int test0 (void)
+{
+  asm ("");
+  return 1; /* line 21 */
+}
+
+int __attribute__((noinline, noclone))
+#ifdef __CET__
+  __attribute__((nocf_check))
+#endif
+test1 (int x)
+{
+  asm ("");
+  return x+1; /* line 31 */
+}
+
+int
+#ifdef __CET__
+  __attribute__((nocf_check))
+#endif
+main()
+{
+  test1 (test0 ()); /* line 40*/
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/empty-inline.exp b/gdb/testsuite/gdb.base/empty-inline.exp
new file mode 100644
index 0000000..c026f73
--- /dev/null
+++ b/gdb/testsuite/gdb.base/empty-inline.exp
@@ -0,0 +1,48 @@ 
+# Copyright 2020-2021 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/>.
+
+standard_testfile .c
+
+if [get_compiler_info] {
+    return -1
+}
+
+if {[test_compiler_info gcc*] && ![supports_statement_frontiers] } {
+    return -1
+}
+
+global srcfile testfile
+
+set options {debug nowarnings optimize=-O2}
+if { [supports_statement_frontiers] } {
+    lappend options additional_flags=-gstatement-frontiers
+}
+
+if { [prepare_for_testing "failed to prepare" $binfile \
+      $srcfile $options] } {
+    return -1
+}
+
+if ![runto_main] {
+    fail "can't run to main"
+    return -1
+}
+
+gdb_test "frame 0" "\\s*\\#0\\s+main.*${srcfile}:40.*" "in main"
+gdb_test "step" ".*test0.*${srcfile}:21.*" "step into test0"
+gdb_test "frame 1" "\\s*\\#1\\s+main.*${srcfile}:40.*" "frame1"
+gdb_test "step" ".*test1.*${srcfile}:31.*" "step into test1"
+gdb_test "frame 1" "\\s*\\#1.*in main.*${srcfile}:40.*" "frame2"
+gdb_test "step" ".*main.*${srcfile}:41.*" "step back to main"
diff --git a/gdb/testsuite/gdb.cp/empty-inline.cc b/gdb/testsuite/gdb.cp/empty-inline.cc
new file mode 100644
index 0000000..0b45839
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/empty-inline.cc
@@ -0,0 +1,33 @@ 
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2020-2021 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/>.  */
+
+/* PR 25987 */
+struct MyClass;
+struct ptr {
+    MyClass* get() { return t; }     /* line 21 */
+    MyClass* t;
+};
+struct MyClass { void call(); };
+void MyClass::call() {
+    *(volatile char*)(nullptr) = 1;  /* line 26 */
+}
+static void intermediate(ptr p) {
+    p.get()->call();                 /* line 29 */
+}
+int main() {
+    intermediate(ptr{new MyClass});
+}
diff --git a/gdb/testsuite/gdb.cp/empty-inline.exp b/gdb/testsuite/gdb.cp/empty-inline.exp
new file mode 100644
index 0000000..9182abc
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/empty-inline.exp
@@ -0,0 +1,51 @@ 
+# Copyright 2020-2021 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/>.
+
+# PR 25987
+standard_testfile .cc
+
+if {[skip_cplus_tests]} {
+    return -1
+}
+
+if {![supports_statement_frontiers] } {
+    return -1
+}
+
+# Compile the test source with USE_NEXT_INLINE_H defined (when
+# use_header is true), or not defined.
+set options {c++ debug nowarnings optimize=-Og}
+lappend options additional_flags=-gstatement-frontiers
+if { [prepare_for_testing "failed to prepare" $testfile \
+      $srcfile $options] } {
+    return -1
+}
+
+if ![runto_main] {
+    fail "can't run to main"
+    return
+}
+
+gdb_test "bt" "\\s*\\#0\\s+main.*" "in main"
+#break at the empty inline function ptr::get
+gdb_test "b get" ".*" "break at get"
+gdb_test "c" ".*" "continue to get"
+#call frame 1 is at line 29
+gdb_test "bt" "\\s*\\#0\\s+ptr::get\[^\r\]*${srcfile}:21\[\r\n\]+\\s*\\#1\\s+intermediate\[^\r\]*${srcfile}:29\[\r\n\]+.*" "at get"
+#print a local value here
+gdb_test "p t" ".*\\\$1 = \\(MyClass \\*\\) 0x.*" "print t"
+gdb_test "c" ".*SIGSEGV.*" "continue to SIGSEGV"
+#call frame 1 is at line 29
+gdb_test "bt" "\\s*\\#0\\s+MyClass::call\[^\r\]*${srcfile}:26\[\r\n\]+\\s*\\#1\\s+0x\[^\r\]*${srcfile}:29\[\r\n\]+.*" "at call"
diff --git a/gdb/testsuite/gdb.cp/step-and-next-inline.cc b/gdb/testsuite/gdb.cp/step-and-next-inline.cc
index d923cc5..698dcd7 100644
--- a/gdb/testsuite/gdb.cp/step-and-next-inline.cc
+++ b/gdb/testsuite/gdb.cp/step-and-next-inline.cc
@@ -46,6 +46,9 @@  tree_check (tree *t, int i)
 #endif	/* USE_NEXT_INLINE_H */
 
 int __attribute__((noinline, noclone))
+#ifdef __CET__
+  __attribute__((nocf_check))
+#endif
 get_alias_set (tree *t)
 {
   if (t != NULL
@@ -59,6 +62,9 @@  get_alias_set (tree *t)
 tree xx;
 
 int
+#ifdef __CET__
+  __attribute__((nocf_check))
+#endif
 main()
 {
   get_alias_set (&xx);
diff --git a/gdb/testsuite/gdb.cp/step-and-next-inline.exp b/gdb/testsuite/gdb.cp/step-and-next-inline.exp
index 08a4b88..3dff7f0 100644
--- a/gdb/testsuite/gdb.cp/step-and-next-inline.exp
+++ b/gdb/testsuite/gdb.cp/step-and-next-inline.exp
@@ -29,13 +29,6 @@  if {[test_compiler_info gcc*] && ![supports_statement_frontiers] } {
 proc do_test { use_header } {
     global srcfile testfile
 
-    if { $use_header } {
-	# This test will not pass due to poor debug information
-	# generated by GCC (at least upto 10.x).  See
-	# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94474
-	return
-    }
-
     set options {c++ debug nowarnings optimize=-O2}
     if { [supports_statement_frontiers] } {
 	lappend options additional_flags=-gstatement-frontiers
@@ -67,41 +60,20 @@  proc do_test { use_header } {
     gdb_test "step" ".*" "step into get_alias_set"
     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
 	"not in inline 1"
-    # It's possible that this first failure (when not using a header
-    # file) is GCC's fault, though the remaining failures would best
-    # be fixed by adding location views support (though it could be
-    # that some easier heuristic could be figured out).  Still, it is
-    # not certain that the first failure wouldn't also be fixed by
-    # having location view support, so for now it is tagged as such.
-    if {[test_compiler_info gcc*] && !$use_header} {
-	setup_kfail "*-*-*" symtab/25507
-    }
     gdb_test "next" ".*TREE_TYPE.*" "next step 1"
     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
 	"not in inline 2"
     gdb_test "next" ".*TREE_TYPE.*" "next step 2"
     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
 	"not in inline 3"
-    if {[test_compiler_info gcc*] && !$use_header} {
-	setup_kfail "*-*-*" symtab/25507
-    }
     gdb_test "next" ".*TREE_TYPE.*" "next step 3"
     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
 	"not in inline 4"
-    if {!$use_header} { setup_kfail "*-*-*" symtab/25507 }
     gdb_test "next" "return 0.*" "next step 4"
     gdb_test "bt" \
 	"\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
 	"not in inline 5"
 
-    if {!$use_header} {
-	# With the debug from GCC 10.x (and earlier) GDB is currently
-	# unable to successfully complete the following tests when we
-	# are not using a header file.
-	kfail symtab/25507 "stepping tests"
-	return
-    }
-
     clean_restart ${executable}
 
     if ![runto_main] {
@@ -119,22 +91,77 @@  proc do_test { use_header } {
     gdb_test "step" ".*if \\(t->x != i\\).*" "step 2"
     gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
 	"in inline 1 pass 2"
-    gdb_test "step" ".*TREE_TYPE.*" "step 3"
+    gdb_test "step" ".*return x.*" "step 3"
+    gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
+	"return from inline 1 pass 2"
+    gdb_test "step" ".*TREE_TYPE.*" "step 4"
     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
 	"not in inline 2 pass 2"
-    gdb_test "step" ".*if \\(t->x != i\\).*" "step 4"
+    gdb_test "step" ".*if \\(t->x != i\\).*" "step 5"
     gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
 	"in inline 2 pass 2"
-    gdb_test "step" ".*TREE_TYPE.*" "step 5"
+    gdb_test "step" ".*return x.*" "step 6"
+    gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
+	"return from inline 2 pass 2"
+    gdb_test "step" ".*TREE_TYPE.*" "step 7"
     gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
 	"not in inline 3 pass 2"
-    gdb_test "step" ".*if \\(t->x != i\\).*" "step 6"
+    gdb_test "step" ".*if \\(t->x != i\\).*" "step 8"
     gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
 	"in inline 3 pass 2"
-    gdb_test "step" "return 0.*" "step 7"
+    gdb_test "step" ".*return x.*" "step 9"
+    gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
+	"return from inline 3 pass 2"
+    gdb_test "step" "return 0.*" "step 10"
     gdb_test "bt" \
 	"\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
 	"not in inline 4 pass 2"
+
+    clean_restart ${executable}
+
+    if ![runto_main] {
+	fail "can't run to main pass 3"
+	return
+    }
+
+    gdb_test "bt" "\\s*\\#0\\s+main.*" "in main pass 3"
+    gdb_test "step" ".*" "step into get_alias_set pass 3"
+    gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
+	"in get_alias_set pass 3"
+    gdb_test "step" ".*TREE_TYPE.*" "step 1 pass 3"
+    gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
+	"not in inline 1 pass 3"
+    gdb_test "step" ".*if \\(t->x != i\\).*" "step 2 pass 3"
+    gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
+	"in inline 1 pass 3"
+    gdb_test "p t->x = 2" ".* = 2.*" "change value pass 3"
+    gdb_test "step" ".*abort.*" "step 4, pass 3"
+    gdb_test "bt" "\\s*\\#0\\s+\[^\r\]*tree_check\[^\r\]*${hdrfile}:.*" \
+	"abort from inline 1 pass 3"
+
+    if ![runto_main] {
+	fail "can't run to main pass 4"
+	return
+    }
+
+    gdb_test "bt" "\\s*\\#0\\s+main.*" "in main pass 4"
+    gdb_test "skip tree_check" ".*" "skip tree_check pass 4"
+    gdb_test "step" ".*" "step into get_alias_set pass 4"
+    gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
+	"in get_alias_set pass 4"
+    gdb_test "step" ".*TREE_TYPE.*" "step 1 pass 4"
+    gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
+	"not in inline 1 pass 4"
+    gdb_test "step" ".*TREE_TYPE.*" "step 2 pass 4"
+    gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
+	"not in inline 2 pass 4"
+    gdb_test "step" ".*TREE_TYPE.*" "step 3 pass 4"
+    gdb_test "bt" "\\s*\\#0\\s+get_alias_set\[^\r\]*${srcfile}:.*" \
+	"not in inline 3 pass 4"
+    gdb_test "step" "return 0.*" "step 4 pass 4"
+    gdb_test "bt" \
+	"\\s*\\#0\\s+(main|get_alias_set)\[^\r\]*${srcfile}:.*" \
+	"not in inline 4 pass 4"
     }
 }
 
-- 
1.9.1