问题描述
我试图使用intel pin获取函数的参数的值。使用示例ManualExamples / malloctrace.cpp,单个参数函数足够简单。然而,当我尝试获得参数值与多个参数我遇到麻烦。
I'm trying to obtain the values of the arguments to a function using intel pin. Single argument functions are simple enough using the example ManualExamples/malloctrace.cpp . However, when I try to get the argument values with multiple arguments I run into trouble.
例如。尝试捕获以下函数的参数值:
Eg. Trying to capture the argument values of the following function:
void funcA(int a, int b, int c) {
printf("Actual: %i %i %i\n", a,b,c);
}
使用以下PIN代码
VOID funcHandler(CHAR* name, int a, int b, int c) {
printf("Pin: %s %i %i %i\n", name, a, b, c);
}
VOID Image(IMG img, VOID *v) {
RTN funcRtn = RTN_FindByName(img, "funcA");
if (RTN_Valid(funcRtn)) {
RTN_Open(funcRtn);
RTN_InsertCall(funcRtn, IPOINT_BEFORE, (AFUNPTR)funcHandler,
IARG_ADDRINT, "funcA", IARG_FUNCARG_ENTRYPOINT_VALUE,
0, IARG_END);
RTN_Close(funcRtn);
}
}
我得到以下输出
Pin: funcA 0 -656937200 -10
Actual: 0 -10 0
Pin: funcA 1 -656937200 -9
Actual: 1 -9 20
Pin: funcA 2 -656937200 -8
Actual: 2 -8 40
我可以看到我很接近,但有些东西没有正确对齐。我知道关于RTN_ReplaceProbed,但我需要使用pin在jit模式,因为我需要指令级仪器。
I can see that I'm close, but something isn't aligned properly. I know about RTN_ReplaceProbed, but I need to use pin in jit mode as I need instruction level instrumentation.
推荐答案
我认为这实际上是一个非常简单的人去修补,因为你已经基本上得到的一切权利开始。
I think it's actually a pretty easy one to fix, since you've basically got everything right to begin with.
唯一的问题是,调用RTN_InsertCall的时候,你只能提取的第一个参数(这就是为什么脚和实际是第一个参数相同,但没有其他人)。您只需给几个参数RTN_InsertCall使funcHandler得到它所需要的所有参数。
The only problem is that when calling RTN_InsertCall, you only extract the first argument (which is why Pin and Actual are the same for the first argument but not the others). You simply need to give a few more arguments to RTN_InsertCall so that funcHandler gets all the arguments it needs.
因此,代替
RTN_InsertCall(funcRtn, IPOINT_BEFORE, (AFUNPTR)funcHandler,
IARG_ADDRINT, "funcA", IARG_FUNCARG_ENTRYPOINT_VALUE,
0, IARG_END);
只需执行
RTN_InsertCall(funcRtn, IPOINT_BEFORE, (AFUNPTR)funcHandler,
IARG_ADDRINT, "funcA", IARG_FUNCARG_ENTRYPOINT_VALUE,
0, IARG_FUNCARG_ENTRYPOINT_VALUE, 1,
IARG_FUNCARG_ENTRYPOINT_VALUE, 2, IARG_END);
我所做的只是添加一对夫妇IARG_FUNCARG_ENTRYPOINT_VALUE 1和2获得第1和第2个参数,之后,你已经拿到了0号参数。
All I did was add a couple more IARG_FUNCARG_ENTRYPOINT_VALUE with 1 and 2 to get the 1st and 2nd arguments, after you already got the 0th argument.
我目前没有在那里我有引脚设置进行测试,但如果它不工作让我知道在机器上。
I'm currently not on the machine where I have Pin set up to test, but if it doesn't work let me know.
这篇关于intel pin RTN_InsertCall多个函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!