Original author(s) | Paul Kranenburg |
---|---|
Developer(s) | Dmitry Levin |
Stable release | 6.2[1]
/ February 26, 2023 |
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, LoongArch, 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[note 1] |
Type | Debugging |
License | LGPL v2.1+[note 2][4] |
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.
Strace was originally written for SunOS by Paul Kranenburg in 1991, according to its copyright notice, and published early in 1992, in volume three of comp.sources.sun. The initial README file contained the following:[5]
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.[6][7] Richard Sladkey combined these separate versions of strace in 1993, and ported the program to SVR4 and Solaris in 1994,[8] resulting in strace 3.0 that was announced in comp.sources.misc in mid-1994.[9]
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)[10] code for non-Linux operating systems was 4.6, released in March 2011.[11] In strace version 4.7, released in May 2012,[12] all non-Linux code had been removed;[13] since strace 4.13,[14] the project follows Linux kernel's release schedule, and with the version 5.0,[15] it follows Linux's versioning scheme as well.
In 2012 strace also gained support for path tracing and file descriptor path decoding.[16] In August 2014, strace 4.9 was released,[17][18] where support for stack traces printing was added. In December 2016,[19][20] syscall fault injection feature was implemented.
Version | Release date | Notable changes |
---|---|---|
6.2 | 2023[21] | Implemented collision resolution for overlapping terminal/sound ioctl commands |
6.1 | 2022[22] | Enhanced decoding of statx syscall and terminal ioctl commands
|
6.0 | 2022[23] | Enhanced decoding of setns syscall and PTP_* ioctl commands
|
5.19 | 2022[24] | The "(deleted)" marker of unlinked file descriptor paths is no longer interpreted as a part of a path; enhanced decoding of arch_prctl , io_uring_register , and prctl syscalls; enhanced decoding of siginfo_t structure
|
5.18 | 2022[25] | |
5.17 | 2022[26] | Added support for a new set_mempolicy_home_node syscall on Linux
|
5.16 | 2022[27] | Added support for printing SELinux context mismatches (--secontext=mismatch option); added support for a new futex_waitv syscall on Linux
|
5.15 | 2021[28] | |
5.14 | 2021[29] | Added support for the new memfd_secret and quotactl_fd syscalls decoding
|
5.13 | 2021[30] | Implemented System Call Vectored ABI support on the IBM POWER architecture |
5.12 | 2021[31] | Added support for the new mount_setattr syscall decoding
|
5.11 | 2021[32] | Added option for injecting data on syscall entry/exit (poke_enter= and poke_exit= parameters of the --inject option); added support for the new epoll_pwait2 syscall decoding; imlemented decoding of FS_IOC_FS[GS]ETXATTR , FS_IOC{,32}_[GS]ETFLAGS , GPIO_* , SIOCADDMULTI , SIOCDELMULTI , SIOCGIFENCAP , SIOCOUTQNSD , SIOCSIFENCAP , SIOCSIFHWBROADCAST , UBI_IOCRPEB , UBI_IOCSPEB , V4L2_BUF_TYPE_META_CAPTURE , V4L2_BUF_TYPE_META_OUTPUT , and VIDIOC_QUERY_EXT_CTRL ioctl commands
|
5.10 | 2020[33] | Stack tracing is supported for non-native personalities when compiled with libdw ; added support for process_madvise syscall decoding
|
5.9 | 2020[34] | Added support for close_range syscall decoding; added support for TEE * ioctl decoding; implemented decoding of {msg,msq,sem}info and {msg,msq,sem}id_ds structures used in the respective System V IPC syscalls commands
|
5.8 | 2020[35] | Changed the list of syscalls covered by the %process group to contain syscalls associated with process lifecycle: kill , tkill , tgkill , pidfd_send_signal , and rt_sigqueueinfo were added, arch_prctl and unshare were removed; added support for faccessat2 syscall decoding; added support for LOOP_CONFIGURE ioctl decoding
|
5.7 | 2020[36] | |
5.6 | 2020[37] | Added long option aliases along with possibilities for more precise option specifications via -e quiet /--quiet , -e decode-fds /--decode-fds , --absolute-timestamps , --relative-timestamps , and --syscall-times options; implemented various syscall statistics improvements
|
5.5 | 2020[38] | |
5.4 | 2019[39] | |
5.3 | 2019[40] | |
5.2 | 2019[41] | |
5.1 | 2019[42] | |
5.0 | 2019[43] | |
4.26 | 2018[44] | |
4.25 | 2018[45] | |
4.24 | 2018[46] | |
4.23 | 2018[47] | |
4.22 | 2018[48] | |
4.21 | 2018[49] | |
4.20 | 2017[50] | |
4.19 | 2017[51] | |
4.18 | 2017[52] | |
4.17 | 2017[53] | |
4.16 | 2017[54] | |
4.15 | 2016[55] | |
4.14 | 2016[56] | |
4.13 | 2016[57] | |
4.12 | 2016[58] | |
4.11 | 2015[59] | |
4.10 | 2015[60] | |
4.9 | 2014[61] | |
4.8 | 2013[62] | |
4.7 | 2012[63] | All non-Linux code had been removed |
4.6 | 2011[64] | |
4.5.20 | 2010 | Added support for new inotify_init1 , perf_event_open , preadv , pwritev , recvmmsg , rt_tgsigqueueinfo syscalls on Linux; -C option added, that combines regular and summary output; added Tile architecture support on Linux
|
4.5.19 | 2009 | Maintainership passed to Dmitry Levin; strace now terminates with the same exit code/signal as the traced program (if it was started by strace); added support for new accept4 , dup3 , epoll_create1 , eventfd2 , inotify_init1 , pipe2 , signalfd4 syscalls on Linux; added Blackfin, AVR32, and CRIS architedcture support on Linux
|
4.5.18 | 2008 | Added support for subpage_prot POWER-specific syscall on Linux
|
4.5.17 | 2008 | -F flag is deprecated, as -f traces vfork on Linux since long time
|
4.5.16 | 2007 | |
4.5.15 | 2007 | Added support for new *at , inotify* , pselect6 , ppoll and unshare syscalls on Linux
|
4.5.14 | 2007 | System call number can be supplied in -e specification
|
4.5.13 | 2005 | Add desc syscall group support to -e trace=
|
4.5.12 | 2005 | |
4.5.11 | 2005 | |
4.5.10 | 2005 | |
4.5.9 | 2004 | |
4.5.8 | 2004 | Decode mbind , [sg]et_mempolicy , waitid , fadvise64{,_64} , and epoll_* syscalls, RTC_* ioctls on Linux
|
4.5.7 | 2004 | |
4.5.6 | 2004 | Added support for 64-bit SPARC architecture on Linux. |
4.5.5 | 2004 | |
4.5.4 | 2004 | -p attaches to all NPTL threads on Linux only when -f is supplied
|
4.5.3 | 2004 | Added support for mq_* syscalls on Linux; -p now attaches to all NPTL threads on Linux
|
4.5.2 | 2004 | |
4.5.1 | 2003 | |
4.5 | 2003 | Maintainership passed to Roland McGrath; added x86-64 support on Linux with support of tracing of compat processes; added support for SH and SH64 architectures on Linux; -E option added
|
4.4 | 2001 | |
4.3.1 | 2001 | |
4.3 | 2001 | Added support for HP PA/RISC and IA-64 architectures on Linux; added support for 32-bit UID/GID syscalls on Linux; added support for FreeBSD on x86 |
4.2 | 2000 | Added support for IBM Z architecture on Linux |
4.1 | 1999 | Added support for MIPS architecture on Linux; strace-graph script added
|
4.0.1 | 1999 | |
4.0 | 1999 | Fixed 64-bit struct stat decoding on Linux; Irix 64 updates; Solaris updates
|
3.99.1 | 1999 | |
3.99 | 1999 | New maintainer, Wichert Akkerman; added support for IBM POWER, SPARC, and ARM architectures on Linux; added support for many syscalls on Linux |
3.1 | 1996 | Added support for the Irix OS, m68k and DEC Alpha architectures on Linux; added support for -o! option syntax; added support for syscall classes (file , process ); added support for IPC syscalls on Sun OS
|
3.0 | 1994[65] | Initial cross-platform version by Richard Sladkey. Includes support for -x , -q , -e (trace , abbrev , verbose , raw , signal , read , and write qualifiers), -c , -i options
|
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:
-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_.*
.-P /etc/ld.so.cache
, for example).-e read=
and -e write=
options).-T
, -c
, -C
, and -w
options; -U
option enables printing of additional information, like minimum and maximum syscall execution time).-t
and -r
options).-e inject=syscall specification:tampering specification
option): modifying return (:retval=
; since strace 4.16) and error code (:error=
; since strace 4.15) of the specified syscalls, inject signals (:signal=
; since strace 4.16), delays (:delay_enter=
and :delay_exit=
; since strace 4.22), and modify data pointed by syscall arguments (:poke_enter=
and :poke_exit=
; since strace 5.11) upon their execution.-y
option; -yy
option provides some additional information, like endpoint addresses for sockets, paths and device major/minor numbers for files).-k
option).-e status=
option; since strace 5.2[note 3]).--pidns-translation
option; since strace 5.9).--secontext
option; since strace 5.12).strace supports decoding of arguments of some classes of ioctl commands, such as BTRFS *, V4L2 *, DM *, NSFS *, MEM*, EVIO*, KVM *, and several others; it also supports decoding of various netlink protocols.
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.[66][67][68]
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.
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:
-z
option, was originally added in strace 4.5, but was never documented as it did not work properly.
Original source: https://en.wikipedia.org/wiki/Strace.
Read more |