Question

I want to use strace to locate where my tiny program do write system call. For example, my strace ouput is like this:

# 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)                = ?

In 7th line from the end, there is a write() system call, Now I want to know in which function or which line of the program it is called. I search the Internet, then I found using option -i to show the address and then using gdb to debug it. But I still donot know how to do. Because the program finishes soon. And everytime I run it, it shows me a different address. How I use this information to debug it and find the caller location.

Was it helpful?

Solution

I want to use strace to locate where my tiny program do write system call.

Strace is the wrong tool for this. Just use 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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top