Advertisement

GDB and constructors

Started by February 07, 2004 01:31 AM
1 comment, last by mr BiCEPS 20 years, 7 months ago
I have been trying several times to set a breakpoint in a constructor with GDB, but it has not worked, even though I have upgraded to the latest version. A google groups search landed me this little piece of information:
quote: 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.
Are there any workarounds for this?
Take this with a grain of salt since I haven''t used gdb since man first tamed lightning and set it to work compiling C programs, but did you try putting a call to a dummy function in the constructor and then setting a breakpoint inside the dummy function?
Advertisement
Well the thought did occur to me, but it''s not really what I want. I''m not asking this because of a specific problem I have, but because I could have used a breakpoint in constructors many times lately and it''s annoying to have to insert lots of cout statements instead because the debugger doesn''t work.

Oh well, I hope they fix it in the next version!

This topic is closed to new replies.

Advertisement