Section 7.2. strace and ltrace


7.2. strace and ltrace

The strace and ltrace tools are utility programs that trace program executions. They are a good addition to a programmer's arsenal of debugging tools. Porting engineers find these tools useful for tracking down hard-to-find problems such as timing-related issues.

The strace tool traces system calls and signals that happen during program execution. Each line in the strace output contains the system call name, followed by its arguments in parentheses and its return value. For example:

open("/dev/null", O_RDONLY) = 3 


Errors display together with the corresponding error return values, as in the following:

open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory) 


As with strace, the ltrace tool is used to trace program execution for diagnosing timing-related issues. The ltrace tool intercepts and records dynamic library calls as well as signals executed and received by the main program, respectively. The ltrace tool prints the library call followed by its arguments and its return value, as shown in the following example:

strlen("apache-ant-1.6.2")   = 16 


You can use both strace and ltrace in lieu of the truss utility present in other UNIX operating platforms.




UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net