Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix for PR 15413 (segfault when completing "condition" for pending bp)
@ 2013-05-06  2:59 Sergio Durigan Junior
  2013-05-06 17:49 ` Pedro Alves
  0 siblings, 1 reply; 7+ messages in thread
From: Sergio Durigan Junior @ 2013-05-06  2:59 UTC (permalink / raw)
  To: GDB Patches; +Cc: Dr. David Alan Gilbert

Hi,

This patch is a fix for PR 15413.  The failure happens when one tries to
complete the argument for the "condition" command if there is only a
pending breakpoint inserted.  In this case, GDB segfaults.

The submitter pinged me on IRC this Sunday with a suggestion to fix the
issue, which correctly eliminated the segfault but still wasn't complete
because the "condition" completer did not complete the breakpoint number
yet.  I modified the code so that the completion now works OK and no
segfault happens.

The fix is trivial IMO, so it shouldn't take long to approve the patch.
Regtested on Fedora 17 x86_64, no regressions.

OK to apply?

-- 
Sergio

gdb/
2013-05-05  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR breakpoints/15413:
	* breakpoint.c (condition_completer): Rewrite parts of the code to
	handle completion of the "condition" command for pending
	breakpoints.

gdb/testsuite/
2013-05-05  Sergio Durigan Junior  <sergiodj@redhat.com>

	PR breakpoints/15413:
	* gdb.base/pending.exp: Add test for completion of the "condition"
	command for pending breakpoints.

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 35ada7a..81bf5ed 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1013,25 +1013,36 @@ condition_completer (struct cmd_list_element *cmd,
 
       ALL_BREAKPOINTS (b)
       {
-	int single = b->loc->next == NULL;
-	struct bp_location *loc;
+	struct bp_location *loc = NULL;
 	int count = 1;
 
-	for (loc = b->loc; loc; loc = loc->next)
+	do
 	  {
 	    char location[50];
 
-	    if (single)
-	      xsnprintf (location, sizeof (location), "%d", b->number);
+	    if (b->loc == NULL)
+	      {
+		/* We're probably dealing with a pending breakpoint.  Just
+		   inform its number.  */
+		xsnprintf (location, sizeof (location), "%d", b->number);
+	      }
 	    else
-	      xsnprintf (location, sizeof (location),  "%d.%d", b->number,
-			 count);
+	      {
+		if (b->loc->next == NULL)
+		  xsnprintf (location, sizeof (location), "%d", b->number);
+		else
+		  xsnprintf (location, sizeof (location),  "%d.%d", b->number,
+			     count);
+
+		loc = b->loc->next;
+	      }
 
 	    if (strncmp (location, text, len) == 0)
 	      VEC_safe_push (char_ptr, result, xstrdup (location));
 
 	    ++count;
 	  }
+	while (loc != NULL);
       }
 
       return result;
diff --git a/gdb/testsuite/gdb.base/pending.exp b/gdb/testsuite/gdb.base/pending.exp
index 68322f5..a8dbef5 100644
--- a/gdb/testsuite/gdb.base/pending.exp
+++ b/gdb/testsuite/gdb.base/pending.exp
@@ -55,6 +55,13 @@ gdb_test_multiple "break pendfunc1" "set pending breakpoint" {
      }
 }
 
+# Complete the condition (PR 15413).
+# This test must come right after we set the first pending breakpoint, and
+# before we set any other breakpoint, since we are testing if the "condition"
+# command can properly complete its argument.  The PR only fails if there
+# is only one pending breakpoint set (without anything else).
+gdb_test "complete condition " "condition 1"
+
 gdb_test "info break" \
     "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
 \[0-9\]+\[\t \]+breakpoint     keep y.*PENDING.*pendfunc1.*" \


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

end of thread, other threads:[~2013-05-07 17:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-06  2:59 [PATCH] Fix for PR 15413 (segfault when completing "condition" for pending bp) Sergio Durigan Junior
2013-05-06 17:49 ` Pedro Alves
2013-05-06 20:57   ` Sergio Durigan Junior
2013-05-06 21:08     ` Pedro Alves
2013-05-07  3:39       ` Sergio Durigan Junior
2013-05-07 16:16         ` Pedro Alves
2013-05-07 17:06           ` Sergio Durigan Junior

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