strace
Original author(s) | Paul Kranenburg |
---|---|
Developer(s) | Dmitry Levin |
Stable release | 5.14[1]
/ September 2, 2021 |
Repository | |
Written in | C[2] |
Operating system | Linux |
Platform | AArch64, DEC Alpha, ARC, ARM EABI/OABI, AVR32, Blackfin, C-SKY, HP PA-RISC, IA-32, IA-64, Motorola 68k, Imagination META, MicroBlaze, MIPS, Nios II, OpenRISC, Power ISA 32/64 bit, RISC-V, System/390/z/Architecture, SuperH 32/64 bit, SPARC 32/64 bit, TILE, TILEPro, TILE-Gx, x86-64, x32 ABI, Xtensa |
Available in | English |
Type | Debugging |
License | LGPL v2.1+ |
Website | strace |
strace is a diagnostic, debugging and instructional userspace utility for Linux. It is used to monitor and tamper with interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state. The operation of strace is made possible by the kernel feature known as ptrace.
Some Unix-like systems provide other diagnostic tools similar to strace, such as truss.
History
Strace was originally written for SunOS by Paul Kranenburg in 1991, according to its copyright notice, and published early in 1992, in the volume three of comp.sources.sun. The initial README file contained the following:[3]
strace(1) is a system call tracer for Sun(tm) systems much like the Sun supplied program trace(1). strace(1) is a useful utility to sort of debug programs for which no source is available which unfortunately includes almost all of the Sun supplied system software.
Later, Branko Lankester ported this version to Linux, releasing his version in November 1992 with the second release following in 1993.[4][5] Richard Sladkey combined these separate versions of strace in 1993, and ported the program to SVR4 and Solaris in 1994,[6] resulting in strace 3.0 that was announced in comp.sources.misc in mid-1994.[7]
Beginning in 1996, strace was maintained by Wichert Akkerman. During his tenure, strace development migrated to CVS; ports to FreeBSD and many architectures on Linux (including ARM, IA-64, MIPS, PA-RISC, PowerPC, s390, SPARC) were introduced. In 2002, the burden of strace maintainership was transferred to Roland McGrath. Since then, strace gained support for several new Linux architectures (AMD64, s390x, SuperH), bi-architecture support for some of them, and received numerous additions and improvements in syscalls decoders on Linux; strace development migrated to git during that period. Since 2009, strace is actively maintained by Dmitry Levin. strace gained support for AArch64, ARC, AVR32, Blackfin, Meta, Nios II, OpenSISC 1000, RISC-V, Tile/TileGx, Xtensa architectures since that time.
The last version of strace that had some (evidently dead)[8] code for non-Linux operating systems was 4.6, released in March 2011.[9] In strace version 4.7, released in May 2012,[10] all non-Linux code had been removed;[11] since strace 4.13,[12] the project follows Linux kernel's release schedule, and with the version 5.0,[13] it follows Linux's versioning scheme as well.
In 2012 strace also gained support for path tracing and file descriptor path decoding.[14] In August 2014, strace 4.9 was released,[15][16] where support for stack traces printing was added. In December 2016,[17][18] syscall fault injection feature was implemented.
Version history
Version | Release date |
---|---|
5.14 | 2 September 2021[19] |
5.13 | 18 July 2021[20] |
5.12 | 26 April 2021[21] |
5.11 | 17 February 2021[22] |
5.10 | 14 December 2020[23] |
5.9 | 24 September 2020[24] |
5.8 | 6 August 2020[25] |
5.7 | 1 June 2020[26] |
5.6 | 7 April 2020[27] |
5.5 | 6 February 2020[28] |
5.4 | 28 November 2019[29] |
5.3 | 25 September 2019[30] |
5.2 | 12 July 2019[31] |
5.1 | 22 May 2019[32] |
5.0 | 19 March 2019[33] |
4.26 | 26 December 2018[34] |
4.25 | 30 October 2018[35] |
4.24 | 14 August 2018[36] |
4.23 | 14 June 2018[37] |
4.22 | 5 April 2018[38] |
4.21 | 13 February 2018[39] |
4.20 | 13 November 2017[40] |
4.19 | 5 September 2017[41] |
4.18 | 5 July 2017[42] |
4.17 | 24 May 2017[43] |
4.16 | 14 February 2017[44] |
4.15 | 14 December 2016[45] |
4.14 | 4 October 2016[46] |
4.13 | 26 July 2016[47] |
4.12 | 31 May 2016[48] |
4.11 | 21 December 2015[49] |
4.10 | 6 March 2015[50] |
4.9 | 15 August 2014[51] |
4.8 | 3 June 2013[52] |
4.7 | 2 May 2012[53] |
4.6 | 15 March 2011[54] |
4.5.20 | 13 April 2010 |
4.5.19 | 21 October 2009 |
4.5.18 | 28 August 2008 |
4.5.17 | 21 July 2008 |
4.5.16 | 3 August 2007 |
4.5.15 | 16 January 2007 |
4.5.14 | 16 January 2007 |
4.5.13 | 3 August 2005 |
4.5.12 | 8 June 2005 |
4.5.11 | 22 March 2005 |
4.5.10 | 13 March 2005 |
4.5.9 | 4 February 2004 |
4.5.8 | 19 October 2004 |
4.5.7 | 31 August 2004 |
4.5.6 | 12 July 2004 |
4.5.5 | 27 June 2004 |
4.5.4 | 3 June 2004 |
4.5.3 | 16 April 2004 |
4.5.2 | 1 March 2004 |
4.5.1 | 13 November 2003 |
4.5 | 24 September 2003 |
4.4 | 19 August 2001 |
4.3.1 | 7 April 2001 |
4.3 | 1 April 2001 |
4.2 | 21 January 2000 |
4.1 | 26 November 1999 |
4.0.1 | 25 July 1999 |
4.0 | 9 July 1999 |
3.99.1 | 9 June 1999 |
3.99 | 27 April 1999 |
3.1 | 1 June 1996 |
3.0 | 9 July 1994[55] |
Usage and features
The most common use is to start a program using strace, which prints a list of system calls made by the program. This is useful if the program continually crashes, or does not behave as expected; for example using strace may reveal that the program is attempting to access a file which does not exist or cannot be read.
An alternative application is to use the -p
flag to attach to a running process. This is useful if a process has stopped responding, and might reveal, for example, that the process is blocking whilst attempting to make a network connection.
Among other features, strace allows the following:
- Specifying a filter of syscall names that should be traced (via the
-e trace=
option): by name, like clone,fork,vfork; using one of the predefined groups, like %ipc or %file; or (since strace 4.17) using regular expression syntax, like-e trace=/clock_.*
. - Specifying a list of paths to be traced (
-P /etc/ld.so.cache
, for example). - Specifying a list of file descriptors whose I/O should be dumped (
-e read=
and-e write=
options). - Counting syscall execution time and count (
-T
,-c
,-C
, and-w
options). - Printing relative or absolute time stamps (
-t
and-r
options). - Modifying return and error code of the specified syscalls, and inject signals upon their execution (since strace 4.15,
-e inject=
option). - Extracting information about file descriptors (including sockets,
-y
option). - Printing stack traces, including (since strace 4.21) symbol demangling (
-k
option). - Filtering by syscall return status (
-e status=
option; since strace 5.2[56]).
strace supports decoding of arguments of some classes of ioctl commands, such as BTRFS_*, V4L2_*, DM_*, NSFS_*, MEM*, EVIO*, KVM_*, and several others.
As strace only details system calls, it cannot be used to detect as many problems as a code debugger such as GNU Debugger (gdb). It is, however, easier to use than a code debugger, and is a very useful tool for system administrators. It is also used by researchers to generate system call traces for later system call replay.[57][58][59]
Examples
The following is an example of typical output of the strace
command:
user@server:~$ strace ls
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC)
getdents64(3, /* 18 entries */, 4096) = 496
getdents64(3, /* 0 entries */, 4096) = 0
close(3) = 0
fstat64(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f2c000
write(1, "autofs\nbackups\ncache\nflexlm\ngames"..., 86autofsA
The above fragment is only a small part of the output of strace when run on the 'ls' command. It shows that the current working directory is opened, inspected and its contents retrieved. The resulting list of file names is written to standard output.
Similar tools
Different operating systems feature other similar or related instrumentation tools, offering similar or more advanced features; some of the tools (although using the same or a similar name) may use completely different work mechanisms, resulting in different feature sets or results. Such tools include the following:
- Linux has ltrace that can trace library and system calls, xtrace that can trace X Window programs,[60] SystemTap, perf, and trace-cmd and KernelShark that extend ftrace.
- AIX provides the truss command
- HP-UX offers the Tusc command
- Solaris / Illumos has truss and DTrace
- UnixWare provides the truss command
- FreeBSD provides the truss command, ktrace and DTrace
- NetBSD provides ktrace and DTrace
- OpenBSD uses ktrace and kdump
- macOS provides ktrace (10.4 and earlier), DTrace (from Solaris) and associated dtruss in 10.5 and later.[61]
- MS Windows has a similar utility called StraceNT, written by Pankaj Garg,[62] and a similar GUI-based utility called Process Monitor, developed by Sysinternals.
See also
References
- ^ "strace 5.14 released" (Mailing list). 2021-09-02. Retrieved 2021-09-02.
- ^ https://openhub.net/p/strace
- ^ Paul Kranenburg (March 2, 1992). "Strace - an alternative syscall tracer". Newsgroup: comp.sources.sun.
- ^ Branko Lankester (November 5, 1992). "first Linux release of strace".
- ^ Branko Lankester (June 18, 1993). "second Linux release of strace".
- ^ "strace". manned.org. June 21, 1994.
- ^ "SUNET's Index of /pub/usenet/ftp.uu.net/comp.sources.misc/volume43/strace". Retrieved January 14, 2015.
- ^ Denys Vlasenko (February 7, 2012). "How about removing non-Linux code?".
- ^ Dmitry V. Levin (March 16, 2011). "strace 4.6 released".
- ^ Dmitry V. Levin (May 2, 2012). "strace 4.7 released".
- ^ Dmitry V. Levin (April 20, 2012). "Noteworthy changes in release 4.7".
- ^ Dmitry V. Levin (October 4, 2016). "strace 4.14 released".
- ^ Dmitry V. Levin (March 19, 2019). "strace 5.0 released".
- ^ Dmitry V. Levin (May 1, 2012). "Noteworthy changes in release 4.7".
- ^ Dmitry V. Levin (August 15, 2014). "strace 4.9 released".
- ^ Dmitry V. Levin (August 15, 2014). "Noteworthy changes in release 4.9".
- ^ Dmitry V. Levin (December 14, 2016). "strace 4.15 released".
- ^ Dmitry V. Levin (December 14, 2016). "Noteworthy changes in release 4.15".
- ^ Dmitry V. Levin (2021-09-02). "strace 5.14 released".
- ^ Dmitry V. Levin (2021-07-18). "strace 5.13 released".
- ^ Dmitry V. Levin (2021-04-26). "strace 5.12 released".
- ^ Dmitry V. Levin (2021-02-17). "strace 5.11 released".
- ^ Dmitry V. Levin (2020-12-14). "strace 5.10 released".
- ^ Dmitry V. Levin (2020-09-24). "strace 5.9 released".
- ^ Dmitry V. Levin (2020-08-06). "strace 5.8 released".
- ^ Dmitry V. Levin (2020-06-01). "strace 5.7 released".
- ^ Dmitry V. Levin (2020-04-07). "strace 5.6 released".
- ^ Dmitry V. Levin (2020-02-06). "strace 5.5 released".
- ^ Dmitry V. Levin (2019-11-28). "strace 5.4 released".
- ^ Dmitry V. Levin (2019-09-25). "strace 5.3 released".
- ^ Dmitry V. Levin (2019-07-12). "strace 5.2 released".
- ^ Dmitry V. Levin (2019-05-22). "strace 5.1 released".
- ^ Dmitry V. Levin (2019-03-19). "strace 5.0 released".
- ^ Dmitry V. Levin (2018-12-26). "strace 4.26 released".
- ^ Dmitry V. Levin (2018-10-30). "strace 4.25 released".
- ^ Dmitry V. Levin (2018-08-14). "strace 4.24 released".
- ^ Dmitry V. Levin (2018-06-14). "strace 4.23 released".
- ^ Dmitry V. Levin (2018-04-05). "strace 4.22 released".
- ^ Dmitry V. Levin (2018-02-13). "strace 4.21 released".
- ^ Dmitry V. Levin (2017-11-13). "strace 4.20 released".
- ^ Dmitry V. Levin (2017-09-05). "strace 4.19 released".
- ^ Dmitry V. Levin (2017-07-05). "strace 4.18 released".
- ^ Dmitry V. Levin (2017-05-24). "strace 4.17 released".
- ^ Dmitry V. Levin (2017-02-14). "strace 4.16 released".
- ^ Dmitry V. Levin (2016-12-14). "strace 4.15 released".
- ^ Dmitry V. Levin (2016-10-04). "strace 4.14 released".
- ^ Dmitry V. Levin (2016-07-26). "strace 4.13 released".
- ^ Dmitry V. Levin (2016-05-31). "strace 4.12 released".
- ^ Dmitry V. Levin (2015-12-21). "strace 4.11 released".
- ^ Dmitry V. Levin (2015-03-06). "strace 4.10 released".
- ^ Dmitry V. Levin (2014-08-15). "strace 4.9 released".
- ^ Dmitry V. Levin (2013-06-03). "strace 4.8 released".
- ^ Dmitry V. Levin (2012-05-02). "strace 4.7 released".
- ^ Dmitry V. Levin (2011-03-15). "strace 4.6 released".
- ^ Rick Sladkey (1994-07-09). "v43i075: strace - system call tracer for sunos, linux, svr4, solaris2, Part01/10".
- ^ Its shorthand for showing only successful calls,
-z
option, was originally added in strace 4.5, but was never documented as it did not work properly. - ^ Horky, Jiri (2013). "The ioapps IO profiler and IO traces replayer". Retrieved 2013-09-16.
- ^ Waterland, Amos (2007). "The sreplay system call replayer". Retrieved 2013-09-16.
- ^ Burton, Ariel (1998). "Workload characterization using lightweight system call tracing and reexecution" (PDF). Retrieved 2013-09-16.
- ^ "XTrace - trace X protocol connections". xtrace.alioth.debian.org. Retrieved 2014-08-12.
- ^ "dtrace(1) Mac OS X Manual Page". Developer.apple.com. Retrieved 2014-07-23.
- ^ "IntellectualHeaven - Strace For Windows". intellectualheaven.com. Retrieved 29 January 2015.
External links
- strace project page
- Manual page
- OS Reviews article on strace
- "System Call Tracing with strace", a talk with an overview of strace features and usage, given by Michael Kerrisk at NDC TechTown 2018
- "Modern strace" (source), a talk with an overview of strace features, given by Dmitry Levin at DevConf.cz 2019