Difference between revisions of "Strace"
Jump to navigation
Jump to search
m (added Category:Development using HotCat) |
|||
Line 3: | Line 3: | ||
Say you have some python application such as [[Reposurgeon]] that you need to understand better. You can attach <code>strace</code> to the <code><abbrev title="process id">pid</abbrev></code> of the running application to see the underlying system calls being made. | Say you have some python application such as [[Reposurgeon]] that you need to understand better. You can attach <code>strace</code> to the <code><abbrev title="process id">pid</abbrev></code> of the running application to see the underlying system calls being made. | ||
<source lang="bash"> | <source lang="bash"> | ||
− | sudo strace -f -s128 -p$(ps -o lwp= -LC python2 | tail -1) | + | sudo strace -f -s128 -e trace=open -p$(ps -o lwp= -LC python2 | tail -1) |
# -f follow child processes | # -f follow child processes | ||
# -s string width | # -s string width | ||
− | + | # -e set which calls you want to see. Using trace=open is like sudo lsof -ad3-999 -c python2 | |
</source> | </source> | ||
Revision as of 00:33, 18 December 2015
System Trace is a tool for hackers.
Say you have some python application such as Reposurgeon that you need to understand better. You can attach strace
to the <abbrev title="process id">pid</abbrev>
of the running application to see the underlying system calls being made.
sudo strace -f -s128 -e trace=open -p$(ps -o lwp= -LC python2 | tail -1)
# -f follow child processes
# -s string width
# -e set which calls you want to see. Using trace=open is like sudo lsof -ad3-999 -c python2
write(1, "reposurgeon: r10952 copynode filemap is <PathMap: branches/784.919Merge/diag/Makefile branches/784.919Merge/diag/changelog branc"..., 1024) = 1024 write(1, "/cmts.cmd.h branches/784.919Merge/diag/cli/commands/cmts_dsg.cmd.h branches/784.919Merge/diag/cli/commands/copy.cmd branches/784"..., 412067840) = 412067840 write(1, "c/zebos/rip/rip_distance.c trunk/linux/src/zebos/rip/rip_distance.h trunk/linux/src/zebos/rip/rip_host.h trunk/linux/src/zebos/r"..., 888) = 888 munmap(0x7f888d31c000, 412069888) = 0 munmap(0x7f885c126000, 412069888) = 0 mmap(NULL, 412069888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f888d31d000 mmap(NULL, 412069888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8874a22000 munmap(0x7f888d31d000, 412069888) = 0 mmap(NULL, 412073984, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f885c126000 munmap(0x7f8874a22000, 412069888) = 0 mremap(0x7f885c126000, 412073984, 412069888, MREMAP_MAYMOVE) = 0x7f885c126000 mmap(NULL, 412073984, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f888d31c000 mremap(0x7f888d31c000, 412073984, 412069888, MREMAP_MAYMOVE) = 0x7f888d31c000 write(1, "reposurgeon: r10952 copynode filemap is <PathMap: branches/784.919Merge/diag/Makefile branches/784.919Merge/diag/changelog branc"..., 1024) = 1024 write(1, "/cmts.cmd.h branches/784.919Merge/diag/cli/commands/cmts_dsg.cmd.h branches/784.919Merge/diag/cli/commands/copy.cmd branches/784"..., 412067840) = 412067840 write(1, "c/zebos/rip/rip_distance.c trunk/linux/src/zebos/rip/rip_distance.h trunk/linux/src/zebos/rip/rip_host.h trunk/linux/src/zebos/r"..., 888) = 888 munmap(0x7f888d31c000, 412069888) = 0 munmap(0x7f885c126000, 412069888) = 0 mmap(NULL, 412069888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f888d31d000 mmap(NULL, 412069888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8874a22000 munmap(0x7f888d31d000, 412069888) = 0 mmap(NULL, 412073984, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f885c126000 munmap(0x7f8874a22000, 412069888) = 0 mremap(0x7f885c126000, 412073984, 412069888, MREMAP_MAYMOVE) = 0x7f885c126000 mmap(NULL, 412073984, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f888d31c000 mremap(0x7f888d31c000, 412073984, 412069888, MREMAP_MAYMOVE) = 0x7f888d31c000 write(1, "reposurgeon: r10952 copynode filemap is <PathMap: branches/784.919Merge/diag/Makefile branches/784.919Merge/diag/changelog branc"..., 1024) = 1024 write(1, "/cmts.cmd.h branches/784.919Merge/diag/cli/commands/cmts_dsg.cmd.h branches/784.919Merge/diag/cli/commands/copy.cmd branches/784"..., 412067840) = 412067840 write(1, "c/zebos/rip/rip_distance.c trunk/linux/src/zebos/rip/rip_distance.h trunk/linux/src/zebos/rip/rip_host.h trunk/linux/src/zebos/r"..., 888) = 888 munmap(0x7f888d31c000, 412069888) = 0 munmap(0x7f885c126000, 412069888) = 0 mmap(NULL, 412069888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f888d31d000 mmap(NULL, 412069888, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8874a22000 munmap(0x7f888d31d000, 412069888) = 0 mmap(NULL, 412073984, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f885c126000 munmap(0x7f8874a22000, 412069888) = 0 mremap(0x7f885c126000, 412073984, 412069888, MREMAP_MAYMOVE) = 0x7f885c126000 mmap(NULL, 412073984, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f888d31c000 mremap(0x7f888d31c000, 412073984, 412069888, MREMAP_MAYMOVE) = 0x7f888d31c000 write(1, "reposurgeon: r10952 copynode filemap is <PathMap: branches/784.919Merge/diag/Makefile branches/784.919Merge/diag/changelog branc"..., 1024) = 1024 write(1, "/cmts.cmd.h branches/784.919Merge/diag/cli/commands/cmts_dsg.cmd.h branches/784.919Merge/diag/cli/commands/copy.cmd branches/784"..., 412067840) = 412067840 write(1, "c/zebos/rip/rip_distance.c trunk/linux/src/zebos/rip/rip_distance.h trunk/linux/src/zebos/rip/rip_host.h trunk/linux/src/zebos/r"..., 888) = 888 munmap(0x7f888d31c000, 412069888) = 0 munmap(0x7f885c126000, 412069888) = 0