2009年8月26日 星期三

Linux debug by using strace

We can use strace to find which libraries are used of the specified program.
Another point is that you can find which configure file was opened by the specified program. Does the specified program open the wrong configuration files not as you expected?

# strace ./myprog -l 1234 -d 4
execve("./tsa", ["./myprog", "-l", "1234", "-d", "4"], [/* 53 vars */]) = 0
brk(0) = 0x9adb000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=108397, ...}) = 0
mmap2(NULL, 108397, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f7e000
close(3) = 0
open("/lib/libpthread.so.0", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \30l\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=131528, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f7d000
mmap2(0x6bd000, 98784, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x6bd000
mmap2(0x6d2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14) = 0x6d2000
mmap2(0x6d4000, 4576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x6d4000
close(3) = 0
open("/lib/libm.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\344h\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=210324, ...}) = 0
mmap2(0x68b000, 163952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x68b000
mmap2(0x6b2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x26) = 0x6b2000
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3

沒有留言: