Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Resubmit process record and replay, 7/10
@ 2008-11-17  2:35 teawater
  2008-11-20  5:12 ` Michael Snyder
  2008-11-20  8:13 ` Pedro Alves
  0 siblings, 2 replies; 5+ messages in thread
From: teawater @ 2008-11-17  2:35 UTC (permalink / raw)
  To: gdb-patches

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

This patch add code to make GNU/Linux native-dependent code can record
execute log with itself.

2008-11-16  Hui Zhu  <teawater@gmail.com>

	Record execute log in linux-nat.

	* linux-nat.c (my_waitpid_record): New function. This function
	can resume and wait inferior and record execute log of it.
	(linux_nat_wait): If process record and replay target is used
	and this is not a step resume, call function
	"my_waitpid_record" instead function "my_waitpid".

 linux-nat.c |  122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 121 insertions(+), 1 deletion(-)

[-- Attachment #2: 7-linux-nat.txt --]
[-- Type: text/plain, Size: 3328 bytes --]

--- a/linux-nat.c
+++ b/linux-nat.c
@@ -50,6 +50,8 @@
 #include "event-loop.h"
 #include "event-top.h"
 
+#include "record.h"
+
 #ifdef HAVE_PERSONALITY
 # include <sys/personality.h>
 # if !HAVE_DECL_ADDR_NO_RANDOMIZE
@@ -518,6 +520,115 @@ my_waitpid (int pid, int *status, int fl
   return ret;
 }
 
+extern struct bp_location *bp_location_chain;
+static struct lwp_info * find_lwp_pid (ptid_t ptid);
+static int
+my_waitpid_record (int pid, int *status, int flags)
+{
+  int ret;
+  struct bp_location *bl;
+  struct breakpoint *b;
+  CORE_ADDR pc;
+  CORE_ADDR decr_pc_after_break;
+  struct lwp_info *lp;
+  int is_breakpoint = 1;
+
+wait_begin:
+  ret = my_waitpid (pid, status, flags);
+  if (ret == -1)
+    {
+      return ret;
+    }
+
+  if (ret == 0)
+    {
+      goto wait_begin;
+    }
+
+  if (WIFSTOPPED (*status) && WSTOPSIG (*status) == SIGTRAP)
+    {
+      /* Check if there is a breakpoint.  */
+      pc = 0;
+      registers_changed ();
+      for (bl = bp_location_chain; bl; bl = bl->global_next)
+	{
+	  b = bl->owner;
+	  gdb_assert (b);
+	  if (b->enable_state != bp_enabled
+	      && b->enable_state != bp_permanent)
+	    continue;
+	  if (!pc)
+	    {
+	      pc = regcache_read_pc (get_thread_regcache (pid_to_ptid (ret)));
+	    }
+	  switch (b->type)
+	    {
+	    default:
+	      if (bl->address == pc)
+		{
+		  goto out;
+		}
+	      break;
+
+	    case bp_watchpoint:
+	      /*XXX teawater: I still not very clear how to deal with it.  */
+	      goto out;
+	      break;
+
+	    case bp_catchpoint:
+	      gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
+	      if (b->ops->breakpoint_hit (b))
+		{
+		  goto out;
+		}
+	      break;
+
+	    case bp_hardware_watchpoint:
+	    case bp_read_watchpoint:
+	    case bp_access_watchpoint:
+	      if (STOPPED_BY_WATCHPOINT (0))
+		{
+		  goto out;
+		}
+	      break;
+	    }
+	}
+
+      lp = find_lwp_pid (pid_to_ptid (ret));
+      if (lp)
+        lp->stopped = 1;
+
+      /* record message */
+      record_message (current_gdbarch);
+
+      /* resume program */
+      linux_ops->to_resume (pid_to_ptid (ret), 1, TARGET_SIGNAL_0);
+      goto wait_begin;
+    }
+
+  is_breakpoint = 0;
+
+out:
+  /* Add gdbarch_decr_pc_after_break to pc because pc will be break at address
+     add gdbarch_decr_pc_after_break when inferior non-step execute.  */
+  if (is_breakpoint)
+    {
+      decr_pc_after_break = gdbarch_decr_pc_after_break
+	(get_regcache_arch (get_thread_regcache (pid_to_ptid (ret))));
+      if (decr_pc_after_break)
+	{
+	  if (!pc)
+	    {
+	      pc = regcache_read_pc (get_thread_regcache (pid_to_ptid (ret)));
+	    }
+	  regcache_write_pc (get_thread_regcache (pid_to_ptid (ret)),
+			     pc + decr_pc_after_break);
+	}
+    }
+
+  return ret;
+}
+
 /* Determine if PTRACE_O_TRACEFORK can be used to follow fork events.
 
    First, we try to enable fork tracing on ORIGINAL_PID.  If this fails,
@@ -2876,7 +2987,16 @@ retry:
 	   queued events.  */
 	lwpid = queued_waitpid (pid, &status, options);
       else
-	lwpid = my_waitpid (pid, &status, options);
+	{
+	  if (RECORD_IS_USED && !record_resume_step)
+	    {
+	      lwpid = my_waitpid_record (pid, &status, options);
+	    }
+	  else
+	    {
+	      lwpid = my_waitpid (pid, &status, options);
+	    }
+	}
 
       if (lwpid > 0)
 	{

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

* Re: [RFA] Resubmit process record and replay, 7/10
  2008-11-17  2:35 [RFA] Resubmit process record and replay, 7/10 teawater
@ 2008-11-20  5:12 ` Michael Snyder
  2008-11-20 15:19   ` teawater
  2008-11-20  8:13 ` Pedro Alves
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Snyder @ 2008-11-20  5:12 UTC (permalink / raw)
  To: teawater; +Cc: gdb-patches

teawater wrote:
> This patch add code to make GNU/Linux native-dependent code can record
> execute log with itself.
> 
> 2008-11-16  Hui Zhu  <teawater@gmail.com>
> 
> 	Record execute log in linux-nat.
> 
> 	* linux-nat.c (my_waitpid_record): New function. This function
> 	can resume and wait inferior and record execute log of it.
> 	(linux_nat_wait): If process record and replay target is used
> 	and this is not a step resume, call function
> 	"my_waitpid_record" instead function "my_waitpid".

Hui, another name change suggestion:
Instead of "my_waitpid_record", how about "process_record_waitpid"?

I don't think it needs to have "linux" in the name, since it is
a static function and can only be invoked from linux-nat.c.

> 
>  linux-nat.c |  122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 121 insertions(+), 1 deletion(-)
> 
> 
> ------------------------------------------------------------------------
> 
> --- a/linux-nat.c
> +++ b/linux-nat.c
> @@ -50,6 +50,8 @@
>  #include "event-loop.h"
>  #include "event-top.h"
>  
> +#include "record.h"
> +
>  #ifdef HAVE_PERSONALITY
>  # include <sys/personality.h>
>  # if !HAVE_DECL_ADDR_NO_RANDOMIZE
> @@ -518,6 +520,115 @@ my_waitpid (int pid, int *status, int fl
>    return ret;
>  }
>  
> +extern struct bp_location *bp_location_chain;
> +static struct lwp_info * find_lwp_pid (ptid_t ptid);
> +static int
> +my_waitpid_record (int pid, int *status, int flags)
> +{
> +  int ret;
> +  struct bp_location *bl;
> +  struct breakpoint *b;
> +  CORE_ADDR pc;
> +  CORE_ADDR decr_pc_after_break;
> +  struct lwp_info *lp;
> +  int is_breakpoint = 1;
> +
> +wait_begin:
> +  ret = my_waitpid (pid, status, flags);
> +  if (ret == -1)
> +    {
> +      return ret;
> +    }
> +
> +  if (ret == 0)
> +    {
> +      goto wait_begin;
> +    }
> +
> +  if (WIFSTOPPED (*status) && WSTOPSIG (*status) == SIGTRAP)
> +    {
> +      /* Check if there is a breakpoint.  */
> +      pc = 0;
> +      registers_changed ();
> +      for (bl = bp_location_chain; bl; bl = bl->global_next)
> +	{
> +	  b = bl->owner;
> +	  gdb_assert (b);
> +	  if (b->enable_state != bp_enabled
> +	      && b->enable_state != bp_permanent)
> +	    continue;
> +	  if (!pc)
> +	    {
> +	      pc = regcache_read_pc (get_thread_regcache (pid_to_ptid (ret)));
> +	    }
> +	  switch (b->type)
> +	    {
> +	    default:
> +	      if (bl->address == pc)
> +		{
> +		  goto out;
> +		}
> +	      break;
> +
> +	    case bp_watchpoint:
> +	      /*XXX teawater: I still not very clear how to deal with it.  */
> +	      goto out;
> +	      break;
> +
> +	    case bp_catchpoint:
> +	      gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
> +	      if (b->ops->breakpoint_hit (b))
> +		{
> +		  goto out;
> +		}
> +	      break;
> +
> +	    case bp_hardware_watchpoint:
> +	    case bp_read_watchpoint:
> +	    case bp_access_watchpoint:
> +	      if (STOPPED_BY_WATCHPOINT (0))
> +		{
> +		  goto out;
> +		}
> +	      break;
> +	    }
> +	}
> +
> +      lp = find_lwp_pid (pid_to_ptid (ret));
> +      if (lp)
> +        lp->stopped = 1;
> +
> +      /* record message */
> +      record_message (current_gdbarch);
> +
> +      /* resume program */
> +      linux_ops->to_resume (pid_to_ptid (ret), 1, TARGET_SIGNAL_0);
> +      goto wait_begin;
> +    }
> +
> +  is_breakpoint = 0;
> +
> +out:
> +  /* Add gdbarch_decr_pc_after_break to pc because pc will be break at address
> +     add gdbarch_decr_pc_after_break when inferior non-step execute.  */
> +  if (is_breakpoint)
> +    {
> +      decr_pc_after_break = gdbarch_decr_pc_after_break
> +	(get_regcache_arch (get_thread_regcache (pid_to_ptid (ret))));
> +      if (decr_pc_after_break)
> +	{
> +	  if (!pc)
> +	    {
> +	      pc = regcache_read_pc (get_thread_regcache (pid_to_ptid (ret)));
> +	    }
> +	  regcache_write_pc (get_thread_regcache (pid_to_ptid (ret)),
> +			     pc + decr_pc_after_break);
> +	}
> +    }
> +
> +  return ret;
> +}
> +
>  /* Determine if PTRACE_O_TRACEFORK can be used to follow fork events.
>  
>     First, we try to enable fork tracing on ORIGINAL_PID.  If this fails,
> @@ -2876,7 +2987,16 @@ retry:
>  	   queued events.  */
>  	lwpid = queued_waitpid (pid, &status, options);
>        else
> -	lwpid = my_waitpid (pid, &status, options);
> +	{
> +	  if (RECORD_IS_USED && !record_resume_step)
> +	    {
> +	      lwpid = my_waitpid_record (pid, &status, options);
> +	    }
> +	  else
> +	    {
> +	      lwpid = my_waitpid (pid, &status, options);
> +	    }
> +	}
>  
>        if (lwpid > 0)
>  	{


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

* Re: [RFA] Resubmit process record and replay, 7/10
  2008-11-17  2:35 [RFA] Resubmit process record and replay, 7/10 teawater
  2008-11-20  5:12 ` Michael Snyder
@ 2008-11-20  8:13 ` Pedro Alves
       [not found]   ` <200811200250.22173.alves.ped@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2008-11-20  8:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: teawater

My 2c.,

On Sunday 16 November 2008 08:23:12, teawater wrote:
> --- a/linux-nat.c
> +++ b/linux-nat.c
> @@ -50,6 +50,8 @@
>  #include "event-loop.h"
>  #include "event-top.h"
>  
> +#include "record.h"
> +
>  #ifdef HAVE_PERSONALITY
>  # include <sys/personality.h>
>  # if !HAVE_DECL_ADDR_NO_RANDOMIZE
> @@ -518,6 +520,115 @@ my_waitpid (int pid, int *status, int fl
>    return ret;
>  }
>  

Can you please try moving all this blob...

> +extern struct bp_location *bp_location_chain;
> +static struct lwp_info * find_lwp_pid (ptid_t ptid);
> +static int
> +my_waitpid_record (int pid, int *status, int flags)
> +{
> +  int ret;
> +  struct bp_location *bl;
> +  struct breakpoint *b;
> +  CORE_ADDR pc;
> +  CORE_ADDR decr_pc_after_break;
> +  struct lwp_info *lp;
> +  int is_breakpoint = 1;
> +
> +wait_begin:
> +  ret = my_waitpid (pid, status, flags);
> +  if (ret == -1)
> +    {
> +      return ret;
> +    }
> +
> +  if (ret == 0)
> +    {
> +      goto wait_begin;
> +    }
> +
> +  if (WIFSTOPPED (*status) && WSTOPSIG (*status) == SIGTRAP)
> +    {
> +      /* Check if there is a breakpoint.  */
> +      pc = 0;
> +      registers_changed ();
> +      for (bl = bp_location_chain; bl; bl = bl->global_next)
> +       {
> +         b = bl->owner;
> +         gdb_assert (b);
> +         if (b->enable_state != bp_enabled
> +             && b->enable_state != bp_permanent)
> +           continue;
> +         if (!pc)
> +           {
> +             pc = regcache_read_pc (get_thread_regcache (pid_to_ptid (ret)));
> +           }
> +         switch (b->type)
> +           {
> +           default:
> +             if (bl->address == pc)
> +               {
> +                 goto out;
> +               }
> +             break;
> +
> +           case bp_watchpoint:
> +             /*XXX teawater: I still not very clear how to deal with it.  */
> +             goto out;
> +             break;
> +
> +           case bp_catchpoint:
> +             gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL);
> +             if (b->ops->breakpoint_hit (b))
> +               {
> +                 goto out;
> +               }
> +             break;
> +
> +           case bp_hardware_watchpoint:
> +           case bp_read_watchpoint:
> +           case bp_access_watchpoint:
> +             if (STOPPED_BY_WATCHPOINT (0))
> +               {
> +                 goto out;
> +               }
> +             break;
> +           }
> +       }
> +
> +      lp = find_lwp_pid (pid_to_ptid (ret));
> +      if (lp)
> +        lp->stopped = 1;
> +
> +      /* record message */
> +      record_message (current_gdbarch);
> +
> +      /* resume program */
> +      linux_ops->to_resume (pid_to_ptid (ret), 1, TARGET_SIGNAL_0);
> +      goto wait_begin;
> +    }
> +
> +  is_breakpoint = 0;
> +
> +out:
> +  /* Add gdbarch_decr_pc_after_break to pc because pc will be break at address
> +     add gdbarch_decr_pc_after_break when inferior non-step execute.  */
> +  if (is_breakpoint)
> +    {
> +      decr_pc_after_break = gdbarch_decr_pc_after_break
> +       (get_regcache_arch (get_thread_regcache (pid_to_ptid (ret))));
> +      if (decr_pc_after_break)
> +       {
> +         if (!pc)
> +           {
> +             pc = regcache_read_pc (get_thread_regcache (pid_to_ptid (ret)));
> +           }
> +         regcache_write_pc (get_thread_regcache (pid_to_ptid (ret)),
> +                            pc + decr_pc_after_break);
> +       }
> +    }
> +
> +  return ret;
> +}
> +

... to the record target?  It seems to be interested in getting
*all* events, instead of letting linux_nat_wait filter some.

>  /* Determine if PTRACE_O_TRACEFORK can be used to follow fork events.
>  
>     First, we try to enable fork tracing on ORIGINAL_PID.  If this fails,
> @@ -2876,7 +2987,16 @@ retry:
>            queued events.  */
>         lwpid = queued_waitpid (pid, &status, options);
>        else
> -       lwpid = my_waitpid (pid, &status, options);
> +       {
> +         if (RECORD_IS_USED && !record_resume_step)
> +           {
> +             lwpid = my_waitpid_record (pid, &status, options);
> +           }
> +         else
> +           {
> +             lwpid = my_waitpid (pid, &status, options);
> +           }
> +       }
>  

Could you do it by instead of calling my_waitpid_record here, make
sure that whatever comes out of my_waitpid results in returning from
linux_nat_wait?

Ideally, we should have a flags parameter in target_wait, like:

 -ptid_t target_wait (ptid_t, struct target_waitstatus *);
 +ptid_t target_wait (ptid_t, struct target_waitstatus *, int target_flags);

... process record would pass a special flag to
linux_nat_wait for this, but I'd be happy if you tried moving
most of the code to the record target, and kept using RECORD_IS_USED,
as I hinted at in another message a new target_is_recording_p () or
somesuch method.

Also, it seems most of the breakpoint checking code should be replaced
by one of the breakpoint_here style predicates exported by breakpoint.h.

-- 
Pedro Alves

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

* Re: [RFA] Resubmit process record and replay, 7/10
  2008-11-20  5:12 ` Michael Snyder
@ 2008-11-20 15:19   ` teawater
  0 siblings, 0 replies; 5+ messages in thread
From: teawater @ 2008-11-20 15:19 UTC (permalink / raw)
  To: Michael Snyder; +Cc: gdb-patches

Thanks Michael.

On Thu, Nov 20, 2008 at 09:57, Michael Snyder <msnyder@vmware.com> wrote:
> teawater wrote:
>>
>> This patch add code to make GNU/Linux native-dependent code can record
>> execute log with itself.
>>
>> 2008-11-16  Hui Zhu  <teawater@gmail.com>
>>
>>        Record execute log in linux-nat.
>>
>>        * linux-nat.c (my_waitpid_record): New function. This function
>>        can resume and wait inferior and record execute log of it.
>>        (linux_nat_wait): If process record and replay target is used
>>        and this is not a step resume, call function
>>        "my_waitpid_record" instead function "my_waitpid".
>
> Hui, another name change suggestion:
> Instead of "my_waitpid_record", how about "process_record_waitpid"?
>
> I don't think it needs to have "linux" in the name, since it is
> a static function and can only be invoked from linux-nat.c.
>

OK. I will change it.

Hui


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

* Re: [RFA] Resubmit process record and replay, 7/10
       [not found]   ` <200811200250.22173.alves.ped@gmail.com>
@ 2008-11-20 16:37     ` teawater
  0 siblings, 0 replies; 5+ messages in thread
From: teawater @ 2008-11-20 16:37 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

Thanks Pedro,


Agree with your idea in record_wait part.  Actually, I plan to do it
after P record check-in in the before.
Now, I will do it  at once. :)

On the other hand, could you let me keep the code in linux-nat.c.
Because I think it can make linux-nat record speed up.

What about write a special function to check the breakpoint? Then both
linux-nat and record_wait can call it.


Hui

On Thu, Nov 20, 2008 at 10:50, Pedro Alves <alves.ped@gmail.com> wrote:
> On Thursday 20 November 2008 02:40:46, Pedro Alves wrote:
>
>> Can you please try moving all this blob...
>
> [...]
>
>> ... to the record target?  It seems to be interested in getting
>> *all* events, instead of letting linux_nat_wait filter some.
>
> Sorry, reading back, I don't think I explained myself that well.  I meant
> something like:
>
> ptid_t
> record_wait (ptid_t ptid, target_waitstatus *status)
> {
>  while (1)
>  {
>     eptid = beneath->to_wait (ptid, &status);
>
>     if (status.kind == TARGET_WAITKIND_TRAP)
>      {
>         if breakpoint_here (pc - pc_adjustement)
>           {
>             got breakpoint;
>             break;
>           }
>         record_message ();
>         beneath->resume (step);
>      }
>      else
>        break probably.
>  }
>
>  if (got breakpoint)
>    adjust_pc;
>  return eptid;
> }
>
> --
> Pedro Alves
>


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

end of thread, other threads:[~2008-11-20  8:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-17  2:35 [RFA] Resubmit process record and replay, 7/10 teawater
2008-11-20  5:12 ` Michael Snyder
2008-11-20 15:19   ` teawater
2008-11-20  8:13 ` Pedro Alves
     [not found]   ` <200811200250.22173.alves.ped@gmail.com>
2008-11-20 16:37     ` teawater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox