This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]