C ++宏登录code的每一行 [英] C++ macro to log every line of code

查看:96
本文介绍了C ++宏登录code的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我和我的经理最近的讨论中,他提到,他以前的一个客户使用C ++宏来记录有关code的每一行的信息。他们所要做的就是开始运行之前启用的环境变量。 (当然环境变量仅在试验台已启用。

During one of my recent discussions with my manager, he mentioned that one of his former clients used a C++ macro to log info about every line of code. All they had to do was enable an environment variable before starting the run. (Of course the environment variable was enabled in the test-bed alone.

日志提到所使用的变量和它们的相应的值太。
例如,对于行:

The log mentioned the variables used and their corresponding values too. For example, for the line:

a = a + b;

日志会这样说:

"a = a + b; (a = 5 + 3)"

就个人而言,我不知道这是否是可能的,但他很肯定这一点已经存在,虽然他不记得了code的细节。

Personally, I was not sure if this was possible, but he was very sure of this having existed, though he did not remember the specifics of the code.

所以,这里是(明显)的问题:这可能吗?你能为这一个提供code?

So, here is the (obvious) question: Is this possible? Can you provide the code for this one?

推荐答案

我不知道,如果每行/变量可以这样进行扩展,但函数调用可以被记录。我已经登录使用 -finstrument函数 GCC的选项所有函数调用。它会调用:

I don't know if every line/variable can be expanded like that, but function calls can be logged. I have logged all function calls using the -finstrument-functions option of gcc. It will call:

  void __cyg_profile_func_enter (void *this_fn, void *call_site);

   void __cyg_profile_func_exit  (void *this_fn, void *call_site);

有关功能的进入和退出。

for function enter and exit.

的文档解释如何使用它。我不知道其他的编译器提供类似的东西。

The docs explain how to use it. I don't know if other compilers offer something similar.

这篇关于C ++宏登录code的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆