Function tracing

Ulrich Drepper drepper@redhat.com
Thu Apr 28 01:18:00 GMT 2005


Vara Prasad wrote:

> int max(int a, int b)
> {
>    if (a < b)
>       return b;
>    else
>       return a;
> }
> 
> What we cannot find out with return probes is, which of the the two
> possible return statements was executed.
> I would think this feature will be very useful for tracing the code
> path.

It is unrealistic to expect this to work.  The compile might not even
generate separate exit paths.  In fact, gcc in most cases will generate
just one ret opcode.  The above function, on x86-64, might be compiled as

  cmp    %esi,%edi
  cmovge %edi,%esi
  mov    %esi,%eax
  retq

If you would want instrumentation, you would have to explicitly replace
the return statement with something you can set a breakpoint on.  This
will never be accepted into the general kernel since it's a major
performance regression.

Simply finding all ret instructions in a function does not achieve
anything since different C return statements might use the same ret
instruction.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/systemtap/attachments/20050428/1b6083ca/attachment.sig>


More information about the Systemtap mailing list