From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5866 invoked by alias); 28 Sep 2012 13:32:41 -0000 Received: (qmail 5854 invoked by uid 22791); 28 Sep 2012 13:32:39 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,T_FRT_BELOW2 X-Spam-Check-By: sourceware.org Received: from mail-pb0-f41.google.com (HELO mail-pb0-f41.google.com) (209.85.160.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Sep 2012 13:32:36 +0000 Received: by pbbrq2 with SMTP id rq2so5570365pbb.0 for ; Fri, 28 Sep 2012 06:32:35 -0700 (PDT) Received: by 10.68.237.3 with SMTP id uy3mr20327963pbc.30.1348839155811; Fri, 28 Sep 2012 06:32:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.80.134 with HTTP; Fri, 28 Sep 2012 06:32:15 -0700 (PDT) In-Reply-To: <87k3vfwpnv.fsf@fleche.redhat.com> References: <87k3vfwpnv.fsf@fleche.redhat.com> From: "Laurent G." Date: Fri, 28 Sep 2012 13:32:00 -0000 Message-ID: Subject: Re: Delete a watchpoint by address to automate segfault tracking To: gdb@sourceware.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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: 2012-09/txt/msg00078.txt.bz2 On Thu, Sep 27, 2012 at 3:39 PM, Tom Tromey wrote: >>>>>> "Laurent" =3D=3D Laurent G writes: > > Laurent> In the article, the author says "I couldn=92t find an easy way t= o track > Laurent> the memory watch number that was created during the first breakp= oint, > Laurent> I just built a gdb counter, and deleted the memory watch when le= aving, > Laurent> since I could predict gdb=92s numbering" and implements watchpoi= nts > Laurent> destruction this way: > > I think $bpnum may hold this. > See the 'Set Breaks' node of the manual. > Or it can perhaps be done from Python. > > Laurent> How can I do a "delete *`print $d`" in GDB? > > A few ways. > > Simplest is to use "eval". > > Otherwise, Python. > > Otherwise, if you have an old gdb and can't upgrade, use set logging to > write out a file with the command you want (using printf), then 'source' > the file. > > Tom Thanks for your reply that helped me a lot. In fact the true issue is that = you can clear a breakpoint by its address: (gdb) clear *0x80a5f90 But for no reason (from a user point of view) you can't do the same thing f= or a watchpoint. If it was possible I could have used: (gdb) eval "delete *0x%x", my_pointer Even if the Python support is great I forgot to tell that the target is an embedded system so I didn't want to compile a Python environment. Anyway, that's may= be not the cleanest way to do so but I did the write-out-a-file things to matc= h the address of the buffer with the number of the watchpoint associated with it. I'm positing my script bellow in the case anyone encounter the same issue: (gdb) set pagination off (gdb) b open_filter.c:30 (gdb) b close_filter.c:100 (gdb) commands 1 (gdb) silent (gdb) watch -l *(int*)*p_data (gdb) set logging file watchpoints.gdb (gdb) set logging on (gdb) eval "echo %d 0x%x\n", $bpnum, p_data (gdb) set logging off (gdb) cont (gdb) end (gdb) commands 2 (gdb) silent (gdb) set logging file match.gdb (gdb) set logging overwrite on (gdb) set logging on (gdb) eval "echo 0x%x\n", p_data (gdb) set logging off (gdb) set logging overwrite off (gdb) shell cat watchpoints.gdb | grep `cat match.gdb` | awk -F" " '{print "delete "$1}' > delete_wp.gdb (gdb) shell line=3D`cat match.gdb`; sed -i "/$line/d" watchpoints.gdb (gdb) source delete_wp.gdb (gdb) cont (gdb) end Regards, Laurent