This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix bug breakpoint before watchpoint increase hit count but didn't show up


Hi

This patch is about watchpoint and breakpoint.
If we do have watchpoint bpstat in bpstat list after the
breakpoint it is not printing right now, but its hitting
count is increased.
As below
(gdb) b 6
Breakpoint 28 at 0x4004c2: file 7143.c, line 6.
(gdb) watch i
Hardware watchpoint 29: i
(gdb) s

Breakpoint 28, main () at 7143.c:6
6	  i = 2;
(gdb) info b
Num     Type           Disp Enb Address            What
28      breakpoint     keep y   0x00000000004004c2 in main at 7143.c:6
	breakpoint already hit 1 time
29      hw watchpoint  keep y                      i
	breakpoint already hit 1 time
(gdb) del
Delete all breakpoints? (y or n) y

here hit count is increased by one but it didn't show up
while stepping.
This one is also same for software bp as well.

so What I do is in bpstat_stop_status make two seprate
list of bpstat one for watchpoint and one for breakpoints
and in the end attach the breakpoints bpstat list to the
watchpoints pbstat list. So that all watchpoint bpstat's
will be before the breakpoint's bpstat's and they will
also print there status if any.

is it ok?

please find the patch in bellow and in attachment as well.

gdb/ChangeLog
2013-09-19  Muhammad Waqas  <mwaqas@codesourcery.com>

	* breakpoint.c (bpstat_stop_status): Add watchpoint
	bpstat's in list just before the breakpoints bpstat's.
	(bpstat_print): Remove trialling space.

testsuite/ChangeLog
2013-09-19  Muhammad Waqas  <mwaqas@codesourcery.com>

	* gdb.base/watchpoint.exp (test_watchpoint_and_breakpoint): Add
	a new test.
	* gdb.base/watchpoint.c (func3): Add a comment.
Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.777
diff -u -p -r1.777 breakpoint.c
--- breakpoint.c	17 Sep 2013 19:32:46 -0000	1.777
+++ breakpoint.c	20 Sep 2013 11:56:58 -0000
@@ -4613,10 +4613,10 @@ bpstat_print (bpstat bs, int kind)
   for (; bs; bs = bs->next)
     {
       val = print_bp_stop_message (bs);
-      if (val == PRINT_SRC_ONLY
-	  || val == PRINT_SRC_AND_LOC
-	  || val == PRINT_NOTHING)
-	return val;
+      if (val == PRINT_SRC_ONLY
+          || val == PRINT_SRC_AND_LOC
+          || val == PRINT_NOTHING)
+        return val;
     }

   /* If we had hit a shared library event breakpoint,
@@ -5240,7 +5240,10 @@ bpstat_stop_status (struct address_space
   struct bp_location *bl;
   struct bp_location *loc;
   /* First item of allocated bpstat's.  */
+  /* Seprate lists for breakpoints and watchpoints bpstat,
+     later merge them in order 1st watchpoints then breakpoints. */
   bpstat bs_head = NULL, *bs_link = &bs_head;
+  bpstat bs_tmp_head = NULL, *bs_tmp_link = &bs_tmp_head;
   /* Pointer to the last thing in the chain currently.  */
   bpstat bs;
   int ix;
@@ -5278,8 +5281,12 @@ bpstat_stop_status (struct address_space
 	  /* Come here if it's a watchpoint, or if the break address
 	     matches.  */

-	  bs = bpstat_alloc (bl, &bs_link);	/* Alloc a bpstat to
-						   explain stop.  */
+	  if (b->type == bp_hardware_watchpoint
+	      || b->type == bp_watchpoint)
+	    bs = bpstat_alloc (bl, &bs_link);   /* Alloc a bpstat to
+                                                   explain stop.  */
+	  else
+	    bs = bpstat_alloc (bl, &bs_tmp_link);

 	  /* Assume we stop.  Should we find a watchpoint that is not
 	     actually triggered, or if the condition of the breakpoint
@@ -5300,6 +5307,10 @@ bpstat_stop_status (struct address_space
 	}
     }

+  /* Attach breakpoint bpstat list to watchpoint bpstat list.  */
+  *bs_link = bs_tmp_head;
+  bs_link = &bs_tmp_head->next;
+
   for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix,
loc); ++ix)
     {
       if (breakpoint_location_address_match (loc, aspace, bp_addr))
Index: ./testsuite/gdb.base/watchpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/watchpoint.c,v
retrieving revision 1.11
diff -u -p -r1.11 watchpoint.c
--- ./testsuite/gdb.base/watchpoint.c	2 Aug 2013 16:41:08 -0000	1.11
+++ ./testsuite/gdb.base/watchpoint.c	20 Sep 2013 11:56:59 -0000
@@ -110,12 +110,12 @@ void
 func3 ()
 {
   int x;
-  int y;
+  int y = 0;

   x = 0;
   x = 1;				/* second x assignment */
   y = 1;
-  y = 2;
+  y = 2;				/* second y assignment */
   buf[26] = 3;
 }

Index: ./testsuite/gdb.base/watchpoint.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/watchpoint.exp,v
retrieving revision 1.66
diff -u -p -r1.66 watchpoint.exp
--- ./testsuite/gdb.base/watchpoint.exp	2 Aug 2013 16:41:08 -0000	1.66
+++ ./testsuite/gdb.base/watchpoint.exp	20 Sep 2013 11:56:59 -0000
@@ -567,6 +567,20 @@ proc test_watchpoint_and_breakpoint {} {
 	}

 	gdb_test_no_output "delete \$bpnum" "delete watch x"
+
+	# This test involves set breakpoint before watchpoint
+	gdb_breakpoint [gdb_get_line_number "second y assignment"]
+	gdb_test "watch y" ".*atchpoint \[0-9\]+: y"
+	gdb_test_multiple "next" "next after watch y" {
+	    -re ".*atchpoint \[0-9\]+: y\r\n\r\nOld value = 0\r\nNew value =
1\r\n.*Breakpoint \[0-9\]+, .* at .*\r\n.*$gdb_prompt $" {
+		pass "next after watch y"
+	    }
+	    -re "Breakpoint (\[0-9\]*), .* at .*$gdb_prompt $" {
+		fail "next after watch y"
+	    }
+	}
+
+	gdb_test_no_output "delete \$bpnum" "delete watch y"
     }
 }

Attachment: wdiff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]