From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14037 invoked by alias); 4 Sep 2010 15:36:19 -0000 Received: (qmail 14028 invoked by uid 22791); 4 Sep 2010 15:36:18 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 04 Sep 2010 15:35:22 +0000 Received: (qmail 20042 invoked from network); 4 Sep 2010 15:35:20 -0000 Received: from unknown (HELO caradoc.them.org) (dan@127.0.0.2) by mail.codesourcery.com with ESMTPA; 4 Sep 2010 15:35:20 -0000 Date: Sat, 04 Sep 2010 22:44:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sourceware.org Subject: [commit] Enable hardware watchpoints for inaccessible constand addresses Message-ID: <20100904153514.GF28036@caradoc.them.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-09/txt/msg00141.txt.bz2 I originally implemented support for watchpoints on inaccessible memory here: http://sourceware.org/ml/gdb-patches/2007-08/msg00417.html That patch was eventually revised to this version: http://sourceware.org/ml/gdb-patches/2008-02/msg00472.html In between those two, I lost a check in can_use_hardware_watchpoints that has turned out to be necessary after all. With today's GDB, we use a hardware watchpoint for "*global_ptr" because we detect that it has one used (non-lazy) memory value; but "*0x0" has none, and we weren't considering the lazy (because it was unreadable) value. This time, I added a test specifically for this scenario. Tested on x86_64-linux, checked in. -- Daniel Jacobowitz CodeSourcery 2010-09-04 Daniel Jacobowitz * breakpoint.c (can_use_hardware_watchpoint): Handle the first value specially. 2010-09-04 Daniel Jacobowitz * gdb.base/watchpoint.exp: Call test_inaccessible_watchpoint before disabling hardware watchpoints. (test_inaccessible_watchpoint): Check that hardware watchpoints are used. Test for watchpoints on a constant address. Index: breakpoint.c =================================================================== RCS file: /cvs/src/src/gdb/breakpoint.c,v retrieving revision 1.512 diff -u -p -r1.512 breakpoint.c --- breakpoint.c 3 Sep 2010 15:42:02 -0000 1.512 +++ breakpoint.c 4 Sep 2010 15:02:57 -0000 @@ -8327,10 +8327,12 @@ can_use_hardware_watchpoint (struct valu { if (VALUE_LVAL (v) == lval_memory) { - if (value_lazy (v)) - /* A lazy memory lvalue is one that GDB never needed to fetch; - we either just used its address (e.g., `a' in `a.b') or - we never needed it at all (e.g., `a' in `a,b'). */ + if (v != head && value_lazy (v)) + /* A lazy memory lvalue in the chain is one that GDB never + needed to fetch; we either just used its address (e.g., + `a' in `a.b') or we never needed it at all (e.g., `a' + in `a,b'). This doesn't apply to HEAD; if that is + lazy then it was not readable, but watch it anyway. */ ; else { Index: testsuite/gdb.base/watchpoint.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/watchpoint.exp,v retrieving revision 1.30 diff -u -p -r1.30 watchpoint.exp --- testsuite/gdb.base/watchpoint.exp 16 Aug 2010 19:19:22 -0000 1.30 +++ testsuite/gdb.base/watchpoint.exp 4 Sep 2010 15:02:58 -0000 @@ -662,7 +662,28 @@ proc test_inaccessible_watchpoint {} { } } - gdb_test "watch *global_ptr" ".*atchpoint \[0-9\]+: \\*global_ptr" + # See whether a watchpoint on a normal variable is a hardware + # watchpoint or not. The watchpoints on NULL should be hardware + # iff this one is. + set watchpoint_msg "Watchpoint" + gdb_test_multiple "watch global_ptr" "watch global_ptr" { + -re "Watchpoint \[0-9\]+: global_ptr\r\n.*$gdb_prompt $" { + pass "watch global_ptr" + } + -re "Hardware watchpoint \[0-9\]+: global_ptr\r\n.*$gdb_prompt $" { + set watchpoint_msg "Hardware watchpoint" + pass "watch global_ptr" + } + } + delete_breakpoints + + # Make sure that we can watch a constant address, and correctly + # use a HW watchpoint if supported. + gdb_test "watch *(int *) 0" \ + "$watchpoint_msg \[0-9\]+: \\*\\(int \\*\\) 0" + delete_breakpoints + + gdb_test "watch *global_ptr" "$watchpoint_msg \[0-9\]+: \\*global_ptr" gdb_test "set \$global_ptr_breakpoint_number = \$bpnum" "" gdb_test "next" ".*global_ptr = buf.*" "global_ptr next" gdb_test_multiple "next" "next over ptr init" { @@ -771,6 +792,8 @@ if [initialize] then { test_complex_watchpoint } + test_inaccessible_watchpoint + # Verify that a user can force GDB to use "slow" watchpoints. # (This proves rather little on kernels that don't support # fast watchpoints, but still...) @@ -849,8 +872,6 @@ if [initialize] then { } } - test_inaccessible_watchpoint - # See above. if [istarget "mips-idt-*"] then { gdb_exit