如何检测 C++ 程序以便存储 args & return 值?

How to instrument C++ program so that args & return values are stored?

我正在开发 C++11 嵌入式 Linux 应用程序。我们目前使用 gcc-6.3.

它需要进行哪些修改(以及哪些部分),因此请记录传递给我们的 C++ 函数的所有参数,以及它们的 return 值?

如果这是唯一的方法,修改 gcc 是一个选项。

您可以考虑使用 plugin (or some extension in MELT).

扩展 GCC

这不是一项简单的任务(可能需要数周或更长时间 的工作),您需要了解passes and the GIMPLE representation. Look at some slides in http://gcc-melt.org/docum.html

的组织

您可以注释您的函数以使用您自己的特定 custom attribute (read about function attributes) then add your custom optimization pass 修改 GIMPLE 来跟踪对这些函数的调用。您可能希望在此类调用之前和之后插入对某些日志记录函数的调用。

(我建议将您的插件设为免费软件,您可能会得到相关帮助;请注意 GCC runtime library exception

除了 Basile 所说的之外,使用 systemtap 也是一种选择,尤其是在必须按需进行检测并且性能不太重要的情况下。