自动添加输入/退出功能日志到项目 [英] Automatically adding Enter/Exit Function Logs to a Project

查看:194
本文介绍了自动添加输入/退出功能日志到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方源代码,我必须调查。我想看看函数是什么顺序调用,但我不想浪费我的时间键入:

I have a 3rd party source code that I have to investigate. I want to see in what order the functions are called but I don't want to waste my time typing:

printf("Entered into %s", __FUNCTION__)

printf("Exited from %s", __FUNCTION__)

对于每个函数,我也不想触摸任何源文件。

for each function, nor do I want to touch any source file.

你有什么建议吗?是否有自动为我自动执行此操作的编译器标志?

Do you have any suggestions? Is there a compiler flag that automagically does this for me?

对注释的说明:


  • 我将交叉编译源代码,在ARM上运行它。

  • 我将使用gcc编译它。

  • 想要分析静态代码。我想跟踪运行时。所以doxygen不会让我的生活更轻松。

  • 我有源代码,我可以编译它。

  • 我不想使用Aspect Oriented编程。

  • I will cross-compile the source to run it on ARM.
  • I will compile it with gcc.
  • I don't want to analyze the static code. I want to trace the runtime. So doxygen will not make my life easier.
  • I have the source and I can compile it.
  • I don't want to use Aspect Oriented Programming.

编辑:
我发现gdb提示符中的frame命令打印当前帧名称,你可以说)在那个时间点。也许,有可能(使用gdb脚本)调用'frame'命令每次调用一个函数。

I found that 'frame' command in the gdb prompt prints the current frame (or, function name, you could say) at that point in time. Perhaps, it is possible (using gdb scripts) to call 'frame' command everytime a function is called. What do you think?

推荐答案

除了通常的调试器和面向方面的编程技术,你还可以注入自己的仪器函数gcc的 -finstrument- functions 命令行选项。您必须实现自己的 __ cyg_profile_func_enter() __ cyg_profile_func_exit()函数(声明为 externC在C ++中)。

Besides the usual debugger and aspect-oriented programming techniques, you can also inject your own instrumentation functions using gcc's -finstrument-functions command line options. You'll have to implement your own __cyg_profile_func_enter() and __cyg_profile_func_exit() functions (declare these as extern "C" in C++).

它们提供了一种跟踪从哪里调用函数的方法。然而,接口有点难以使用,因为例如,被调用的函数的地址及其调用位置被传递而不是函数名称。您可以记录地址,然后使用类似于 <$ c,从符号表中提取相应的名称$ c> objdump --syms nm ,假设符号尚未从相关二进制文件中删除。

They provide a means to track what function was called from where. However, the interface is a bit difficult to use since the address of the function being called and its call site are passed instead of a function name, for example. You could log the addresses, and then pull the corresponding names from the symbol table using something like objdump --syms or nm, assuming of course the symbols haven't been stripped from the binaries in question.

它可能只是更容易使用 gdb 。 YMMV。 :)

It may just be easier to use gdb. YMMV. :)

这篇关于自动添加输入/退出功能日志到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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