BlogBlog ÜbersichtjailscriptportsoptFreeBSDLinksThermoskanne

Aufgerufene Systemcalls eines Programms aufzeichen

Möchte man die Systemcalls aufzeichnen, welche von einem Programm aufgerufen werden, so kann man dazu truss verwenden. Damit truss eingesetzt werden kann, muss zuerst das procfs Dateisystem gemountet werden:

# mount_procfs procfs /proc

Ohne Optionen schickt truss die Ausgabe auf die Standard-Error-Ausgabe:

# truss <Befehl>

Durch das Verwenden der -d Option wird vor jedem Systemcall die Zeit angezeigt, die seit dem Aufrufen des Befehls vergangen ist, bis der Systemcall ausgeführt wurde. In folgendem Beispiel werden alle Systemcalls auf die Standard-Error Ausgabe ausgegeben, welche durch den sleep Befehl aufgerufen werden:

# truss -d sleep 1
0.000136889 mmap(0x0,3904,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 671559680 (0x28073000)
0.000414299 munmap(0x28073000,3904) = 0 (0x0)
0.000603429 __sysctl(0xbfbfe9f8,0x2,0x2806f738,0xbfbfe9f4,0x0,0x0) = 0 (0x0)
0.000799264 mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 671559680 (0x28073000)
0.000998731 issetugid() = 0 (0x0)
0.001246248 open("/etc/libmap.conf",O_RDONLY,0666) = 3 (0x3)
0.001419175 fstat(3,{mode=-r--r--r-- ,inode=49501,size=3055,blksize=4096}) = 0 (0x0)
0.001612775 read(3,"# /etc/libmap.conf for FreeBSD 6"...,4096) = 3055 (0xbef)
0.001860572 read(3,0x28077000,4096) = 0 (0x0)
0.002042159 close(3) = 0 (0x0)
0.002239391 open("/var/run/ld-elf.so.hints",O_RDONLY,00) = 3 (0x3)
0.002414274 read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\M-+\0\0"...,128) = 128 (0x80)
0.002610388 lseek(3,0x80,SEEK_SET) = 128 (0x80)
0.002782477 read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,171) = 171 (0xab)
0.002967975 close(3) = 0 (0x0)
0.003166045 access("/lib/libc.so.6",0) = 0 (0x0)
0.003359087 open("/lib/libc.so.6",O_RDONLY,00) = 3 (0x3)
0.003532572 fstat(3,{mode=-r--r--r-- ,inode=16469,size=906276,blksize=4096}) = 0 (0x0)
0.003716395 read(3,"\^?ELF\^A\^A\^A\t\0\0\0\0\0\0\0"...,4096) = 4096 (0x1000)
0.003923404 mmap(0x0,925696,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_NOCORE,3,0x0) = 671592448 (0x2807b000)
0.004118680 mprotect(0x28140000,4096,PROT_READ|PROT_WRITE|PROT_EXEC) = 0 (0x0)
0.004304179 mprotect(0x28140000,4096,PROT_READ|PROT_EXEC) = 0 (0x0)
0.004487442 mmap(0x28141000,24576,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,3,0xc5000) = 672403456 (0x28141000)
0.004695290 mmap(0x28147000,90112,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_ANON,-1,0x0) = 672428032 (0x28147000)
0.004889169 close(3) = 0 (0x0)
0.005069080 mmap(0x0,36864,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 672518144 (0x2815d000)
0.005328890 sysarch(0xa,0xbfbfeb80) = 0 (0x0)
0.005506008 mmap(0x0,176,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 672555008 (0x28166000)
0.005712738 munmap(0x28166000,176) = 0 (0x0)
0.005887341 mmap(0x0,22384,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 672555008 (0x28166000)
0.006272585 munmap(0x28166000,22384) = 0 (0x0)
0.006495519 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)
0.006731862 sigprocmask(SIG_SETMASK,0x0,0x0) = 0 (0x0)
1.006956751 nanosleep({1.000000000}) = 0 (0x0)
1.007179684 exit(0x0)
1.007179684 process exit, rval = 0

Möchte man die Ausgabe von truss in einer Datei speichern, kann die -o Option verwendet werden. Auch lassen sich die Systemcalls eines bereits laufenden Prozesses aufzeichnen, dazu muss nur die Prozess-ID mit der -p Option an truss übergeben werden. Folgendes Beispiel zeichnet die Systemcalls des laufenden portsnap Prozesses auf und speichert sie unter /tmp/portsnap.truss:

# portsnap fetch update &
[1] 20694
# truss -o /tmp/portsnap.truss -p 20694
[1] + Fertig

truss befindet sich auf FreeBSD bereits im Basissystem. Mehr Informationen zu truss findet man in der Manpage truss(1).

 Permalink

Comments

No new comments allowed (anymore) on this post.