Stackwalk64 problems

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: John Kirk (john_at_-removethis-demonware.net)
Date: 05/20/04


Date: Thu, 20 May 2004 17:11:30 GMT

Hi,

Setup: MSVC6, WinXP (sp2), latest platform SDK (Feb 2003)

I'm trying to use dbghelp.dll to get a stack trace, unfortunately I think
StackWalk64 is misbehaving. The output of the program below differs
depending on the version of dbghelp.dll used, neither of which are correct:

dbghelp.dll ver 5.1 outputs:
Stack depth = 2

dbghelp.dll ver 6.2 outputs:
Stack depth = 3

The output stack depth should at least 100. I have seen several examples
of StackWalk and StackWalk64 that use separate threads but that's not an
option for me. Have a forgotten to initialize something? What am I doing
wrong?

Thanks in advance,

John.

Here's the code:

#include <stdio.h>
#include <windows.h>
#include <Dbghelp.h>

#pragma comment(lib, "dbghelp")

void stackTest()
{
     HANDLE hProcess = GetCurrentProcess();
     HANDLE hThread = GetCurrentThread();

     CONTEXT context;
     memset(&context, 0, sizeof(CONTEXT));
     context.ContextFlags = CONTEXT_FULL;

     BOOL contextOk = GetThreadContext(hThread, &context);

     STACKFRAME64 stackframe;
     memset(&stackframe, 0, sizeof(STACKFRAME64));

     stackframe.AddrPC.Offset = context.Eip;
         stackframe.AddrPC.Mode = AddrModeFlat;
     stackframe.AddrFrame.Offset = context.Ebp;
     stackframe.AddrFrame.Mode = AddrModeFlat;

     if(SymInitialize(hProcess, NULL, true))
     {
         int depth = 0;

         while( StackWalk64(IMAGE_FILE_MACHINE_I386,
                            hProcess,
                            hThread,
                            &stackframe,
                            &context,
                            NULL,
                            SymFunctionTableAccess64,
                            SymGetModuleBase64,
                            NULL))
         {
             if(stackframe.AddrPC.Offset!=0)
             {
                 depth++;
             }
         }

         SymCleanup(hProcess);

         printf("Stack depth = %i\n", depth);
     }
}

void testAfter(int depth)
{
     if(depth > 0)
     {
         depth--;
         testAfter(depth);
     }
     else
     {
         stackTest();
     }
}

int main(int argc, char* argv[])
{
     testAfter(100);
     return 0;
}



Relevant Pages

  • StackWalk64 problems
    ... I'm trying to use dbghelp.dll to get a stack trace, ... StackWalk64 is misbehaving. ... Stack depth = 2 ...
    (microsoft.public.vc.language)
  • Stackwalk64 problems
    ... I'm trying to use dbghelp.dll to get a stack trace, ... StackWalk64 is misbehaving. ... Stack depth = 2 ...
    (microsoft.public.vc.debugger)
  • Re: Stackwalk64 problems
    ... >StackWalk64 is misbehaving. ... >dbghelp.dll ver 5.1 outputs: ... >The output stack depth should at least 100. ... Frame pointer omission can make it difficult ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Stackwalk64 problems
    ... >StackWalk64 is misbehaving. ... >dbghelp.dll ver 5.1 outputs: ... >The output stack depth should at least 100. ... Frame pointer omission can make it difficult ...
    (microsoft.public.vc.debugger)
  • console handover badness [was: stack overflow on Sparc64]
    ... Locked up after "console: colour dummy device ... Are you sure you didn't see a "Stack overflow" message on the ... the kernel disables the PROM console. ... khelper used greatest stack depth: ...
    (Linux-Kernel)