DTrace - How do I correctly retrieve initial parameters in the return probe

StackOverflow https://stackoverflow.com/questions/11583072

  •  22-06-2021
  •  | 
  •  

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.

有帮助吗?

解决方案

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;
}

其他提示

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top