在函數(shù)返回處下的探針可以獲取到程序的返回值舞虱。
C++代碼如下:
#include<stdio.h>
#include<string>
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獲取傳入的參數(shù)借嗽,$$return獲取返回值
執(zhí)行探針:
stap -c ./test test.stp
執(zhí)行結果如下: