Print n levels of callstack?

前端 未结 4 1930
谎友^
谎友^ 2020-12-29 11:18

Using C++ with Visual Studio, I was wondering if there\'s an API that will print the callstack for me. Preferably, I\'d like to print a callstack 5 levels deep. Does windo

相关标签:
4条回答
  • 2020-12-29 11:50

    There is a number of ways to do this.

    See How to Log Stack Frames with Windows x64

    In my opinion, the simplest and as well the most reliable way is the Win32 API function:

    USHORT WINAPI CaptureStackBackTrace(
         __in       ULONG FramesToSkip,
         __in       ULONG FramesToCapture,
         __out      PVOID *BackTrace,
         __out_opt  PULONG BackTraceHash
    );
    

    This FramesToCapture parameter, determines the maximum call stack depth returned.

    0 讨论(0)
  • 2020-12-29 11:54

    Have a look at the Stackwalk and Stackwalk64 API of the DbgHelp API.

    0 讨论(0)
  • 2020-12-29 11:57

    I believe you can get that out of their debugger API (dbghelp).

    0 讨论(0)
  • 2020-12-29 12:16

    It looks like Microsoft's DbgHelp library can do what you want. Consult the StackWalk64 function's documentation on MSDN for more information. Also, this CodeProject article may be useful.

    0 讨论(0)
提交回复
热议问题