From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23223 invoked by alias); 15 Feb 2007 13:35:27 -0000 Received: (qmail 23214 invoked by uid 22791); 15 Feb 2007 13:35:25 -0000 X-Spam-Check-By: sourceware.org Received: from mailgw3.technion.ac.il (HELO mailgw3.technion.ac.il) (132.68.238.35) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 15 Feb 2007 13:35:18 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mailgw3.technion.ac.il (Postfix) with ESMTP id 33F8B173B5B; Thu, 15 Feb 2007 15:35:15 +0200 (IST) Received: from mailgw3.technion.ac.il ([127.0.0.1]) by localhost (mailgw3.technion.ac.il [127.0.0.1]) (amavisd-new, port 10024) with LMTP id H9LtpppZEFHW; Thu, 15 Feb 2007 15:35:15 +0200 (IST) Received: from techunix.technion.ac.il (techunix.technion.ac.il [132.68.1.28]) by mailgw3.technion.ac.il (Postfix) with ESMTP id 0EC81173AB0; Thu, 15 Feb 2007 15:35:14 +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 8A2EB14A44; Thu, 15 Feb 2007 15:35:14 +0200 (IST) (envelope-from mveksler@tx.technion.ac.il) Message-ID: <45D46192.30504@tx.technion.ac.il> Date: Thu, 15 Feb 2007 15:38:00 -0000 From: Michael Veksler User-Agent: Thunderbird 2.0b2 (X11/20070116) MIME-Version: 1.0 To: Ross Boylan Cc: gdb@sourceware.org Subject: Re: Associating C++ new with constructor References: <20070215073516.GW5871@wheat.betterworld.us> In-Reply-To: <20070215073516.GW5871@wheat.betterworld.us> 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-02/txt/msg00158.txt.bz2 Ross Boylan wrote: > This is NOT about the problems setting a breakpoint on a C++ > constructor! > > I've been looking for a way to count creations and destructions of C++ > objects, with the counts kept on a per class basis. Many (9?) years ago I have written a dumb perl script to do this task. It is still being used from time to time, despite valgrind's massif. I can't give you the script, without considerable paperwork, since it is (C) IBM (and I won't try because it is too embarrassing to release such a trivial script). The idea is simple, and took me less than a day to implement: Define a template class that can monitor object creation and destruction. Insert a member of this type into all non-POD classes: class MyFoo { .... .... ... Count m_count_for_MyFoo; }; This member will be constructed every time your MyFoo is constructed. Inside the Count class you can do whatever you want, every Count class may update a global registry, from which you can print statistics for all Count classes. Note that the perl script simply detects "class ....." and inserts the members into it. The nice thing about this template thing, is that it should work well even if your MyFoo is also templated, and it works well for all possible constructors. It is imperfect since it can't reliably detect all non-POD classes, and it does not work for std::*** classes. To make it 100% reliable, I had to write a complete C++ parser!. -- Michael Veksler http:///tx.technion.ac.il/~mveksler