views:

235

answers:

3

I am working on a 3rd party c++ app. It is crashing during the exit. If I look at the stack all I get is the __static_initialization_and_destruction_0 function and lots of questions marks. Project is huge and unfortunately it has many static objects. Is there any way to find out which one is crashing?

+1  A: 

If you can, run with a debugger attached and it'll let you break at the point of the crash.

Otherwise, you might try adding logging information in the destructors, such as:

std::cout << "In ~SomeObject." << std::endl;
GMan
it does, but function name is (??) which is not helping.
l.thee.a
Try backing up a bit in the stack. Did you try `cout`ing some info.?
GMan
A: 

The invalid call stack may indicate that the stack has been corrupted by one of the destructors. I suggest that you place a breakpoint in every destructor for which a static object is instantiated, then you may determine which was the last destructor that executed.

Also at each break, you should observe the call stack for signs that it has been corrupted. If you place the breaks at the end of each destructor, you are likely to see the corrupt stack before it actually crashes.

If you have many objects of one type, you might remove the breakpoint for that class once you have satisfied yourself that it executes correctly. Also you may be able to place breakpoints only in classes that are only ever instantiated statically.

Clifford
+1  A: 

Although, this is probably not the advice you are looking for, avoid the use of static objects. The reason for this is that there is no way to guarantee the order of construction and destruction.

I am guessing here but it is entirely possible that one static object depends on another static object. Since there is no way of guaranteeing the order of destruction, you are ending up in trouble.

It may well be worth your while to change your static objects to pointers that you create at the beginning of you main function and destroy at the end of your main function. You then have the option of ordering them appropriately.

doron