Using ltrace and strace Utilities223
It can read existing C files or take its input from standard input. This utility is not exten-
sively used in C software development but may be useful in some cases.
7.6Using ltrace and strace Utilities
The
ltrace
program is a tracing utility for library function calls. It runs a program and logs all
library function calls by that program. You can also use this utility to log system calls made by a
program. The utility can also monitor child processes created by fork() or clone() system calls.
This utility is very useful to quickly trace the failure point of an executable program. The utility
may also print the time at which a particular function call or system call is executed with a reso-
lution of microseconds.
Consider the simple single-line program that prints the string “Hello world” and then
exits. Using
ltrace
with the executable of this program produces the following result.
[root@boota ltrace]# ltrace -S -tt ./a.out
22:21:48.325970 SYS_uname(0xbffff3b4) = 0
22:21:48.327037 SYS_brk(NULL) = 0x080495f8
22:21:48.327511 SYS_mmap(0xbffff104, 0xcccccccd, 0x400165f8,
4096, 640) = 0x40017000
22:21:48.328212 SYS_open("/etc/ld.so.preload", 0, 010) = -2
22:21:48.329000 SYS_open("/etc/ld.so.cache", 0, 00) = 3
22:21:48.329657 SYS_197(3, 0xbfffea64, 0, 0xbfffea64, 0) = 0
22:21:48.331719 SYS_mmap(0xbfffea34, 0, 0x400165f8, 1, 3) =
0x40018000
22:21:48.332460 SYS_close(3) = 0
22:21:48.332908 SYS_open("/lib/i686/libc.so.6", 0,
027777765514) = 3
22:21:48.333620 SYS_read(3, "\177ELF\001\001\001", 1024) =
1024
22:21:48.334256 SYS_197(3, 0xbfffeaa4, 3, 0xbfffeaa4, 0) = 0
22:21:48.334917 SYS_mmap(0xbfffe994, 0x0012f728, 0x400165f8,
0xbfffe9c0, 5) = 0x4002c000
22:21:48.335584 SYS_mprotect(0x40152000, 38696, 0, 0x4002c000,
0x00126000) = 0
22:21:48.336209 SYS_mmap(0xbfffe994, 24576, 0x400165f8,
0xbfffe9cc, 3) = 0x40152000
22:21:48.336953 SYS_mmap(0xbfffe994, 0xbfffe9cc, 0x400165f8,
0x40158000, 14120) = 0x40158000
22:21:48.337642 SYS_close(3) = 0
22:21:48.340431 SYS_munmap(0x40018000, 77871) = 0
22:21:48.341060 SYS_getpid() = 32540
22:21:48.341562 __libc_start_main(0x08048460, 1, 0xbffff88c,
0x080482e4, 0x080484c0
22:21:48.342232 __register_frame_info(0x08049508, 0x080495e0,
0xbffff828, 0x0804838e, 0x080482e4) = 0x401575e0
22:21:48.343064 printf("Hello world\n"
Next Page >>
<< Previous Page
Back to the Table of Contents