stap探测程序的传入参数和返回值

在函数返回处下的探针可以获取到程序的返回值。

C++代码如下:

#include

#include

using namespace std;

int testB()

{

        return 10;

}

char *testA(int a)

{

        int b = a + 10;

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

        string result = "hello,world";

        return (char *)result.c_str();

}

int main()

{

        char *p = testA(2);

        printf("%s    %d\n",p, testB());

        return 0;

}

编写stp文件如下:

probe process("./test").function("testA").return {

        printf("arg:%s    ret:%s\n",$$parms, $$return$)

}

probe process("./test").function("testB").return {

        printf("arg:%s    ret:%s\n",$$parms, $$return$)

}

其中,$$parms获取传入的参数,$$return获取返回值

执行探针:

stap -c ./test test.stp

执行结果如下:


你可能感兴趣的:(stap探测程序的传入参数和返回值)