Visual Studio 函数调试

发布于 2024-11-01 17:07:19 字数 220 浏览 7 评论 0原文

我正在开发VS 2008。我希望获得所有方法的以下信息:

1)调用进入的时间

2)调用退出的时间和返回值。

GDB 允许我在每个函数入口和出口处设置断点,并在断点处运行脚本,然后继续调试。我厌倦了寻找在 VS 上做类似事情的解决方案。我什至想过编写一个脚本来解析我的整个代码并在入口和出口处编写 fprintf,但这非常复杂。迫切寻求帮助。

I am working on VS 2008. I wish to get the following information for all my methods:

1) Time at call entry

2) Time at call exit and the return value.

GDB allows me to set a break point at each function entry and exit and run a script at the breakpoint and then continue debugging. I am tired of looking for solutions to do something similar on VS. I even thought of writing a script to parse my entire code and write fprintf's at entry and exit but this is very complex. Desperately looking for help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

对不⑦ 2024-11-08 17:07:19

使用windbg,您还可以在每个函数入口处设置并运行脚本。
例如,以下命令将在模块的所有函数上添加断点,显示函数名称、当前时间,运行直到函数退出,显示时间并继续。

bm yourmodule!* "kcL1;.echotime;gu;.echotime;gc"

using windbg, you can also set at each function entry and run a script.
For instance the following command will add a breakpoint on all functions of your module, display the name of the function, the current time, run until the function exit, display the time and continue.

bm yourmodule!* "kcL1;.echotime;gu;.echotime;gc"
指尖上得阳光 2024-11-08 17:07:19

基本上,这是一个功能级别的基于时间的分析 (TBP)。有几种工具可以在这方面为您提供帮助:

我建议您先尝试使用 AMD CodeAnalyst。如果您没有 Visual Studio Premium 或 Ultimate 版本。

Basically this is a function level Time-Based Profiling (TBP). Several tools can help you on this:

I suggest you to try with AMD CodeAnalyst first. If you don't have Visual Studio Premium or Ultimate edition.

╭⌒浅淡时光〆 2024-11-08 17:07:19

我假设你正在起诉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_++) << ":begin\t" << GetTickCount64() << std::endl;
    }

    ~ShowTimestamp() {
        std::cout << func_ << ":" << (--level_) << ":end\t" << 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

I assume you are suing c++. You can define a time trace class which display the timestamps

/* 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_++) << ":begin\t" << GetTickCount64() << std::endl;
    }

    ~ShowTimestamp() {
        std::cout << func_ << ":" << (--level_) << ":end\t" << GetTickCount64() << std::endl;
    }
};

#ifndef NO_TRACE_TIMER
  #define TIMESTAMP_TRACER     ShowTimestamp _stt_(__FUNCTION__); 
#elif
  #define TIMESTAMP_TRACER
#endif

The level_ should be declared in a CPP file separately.

// You need to define the static member in a CPP file         
int ShowTimestamp::level_ = 0;

In your code, you can do

int Foo(int bar) {
  TIMESTAMP_TRACER 

  // all the other things.
  ......

  return bar;
}

If you don't want to trace timer any longer, you can just define NO_TRACE_TIMER

稚然 2024-11-08 17:07:19

Visual Studio 不适合这样做;你必须使用WinDbg。它有自己的脚本语言,可以让您完成您想要的事情。不幸的是我对它的脚本语言一无所知;您必须阅读帮助文件(实际上或多或少有用一次)。

Visual Studio is not suited for this; you would have to use WinDbg. It has its own scripting language that would allow you to do what you are seeking. Unfortunately I don't know the first thing about it's scripting language; you will have to read the help file (which is actually more-or-less useful, for once).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文