Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Pedro Alves <pedro@codesourcery.com>,
	ping huang <harderock@gmail.com>,
		shuchang zhou <shuchang.zhou@gmail.com>
Cc: gdb-patches@sourceware.org,
	Joel Brobecker <brobecker@adacore.com>,
		Michael Snyder <msnyder@vmware.com>,
	paawan oza <paawan1982@yahoo.com>,
		Tom Tromey <tromey@redhat.com>
Subject: Re: [RFC] Add support of software single step to process record
Date: Tue, 25 May 2010 05:14:00 -0000	[thread overview]
Message-ID: <AANLkTin8YlU8tJyWj8ji-FOwANvJZxagchVvMVnGT8kN@mail.gmail.com> (raw)
In-Reply-To: <201001081624.12634.pedro@codesourcery.com>

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

Thanks Pedro.

On Sat, Jan 9, 2010 at 00:24, Pedro Alves <pedro@codesourcery.com> wrote:
> On Monday 04 January 2010 14:23:21, Hui Zhu wrote:
>> Sorry guys, the prev patch is so ugly.
>
> :-)
>
>> Thanks for teach me clear about the gdbarch_software_single_step, Pedro.
>> I did some extend with your idea.  Because record_wait need
>> record_resume_step point out this resume is signal step or continue.
>>
>>       if (!step)
>>         {
>>           /* This is not hard single step.  */
>>           if (!gdbarch_software_single_step_p (gdbarch))
>>             {
>>               /* This is a normal continue.  */
>>               step = 1;
>>             }
>>           else
>>             {
>>               /* This arch support soft sigle step.  */
>>               if (single_step_breakpoints_inserted ())
>>                 {
>>                   /* This is a soft single step.  */
>>                   record_resume_step = 1;
>>                 }
>>               else
>>                 {
>>                   /* This is a continue.
>>                      Try to insert a soft single step breakpoint.  */
>>                   if (!gdbarch_software_single_step (gdbarch,
>>                                                      get_current_frame ()))
>>                     {
>>                       /* This system don't want use soft single step.
>>                          Use hard sigle step.  */
>>                       step = 1;
>>                     }
>>                 }
>>             }
>>         }
>
> Cool, this looks pretty clear to me now.  Thanks.
>
>
>
>> @@ -1077,6 +1111,7 @@ record_wait (struct target_ops *ops,
>>           /* This is not a single step.  */
>>           ptid_t ret;
>>           CORE_ADDR tmp_pc;
>> +          struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
>>
>>           while (1)
>>             {
>> @@ -1099,6 +1134,9 @@ record_wait (struct target_ops *ops,
>>                   tmp_pc = regcache_read_pc (regcache);
>>                   aspace = get_regcache_aspace (regcache);
>>
>> +                  if (gdbarch_software_single_step_p (gdbarch))
>> +                    remove_single_step_breakpoints ();
>
> This will gdb_assert inside remove_single_step_breakpoints
> if SSS bkpts are not inserted, but gdbarch_software_single_step_p
> returns true.  This instead is safer:
>
>                  if (single_step_breakpoints_inserted ())
>                    remove_single_step_breakpoints ();

OK.  I will fix it.

>
> But, what if it was infrun that had inserted the single-step
> breakpoints, for a "next" or "step", etc.?  Shouldn't you check
> for record_resume_step too?
>
>               if (!record_resume_step && single_step_breakpoints_inserted ())
>                 remove_single_step_breakpoints ();
>
> Otherwise, the check below for
>
>                  else if (breakpoint_inserted_here_p (aspace, tmp_pc))
>                    {
>                      /* There is a breakpoint here.  Let the core
>                         handle it.  */
>                      if (software_breakpoint_inserted_here_p (aspace, tmp_pc))
>                        {
>
> would fail, and the finished single-step wouldn't be reported to the
> core, right?

I think this single step will be handle by line:
      if (record_resume_step)
	{
	  /* This is a single step.  */
	  return record_beneath_to_wait (record_beneath_to_wait_ops,
					 ptid, status, options);
	}

>
>
> Lastly, you may also want to confirm that the SSS bkpt managed by record.d itself explains the SIGTRAP before removing before issueing another
> single-step.  If any unexplainable SIGTRAP happens for any reason while
> single-stepping, you should report it to infrun instead.  In other words:
>
> With software single-stepping, we can distinguish most random
> SIGTRAPs from SSS SIGTRAPs, so:
>
>                      /* This must be a single-step trap.  Record the
>                         insn and issue another step.  */
>
> ... the "must" here ends up being a bit too strong.  I'd certainly
> understand ignoring this for simplicity or performance reasons though.

Ah.  Looks we didn't have good way to handle it.  I change this comment to:
		      /* This is a single-step trap.  Record the
		         insn and issue another step.
                         FIXME: this part can be a random SIGTRAP too.
                         But GDB cannot handle it.  */


Shuchang,  could you try your code just use command si and
reverse-xxx.  If that part OK.  Please help me try this patch.

Ping, please help me test this patch.  And about hellogcc, you can find us in:
https://groups.google.com/group/hellogcc
https://webchat.freenode.net/ #hellogcc

Thanks,
Hui

2010-05-25  Hui Zhu  <teawater@gmail.com>

	* breakpoint.c (single_step_breakpoints_inserted): New
	function.
	* breakpoint.h (single_step_breakpoints_inserted): Extern.
	* record.c (record_resume): Add code for software single step.
	(record_wait): Ditto.

[-- Attachment #2: prec_software_single_step.txt --]
[-- Type: text/plain, Size: 4349 bytes --]

---
 breakpoint.c |   10 ++++++++++
 breakpoint.h |    1 +
 record.c     |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 63 insertions(+), 5 deletions(-)

--- a/breakpoint.c
+++ b/breakpoint.c
@@ -10293,6 +10293,16 @@ insert_single_step_breakpoint (struct gd
 	     paddress (gdbarch, next_pc));
 }
 
+/* Check if the breakpoints used for software single stepping
+   were inserted or not.  */
+
+int
+single_step_breakpoints_inserted (void)
+{
+  return (single_step_breakpoints[0] != NULL
+          || single_step_breakpoints[1] != NULL);
+}
+
 /* Remove and delete any breakpoints used for software single step.  */
 
 void
--- a/breakpoint.h
+++ b/breakpoint.h
@@ -983,6 +983,7 @@ extern int remove_hw_watchpoints (void);
    twice before remove is called.  */
 extern void insert_single_step_breakpoint (struct gdbarch *,
 					   struct address_space *, CORE_ADDR);
+extern int single_step_breakpoints_inserted (void);
 extern void remove_single_step_breakpoints (void);
 
 /* Manage manual breakpoints, separate from the normal chain of
--- a/record.c
+++ b/record.c
@@ -1007,9 +1007,43 @@ record_resume (struct target_ops *ops, p
 
   if (!RECORD_IS_REPLAY)
     {
+      struct gdbarch *gdbarch = target_thread_architecture (ptid);
+
       record_message (get_current_regcache (), signal);
-      record_beneath_to_resume (record_beneath_to_resume_ops, ptid, 1,
-                                signal);
+
+      if (!step)
+        {
+          /* This is not hard single step.  */
+          if (!gdbarch_software_single_step_p (gdbarch))
+            {
+              /* This is a normal continue.  */
+              step = 1;
+            }
+          else
+            {
+              /* This arch support soft sigle step.  */
+              if (single_step_breakpoints_inserted ())
+                {
+                  /* This is a soft single step.  */
+                  record_resume_step = 1;
+                }
+              else
+                {
+                  /* This is a continue.
+                     Try to insert a soft single step breakpoint.  */
+                  if (!gdbarch_software_single_step (gdbarch,
+                                                     get_current_frame ()))
+                    {
+                      /* This system don't want use soft single step.
+                         Use hard sigle step.  */
+                      step = 1;
+                    }
+                }
+            }
+        }
+
+      record_beneath_to_resume (record_beneath_to_resume_ops,
+                                ptid, step, signal);
     }
 }
 
@@ -1082,6 +1116,7 @@ record_wait (struct target_ops *ops,
 	  /* This is not a single step.  */
 	  ptid_t ret;
 	  CORE_ADDR tmp_pc;
+          struct gdbarch *gdbarch = target_thread_architecture (inferior_ptid);
 
 	  while (1)
 	    {
@@ -1104,6 +1139,9 @@ record_wait (struct target_ops *ops,
 		  tmp_pc = regcache_read_pc (regcache);
 		  aspace = get_regcache_aspace (regcache);
 
+                  if (single_step_breakpoints_inserted ())
+                    remove_single_step_breakpoints ();
+
 		  if (target_stopped_by_watchpoint ())
 		    {
 		      /* Always interested in watchpoints.  */
@@ -1124,8 +1162,12 @@ record_wait (struct target_ops *ops,
 		    }
 		  else
 		    {
-		      /* This must be a single-step trap.  Record the
-		         insn and issue another step.  */
+		      /* This is a single-step trap.  Record the
+		         insn and issue another step.
+                         FIXME: this part can be a random SIGTRAP too.
+                         But GDB cannot handle it.  */
+                      int step = 1;
+
 		      if (!record_message_wrapper_safe (regcache,
                                                         TARGET_SIGNAL_0))
   			{
@@ -1134,8 +1176,13 @@ record_wait (struct target_ops *ops,
                            break;
   			}
 
+                      if (gdbarch_software_single_step_p (gdbarch)
+                          && gdbarch_software_single_step (gdbarch,
+                                                           get_current_frame ()))
+                        step = 0;
+
 		      record_beneath_to_resume (record_beneath_to_resume_ops,
-						ptid, 1,
+						ptid, step,
 						TARGET_SIGNAL_0);
 		      continue;
 		    }

  reply	other threads:[~2010-05-25  3:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-18  8:21 Hui Zhu
2009-12-18 19:37 ` Michael Snyder
2009-12-20 13:48   ` Joel Brobecker
2009-12-23  6:38     ` Hui Zhu
2009-12-23  6:52       ` Joel Brobecker
2009-12-23  9:24         ` Hui Zhu
     [not found]           ` <8d62b6fe0912231751p1202294cw83430e8d53af0951@mail.gmail.com>
2009-12-24  1:54             ` Fwd: " shuchang zhou
2009-12-24 17:38           ` Pedro Alves
2010-01-04 14:23             ` Hui Zhu
2010-01-08 16:24               ` Pedro Alves
2010-05-25  5:14                 ` Hui Zhu [this message]
2010-05-27  6:51                   ` Hui Zhu
2010-06-11 13:55                     ` Pedro Alves
2010-06-20  7:29                       ` Hui Zhu
2010-06-22 10:13                         ` Pedro Alves
2010-07-19  7:58                           ` Hui Zhu
2009-12-22 18:23 ` Tom Tromey
2009-12-23  3:09   ` Hui Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTin8YlU8tJyWj8ji-FOwANvJZxagchVvMVnGT8kN@mail.gmail.com \
    --to=teawater@gmail.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=harderock@gmail.com \
    --cc=msnyder@vmware.com \
    --cc=paawan1982@yahoo.com \
    --cc=pedro@codesourcery.com \
    --cc=shuchang.zhou@gmail.com \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox