Friday, March 20, 2009

Finding a Stack Overflow

Today I had a little difficulty tracking down a Stack Overflow problem when debugging a Windows Mobile 5.0 project using the emulator. The Call Stack Window was blank, kinda difficult to find where in the code the problem occured.

Thankfully there's an easy solution! Open the Exceptions Window (shown below) and toggle on the appropriate exception types, in this case its Stack Overflow. Now the IDE stops at the source of the problem, with a full Call Stack Window, nice!


If you're still having problems breaking in the code when the Stack Overflow occurs, check on the Linker System settings page for the Stack Reserve Size and Stack Commit Size. Try setting both the Stack Reserve Size and Stack Commit Size to zero.

The combination of turning on the Stack Overflow Exception Type, and setting Stack Reserve Size to zero seemed to allow the debugger to stop with a full Call Stack Window, giving me more information about the source of the problem.