Strace
Revision as of 18:55, 17 December 2015 by Freephile (talk | contribs) (added Category:Development using HotCat)
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 -p$(ps -o lwp= -LC python2 | tail -1)
# -f follow child processes
# -s string width
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