程序执行的自动跟踪 [英] Automatic tracing of program execution

查看:265
本文介绍了程序执行的自动跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果我们能够使任何C或C ++应用程序跟踪。

I would like to know if we can enable tracing in any C or C++ application.

例如,用gcc的选项或一个小工具,我将启用跟踪,要么痕迹印在控制台或转储到一个文件中。

For example, with a gcc option or a small tool, I will enable trace and either trace is printed on console or dumped to a file.

由于有大量的文件和功能/班,我不希望启动手动添加跟踪打印。

Since there are lots of files and function / classes, I don't want to start adding the trace prints manually.

如果这样的工具都没有,下一个选择是使用脚本,并尝试在跟踪印刷补充。

If such tools are not available, next choice is use scripting and try to add at the trace printing.

strace的,因为它主要是给系统调用是不是很多有用的。

strace is not much useful as it gives mainly the system calls.

推荐答案

要跟踪函数入口/出口,就可以重新编译code与选项<一个href=\"http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/$c$c-Gen-Options.html#index-finstrument_002dfunctions-1976\"><$c$c>-finstrument-functions这样每次调用函数的时候,一个 __ cyg_profile_func_enter()函数被调用,而 __ cyg_profile_func_exit()被调用的时候该函数返回。

To trace the function entry/exit, you can recompile your code with the option -finstrument-functions so that each time a function is invoked, a __cyg_profile_func_enter() function is called, and __cyg_profile_func_exit() is called when the function returns.

您可以实现这些功能,以跟踪上被调用函数的地址,并使用纳米转换地址为函数名。

You can implement those functions to trace the addresses on the called functions, and them use nm to convert the addresses into function names.

修改 etrace 做这一切:它提供了源$ C ​​$ C为 __ cyg_profile_func_enter() __ cyg_profile_func_exit()和写地址命名管道和Perl和Python脚本功能读取的地址和函数名和缩进做实际的跟踪。

EDIT: etrace does all this: it provides the source code for the __cyg_profile_func_enter() and __cyg_profile_func_exit() and functions that write the addresses to a named pipe and a Perl and a Python script to read the addresses and do the actual tracing with the function names and indentation.

这篇关于程序执行的自动跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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