public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Pedro Alves <palves@redhat.com>
Cc: Yao Qi <qiyaoltc@gmail.com>,  gdb-patches@sourceware.org
Subject: Re: [PATCH 4/7] Insert breakpoint even when the raw breakpoint is found
Date: Mon, 25 Apr 2016 08:45:00 -0000	[thread overview]
Message-ID: <864maqgjrn.fsf@gmail.com> (raw)
In-Reply-To: <570CC2DA.6050504@redhat.com> (Pedro Alves's message of "Tue, 12	Apr 2016 10:41:46 +0100")

Pedro Alves <palves@redhat.com> writes:

> Nothing else, that's all I meant.
>
> Actually, now that I look closer, I think we could merge the new
> code with the code that handles inserting a new raw breakpoint just below.
>
> For example:

Looks yours is good to me.  I pushed it in.

-- 
Yao (齐尧)
From 20249ae4551ae7b2193caed73d9ce8d594f38754 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Mon, 25 Apr 2016 09:43:36 +0100
Subject: [PATCH] Insert breakpoint even when the raw breakpoint is found

When GDBserver inserts a breakpoint, it looks for raw breakpoint, if
the raw breakpoint is found, increase its refcount, and return.  This
doesn't work when it steps over a breakpoint using software single
step and the underneath instruction of breakpoint is branch to self.

When stepping over a breakpoint on ADDR using software single step,
GDBserver uninsert the breakpoint, so the corresponding raw breakpoint
RAW's 'inserted' flag is zero.  Then, GDBserver insert single step
breakpoint at the same address ADDR because the instruction is branch
to self, the same raw brekapoint RAW is found, and increase the
refcount.  However, the raw breakpoint is not inserted, and the
program won't stop.

gdb/gdbserver:

2016-04-25  Pedro Alves  <palves@redhat.com>
	    Yao Qi  <yao.qi@linaro.org>

	* mem-break.c (set_raw_breakpoint_at): Create a raw breakpoint
	object.  Insert it if it is not inserted yet.  Increase the
	refcount and link it into the proc's raw breakpoint list.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0b08605..5c94832 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2016-04-25  Pedro Alves  <palves@redhat.com>
+	    Yao Qi  <yao.qi@linaro.org>
+
+	* mem-break.c (set_raw_breakpoint_at): Create a raw breakpoint
+	object.  Insert it if it is not inserted yet.  Increase the
+	refcount and link it into the proc's raw breakpoint list.
+
 2016-04-25  Yao Qi  <yao.qi@linaro.org>
 
 	* breakpoint.c (should_be_inserted): Return 0 if the location's
diff --git a/gdb/gdbserver/mem-break.c b/gdb/gdbserver/mem-break.c
index b06f8e9..419db9e 100644
--- a/gdb/gdbserver/mem-break.c
+++ b/gdb/gdbserver/mem-break.c
@@ -390,6 +390,7 @@ set_raw_breakpoint_at (enum raw_bkpt_type type, CORE_ADDR where, int kind,
 {
   struct process_info *proc = current_process ();
   struct raw_breakpoint *bp;
+  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
 
   if (type == raw_bkpt_type_sw || type == raw_bkpt_type_hw)
     {
@@ -408,32 +409,39 @@ set_raw_breakpoint_at (enum raw_bkpt_type type, CORE_ADDR where, int kind,
   else
     bp = find_raw_breakpoint_at (where, type, kind);
 
-  if (bp != NULL)
+  if (bp == NULL)
     {
-      bp->refcount++;
-      return bp;
+      bp = XCNEW (struct raw_breakpoint);
+      bp->pc = where;
+      bp->kind = kind;
+      bp->raw_type = type;
+      make_cleanup (xfree, bp);
     }
 
-  bp = XCNEW (struct raw_breakpoint);
-  bp->pc = where;
-  bp->kind = kind;
-  bp->refcount = 1;
-  bp->raw_type = type;
-
-  *err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
-  if (*err != 0)
+  if (!bp->inserted)
     {
-      if (debug_threads)
-	debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n",
-		      paddress (where), *err);
-      free (bp);
-      return NULL;
+      *err = the_target->insert_point (bp->raw_type, bp->pc, bp->kind, bp);
+      if (*err != 0)
+	{
+	  if (debug_threads)
+	    debug_printf ("Failed to insert breakpoint at 0x%s (%d).\n",
+			  paddress (where), *err);
+
+	  do_cleanups (old_chain);
+	  return NULL;
+	}
+
+      bp->inserted = 1;
     }
 
-  bp->inserted = 1;
-  /* Link the breakpoint in.  */
-  bp->next = proc->raw_breakpoints;
-  proc->raw_breakpoints = bp;
+  discard_cleanups (old_chain);
+
+  /* Link the breakpoint in, if this is the first reference.  */
+  if (++bp->refcount == 1)
+    {
+      bp->next = proc->raw_breakpoints;
+      proc->raw_breakpoints = bp;
+    }
   return bp;
 }
 

  reply	other threads:[~2016-04-25  8:45 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 16:10 [PATCH 0/7 V2] Step over instruction branches to itself Yao Qi
2016-03-23 16:10 ` [PATCH 3/7] Force to insert software single step breakpoint Yao Qi
2016-04-11 14:31   ` Pedro Alves
2016-04-13 16:21     ` Yao Qi
2016-04-19 14:54     ` Yao Qi
2016-04-19 15:17       ` Pedro Alves
2016-04-20  7:50     ` Yao Qi
2016-04-22 16:36       ` Pedro Alves
2016-04-25  8:40         ` Yao Qi
2016-03-23 16:10 ` [PATCH 1/7] New test case gdb.trace/signal.exp Yao Qi
2016-04-08 16:52   ` Pedro Alves
2016-04-11  8:41     ` Yao Qi
2016-04-11 14:04       ` Pedro Alves
2016-04-22 10:53         ` Yao Qi
2016-04-26 12:57           ` Pedro Alves
2016-04-11 14:08       ` Pedro Alves
2016-03-23 16:10 ` [PATCH 5/7] [GDBserver] Don't error in reinsert_raw_breakpoint if bp->inserted Yao Qi
2016-04-11 14:54   ` Pedro Alves
2016-03-23 16:10 ` [PATCH 2/7] Deliver signal in hardware single step Yao Qi
2016-04-11 14:10   ` Pedro Alves
2016-04-22 10:54     ` Yao Qi
2016-03-23 16:10 ` [PATCH 4/7] Insert breakpoint even when the raw breakpoint is found Yao Qi
2016-04-11 14:41   ` Pedro Alves
2016-04-12  9:04     ` Yao Qi
2016-04-12  9:41       ` Pedro Alves
2016-04-25  8:45         ` Yao Qi [this message]
2016-03-23 16:10 ` [PATCH 6/7] Resume the inferior with signal rather than stepping over Yao Qi
2016-04-11 15:29   ` Pedro Alves
2016-03-23 16:26 ` [PATCH 7/7] New test case gdb.base/branch-to-self.exp Yao Qi
2016-04-11 15:34   ` Pedro Alves
2016-04-25  8:58     ` Yao Qi

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=864maqgjrn.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).