Search code examples
visual-c++visual-studio-2008windows-ce

Locate a stack overflow


I am trying to debug somebody else's code and after running the application in debug mode for about 12 hours I get a first chance exception at 0x400795f4 in XXXX Cx00000FD Stack Overflow. I have turned on break at this exception but it does not break there and by the time it happens the application has stopped running at file atlosapice.h line 906 which is the wvsprinfw function.

I was wondering if there were anything else that I could do to try and find this? The application that I am trying to debug is running on WinCE 6.0 and using Visual Studio 2008.


Solution

  • Take a look through the application for printf() like functions. Be sure to include NKDbgPrintfW(), RETAILMSG, DEBUGMSG, and other debugging macros. Before and after each of those calls put something like this:

    printf( "++%s(%d)\n", __FILE__, __LINE__ );
    printf( "some printf\n" ); // the printf already in the code
    printf( "--%s(%d)\n", __FILE__, __LINE__ );
    

    Then, watch the output window and see what is the last thing printed before the exception.

    What is probably happening is that the printf specified the wrong format specifier for some item, too many format specifiers, or not enough format specifiers.

    For example:

    long z = 'A';
    printf("%c\n", z);  // undefined behavior