Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gdb 如何使用strace定位一个属于哪个函数的系统调用?_Gdb_Strace - Fatal编程技术网

Gdb 如何使用strace定位一个属于哪个函数的系统调用?

Gdb 如何使用strace定位一个属于哪个函数的系统调用?,gdb,strace,Gdb,Strace,我想使用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 [2ab2f8

我想使用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()
系统调用,现在我想知道它在程序的哪个函数或哪一行被调用。我在互联网上搜索,然后用option
-I
显示地址,然后用gdb调试地址。但我还是不知道该怎么做。因为节目很快就要结束了。每次我运行它,它都会显示不同的地址。如何使用此信息调试它并找到调用方位置

我想使用strace来定位我的小程序在哪里进行
写入
系统调用

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.

是的,对于系统调用编写,您的方法确实有效。但当我试图捕获syscall read时,它似乎不起作用。为什么?GDB似乎无法捕获系统调用0: