public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Jim Keniston <jkenisto@us.ibm.com>
To: "Stone, Joshua I" <joshua.i.stone@intel.com>
Cc: systemtap@sourceware.org
Subject: Re: function probe oddities
Date: Tue, 11 Jul 2006 22:53:00 -0000	[thread overview]
Message-ID: <1152658407.2740.100.camel@dyn9047018079.beaverton.ibm.com> (raw)
In-Reply-To: <C56DB814FAA30B418C75310AC4BB279D3C5084@scsmsx413.amr.corp.intel.com>

On Tue, 2006-07-11 at 14:52, Stone, Joshua I wrote:
> I've recently noticed that it's possible to have function probe that
> don't behave quite like one would expect.  The problem is when you have
> a loop at the very beginning of a function, such that there aren't any
> prior instructions that aren't part of the loop.  You then get a probe
> that fires on every iteration of the loop, instead of only at the
> entrance to the function as desired.
> 
> Consider this trivial example:
> 
> void simple()
> {
>     do
>         work();
>     while (test());
> }
> 
> 00000000 <simple>:
>    0:   e8 0a 00 00 00          call   f <work>
>    5:   e8 06 00 00 00          call   10 <test>
>    a:   85 c0                   test   %eax,%eax
>    c:   75 f2                   jne    0 <simple>
>    e:   c3                      ret
> 

So weird, yet so innocent.  (The problem, not Josh. :-))

> 
> There isn't anywhere that you could place a probe that will only fire at
> the beginning of the function!  This kind of thing is probably a rare
> occurrence, but I have seen it in real code.  I'm not sure that we can
> do anything about it, but this limitation should at least be noted.

Yes, a patch to Documentation/kprobes.txt is warranted.  I'll do it when
I get back from vacation, if nobody beats me to it.

> 
> Also affected are kretprobes, which may end up registering the kretprobe
> instance many times.

Yes, indeed.

> 
> On a related note, I have noticed that function() and function().return
> probes are not always placed at the same address.  I would guess that
> this is because the former needs to be after the prologue, but the
> latter doesn't care about the prologue.

Kretprobes wants kp.addr to be the first instruction of the function, so
it can be sure of where to find the return address (as specified by the
ABI).  There's actually no reason you couldn't specify a later
instruction, so long as the return address is still where kretprobes
looks for it.  That wouldn't help in this case, though.

> However, since two aggregate
> probes would be faster than taking two consecutive debug traps, it would
> be nice if these used the same address.

Nice, but not a big concern.

> My 'real-world' scenario that triggered this investigation had a
> function with a small prologue followed immediately by a loop body.  I
> was trying to trace the call sequence using thread_indent().  I ended up
> with what looked like a whole lot of function entrances with only one
> function exit.  It turns out that the call-probe (post-prologue) was
> firing every time through the loop, but the return-probe (pre-prologue)
> only fired once.
> 
> Given that we may not be able to fix the looping problem, I think I
> would prefer that the return probes carried the same weird behavior.  If
> the return probe used the same address as the call probe, then at least
> I could get a 1:1 mapping between call/return probes...

As previously mentioned, adjusting kretprobes would be problematic.

The gcc folks may come to our rescue, though -- e.g., by helping
SystemTap notice such situations.  Back when SystemTap was having
trouble locating the end of the prologue for some functions, I suggested
training SystemTap in each architecture's ABI, so it could find the args
right at function entry.  The preferred solution, as I recall, was to
enhance the dwarf info.

It's an interesting problem, all right.

> 
> 
> Josh

Jim

  reply	other threads:[~2006-07-11 22:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-11 21:52 Stone, Joshua I
2006-07-11 22:53 ` Jim Keniston [this message]
2006-07-12  0:31 ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1152658407.2740.100.camel@dyn9047018079.beaverton.ibm.com \
    --to=jkenisto@us.ibm.com \
    --cc=joshua.i.stone@intel.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).