|
From: Josef W. <Jos...@gm...> - 2010-09-17 06:23:45
|
On Friday 17 September 2010, Scott Pakin wrote:
> How can my instrumentation code reliably detect function calls?
If there is debug information available for the functions you want
to catch, it should be enough to ask VG core for every guest instruction
whether this is the first instruction of a function with
VG_(get_fnname_if_entry).
You could argue that you do not want to interpret a jump to a first
instruction of a function as a call (which above would do). However,
such a case is ambigous anyway: it could have been a call, converted
to a jump due to tail recursion optimization by the compiler.
> I had thought I could look for an Ijk_Call JumpKind in either an
> Ist_Exit statement or in the IRSB's jumpkind, but those don't seem to
> catch everything. The particular code I want to catch is the
> following (amd64-linux):
>
> 0x4004CD: call 0x4004DC
>
> ------ IMark(0x4004CD, 5) ------
> PUT(168) = 0x4004CD:I64
> t2 = Sub64(GET:I64(32),0x8:I64)
> PUT(32) = t2
> STle(t2) = 0x4004D2:I64
> t3 = 0x4004DC:I64
> ====== AbiHint(Sub64(t2,0x80:I64), 128, t3) ======
>
> 0x4004DC: pushq %rbp
>
> ------ IMark(0x4004DC, 1) ------
> PUT(168) = 0x4004DC:I64
> t4 = GET:I64(40)
> t5 = Sub64(GET:I64(32),0x8:I64)
> PUT(32) = t5
> STle(t5) = t4
>
> I, for one, don't see anything in the call statement's IR that
> indicates that control is being transferred as the result of a
> function call.
Yes. VG does not keep the jump kind information when chasing over
function calls (that would make up a good wish item "bug" report).
However, you can switch off chasing with
VG_(clo_vex_control).guest_chase_thresh = 0;
and then, above issue does not happen.
However, you should keep in mind that the jumpkind info by VEX
is a heuristic, which only is quite good on x86/x86-64.
For PPC this is unreliable, as PPC does not have explicit CALL
instructions, but does use specific branch instruction, able to
store a return address in a (link) register, and jump to the
address stored in that register. However, it is not clear that
the latter is always a return...
Josef
>
> Thanks,
> -- Scott
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________
> Valgrind-developers mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-developers
>
|