How to get functions' local variables?

HeTak hetakcoder at gmail.com
Mon Aug 3 05:33:52 UTC 2015


Thank you for the answer, Mark :)

It sounds kinda tricky to do so.. but maybe I give it a try ;)

Cheerio
HeTak

On Sun, Aug 2, 2015 at 11:25 PM, Mark Johnston <markj at freebsd.org> wrote:

> On Sun, Aug 02, 2015 at 10:22:39AM +0430, HeTak wrote:
> > Hi there,
> >
> > My question is: How I can check a function's local varibales' value using
> > dtrace?
> >
> > I'm a newbie in using dtrace and it's a bit weird for me..I went through
> > manuals and so, but did not get that. :(
> >
> > What I could find out is that via args, I can get functions' input
> > arguments. But I could not find out how I can check the value of a
> variable
> > which is defined inside my goal function's scope. Isn't this feature
> > available in Dtrace?
>
> No, DTrace doesn't support that feature. It can be approximated for
> userland programs using the PID provider, since that lets you
> effectively place breakpoints on arbitrary instructions, and using
> curthread->td_intr_frame, you can retrieve the register set of the
> interrupted thread. So if you could map a source line number and local
> variable name to a function offset and register (or stack offset), you
> should be able to retrieve the variable's value. But as far as I know,
> nothing exists to do this automatically.
>
> I'm not sure how hard it would be to write a program to use DWARF info
> to generate a D script which can retrieve a local variable's value.
> Seems like an interesting experiment? :)
>
> -Mark
>


More information about the freebsd-dtrace mailing list