美文网首页
stap探测程序的执行流程

stap探测程序的执行流程

作者: pandazhong | 来源:发表于2018-10-16 20:00 被阅读0次

    用stap来查看程序的执行流程:

    代码编写如下:

    #include <stdio.h>

    int testA()

    {

            int a = 10;

            return a;

    }

    int testB()

    {

            return 5+testA();

    }

    int main()

    {

            int a = testB();

            printf("a=%d\n", a);

            return 0;

    }

    编写查看程序执行流程的stp文件:

    probe process("./func").function("*").call {

            printf("%s -> %s\n", thread_indent(4),ppfunc())

    }

    probe process("./func").function("*").return {

            printf("%s <- %s\n", thread_indent(-4), ppfunc())

    }

    其中thread_indent(4)是用来控制缩进,ppfunc()是用来获取当前函数名称,注意,ppfunc()如果获取的是C++的函数名,则函数名会被截断,如果要获取完整函数名称,则要调用probefunc()函数。

    执行程序: stap -c ./func traceback.stp

    输入如下:

    相关文章

      网友评论

          本文标题:stap探测程序的执行流程

          本文链接:https://www.haomeiwen.com/subject/vndhzftx.html