How to Log Stack Frames with Windows x64

前端 未结 12 1048
-上瘾入骨i
-上瘾入骨i 2020-12-07 14:48

I am using Stackdumps with Win32, to write all return adresses into my logfile. I match these with a mapfile later on (see my article [Post Mortem Debugging][1]).

<

12条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 15:35

    When using StackWalk64 you are iterating through the thread's entire stack whether there is valid data or not. Once you hit a return address of 0 you should terminate the walk, like so:

    for (ULONG Frame = 0; ; Frame++)
    {
      if (FALSE == StackWalk64(...))
      {
        printf("Stack walk failed!\n");
        break;
      }  
    
      if (stackFrame.AddrPC.Offset == 0)
      {
        printf("Stack walk complete!\n");
        break;
      }
    
      do_something();
    }
    

提交回复
热议问题