|
From: <Nic...@cs...> - 2003-12-09 23:03:46
|
Hi,
Sorry if this is a repost - webmail was screwing up for me.
I've been trying to get a valgrind skin i'm tinkering with to get a program to report whenever it calls or returns from a function. However, I'm getting some really wierd data. This is the instrumentation:
UCodeBlock* SK_(instrument)(UCodeBlock* cb, Addr a){
UCodeBlock *newCb;
Int i;
UInstr* u;
newCb=VG_(setup_UCodeBlock)(cb);
if (VG_(get_fnname_if_entry)(a, name, 100)){
if (VG_(get_filename_linenum)(a, file, 100,&line)){
VG_(call_helper_0_0)(newCb, (Addr) & printNameAndInfo);
}else {
VG_(call_helper_0_0)(newCb, (Addr) & printName);
}
}
for (i = 0; i < VG_(get_num_instrs)(cb); i++) {
u = VG_(get_instr)(cb, i);
if (((u->opcode) == JMP) &&
((u->jmpkind)==JmpRet) )
{
VG_(get_fnname)(a, name, 100); // hopefully always works?
VG_(call_helper_0_0)(newCb, (Addr) &printRet);
}
if (((u->opcode) == JMP) &&
((u->jmpkind)==JmpCall) )
{
VG_(get_fnname)(a, name, 100); // hopefully always works?
VG_(call_helper_0_0)(newCb, (Addr) &printCall);
}
VG_(copy_UInstr)(newCb, u);
}
VG_(free_UCodeBlock)(cb);
return newCb;
}
For the following program:
int main(int argc, char **argv){
a();
b();
return 0;
}
void a(){
printf("in a\n");
};
int b(){
printf("in b\n");
return 1;
};
we start with
CALL from __libc_start_main
main @ a.c LINE 6
CALL from main
a @ a.c LINE 13
Which is good. All execution inside the program seems to be fine
as long as no library functions are called ;) However, a() calls a library
function, and I get told:
CALL from a
CALL from a
CALL from a
RET from a
CALL from a
a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
CALL from a
RET from a
RET from a
RET from a
RET from a
RET from a
_IO_printf
CALL from _IO_printf
...
And then a whole load of stuff inside libc, which I can't easily verify as
correct or incorrect atm.
I just tried this again and setting LD_BIND_NOW=1 seems to cause the
calling of a() to behave as expected, and a lot of other junk to
disappear, but b() is still the same. (loads of "CALL" and "RET"
statements spewed out saying that they're at the address of the entry
point of the function, according to the %eip as reported by valgrind)
Am I misunderstanding something about UCode or what? I'm sure this is a solved problem, since I imagine every single skin would depend on the behavior that I am hoping for (one call of the instrumentation code for every call/ret).
Thanks a million,
Nick
|