Stackwalk64 problems
From: John Kirk (john_at_-removethis-demonware.net)
Date: 05/20/04
- Next message: Slava M. Usov: "Re: How to terminate a socket in CLOSE_WAIT state"
- Previous message: qfel: "Re: Where is the Main Window"
- Next in thread: Ivan Brugiolo [MSFT]: "Re: Stackwalk64 problems"
- Reply: Ivan Brugiolo [MSFT]: "Re: Stackwalk64 problems"
- Reply: Severian: "Re: Stackwalk64 problems"
- Reply: Faisal Masoor: "Re: Stackwalk64 problems"
- Reply: John Kirk: "Re: Stackwalk64 problems"
- Reply: Garfield Lewis: "Re: Stackwalk64 problems"
- Messages sorted by: [ date ] [ thread ]
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;
}
- Next message: Slava M. Usov: "Re: How to terminate a socket in CLOSE_WAIT state"
- Previous message: qfel: "Re: Where is the Main Window"
- Next in thread: Ivan Brugiolo [MSFT]: "Re: Stackwalk64 problems"
- Reply: Ivan Brugiolo [MSFT]: "Re: Stackwalk64 problems"
- Reply: Severian: "Re: Stackwalk64 problems"
- Reply: Faisal Masoor: "Re: Stackwalk64 problems"
- Reply: John Kirk: "Re: Stackwalk64 problems"
- Reply: Garfield Lewis: "Re: Stackwalk64 problems"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|