public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Make "skip" work on inline frames
@ 2019-10-18 12:52 Bernd Edlinger
  2019-10-19  4:40 ` Bernd Edlinger
  0 siblings, 1 reply; 25+ messages in thread
From: Bernd Edlinger @ 2019-10-18 12:52 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 432 bytes --]

Hi,

I noticed that skip is not working well on inlined frames which may
happen in optimized gcc stage3 binary, where step stops at functions
which are marked for skip, whenever they happen to be in-lined, where
it is ignored if the frame is marked for skip, thus currently
skipped frames are only checked when the skipped function
is not inlined, which is usually only the case in non-optimized builds.


Thanks
Bernd.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Check-all-inline-frames-if-they-are-marked-for-skip.patch --]
[-- Type: text/x-patch; name="0001-Check-all-inline-frames-if-they-are-marked-for-skip.patch", Size: 4418 bytes --]

From 6f24c762bf45d7b1b2d2e9285dfe2250b654b8ea Mon Sep 17 00:00:00 2001
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
Date: Fri, 18 Oct 2019 14:28:45 +0200
Subject: [PATCH] Check all inline frames if they are marked for skip.

This makes the skip command work in optimized builds,
where skipped functions may be inlined.
Previously that was only working when stepping into
a non-inlined function.
---
 gdb/infcmd.c | 15 ++++++++++++++-
 gdb/infrun.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 7105774..9e4de66 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -58,6 +58,7 @@
 #include "thread-fsm.h"
 #include "top.h"
 #include "interps.h"
+#include "skip.h"
 #include "gdbsupport/gdb_optional.h"
 #include "source.h"
 #include "cli/cli-style.h"
@@ -1112,6 +1113,9 @@ prepare_one_step (struct step_command_fsm *sm)
 	      && inline_skipped_frames (tp))
 	    {
 	      ptid_t resume_ptid;
+	      const char *fn = NULL;
+	      symtab_and_line sal;
+	      struct symbol *sym;
 
 	      /* Pretend that we've ran.  */
 	      resume_ptid = user_visible_resume_ptid (1);
@@ -1119,7 +1123,16 @@ prepare_one_step (struct step_command_fsm *sm)
 
 	      step_into_inline_frame (tp);
 	      sm->count--;
-	      return prepare_one_step (sm);
+
+	      sal = find_frame_sal (frame);
+	      sym = get_frame_function (frame);
+
+	      if (sym != NULL)
+		fn = SYMBOL_PRINT_NAME (sym);
+
+	      if (sal.line == 0
+		  || !function_name_is_marked_for_skip (fn, sal))
+		return prepare_one_step (sm);
 	    }
 
 	  pc = get_frame_pc (frame);
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 07aebfa..04c1eee 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4041,6 +4041,45 @@ stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
   return 0;
 }
 
+/* Look for an inline frame that is marked for skip.
+   If PREV_FRAME is TRUE start at the previous frame,
+   otherwise start at the current frame.  Stop at the
+   first non-inline frame, or at the frame where the
+   step started.  */
+
+static bool
+inline_frame_is_marked_for_skip (bool prev_frame, struct thread_info *tp)
+{
+  struct frame_info *frame = get_current_frame ();
+
+  if (prev_frame)
+    frame = get_prev_frame (frame);
+
+  for (; frame != NULL; frame = get_prev_frame (frame))
+    {
+      const char *fn = NULL;
+      symtab_and_line sal;
+      struct symbol *sym;
+
+      if (frame_id_eq (get_frame_id (frame), tp->control.step_frame_id))
+	break;
+      if (get_frame_type (frame) != INLINE_FRAME)
+	break;
+
+      sal = find_frame_sal (frame);
+      sym = get_frame_function (frame);
+
+      if (sym != NULL)
+	fn = SYMBOL_PRINT_NAME (sym);
+
+      if (sal.line != 0
+	  && function_name_is_marked_for_skip (fn, sal))
+	return true;
+    }
+
+  return false;
+}
+
 /* If the event thread has the stop requested flag set, pretend it
    stopped for a GDB_SIGNAL_0 (i.e., as if it stopped due to
    target_stop).  */
@@ -6531,7 +6570,8 @@ process_event_stop_test (struct execution_control_state *ecs)
 	tmp_sal = find_pc_line (ecs->stop_func_start, 0);
 	if (tmp_sal.line != 0
 	    && !function_name_is_marked_for_skip (ecs->stop_func_name,
-						  tmp_sal))
+						  tmp_sal)
+	    && !inline_frame_is_marked_for_skip (true, ecs->event_thread))
 	  {
 	    if (execution_direction == EXEC_REVERSE)
 	      handle_step_into_function_backward (gdbarch, ecs);
@@ -6697,7 +6737,14 @@ process_event_stop_test (struct execution_control_state *ecs)
 
 	  if (call_sal.line == ecs->event_thread->current_line
 	      && call_sal.symtab == ecs->event_thread->current_symtab)
-	    step_into_inline_frame (ecs->event_thread);
+	    {
+	      step_into_inline_frame (ecs->event_thread);
+	      if (inline_frame_is_marked_for_skip (false, ecs->event_thread))
+		{
+		  keep_going (ecs);
+		  return;
+		}
+	    }
 
 	  end_stepping_range (ecs);
 	  return;
@@ -6731,7 +6778,8 @@ process_event_stop_test (struct execution_control_state *ecs)
 	fprintf_unfiltered (gdb_stdlog,
 			    "infrun: stepping through inlined function\n");
 
-      if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
+      if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL
+	  || inline_frame_is_marked_for_skip (false, ecs->event_thread))
 	keep_going (ecs);
       else
 	end_stepping_range (ecs);
-- 
1.9.1


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2019-12-17 13:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-18 12:52 [PATCH] Make "skip" work on inline frames Bernd Edlinger
2019-10-19  4:40 ` Bernd Edlinger
2019-10-20  6:48   ` [PATCHv2] " Bernd Edlinger
2019-10-26  8:06     ` [PING] " Bernd Edlinger
2019-10-27  1:52     ` Simon Marchi
2019-10-27  2:18       ` Simon Marchi
2019-10-30 21:56         ` Bernd Edlinger
2019-10-31 16:42           ` Pedro Alves
2019-10-31 16:53             ` Simon Marchi
2019-10-31 18:00               ` Pedro Alves
2019-10-31 19:19                 ` [PATCHv3] " Bernd Edlinger
2019-11-24 11:22                   ` [PATCHv4] " Bernd Edlinger
2019-12-01 20:46                     ` [PING] " Bernd Edlinger
2019-12-02  2:34                     ` Simon Marchi
2019-12-02 16:47                       ` [PATCHv5] " Bernd Edlinger
2019-12-03  4:22                         ` Simon Marchi
2019-12-14 13:55                         ` [PING] " Bernd Edlinger
2019-12-15  0:46                         ` Simon Marchi
2019-12-15 11:25                           ` [PATCHv6] " Bernd Edlinger
2019-12-15 13:12                             ` Simon Marchi
2019-12-15 18:18                               ` Bernd Edlinger
2019-12-17  2:01                                 ` Simon Marchi
2019-12-17 13:00                                   ` Bernd Edlinger
2019-10-30 20:06       ` [PATCHv2] " Bernd Edlinger
2019-10-30 20:18         ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).