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

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

问题描述

我有一个第三方源$ C ​​$ C,我要调查。我希望看到什么样的顺序函数调用,但我不想浪费我的时间打字:

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编译。

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

  • 我有来源,我可以编译它。

  • 我不希望使用面向方面的编程。

编辑:
我发现,在gdb提示框命令打印当前帧(或函数名,你可以说)在那个时间点。也许,这是可能的(用gdb脚本)来调用框架命令每次一个函数被调用。你觉得呢?

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的<一个href=\"http://gcc.gnu.org/onlinedocs/gcc/$c$c-Gen-Options.html#index-finstrument_002dfunctions-2112\"><$c$c>-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++).

它们提供跟踪什么功能是从那里称为一种手段。然而,界面有点困难,因为使用该函数的地址,被称为其调用点传递,而不是函数名称,例如。你可以登录地址,然后使用类似 从符号表拉对应名称objdump的 - SYMS 纳米 < /一>,假定当然符号没有从所讨论的二进制剥离

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 。情况因人而异。 :)

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

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

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