Zeu*_*eus 5 c++ windows debugging callstack
我尝试了以下链接,来自StackOverflow和其他网站,[我试过,但它没有帮助我,所以我无法避免重复]
http://www.codeproject.com/KB/threads/StackWalker.aspx
http://jpassing.com/2008/03/12/walking-the-stack-of-the-current-thread/
但是没有一个代码适用于我.我是Windows C++环境的新手,我无法获得上述任何代码.
我正在寻找一个调用堆栈格式,如
FUNCTION_NAME_DEPTH_1:_LINE_NUM__
FUNCTION_NAME_DEPTH_1:_LINE_NUM__
FUNCTION_NAME_DEPTH_1:_LINE_NUM__ ...
只是功能名称和行号.
我的环境:
Visual Studio 2010
SDK:v7.1
Windows 7 Pro SP1
如果有人发布一个头文件,[似乎很少可用,但没有工作],我们可以包含在我们的cpp文件中并使用像'PrintFunctionCallStack();这样的调用打印调用堆栈,这将是很简单的..BTW在Linux/Mac中,它变得容易多了,我能够从回溯中获得调用堆栈,而且它非常简单,我自己在几分钟内完成了它.在Windows中,我已经尝试了两天,但毫不奇怪.
Linux/Mac堆栈跟踪代码,我还没有解码符号名称.
#ifndef _STACKTRACE_H_
#define _STACKTRACE_H_
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>
#include <cxxabi.h>
#include <iostream>
static inline void PrintStackTrace()
{
cout<<"##############################################\n";
unsigned int maxStackCount = 63;
void* addressList[maxStackCount+1];
int addrLen = backtrace(addressList, sizeof(addressList) / sizeof(void*));
if (addrLen == 0) {
cout<<"Empty Stack, Probably Corrupted it seems ###\n";
return;
}
char** symbolList = backtrace_symbols(addressList, addrLen);
for (int i = 1; i < addrLen; i++) // Skipped First, 'i' begins with '1'
{
cout<<"###: "<<symbolList[i]<<":###\n";
}
free(symbolList);
cout<<"##############################################\n";
}
#endif
Run Code Online (Sandbox Code Playgroud)
如果你的环境是Visual Studio,你可以插入一个Tracepoint并输入
$CALLSTACK
Run Code Online (Sandbox Code Playgroud)
在其编辑框中,选中打印消息后。
为此,右键单击所需的行,然后选择“断点”>“插入断点”(或者,单击所需的编辑器行的左侧插入一个断点,然后选择“命中时”)。
然后您将在输出窗口中看到详细的报告,其中包含文件名、行号和函数名称。它帮助我成功地发现了一些内存泄漏。
| 归档时间: |
|
| 查看次数: |
7929 次 |
| 最近记录: |