User forums > Help
Breakpoint in constructor/destructor
tom0769:
Hi,
I'm using winXP/2K.
I have a problem with setting breakpoints in constructors/destructors.
Sometimes the debugger stops at the desired point, sometimes not.
I could not find the reason for this.
If for example a breakpoint in a destructor does not work, I set
the breakpoint in a function called in the destructor and the debugger stops there.
I step through this function an then reach the destructor.
Do I have to consider special settings or is it a problem with gdb?
I used DEV-C++ before and there where similar problems.
Tom
Profic:
I've read about this but can't remember where. Due to standart compiler generate not one constructor|destructor body, but many. That's why breakpoints in them didn't work as expected. However there was mentioned that gdb 6.3 can handle this situation in proper way.
Urxae:
Are you compiling with optimizations on? If so, turn them off. Optimizations can do weird things when debugging, as things may be reordered or optimized out. Also, debugging information such as linenumbers may not always play nice with optimizations (especially inlining).
If you're debugging something that only shows up while optimizations are on, don't be surprised if debugging doesn't work as you expected.
My first guesses as to skipping breakpoints in this scenario would be
* the breakpoint is placed on a line that is optimized out. Does it do anything that is observable afterwards? If so the next question is: is it observed afterwards? The compiler is free to perform any optimization that doesn't change what the program does, so if the program runs with the exact same result without that line it is free to generate no code for it at all, and so there might be no place to break on.
* the destructor is inlined. I'm not sure if the debugging information includes the correct information about linenumbers that code generated for inlined functions comes from, it might show as the location of the call point.
RayGun:
Hello, people!
Have recently started toying with Code::Blocks (1.0 rc 2), looks better then Dev-C++ to me.
However, I've got the same problem with constructors/destructors and GDB.
GDB is 6.3, optimizations are off, debugging symbols/profile code when executed - on.
Cannot hit breakpoints in constructor/destructor (although step-in reaches the constructor).
Any ideas on how to remedy this?
mandrav:
Wait for the next update. It will set breakpoints in ctors/dtors.
(it should support it already but a bug prevented this)
Navigation
[0] Message Index
[#] Next page
Go to full version