From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3296 invoked by alias); 14 Mar 2007 09:20:48 -0000 Received: (qmail 3280 invoked by uid 22791); 14 Mar 2007 09:20:46 -0000 X-Spam-Check-By: sourceware.org Received: from mailgw1.technion.ac.il (HELO mailgw1.technion.ac.il) (132.68.238.34) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 14 Mar 2007 09:20:41 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailgw1.technion.ac.il (Postfix) with ESMTP id D5393AC622; Wed, 14 Mar 2007 11:20:37 +0200 (IST) Received: from mailgw1.technion.ac.il ([127.0.0.1]) by localhost (mailgw1.technion.ac.il [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ZRh2DZoGmzcC; Wed, 14 Mar 2007 11:20:37 +0200 (IST) Received: from techunix.technion.ac.il (techunix.technion.ac.il [132.68.1.28]) by mailgw1.technion.ac.il (Postfix) with ESMTP id 2CCBAAC605; Wed, 14 Mar 2007 11:20:23 +0200 (IST) Received: from tp-veksler.haifa.ibm.com (techunix.technion.ac.il [132.68.1.28]) by techunix.technion.ac.il (Postfix) with ESMTP id 12A5914ABA; Wed, 14 Mar 2007 11:20:23 +0200 (IST) (envelope-from mveksler@tx.technion.ac.il) Message-ID: <45F7BE52.8020409@tx.technion.ac.il> Date: Wed, 14 Mar 2007 09:20:00 -0000 From: Michael Veksler User-Agent: Thunderbird 2.0b2 (X11/20070116) MIME-Version: 1.0 To: "Ed S. Peschko" Cc: Eli Zaretskii , gdb@sourceware.org Subject: Re: dynamic breakpoints/watchpoints References: <20070314002242.GB17710@venus> <20070314083409.GA21561@venus> In-Reply-To: <20070314083409.GA21561@venus> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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-03/txt/msg00196.txt.bz2 Ed S. Peschko wrote: > For example, > > int main() > { > ==> int stuff; > aha(); > aha2(); > } > > > int aha() > { > fprintf(stderr, "HERE1"); > } > > int aha2() > { > fprintf(stderr, "HERE"); > } > > Suppose that I'm at the '==>'. if I say bc /HERE/", I would break in the > function 'aha', at the fprintf statement HERE1'. If I said bc /HERE/ at THAT > point, then I'd break at 'HERE2'. The breakpoint changes as you go along. > What I usually do is use emacs' tags system to search for the string, and then manually put breakpoints at the relevant locations. This works well when there is only couple of matching lines. My normal use case is: 1. An error text is printed, or some activity is logged into a file. 2. I want to stop right at the place that caused that behavior. So I perform the following: 1. Try to guess how the relevant code looks like 2. Look for all occurrences of such code using grep/tags 3. If search result is too wide or too narrow go to step i. 4. Break at all relevant locations This process is quite long and prone to errors. It would be much better if it were integrated into gdb+libc+libstdc++ in the following way: 1. libc+libstdc++ will have hooks that gdb will be able to use to intercept FILE/stream writes. 2. A slower alternative to 1 is for for GDB to intercept write system calls, and check their contents. To improve granularity in C, buffering should be set to line granularity. In C++, buffering should be eliminated (unless people use std::endl instead of the much better "\n"). 3. GDB will stop at each write, and look for the requested text. If the text is encountered - break. This technique can be implemented to a limited extend by a conditional breakpoint on write() which will wait for memmem(name_of_buffer_arg, size_of_buffer, your_text, strlen(your_text) ). But that is ugly, imperfect and is not something you want to require from average users to implement. I was never desperate enough to implement this in my code. This should be implemented in gdb+glibc+libstdc++. My proposed feature seems easier to implement and more powerful in the cases that interest me (and you?). Even the watchpoints of std::string can be implemented by some hooks provided by the libstdc++ team. They could add an strcmp looking for the requested string, every time the string is mutated, and then GDB will be able to break on a match. Other data-types are more complicated, and most of them are impractical candidates for dynamic watchpoints (unless GCC is heavily modified to insert hooks for all updates to, for example, int variables - this will be slow as hell). --- Michael