1 Star2 Stars3 Stars4 Stars5 Stars (还没有评分)
Loading...

DTrace tricks and tips (16) -利用“-F”选项显示函数调用关系

可以利用DTrace的“-F”选项显示函数之间的调用关系,这对分析代码来说是个绝对好用的工具。以下面脚本为例:

#!/usr/sbin/dtrace -Fs

pid$target:::entry,
pid$target:::return
{
}
syscall:::entry,
syscall:::return
/pid == $target/
{
}

运行脚本:

-bash-3.2# ./debug.d -p 2435
dtrace: script './debug.d' matched 14448 probes
CPU FUNCTION
 12  <= fork1
 12  <- __fork1
 12  -> continue_fork
 12    -> lmutex_lock
 12    <- lmutex_lock
 12    -> lmutex_unlock
 12    <- lmutex_unlock
 12  <- continue_fork
 12  -> __lwp_sigmask
 12    -> __systemcall
 12      => lwp_sigmask
 12      <= lwp_sigmask
 12    <- __systemcall
 12  <- __lwp_sigmask
......

可以看到进入函数时,会在函数名前打印“->”(如果是系统调用,符号为“=>”);离开函数时,会在函数名前打印“<-”(如果是系统调用,符号为“<=”)。
另外,可以看到__lwp_sigmask调用了__systemcall,而__systemcall又调用lwp_sigmask。函数调用关系一目了然。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.