Visual Studio函数调试
Visual Studio Function Debugging
我正在开发VS 2008。我想获得以下所有方法的信息:
1)呼叫进入时间
2)调用退出时间和返回值。
GDB允许我在每个函数入口和退出处设置断点,并在断点处运行脚本,然后继续调试。我厌倦了寻找解决方案来做类似的VS.我甚至想到写一个脚本来解析我的整个代码,并在进入和退出时编写fprintf,但这是非常复杂的。迫切寻求帮助
使用windbg,您还可以在每个函数入口设置并运行脚本。例如,下面的命令将在模块的所有函数上添加一个断点,显示函数的名称,当前时间,运行直到函数退出,显示时间并继续。
bm yourmodule!* "kcL1;.echotime;gu;.echotime;gc"
基本上这是一个功能级别的基于时间的分析(TBP)。以下工具可以帮助您:
- Visual Studio Profiling Tools:仅在Visual Studio Ultimate和Premium版本中可用。http://msdn.microsoft.com/en-us/library/z9z62c29.aspx
- Intel vTune:它可以做很多事情,包括功能级分析。http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/ AMD CodeAnalyst:这是一个免费的工具。它也可以与英特尔CPU一起工作(功能有限,但足以满足您的目的)。它可以做源代码级别的分析:http://developer.amd.com/cpu/codeanalyst/codeanalystwindows/pages/default.aspx
我建议您先尝试使用AMD CodeAnalyst。如果你没有Visual Studio高级版或终极版。
我假设您正在使用c++。您可以定义一个显示时间戳
的时间跟踪类。/* define this in a header file */
class ShowTimestamp {
private:
static int level_; // nested level for function call tree
private:
const char *func_;
public:
ShowTimestamp(const char* f) : func_(f) {
std::cout << func_ << ":" << (level_++) << ":begint" << GetTickCount64() << std::endl;
}
~ShowTimestamp() {
std::cout << func_ << ":" << (--level_) << ":endt" << GetTickCount64() << std::endl;
}
};
#ifndef NO_TRACE_TIMER
#define TIMESTAMP_TRACER ShowTimestamp _stt_(__FUNCTION__);
#elif
#define TIMESTAMP_TRACER
#endif
level_应该在CPP文件中单独声明。
// You need to define the static member in a CPP file
int ShowTimestamp::level_ = 0;
在您的代码中,您可以执行
int Foo(int bar) {
TIMESTAMP_TRACER
// all the other things.
......
return bar;
}
如果您不想再跟踪计时器,您可以定义NO_TRACE_TIMER
Visual Studio不适合;你必须使用WinDbg。它有自己的脚本语言,可以让你做你想做的事情。不幸的是,我对它的脚本语言一无所知;您必须阅读帮助文件(这实际上或多或少有用一次)。
相关文章:
- 无法使函数公开。获取:"LNK2005"错误。如何调试链接器错误
- 如何调试Cpp程序中的析构函数
- 将C++函数从 DLL 导出为 C 时调试和发布之间的差异
- 调试 - 单步执行 (F11) 不会直接转到函数
- 如何关闭用于在程序中打印调试数据的函数
- 在h文件上内联发布版本并在cpp上实现调试版本的函数
- 使用向量的函数崩溃,调试器说访问冲突读取位置
- 正确编码和调试的命名空间中未解析的函数
- 函数在正常运行时不起作用,但在调试时起作用
- 函数无法正常工作,调试器没有帮助
- OpenGL 调试 错误回调函数的 ID 参数是什么?
- 如何定义具有依赖于符号调试的参数的函数
- 如何调试指针参数是否通过函数修改
- Qtcpserver 仅在调试器下在侦听函数上返回未知错误
- Vulkan API 调试函数指针类型转换错误
- 调试函数参数的值(以C++为单位)
- 如何在C++内联成员函数中添加Android调试函数(LOGE,LOGW..)
- 调试函数的优化代码(带有模板的c++11)
- 在C++中取消调试函数的更好方法
- 使用 gdb 在问号中显示段错误进行调试 函数"?? ()"