Linux strace解决段错误

帮老丁调试他的xfa程序,这个程序有段错误。用gdb调试,bt查看堆栈信息的时候可以比较明确地定位到几个函数去,但是懒得去一步步查看。想起strace来跟踪一下系统调用。   

strace -f -o generateallxfa.strace ./generateallxfa -ruleno 1 -rulefile ./experiment/ftp-refined.re
1) processing regex:: <.*[sS][iI][tT][eE]#.*[cC][hH][mM][oO][dD]> <set_only_bit>
[root@localhost XFA]# cat generateallxfa.strace
9224  execve("./generateallxfa", ["./generateallxfa", "-ruleno", "1", "-rulefile", "./experiment/ftp-refined.re"], [/* 36 vars */]) = 0
9224  brk(0)                            = 0x869b000
9224  access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
9224  open("/etc/ld.so.cache", O_RDONLY) = 3
9224  fstat64(3, {st_mode=S_IFREG|0644, st_size=57735, ...}) = 0
9224  mmap2(NULL, 57735, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fdf000
9224  close(3)                          = 0
9224  open("/usr/lib/libstdc++.so.6", O_RDONLY) = 3
9224  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 \322\30\0074\0\0\0"..., 512) = 512
9224  fstat64(3, {st_mode=S_IFREG|0666, st_size=964412, ...}) = 0
9224  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fde000
9224  mmap2(0x7146000, 985260, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7146000
9224  mmap2(0x722c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe6) = 0x722c000
9224  mmap2(0x7231000, 22700, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7231000
9224  close(3)                          = 0
9224  open("/lib/libm.so.6", O_RDONLY)  = 3
9224  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20d\206\0004\0\0\0"..., 512) = 512
9224  fstat64(3, {st_mode=S_IFREG|0755, st_size=208352, ...}) = 0
9224  mmap2(0x863000, 155760, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x863000
9224  mmap2(0x888000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x24) = 0x888000
9224  close(3)                          = 0
9224  open("/lib/libgcc_s.so.1", O_RDONLY) = 3
9224  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0`&\1\0024\0\0\0"..., 512) = 512
9224  fstat64(3, {st_mode=S_IFREG|0755, st_size=46476, ...}) = 0
9224  mmap2(0x2011000, 48036, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2011000
9224  mmap2(0x201c000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa) = 0x201c000
9224  close(3)                          = 0
9224  open("/lib/libc.so.6", O_RDONLY)  = 3
9224  read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320/s\0004\0\0\0"..., 512) = 512
9224  fstat64(3, {st_mode=S_IFREG|0755, st_size=1606808, ...}) = 0
9224  mmap2(0x71d000, 1324452, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x71d000
9224  mmap2(0x85b000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13e) = 0x85b000
9224  mmap2(0x85e000, 9636, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x85e000
9224  close(3)                          = 0
9224  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fdd000
9224  set_thread_area({entry_number:-1 -> 6, base_addr:0xb7fddad0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
9224  mprotect(0x85b000, 8192, PROT_READ) = 0
9224  mprotect(0x888000, 4096, PROT_READ) = 0
9224  mprotect(0x722c000, 16384, PROT_READ) = 0
9224  mprotect(0x719000, 4096, PROT_READ) = 0
9224  munmap(0xb7fdf000, 57735)         = 0
9224  brk(0)                            = 0x869b000
9224  brk(0x86bc000)                    = 0x86bc000
9224  open("./experiment/ftp-refined.re", O_RDONLY) = 3
9224  fstat64(3, {st_mode=S_IFREG|0766, st_size=596, ...}) = 0
9224  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fed000
9224  read(3, ".*[sS][iI][tT][eE]#.*[cC][hH][mM"..., 4096) = 596
9224  fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
9224  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fec000
9224  write(1, "1) processing regex:: <.*[sS][iI"..., 81) = 81
9224  brk(0x86dd000)                    = 0x86dd000
9224  brk(0x86fe000)                    = 0x86fe000
9224  brk(0x871f000)                    = 0x871f000
9224  brk(0x8740000)                    = 0x8740000
9224  brk(0x8761000)                    = 0x8761000
9224  brk(0x8782000)                    = 0x8782000
9224  brk(0x87a3000)                    = 0x87a3000
9224  brk(0x87c4000)                    = 0x87c4000
9224  brk(0x87e5000)                    = 0x87e5000
9224  brk(0x8806000)                    = 0x8806000
9224  brk(0x8827000)                    = 0x8827000
9224  brk(0x8848000)                    = 0x8848000
9224  brk(0x8869000)                    = 0x8869000
9224  brk(0x888a000)                    = 0x888a000
9224  brk(0x88ab000)                    = 0x88ab000
9224  brk(0x88cc000)                    = 0x88cc000
9224  brk(0x88ed000)                    = 0x88ed000
9224  brk(0x890e000)                    = 0x890e000
9224  brk(0x892f000)                    = 0x892f000
9224  brk(0x8950000)                    = 0x8950000
9224  brk(0x8971000)                    = 0x8971000
9224  brk(0x8992000)                    = 0x8992000
9224  brk(0x89b3000)                    = 0x89b3000
9224  brk(0x89d4000)                    = 0x89d4000
9224  brk(0x89f5000)                    = 0x89f5000
9224  brk(0x8a16000)                    = 0x8a16000
9224  brk(0x8a37000)                    = 0x8a37000
9224  brk(0x8a58000)                    = 0x8a58000
9224  brk(0x8a79000)                    = 0x8a79000
9224  brk(0x8a9a000)                    = 0x8a9a000
9224  brk(0x8abb000)                    = 0x8abb000
9224  brk(0x8adc000)                    = 0x8adc000
9224  brk(0x8afd000)                    = 0x8afd000
9224  brk(0x8b1e000)                    = 0x8b1e000
9224  brk(0x8b3f000)                    = 0x8b3f000
9224  brk(0x8b60000)                    = 0x8b60000
9224  brk(0x8b81000)                    = 0x8b81000
9224  brk(0x8ba2000)                    = 0x8ba2000
9224  brk(0x8bc3000)                    = 0x8bc3000
9224  brk(0x8be4000)                    = 0x8be4000
9224  brk(0x8c05000)                    = 0x8c05000
9224  brk(0x8c26000)                    = 0x8c26000
9224  brk(0x8c47000)                    = 0x8c47000
9224  brk(0x8c68000)                    = 0x8c68000
9224  brk(0x8c89000)                    = 0x8c89000
9224  brk(0x8caa000)                    = 0x8caa000
9224  brk(0x8ccb000)                    = 0x8ccb000
9224  brk(0x8cec000)                    = 0x8cec000
9224  brk(0x8d0d000)                    = 0x8d0d000
9224  brk(0x8d2e000)                    = 0x8d2e000
9224  brk(0x8d4f000)                    = 0x8d4f000
9224  brk(0x8d70000)                    = 0x8d70000
9224  brk(0x8d91000)                    = 0x8d91000
9224  brk(0x8db2000)                    = 0x8db2000
9224  brk(0x8dd3000)                    = 0x8dd3000
9224  brk(0x8df4000)                    = 0x8df4000
9224  brk(0x8e15000)                    = 0x8e15000
9224  brk(0x8e36000)                    = 0x8e36000
9224  brk(0x8e57000)                    = 0x8e57000
9224  brk(0x8e78000)                    = 0x8e78000
9224  brk(0x8e99000)                    = 0x8e99000
9224  brk(0x8eba000)                    = 0x8eba000
9224  brk(0x8edb000)                    = 0x8edb000
9224  brk(0x8efc000)                    = 0x8efc000
9224  brk(0x8f1d000)                    = 0x8f1d000
9224  brk(0x8f3e000)                    = 0x8f3e000
9224  brk(0x8f5f000)                    = 0x8f5f000
9224  brk(0x8f80000)                    = 0x8f80000
9224  brk(0x8fa1000)                    = 0x8fa1000
9224  brk(0x8fc2000)                    = 0x8fc2000
9224  brk(0x8fe3000)                    = 0x8fe3000
9224  brk(0x9004000)                    = 0x9004000
9224  brk(0x9025000)                    = 0x9025000
9224  brk(0x9046000)                    = 0x9046000
9224  brk(0x9067000)                    = 0x9067000
9224  brk(0x9088000)                    = 0x9088000
9224  brk(0x90a9000)                    = 0x90a9000
9224  brk(0x90ca000)                    = 0x90ca000
9224  brk(0x90eb000)                    = 0x90eb000
9224  brk(0x910c000)                    = 0x910c000
9224  brk(0x912d000)                    = 0x912d000
9224  brk(0x914e000)                    = 0x914e000
9224  brk(0x916f000)                    = 0x916f000
9224  brk(0x9190000)                    = 0x9190000
9224  brk(0x91b1000)                    = 0x91b1000
9224  brk(0x91d2000)                    = 0x91d2000
9224  brk(0x91f3000)                    = 0x91f3000
9224  brk(0x9214000)                    = 0x9214000
9224  brk(0x9235000)                    = 0x9235000
9224  brk(0x9256000)                    = 0x9256000
9224  brk(0x9277000)                    = 0x9277000
9224  brk(0x9298000)                    = 0x9298000
9224  brk(0x92b9000)                    = 0x92b9000
9224  brk(0x92da000)                    = 0x92da000
9224  brk(0x92fb000)                    = 0x92fb000
9224  time(NULL)                        = 1313917094
9224  brk(0x931c000)                    = 0x931c000
9224  time(NULL)                        = 1313917094
9224  open("debug/1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory)
9224  --- SIGSEGV (Segmentation fault) @ 0 (0) ---
9224  +++ killed by SIGSEGV +++

红色部分可以清晰地看到缺少这个debug/1导致的,极有可能是debug目录不存在,但是看了下发现debug目录还是存在的,只是名字竟然叫Debug

Linux下面区分大小写,导致没有directory。这也是因为老丁拿到的代码是在cygwin下的。

附上strace用法:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwdysd.html