This is the mail archive of the gdb-prs@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]

[Bug breakpoints/7143] Watchpoint does not trigger when first set


------- Additional Comments From naaaag at gmail dot com  2009-01-09 16:48 -------
Well formed problem. Relevant snippets from this test case : 

int i = 0;

int main ()
{
  i = 1;
  i = 2;
  i = 3;
  return 0;
}

(gdb) break main
Breakpoint 1 at 0x80483c3: file x2.c, line 5.
(gdb) run
Starting program: /gehman/home/chastain/tmp/x2 

Breakpoint 1, main () at x2.c:5
5	  i = 1;
(gdb) watch i
Hardware watchpoint 2: i
(gdb) next
6	  i = 2;
(gdb) next
Hardware watchpoint 2: i

Old value = 0
New value = 2
main () at x2.c:7
7	  i = 3;

Change from 0->1 is not 'watched'. 

Breakpoint will be hit , before executing the instruction. Whereas
Watchpoint will be hit , after  executing the instruction. 

In the first 'next' after 'watch' , breakpoints are not enabled , as current pc
is still pointing to breakpoint 1 ( 'main' ). 

infrun.c : 

    791   if (oneproc)
    792     /* We will get a trace trap after one instruction.
    793        Continue it automatically and insert breakpoints then.  */
    794     stepping_over_breakpoint = 1;
    795   else
    796     insert_breakpoints ();

Here the watchpoints can be enabled even for single stepping. Following can be
done : 

1. in breakpoint.c, rename insert_watchpoints to a local function (static
function ) and add a boolean parameter , say watchpoint only. 
   -> And skip non-watchpoint bpts if watchpoint_only=TRUE.
2. Create insert_watchpoints , which calls insert_watchpoints_local with FALSE. 
3. Introduce a new function insert_watchpoints , which calls
insert_watchpoints_local with TRUE. 
4. In infrun.c:proceed , if ( single stepping ) call insert_watchpoints.

With a modified gdb : 

Breakpoint 1, main () at x2.c:5
5         i = 1;
(top-gdb) watch i
Hardware watchpoint 2: i
(top-gdb) next
During symbol reading, incomplete CFI data; unspecified registers (e.g., rax) at
0x4004ac.
Hardware watchpoint 2: i

Old value = 0
New value = 1
main () at x2.c:6
6         i = 2;
(top-gdb) next
Hardware watchpoint 2: i

Old value = 1
New value = 2
main () at x2.c:7
7         i = 3;
(top-gdb) next
Hardware watchpoint 2: i

Old value = 2
New value = 3
main () at x2.c:8


-------------------------------------------------------------------------------
Following are the code changes : ( apologize , I am still a newbie to the gdb
dev processes . Will try improve the same :-) ).

breakpoint.h : 

@@ -717,6 +717,8 @@ extern void set_breakpoint (char *addres
 
 extern void insert_breakpoints (void);
 
+extern void insert_watchpoints (void);
+
 extern int remove_breakpoints (void);
 
breakpoint.c : 

@@ -210,6 +210,8 @@ unlink_locations_from_global_list (struc
 static int
 is_hardware_watchpoint (struct breakpoint *bpt);
 
+static void insert_breakpoints_local (int watchpoint_only);
+
 /* Prototypes for exported functions. */
 
 /* If FALSE, gdb will not use hardware support for watchpoints, even
@@ -1220,6 +1222,18 @@ Note: automatically using hardware break
 void
 insert_breakpoints (void)
 {
+  insert_breakpoints_local(FALSE); 
+}
+
+void
+insert_watchpoints (void)
+{
+  insert_breakpoints_local(TRUE); 
+}
+
+static void
+insert_breakpoints_local (int watchpoint_only)
+{
   struct breakpoint *bpt;
   struct bp_location *b, *temp;
   int error = 0;
@@ -1244,6 +1258,9 @@ insert_breakpoints (void)
       if (!breakpoint_enabled (b->owner))
        continue;
 
+      if (watchpoint_only && !is_hardware_watchpoint(b->owner))
+        continue;
+
       /* There is no point inserting thread-specific breakpoints if the
         thread no longer exists.  */
       if (b->owner->thread != -1
@@ -1707,6 +1724,14 @@ breakpoint_here_p (CORE_ADDR pc)
 
   ALL_BP_LOCATIONS (bpt)
     {
+      struct breakpoint *b=bpt->owner;
+      
+      if (bpt->loc_type == bp_loc_hardware_breakpoint && 
+          (b->type == bp_hardware_watchpoint || 
+          b->type == bp_read_watchpoint     ||
+          b->type == bp_access_watchpoint))
+       continue;
+
       if (bpt->loc_type != bp_loc_software_breakpoint
          && bpt->loc_type != bp_loc_hardware_breakpoint)
        continue;

infrun.c : 

@@ -789,9 +789,13 @@ proceed (CORE_ADDR addr, enum target_sig
     oneproc = 1;
 
   if (oneproc)
+  {
     /* We will get a trace trap after one instruction.
-       Continue it automatically and insert breakpoints then.  */
+       Continue it automatically and insert breakpoints then. But
+       watchpoints are different as they needs to be enabled  now. */
     stepping_over_breakpoint = 1;
+    insert_watchpoints (); 
+  }
   else
     insert_breakpoints ();

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=7143

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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