jas
jas

Reputation: 49

How to trace a function using dtrace?

I was making a few changes in the dhcpagent command and on testing, it sort of fails. Now I know which function is being called in the end before dhcpagent exits. I want to trace the control from dhcpagent to that particular function lets say foo().I am looking for who called foo() and who called that function and so on, like a family tree, from dhcpagent to foo(). How do I do this ? I have very basic knowledge of dtrace, like how to construct a basic script, but no more. Could you suggest a script/resource from where I can learn and write the script myself ?

What I did try:

pid$target::functionname:entry  //and the target was dhcpagent from the command line

Thanks

Upvotes: 2

Views: 467

Answers (1)

Nan Xiao
Nan Xiao

Reputation: 17467

I think the following script can help you:

#!/usr/sbin/dtrace -Fs
pid$target:::entry,  
pid$target:::return
{
}

In the above script, it can print how the function is called. But the output maybe awesome large!
If you only cared about dhcpagent module, I think the following script is a better choice:

#!/usr/sbin/dtrace -Fs
pid$target:dhcpagent::entry,  
pid$target:dhcpagent::return
{
}

Upvotes: 2

Related Questions