Probes not firing #1

Closed
sartak opened this Issue Aug 18, 2012 · 2 comments

Comments

Projects
None yet
1 participant
Contributor

sartak commented Aug 18, 2012

Hi Chris,

Today I've been looking into getting the libusdt implementation of this module working, but for some reason probes aren't registering or firing correctly. Here's what I've been seeing. I'm starting with the synopsis of Devel::DTrace::Provider:

use Devel::DTrace::Provider;
my $provider = Devel::DTrace::Provider->new('provider1', 'perl');
my $probe = $provider->probe('probe1', 'string');
$probe->fire('foo');

I stick this into a file and it warns:

Probe takes 0 arguments, 1 provided at test.pl line 6.

OK, so something isn't registering correctly. I'll deal with probe arguments later. Removed the 'foo', argument to $probe->fire. The Perl script runs cleanly, but when I try to investigate that user-space probe with DTrace:

sudo dtrace -Zn '*provider1*:::, *provider1*::, *provider1*:, *provider1* { }'
dtrace: description '*provider1*:::, *provider1*::, *provider1*:, *provider1* ' matched 0 probes
^C

I run the test script again but DTrace doesn't catch any probe firings. All right, time to bust out.... DTrace.

> sudo dtrace -Zn 'pid4076::usdt*:entry, pid4076::usdt*:return {}'
dtrace: description 'pid4076::usdt*:entry, pid4076::usdt*:return ' matched 60 probes
CPU     ID                    FUNCTION:NAME
  1   3652       usdt_create_provider:entry 
  1   6064      usdt_create_provider:return 
  1   3653          usdt_create_probe:entry 
  1   6065         usdt_create_probe:return 
  1   3654    usdt_provider_add_probe:entry 
  1   6066   usdt_provider_add_probe:return 
  1   3660            usdt_fire_probe:entry 
  1   6071           usdt_fire_probe:return 

So it looks like it's calling all the right libusdt functions. Looking into usdt_fire_probe, ...

void
usdt_fire_probe(usdt_probe_t *probe, size_t argc, void **nargv)
{
        if (probe != NULL)
                usdt_probe_args(probe->probe_addr, argc, nargv);
}

Fair enough, but usdt_probe_args is the assembly magic to do the real work, and I don't know know how to trace that. Trying to pull everything out with the pid provider is not the way to do it apparently:

sudo dtrace -Zn 'pid4351::usdt_fire_probe:entry { this->interesting = 1 } pid4351::usdt_fire_probe:return { this->interesting = 0; trace(arg1) } pid4351::: /this->interesting/ {}'
dtrace: description 'pid4351::usdt_fire_probe:entry ' matched 850096 probes
CPU     ID                    FUNCTION:NAME
  0  32355            usdt_fire_probe:entry 
  0  32356           usdt_fire_probe:return   140387184326672

Using a trick to follow that probe->probe_addr pointer (from https://blogs.oracle.com/peteh/entry/dereferencing_user_space_pointers_in )

sudo dtrace -Zn 'pid4380::usdt_fire_probe:entry { } pid4380::usdt_fire_probe:return { self->arg1 = arg1; self->probe_addr = *(uint32_t *)copyin(self->arg1, 4); printf("probe_addr %#p", self->probe_addr) } '
dtrace: description 'pid4380::usdt_fire_probe:entry ' matched 2 probes
CPU     ID                    FUNCTION:NAME
  0 222335            usdt_fire_probe:entry 
  0 222336           usdt_fire_probe:return probe_addr 0x3140a7e0

So probe->probe_addr looks legitimate as well, but I don't know how to proceed from here.

Any ideas?

Contributor

sartak commented Aug 18, 2012

I fixed the problems and made a pull request for you. :)

@sartak sartak closed this Aug 18, 2012

Contributor

sartak commented Aug 19, 2012

Realized while trying to fall asleep that I wasn't getting the output I was expected, and I remembered that I keep confusing self-> and this->.

sudo dtrace -Zn 'pid$target::usdt_fire_probe:entry { self->interesting = 1 } pid$target::usdt_fire_probe:return { self->interesting = 0; trace(arg1) } pid$target::: /self->interesting/ { trace("...") }' -p 8081
dtrace: description 'pid$target::usdt_fire_probe:entry ' matched 836581 probes
dtrace: pid 8081 has exited
CPU     ID                    FUNCTION:NAME
  1  14214            usdt_fire_probe:entry   ...                              
  1 1046082                usdt_fire_probe:1   ...                              
  1 1046083                usdt_fire_probe:4   ...                              
  1 1046084                usdt_fire_probe:7   ...                              
  1 1046085                usdt_fire_probe:9   ...                              
  1 1046086                usdt_fire_probe:a   ...                              
  1  14215           usdt_fire_probe:return                 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment