「truss」の版間の差分

提供: FreeBSD入門
移動: 案内検索
(ページの作成:「<!-- vim: fileencoding=utf-8 filetype=mediawiki --> [[{{PAGENAME}}]] とは、システムコールをトレースします。 '''読み方''' ;[[{{PAGENAME}}]]:...」)
 
行31: 行31:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
% truss /bin/echo hello
 
% truss /bin/echo hello
 +
</syntaxhighlight>
 +
 +
 +
<syntaxhighlight lang="bash">
 +
% truss /bin/echo hello
 +
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366255104 (0x800637000)
 +
issetugid(0x800638015,0x80062cd7e,0x8008487f0,0x8008487c0,0xb297,0x0) = 0 (0x0)
 +
open("/etc/libmap.conf",O_RDONLY,0666)          ERR#2 'No such file or directory'
 +
open("/var/run/ld-elf.so.hints",O_RDONLY,057)    = 3 (0x3)
 +
read(3,"Ehnt\^A\0\0\0\M^@\0\0\0U\^A\0\0"...,128) = 128 (0x80)
 +
lseek(3,0x80,SEEK_SET)                          = 128 (0x80)
 +
read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,341) = 341 (0x155)
 +
close(3)                                        = 0 (0x0)
 +
access("/lib/libc.so.7",0)                      = 0 (0x0)
 +
open("/lib/libc.so.7",O_RDONLY,040737540)        = 3 (0x3)
 +
fstat(3,{ mode=-r--r--r-- ,inode=49544,size=1315160,blksize=32768 }) = 0 (0x0)
 +
pread(0x3,0x80083af40,0x1000,0x0,0x101010101010101,0x8080808080808080) = 4096 (0x1000)
 +
mmap(0x0,3432448,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) = 34368425984 (0x800849000)
 +
mmap(0x800849000,1179648,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,3,0x0) = 34368425984 (0x800849000)
 +
mmap(0x800b69000,45056,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,3,0x120000) = 34371702784 (0x800b69000)
 +
mmap(0x800b74000,110592,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34371747840 (0x800b74000)
 +
close(3)                                        = 0 (0x0)
 +
mmap(0x0,102400,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366287872 (0x80063f000)
 +
sysarch(0x81,0x7fffffffcc90,0x80063d088,0x0,0xffffffffffad0580,0x8080808080808080) = 0 (0x0)
 +
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
 +
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
 +
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
 +
sigprocmask(SIG_SETMASK,0x0,0x0)                = 0 (0x0)
 +
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
 +
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
 +
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
 +
sigprocmask(SIG_SETMASK,0x0,0x0)                = 0 (0x0)
 +
readlink("/etc/malloc.conf",0x7fffffffcef0,1024) ERR#2 'No such file or directory'
 +
issetugid(0x800945bc1,0x7fffffffcef0,0xffffffffffffffff,0x0,0x2,0x2) = 0 (0x0)
 +
break(0x800000)                                  = 0 (0x0)
 +
mmap(0x0,4194304,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34371858432 (0x800b8f000)
 +
mmap(0x800f8f000,462848,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34376052736 (0x800f8f000)
 +
munmap(0x800b8f000,462848)                      = 0 (0x0)
 +
hello
 +
writev(0x1,0x800c07040,0x2,0x7fffffffd818,0x600d10,0x7fffffffca30) = 6 (0x6)
 +
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
 +
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
 +
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
 +
sigprocmask(SIG_SETMASK,0x0,0x0)                = 0 (0x0)
 +
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
 +
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
 +
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
 +
sigprocmask(SIG_SETMASK,0x0,0x0)                = 0 (0x0)
 +
process exit, rval = 0
 
</syntaxhighlight>
 
</syntaxhighlight>
  

2013年6月5日 (水) 22:38時点における版


truss とは、システムコールをトレースします。

読み方

truss
とらす

概要

truss とは、システムコールをトレースします。

truss ユーテリティは、指定されたプロセス、もしくは、プログラムのシステムコールの呼び出しをトレースします。 出力は、指定された出力ファイルか、デフォルトでは、標準エラーに出力されます。ptrace を通して、モニタリングされます。

インストール

コマンドラインオプション

usage: truss [-cfaedDS] [-o file] [-s strsize] -p pid
       truss [-cfaedDS] [-o file] [-s strsize] command [args]

使い方

echo hello を実行して、システムコールの呼び出しをトレースします。

% truss /bin/echo hello


% truss /bin/echo hello
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366255104 (0x800637000)
issetugid(0x800638015,0x80062cd7e,0x8008487f0,0x8008487c0,0xb297,0x0) = 0 (0x0)
open("/etc/libmap.conf",O_RDONLY,0666)           ERR#2 'No such file or directory'
open("/var/run/ld-elf.so.hints",O_RDONLY,057)    = 3 (0x3)
read(3,"Ehnt\^A\0\0\0\M^@\0\0\0U\^A\0\0"...,128) = 128 (0x80)
lseek(3,0x80,SEEK_SET)                           = 128 (0x80)
read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,341) = 341 (0x155)
close(3)                                         = 0 (0x0)
access("/lib/libc.so.7",0)                       = 0 (0x0)
open("/lib/libc.so.7",O_RDONLY,040737540)        = 3 (0x3)
fstat(3,{ mode=-r--r--r-- ,inode=49544,size=1315160,blksize=32768 }) = 0 (0x0)
pread(0x3,0x80083af40,0x1000,0x0,0x101010101010101,0x8080808080808080) = 4096 (0x1000)
mmap(0x0,3432448,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) = 34368425984 (0x800849000)
mmap(0x800849000,1179648,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,3,0x0) = 34368425984 (0x800849000)
mmap(0x800b69000,45056,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,3,0x120000) = 34371702784 (0x800b69000)
mmap(0x800b74000,110592,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 34371747840 (0x800b74000)
close(3)                                         = 0 (0x0)
mmap(0x0,102400,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366287872 (0x80063f000)
sysarch(0x81,0x7fffffffcc90,0x80063d088,0x0,0xffffffffffad0580,0x8080808080808080) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
readlink("/etc/malloc.conf",0x7fffffffcef0,1024) ERR#2 'No such file or directory'
issetugid(0x800945bc1,0x7fffffffcef0,0xffffffffffffffff,0x0,0x2,0x2) = 0 (0x0)
break(0x800000)                                  = 0 (0x0)
mmap(0x0,4194304,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34371858432 (0x800b8f000)
mmap(0x800f8f000,462848,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34376052736 (0x800f8f000)
munmap(0x800b8f000,462848)                       = 0 (0x0)
hello
writev(0x1,0x800c07040,0x2,0x7fffffffd818,0x600d10,0x7fffffffca30) = 6 (0x6)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|
SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|
SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
process exit, rval = 0

呼び出し回数や呼び出し時間のサマリを表示します。

% truss -S -c /bin/echo hello
hello
syscall                     seconds   calls  errors
readlink                0.000009778       1       1
lseek                   0.000007333       1       0
mmap                    0.000073822       8       0
open                    0.000035689       3       1
close                   0.000016134       2       0
fstat                   0.000012222       1       0
break                   0.000008311       1       0
access                  0.000010267       1       0
sigprocmask             0.000074800       8       0
munmap                  0.000008800       1       0
read                    0.000036666       2       0
                      ------------- ------- -------
                        0.000293822      29       2

出力を /tmp/truss.out にします。

truss -o /tmp/truss.out /bin/echo hello

すでに実行されているプロセス(プロセスID 123) をトレースします。

truss -p 123

関連項目