[2/2] Replace address and aspace with thread in struct step_over_info

Message ID 1460726961-27486-3-git-send-email-yao.qi@linaro.org
State New, archived
Headers

Commit Message

Yao Qi April 15, 2016, 1:29 p.m. UTC
  This patch replaces the fields aspace and address in
'struct step_over_info' with 'thread', because aspace and thread can
be got from thread.

gdb:

2016-04-15  Yao Qi  <yao.qi@linaro.org>

	* infrun.c (struct step_over_info) <aspace>: Remove
	<address>: Remove.
	<thread>: New field.
	(set_step_over_info): Update.
	(clear_step_over_info): Update.
	(stepping_past_nonsteppable_watchpoint): Update.
---
 gdb/infrun.c | 47 +++++++++++++++++++++--------------------------
 1 file changed, 21 insertions(+), 26 deletions(-)
  

Comments

Pedro Alves April 19, 2016, 10:43 a.m. UTC | #1
On 04/15/2016 02:29 PM, Yao Qi wrote:
> This patch replaces the fields aspace and address in
> 'struct step_over_info' with 'thread', because aspace and thread can
> be got from thread.
> 

>  
> @@ -1366,10 +1350,21 @@ int
>  stepping_past_instruction_at (struct address_space *aspace,
>  			      CORE_ADDR address)
>  {
> -  return (step_over_info.aspace != NULL
> -	  && breakpoint_address_match (aspace, address,
> -				       step_over_info.aspace,
> -				       step_over_info.address));
> +  if (step_over_info.thread != NULL)
> +    {
> +      struct regcache *regcache;
> +
> +      regcache = get_thread_regcache (step_over_info.thread->ptid);
> +
> +      /* The step-over isn't finished or is still valid, so the PC got
> +	 from regcache is the value when thread stops, rather than the
> +	 value after step-over.  */

I think this is problematic.

While a thread is being stepped past a breakpoint, it's possible that the
user sets some other breakpoint, and then we end up in stepping_past_instruction_at
deciding whether we can insert that new breakpoint, while the step-over thread
is running.

As soon as the step-over thread is resumed for the actual step-over, it's
regcache is flushed (target_resume -> registers_changed_ptid).  From that point
and until the thread stops again, trying to fetch its regcache will error out,
because you can't read registers from a thread that is running.

Example (haven't tried it):

- A program with two threads, thread 1 and thread 2.

- non-stop mode on.

- Thread 1 continuously stepping over this:

  while (1) i++;     << breakpoint here:

  E.g., with:

  (gdb) thread 1
  (gdb) b $breakpoint_here_line
  (gdb) n&

- Switch to thread 2, which is stopped elsewhere (so inserting
  a breakpoint works when native debugging), and set some breakpoint:

  (gdb) thread 2
  (gdb) b foo

Thanks,
Pedro Alves
  
Yao Qi April 19, 2016, 1:54 p.m. UTC | #2
Pedro Alves <palves@redhat.com> writes:

> I think this is problematic.
>
> While a thread is being stepped past a breakpoint, it's possible that the
> user sets some other breakpoint, and then we end up in
> stepping_past_instruction_at
> deciding whether we can insert that new breakpoint, while the step-over thread
> is running.
>
> As soon as the step-over thread is resumed for the actual step-over, it's
> regcache is flushed (target_resume -> registers_changed_ptid).  From that point
> and until the thread stops again, trying to fetch its regcache will error out,
> because you can't read registers from a thread that is running.

OK, that is a good case.  I didn't think of it.  I withdraw the patch.
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 9017b0a..72f7fe4 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1282,16 +1282,12 @@  enum step_over_what_flag
   };
 DEF_ENUM_FLAGS_TYPE (enum step_over_what_flag, step_over_what);
 
-/* Info about an instruction that is being stepped over.  */
+/* Info about a thread that is being stepped over.  */
 
 struct step_over_info
 {
-  /* If we're stepping past a breakpoint, this is the address space
-     and address of the instruction the breakpoint is set at.  We'll
-     skip inserting all breakpoints here.  Valid iff ASPACE is
-     non-NULL.  */
-  struct address_space *aspace;
-  CORE_ADDR address;
+  /* We're stepping over the thread to pass a breakpoint.  */
+  struct thread_info *thread;
 
   /* The instruction being stepped over triggers a nonsteppable
      watchpoint.  If true, we'll skip inserting watchpoints.  */
@@ -1331,18 +1327,7 @@  static void
 set_step_over_info (struct thread_info *thread,
 		    int nonsteppable_watchpoint_p)
 {
-  if (thread != NULL)
-    {
-      struct regcache *regcache = get_thread_regcache (thread->ptid);
-
-      step_over_info.aspace = get_regcache_aspace (regcache);
-      step_over_info.address = regcache_read_pc (regcache);
-    }
-  else
-    {
-      step_over_info.aspace = NULL;
-      step_over_info.address = 0;
-    }
+  step_over_info.thread = thread;
   step_over_info.nonsteppable_watchpoint_p = nonsteppable_watchpoint_p;
 }
 
@@ -1355,8 +1340,7 @@  clear_step_over_info (void)
   if (debug_infrun)
     fprintf_unfiltered (gdb_stdlog,
 			"infrun: clear_step_over_info\n");
-  step_over_info.aspace = NULL;
-  step_over_info.address = 0;
+  step_over_info.thread = NULL;
   step_over_info.nonsteppable_watchpoint_p = 0;
 }
 
@@ -1366,10 +1350,21 @@  int
 stepping_past_instruction_at (struct address_space *aspace,
 			      CORE_ADDR address)
 {
-  return (step_over_info.aspace != NULL
-	  && breakpoint_address_match (aspace, address,
-				       step_over_info.aspace,
-				       step_over_info.address));
+  if (step_over_info.thread != NULL)
+    {
+      struct regcache *regcache;
+
+      regcache = get_thread_regcache (step_over_info.thread->ptid);
+
+      /* The step-over isn't finished or is still valid, so the PC got
+	 from regcache is the value when thread stops, rather than the
+	 value after step-over.  */
+      return breakpoint_address_match (aspace, address,
+				       get_regcache_aspace (regcache) ,
+				       regcache_read_pc (regcache));
+    }
+  else
+    return 0;
 }
 
 /* See infrun.h.  */
@@ -1385,7 +1380,7 @@  stepping_past_nonsteppable_watchpoint (void)
 static int
 step_over_info_valid_p (void)
 {
-  return (step_over_info.aspace != NULL
+  return (step_over_info.thread != NULL
 	  || stepping_past_nonsteppable_watchpoint ());
 }