Print n levels of callstack?

c, c++, debugging, visual-c++, visual-studio

Solution

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.

Problem

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 windows provide a simple API to allow me to do this?

Original source

Related problems