From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25710 invoked by alias); 15 Jul 2004 10:30:18 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 25420 invoked from network); 15 Jul 2004 10:30:16 -0000 Received: from unknown (HELO blount.mail.mindspring.net) (207.69.200.226) by sourceware.org with SMTP; 15 Jul 2004 10:30:16 -0000 Received: from user-119a90a.biz.mindspring.com ([66.149.36.10] helo=berman.michael-chastain.com) by blount.mail.mindspring.net with esmtp (Exim 3.33 #1) id 1Bl3VG-0004LB-00; Thu, 15 Jul 2004 06:30:14 -0400 Received: by berman.michael-chastain.com (Postfix, from userid 502) id 903344B104; Thu, 15 Jul 2004 06:30:16 -0400 (EDT) To: gdb@sources.redhat.com, rolandz@poczta.fm Subject: Re: How to setup a breakpoint on constructor Message-Id: <20040715103016.903344B104@berman.michael-chastain.com> Date: Thu, 15 Jul 2004 11:31:00 -0000 From: mec.gnu@mindspring.com (Michael Elizabeth Chastain) X-SW-Source: 2004-07/txt/msg00163.txt.bz2 > Is there anything different in the constructor in comparision to normal > function since I cannot break the program in there? Yes, this is a long-standing problem with gdb and gcc 3.X. See the PROBLEMS file: gdb/1091: Constructor breakpoints ignored gdb/1193: g++ 3.3 creates multiple constructors: gdb 5.3 can't set breakpoints When gcc 3.x compiles a C++ constructor or C++ destructor, it generates 2 or 3 different versions of the object code. These versions have unique mangled names (they have to, in order for linking to work), but they have identical source code names, which leads to a great deal of confusion. Specifically, if you set a breakpoint in a constructor or a destructor, gdb will put a breakpoint in one of the versions, but your program may execute the other version. This makes it impossible to set breakpoints reliably in constructors or destructors. gcc 3.x generates these multiple object code functions in order to implement virtual base classes. gcc 2.x generated just one object code function with a hidden parameter, but gcc 3.x conforms to a multi-vendor ABI for C++ which requires multiple object code functions. Things you can try: . modify your program so that the constructors that you want to breakpoint call some function that is not a constructor, and break on that. . run 'nm a.out | c++filt' to find the symbols in your program. break on the absolute address: "break *0x01234567". this is very crude (1960's technique) but it does work. . use nm, c++filt, and 'strip -N' to strip out symbols for not-in-charge constructors. This is scriptable, if someone wants to write a little script. It's a hard problem. Michael C