This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: Breakpoints in constructor/destructor
- From: Michael Elizabeth Chastain <mec at shout dot net>
- To: gdb at sources dot redhat dot com, mjeng at siue dot edu
- Date: Mon, 23 Jun 2003 22:53:13 -0400
- Subject: Re: Breakpoints in constructor/destructor
I can shed a little light ...
When gcc compiles any constructor or any destructor, it generates *two*
functions in the object code (sometimes three, but I have never seen
three). This is part of the implementation of virtual base classes in
C++.
These two object code functions have different names for the linker (or
else the program wouldn't even link properly), but gdb thinks that these
functions have the same name, and confusion ensues. You set a
breakpoint -- it goes into one copy of the function -- but not the
other. And then your program executes the other one.
Try this: compile your program with "-S" to get assembly code.
Then read the assembly code. You will see two copies of
'MyNumber::MyNumber' and 'MyNumber::~MyNumber'. To make the assembly
code easier to visualize, you can call 'APointLessFunction' in the
constructor, and then you can find two object-code functions with calls
to 'APointLessFunction'.
This won't help you set breakpoints in the constructor, but I hope it
will help explain gdb's behavior.
Michael C