tags:

views:

61

answers:

2

Hi folks, im a little bit newbie on gdb so here goes:

Im working on cpp unit testing operation right now. I try to construct string objects with invalid parameters like null_char but program expectedly gives exceptions :). When i try to debug the app using gdb, i type bt after the crash, but it gives me no stack message. Any ideas to why that might happen? Thanks in advance.

+1  A: 

Add the -g option to your compiler command line to add debugging symbols. That helps a lot with gdb.

Delan Azabani
and -O0 helps alot too - sometimes optimizations make the codepath seen in the debugging quite "wild" =)
rasjani
Thanks for that tip, that's great!
Delan Azabani
I go in the code step by step and i think i am in debug mode so there are no optimizations i think..
LostMohican
Debug flags (-g) and optimization level (-O0 through -O3) are independent. You can use a high level of optimization even if you have a debug flag set, and it will make debugging confusing. It's best to check your CXXFLAGS and make sure that the right options are set.
dublev
Thanks dublev, valuable info :)
LostMohican
+1  A: 

Maybe the stack is just not useful because the exception is never caught? Be aware of catchpoints in gdb:

catch throw

breaks when an exception is thrown.

catch catch

breaks when an exception is caught.

Frank