From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26590 invoked by alias); 4 Jun 2010 22:54:20 -0000 Received: (qmail 26582 invoked by uid 22791); 4 Jun 2010 22:54:19 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Jun 2010 22:54:13 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o54Ms9Wt026690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Jun 2010 18:54:09 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o54Ms6O5013015 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 4 Jun 2010 18:54:08 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id o54Ms6hT011991; Sat, 5 Jun 2010 00:54:06 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id o54Ms5EP011990; Sat, 5 Jun 2010 00:54:05 +0200 Date: Fri, 04 Jun 2010 22:54:00 -0000 From: Jan Kratochvil To: Chris Moller Cc: "gdb-patches@sourceware.org" Subject: Re: [patch] pr11371 conditional watchpoints with a function in the condition. Message-ID: <20100604225405.GA9012@host0.dyn.jankratochvil.net> References: <4C0936B5.9080002@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4C0936B5.9080002@redhat.com> User-Agent: Mutt/1.5.20 (2009-12-10) 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-06/txt/msg00150.txt.bz2 On Fri, 04 Jun 2010 19:24:05 +0200, Chris Moller wrote: > if the condition associated with a > watchpoint contained a function call, it resulted in a segfault. > --- breakpoint.c 13 May 2010 22:44:02 -0000 1.486 > +++ breakpoint.c 2 Jun 2010 19:39:12 -0000 > @@ -1355,7 +1355,10 @@ > /* We don't free locations. They are stored in bp_location array and > update_global_locations will eventually delete them and remove > breakpoints if needed. */ > - b->loc = NULL; > + > + if (b->type != bp_watchpoint && b->type != bp_hardware_watchpoint && > + b->enable_state != bp_call_disabled) > + b->loc = NULL; This change has a regression for: int a[1000], *p = a; int main (void) { int i; for (i = 0; i < 100; i++) p++; return 0; } ./gdb -nx -ex 'watch *p' -ex r ./pr11371regression Watchpoint 1: *p Starting program: .../pr11371regression Program exited normally. -> Watchpoint 1: *p Starting program: .../pr11371regression Warning: Could not insert hardware watchpoint 1. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. (gdb) p i $1 = 2 The crash happened due to referencing unallocated memory of a freed bp_location. Your patch avoids freeing bp_locations in some cases. But it is not correct as these bp_locations become superfluous causing needless hardware watchpoints. I believe this `b->loc = NULL' should remain in place, there is more a problem of bpstat not linked to thread should get cleared its stale bp_location reference. I was thinking more about something around the patch below but it does not work anyway so just posting FYI. Also maybe on should pre-apply: [patch 1/3] Clear stale specific locs, not whole bpts [rediff] http://sourceware.org/ml/gdb-patches/2010-05/msg00366.html BTW the testcase gdb.base/pr11371.exp PASSes for me even on FSF GDB HEAD. Thanks, Jan --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -4108,6 +4111,9 @@ bpstat_stop_status (struct address_space *aspace, /* Print nothing for this entry if we dont stop or dont print. */ if (bs->stop == 0 || bs->print == 0) bs->print_it = print_it_noop; + + if (b->type == bp_hardware_watchpoint) + break; } }