From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32705 invoked by alias); 3 Dec 2007 17:54:55 -0000 Received: (qmail 32695 invoked by uid 22791); 3 Dec 2007 17:54:55 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 03 Dec 2007 17:54:44 +0000 Received: (qmail 2309 invoked from network); 3 Dec 2007 17:54:42 -0000 Received: from unknown (HELO localhost) (jimb@127.0.0.2) by mail.codesourcery.com with ESMTPA; 3 Dec 2007 17:54:42 -0000 To: gdb@sourceware.org Subject: Re: Watchpoints with condition References: <200711301925.20196.vladimir@codesourcery.com> <20071130234853.GA27583@caradoc.them.org> From: Jim Blandy Date: Mon, 03 Dec 2007 17:54:00 -0000 In-Reply-To: <20071130234853.GA27583@caradoc.them.org> (Daniel Jacobowitz's message of "Fri, 30 Nov 2007 18:48:54 -0500") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2007-12/txt/msg00011.txt.bz2 Daniel Jacobowitz writes: > On Fri, Nov 30, 2007 at 03:30:21PM -0800, Jim Blandy wrote: >> Isn't that equivalent to 'watch foo == 1'? > > Not quite. > > watch foo == 1 > > stops when foo becomes 1 or non-1. > > watch foo if foo == 1 > > stops only when foo becomes 1. Okay, so 'watch foo if foo == 1' has some interesting behavior: - if foo is 1 when the watchpoint is set, then the watchpoint doesn't trigger until foo becomes != 1, and then becomes 1 again. - If foo is != 1 when the watchpoint is set, then the command is equivalent to watch foo == 1. The first case seems really obscure; I assumed that wasn't what Eli was using conditional watchpoints for "quite a lot". I think any time you have 'watch X if Y', and X is a subexpression of Y, and Y is initially false, it's equivalent to 'watch Y != 0' (or simply 'watch Y' if Y is a boolean expression). X gets watched automatically because it appears in Y, and the only time the expression changes value is when it becomes true. I think the only valuable use case for conditional watchpoints is the one you mentioned, where Y is something expensive, and X is some cheaper conservative approximation to the condition we really want.