Re: Stackwalk64 problems
From: Faisal Masoor (fmansoor_at_softpak.com)
Date: 05/21/04
- Previous message: Patrick Zou: "Re: exposing a driver"
- In reply to: John Kirk: "Stackwalk64 problems"
- Next in thread: John Kirk: "Re: Stackwalk64 problems"
- Reply: John Kirk: "Re: Stackwalk64 problems"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 21 May 2004 09:57:13 +0500
Hello John
This problem is not due to dbghelp.dll it is due to compiler optimization
your program is
producing correct stack depth but in release build the compiler is
optimizing your code thus is not calling the testAfter function
recursively take a look at the disassembly of your testAfter function in
release build.
-------------------------------Relase
Build-------------------------------------------------------------------
52: void testAfter(int depth)
53: {
00401120 jmp stackTest (00401000) //Look Here This directly jumps
to stackTest
--- No source
ile -----------------------------------------------------------------------
---------------------------------
00401125 nop
00401126 nop
00401127 nop
00401128 nop
00401129 nop
0040112A nop
0040112B nop
0040112C nop
0040112D nop
0040112E nop
0040112F nop
--- E:\My
rojects\StkWalkProb\a.cpp -------------------------------------------------
-------------------------------------
54: if(depth > 0)
55: {
56: depth--;
57: testAfter(depth);
58: }
59: else
60: {
61: stackTest();
62: }
63: }
64:
----------------------------------------------------------------------------
---------------
Faisal Mansoor
----------------------------------------------------------------------------
---------------
"John Kirk" <john@-removethis-demonware.net> wrote in message
news:Xns94EFB9116CFADjohndemonwarenet@194.125.133.14...
> 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;
> }
- Previous message: Patrick Zou: "Re: exposing a driver"
- In reply to: John Kirk: "Stackwalk64 problems"
- Next in thread: John Kirk: "Re: Stackwalk64 problems"
- Reply: John Kirk: "Re: Stackwalk64 problems"
- Messages sorted by: [ date ] [ thread ]