如何告诉GCC仪器的code。与调用我自己的函数code的每个_LINE_? [英] How to tell gcc to instrument the code with calls to my own function each _line_ of code?

查看:151
本文介绍了如何告诉GCC仪器的code。与调用我自己的函数code的每个_LINE_?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,存在的来源:

void my_special_debugging_function(const char* function_name, const char* file_name, int line_number);

void func1() {
    func3();
    func4();
}

void foo() {
    func1();
    if(qqq) {
        func2();
    };
    func3();
    func4();
    for(...) {
        func5();
    }
}

这应该编译:

void my_special_debugging_function(const char* function_name, const char* file_name, int line_number);

void func1() {
    my_special_debugging_function("func1", "prog.c", 3);
    func3();
    my_special_debugging_function("func1", "prog.c", 4);
    func4();
    my_special_debugging_function("func1", "prog.c", 5);
}

void foo() {
    my_special_debugging_function("foo", "prog.c", 8);
    func1();
    my_special_debugging_function("foo", "prog.c", 9);
    if(qqq) {
        my_special_debugging_function("foo", "prog.c", 10);
        func2();
        my_special_debugging_function("foo", "prog.c", 11);
    };
    my_special_debugging_function("foo", "prog.c", 12);
    func3();
    my_special_debugging_function("foo", "prog.c", 13);
    func4();
    my_special_debugging_function("foo", "prog.c", 14);
    for(...) {
        my_special_debugging_function("foo", "prog.c", 15);
        func5();
        my_special_debugging_function("foo", "prog.c", 16);
    }
    my_special_debugging_function("foo", "prog.c", 17);
}

当然,my_special_debugging_function应该可以使用回溯功能。

有GCC的选项呢?或者是有在烃源$ C ​​$ C级做的工具吗? (例如生成与我的功能,其他的C源集)

Is there option of gcc to do it? Or is there a tool to do it at souce code level? (e.g. generate other C souce with my function)

@related http://stackoverflow.com/questions/3989992/how-to-interleave-c-c-souce-with-my-string-only-inside-functions-at-appropri

@related http://stackoverflow.com/questions/3992587/what-profiler-should-i-use-to-measure-real-time-including-waiting-for-syscalls

推荐答案

请参阅 -finstrument函数 GCC的文档中获得。您可能需要使用提供dladdr()中的调试功能,也可能需要使用 -Wl,-export动态

See -finstrument-functions in the GCC documentation. You may want to use dladdr() in the debugging function, which may also require linking with -Wl,-export-dynamic.

这篇关于如何告诉GCC仪器的code。与调用我自己的函数code的每个_LINE_?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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