【问题标题】:How to use strace to locate one system call belong which function?如何使用 strace 定位一个系统调用属于哪个函数?
【发布时间】:2013-12-05 06:55:02
【问题描述】:

我想使用 strace 来定位我的小程序执行write 系统调用的位置。例如,我的 strace 输出是这样的:

# strace -i regget -f  /home/lucid/.config/ctsc.ini Admin Password 
[2ac5b250] execve("/usr/sbin/regget", ["regget", "-f", "/home/lucid/.config/ctsc.ini", "Admin", "Password"], [/* 24 vars */]) = 0
[2ab2f8aa] brk(0)                       = 0x13000
[2ab2ff0c] uname({sys="Linux", node="localhost", ...}) = 0
[2ab2fcec] access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
[2ab2fe48] mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ab4a000
[2ab2fcec] access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/v7l/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/v7l/neon/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/v7l/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/v7l/neon", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/v7l/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/v7l/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/v7l/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/v7l", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/neon/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/neon", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/tls/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/tls", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/v7l/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/v7l/neon/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/v7l/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/v7l/neon", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/v7l/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/v7l/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/v7l/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/v7l", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/neon/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/neon/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/neon/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/neon", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/vfp/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib/vfp", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/home/lucid/lib/libreg_lib.so", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fb30] stat64("/home/lucid/lib", 0x7e8fedd0) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/etc/ld.so.cache", O_RDONLY) = 3
[2ab2fb74] fstat64(3, {st_mode=S_IFREG|0644, st_size=73348, ...}) = 0
[2ab2fe48] mmap2(NULL, 73348, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2ac0d000
[2ab2fbec] close(3)                     = 0
[2ab2fcec] access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/usr/lib/libreg_lib.so", O_RDONLY) = 3
[2ab2fc2c] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\364\22\0\0004\0\0\0"..., 512) = 512
[2ab2fb74] fstat64(3, {st_mode=S_IFREG|0755, st_size=37676, ...}) = 0
[2ab2fe48] mmap2(NULL, 51700, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2ac36000
[2ab2fecc] mprotect(0x2ac3a000, 28672, PROT_NONE) = 0
[2ab2fe48] mmap2(0x2ac41000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3) = 0x2ac41000
[2ab2fbec] close(3)                     = 0
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/v7l/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/neon/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("$/opt/glib-2.32.3/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
[2ab2fcec] access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
[2ab2fbac] open("/lib/libc.so.6", O_RDONLY) = 3
[2ab2fc2c] read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0AU\1\0004\0\0\0"..., 512) = 512
[2ab2fb74] fstat64(3, {st_mode=S_IFREG|0755, st_size=931264, ...}) = 0
[2ab2fe48] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ab5c000
[2ab2fe48] mmap2(NULL, 967956, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x2ac43000
[2ab2fecc] mprotect(0x2ad22000, 32768, PROT_NONE) = 0
[2ab2fe48] mmap2(0x2ad2a000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xdf) = 0x2ad2a000
[2ab2fe48] mmap2(0x2ad2d000, 9492, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x2ad2d000
[2ab2fbec] close(3)                     = 0
[2ab2fe48] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2aad9000
[2ab21996] set_tls(0x2aad94c0, 0xf0005, 0x2aad9b98, 0x2aad94c0, 0x2ab3e000) = 0
[2ab2fecc] mprotect(0x2ad2a000, 8192, PROT_READ) = 0
[2ab2fecc] mprotect(0x2ac41000, 4096, PROT_READ) = 0
[2ab2fecc] mprotect(0x11000, 4096, PROT_READ) = 0
[2ab2fecc] mprotect(0x2ab3d000, 4096, PROT_READ) = 0
[2ab2fe8c] munmap(0x2ac0d000, 73348)    = 0
[2acd412a] brk(0)                       = 0x13000
[2acd412a] brk(0x34000)                 = 0x34000
[2acce6ac] open("/home/lucid/.config/ctsc.ini", O_RDONLY) = 3
[2accdc58] fstat64(3, {st_mode=S_IFREG|0664, st_size=2192, ...}) = 0
[2acd78e8] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2abaa000
[2accec3c] read(3, "\n[Configure]\nIsInputPasswd=y\nRoo"..., 4096) = 2192
[2accec3c] read(3, "", 4096)            = 0
[2ac9208e] close(3)                     = 0
[2acd797c] munmap(0x2abaa000, 4096)     = 0
[2acce6ac] open("/home/lucid/.config/ctsc.ini", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
[2accdc58] fstat64(3, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
[2acd78e8] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ab13000
[2acceccc] write(3, "\n[Configure]\nIsInputPasswd=y\nRoo"..., 2192) = 2192
[2ac9208e] close(3)                     = 0
[2acd797c] munmap(0x2ab13000, 4096)     = 0
[2accdc58] fstat64(1, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
[2acd78e8] mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2ab14000
[2acceccc] write(1, "abc123\n", 7)      = 7
[2acb520e] exit_group(0)                = ?

倒数第 7 行,有一个write() 系统调用,现在我想知道它是在哪个函数或程序的哪一行调用的。我在网上搜索,然后我发现使用选项-i显示地址,然后使用gdb调试它。但我仍然不知道该怎么做。因为程序很快结束。每次我运行它时,它都会显示一个不同的地址。我如何使用这些信息来调试它并找到调用者的位置。

【问题讨论】:

    标签: gdb strace


    【解决方案1】:

    我想使用 strace 来定位我的小程序执行write 系统调用的位置。

    Strace 是这个错误的工具。只需使用 GDB:

    gdb --args regget -f  /home/lucid/.config/ctsc.ini Admin Password
    (gdb) start
    # GDB stops in main
    (gdb) catch syscall write
    (gdb) continue
    # GDB stop just before executing write(2)
    (gdb) where
    # GDB tells you where in your program write was called from.
    

    【讨论】:

    猜你喜欢
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 2014-02-01
    相关资源
    最近更新 更多