visual-studio 打印 n 级调用堆栈?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1341796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Print n levels of callstack?
提问by
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?
在 Visual Studio 中使用 C++,我想知道是否有一个 API 可以为我打印调用堆栈。最好,我想打印一个 5 级深的调用堆栈。Windows 是否提供了一个简单的 API 来允许我这样做?
采纳答案by RED SOFT ADAIR
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:
在我看来,最简单也是最可靠的方法是 Win32 API 函数:
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.
此 FramesToCapture 参数确定返回的最大调用堆栈深度。
回答by bcat
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 articlemay be useful.
看起来微软的 DbgHelp 库可以做你想做的事。有关详细信息,请参阅 MSDN 上的 StackWalk64 函数文档。此外,这篇 CodeProject 文章可能很有用。
回答by T.E.D.
回答by steve
Have a look at the Stackwalk and Stackwalk64 API of the DbgHelp API.
查看 DbgHelp API 的 Stackwalk 和 Stackwalk64 API。

