Question

I'm trying to read the initial arguments that was passed into the function in my return probe. Unlike the entry probe, the argument variables(arg0,arg1,...) in the return probe do not contain the initial parameters, and I'm not sure how I would be able to retrieve those values.

Also, I would like to avoid storing the values in global variables because of the concurrency issues.

Was it helpful?

Solution

You can save the parameters in thread-local storage, e.g.

pid$target:foo:bar:entry
{
    self->arg0 = arg0;
    self->arg1 = arg1;
    /*
     * Avoid the race in which dtrace(1) attaches to the victim during
     * the window between the two probes.
     */
    self->trace = 1;
}

pid$target:foo:bar:return
/self->trace/
{
    printf("arg0 = 0x%x, arg1 = 0x%x\n", self->arg0, self->arg1);
    /* Deallocate the thread-local storage. */
    self->arg0 = 0;
    self->arg1 = 0;
}

OTHER TIPS

As rmh answered - using local variables is the way to do it. Otherwise, dtrace would have to save the values for you on entry - and it doesnt know anything about the incoming arguments or your expectations, and would have to garbage collect. (Technically, it does know whats going to happen - eventually - but that would add complex overhead vs the local variables approach which is mapped to a simple set of virtual D instructions).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top