From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7869 invoked by alias); 4 Mar 2010 15:39:26 -0000 Received: (qmail 7852 invoked by uid 22791); 4 Mar 2010 15:39:24 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 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; Thu, 04 Mar 2010 15:39:20 +0000 Received: (qmail 10438 invoked from network); 4 Mar 2010 15:39:18 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 4 Mar 2010 15:39:18 -0000 From: Pedro Alves To: Eli Zaretskii Subject: Re: Watching expressions that don't involve memory (e.g., watch $regfoo) Date: Thu, 04 Mar 2010 15:39:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-19-generic; KDE/4.3.2; x86_64; ; ) Cc: gdb-patches@sourceware.org References: <201003040156.44957.pedro@codesourcery.com> <201003041316.29257.pedro@codesourcery.com> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201003041539.16538.pedro@codesourcery.com> X-IsSubscribed: yes 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-03/txt/msg00182.txt.bz2 On Thursday 04 March 2010 14:11:27, Eli Zaretskii wrote: > > From: Pedro Alves > > Date: Thu, 4 Mar 2010 13:16:29 +0000 > > > > On Thursday 04 March 2010 04:12:19, Eli Zaretskii wrote: > > > > From: Pedro Alves > > > > Date: Thu, 4 Mar 2010 01:56:44 +0000 > > > > > > > > Anyone else things this is useful? > > > > > > I do. (Somehow, I thought it actually did work at some point in the > > > past, but maybe I was dreaming.) > > > > Indeed, I tried it on 5.3 and 6.0 gdbs, and it worked. Looking > > at the code, I guess it broke with the support for > > multi-location breakpoints, in 6.8. I guess I shall drop the > > NEWS entry, as it's a regression fix afterall? > > There's nothing wrong with saying "works again", if it was broken for > a long time. But if it became broken in 6.8, maybe it's not enough > time. I agree. > > > I think I'll add a simple test that watches for "watch $pc", > > so that we don't regress again. > > Yes, thanks. I've applied this patch below. -- Pedro Alves 2010-03-04 Pedro Alves gdb/ * breakpoint.c (update_watchpoint): Create a sentinel location if the software watchpoint isn't watching any memory. (breakpoint_address_bits): Skip dummy software watchpoint locations. gdb/testsuite/ * gdb.base/watch-non-mem.c, gdb.base/watch-non-mem.exp: New. --- gdb/breakpoint.c | 22 ++++++++++++++++- gdb/testsuite/gdb.base/watch-non-mem.c | 27 ++++++++++++++++++++ gdb/testsuite/gdb.base/watch-non-mem.exp | 40 +++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) Index: src/gdb/breakpoint.c =================================================================== --- src.orig/gdb/breakpoint.c 2010-03-04 14:48:59.000000000 +0000 +++ src/gdb/breakpoint.c 2010-03-04 15:05:29.000000000 +0000 @@ -1237,6 +1237,19 @@ update_watchpoint (struct breakpoint *b, value_free (v); } + /* If a software watchpoint is not watching any memory, then the + above left it without any location set up. But, + bpstat_stop_status requires a location to be able to report + stops, so make sure there's at least a dummy one. */ + if (b->type == bp_watchpoint && b->loc == NULL) + { + b->loc = allocate_bp_location (b); + b->loc->pspace = frame_pspace; + b->loc->address = -1; + b->loc->length = -1; + b->loc->watchpoint_type = -1; + } + /* We just regenerated the list of breakpoint locations. The new location does not have its condition field set to anything and therefore, we must always reparse the cond_string, independently @@ -4516,7 +4529,14 @@ breakpoint_address_bits (struct breakpoi for (loc = b->loc; loc; loc = loc->next) { - int addr_bit = gdbarch_addr_bit (loc->gdbarch); + int addr_bit; + + /* Software watchpoints that aren't watching memory don't have + an address to print. */ + if (b->type == bp_watchpoint && loc->watchpoint_type == -1) + continue; + + addr_bit = gdbarch_addr_bit (loc->gdbarch); if (addr_bit > print_address_bits) print_address_bits = addr_bit; } Index: src/gdb/testsuite/gdb.base/watch-non-mem.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ src/gdb/testsuite/gdb.base/watch-non-mem.c 2010-03-04 15:21:34.000000000 +0000 @@ -0,0 +1,27 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int global = 0; + +int main() +{ + global++; + global++; + global++; + + return 0; +} Index: src/gdb/testsuite/gdb.base/watch-non-mem.exp =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ src/gdb/testsuite/gdb.base/watch-non-mem.exp 2010-03-04 15:20:41.000000000 +0000 @@ -0,0 +1,40 @@ +# Copyright 2010 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# +# Tests watchpoints that watch expressions that don't involve memory. +# + +set testfile "watch-non-mem" +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { + untested ${testfile}.exp + return -1 +} + +if ![runto_main] then { + fail "Can't run to main" + return +} + +gdb_test "watch \$pc" \ + "Watchpoint .*: .pc" \ + "set write watchpoint on \$pc" + +gdb_test "continue" \ + "Watchpoint 2: .pc.*Old value = .*New value = .*" \ + "watchpoint on \$pc works"