Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Showcases

The following examples illustrate how tracexec can be used to inspect builds, trace command execution, and launch a debugger.

Perfetto Trace Export

tracexec supports exporting exec traces to perfetto trace format, which could be viewed in the Perfetto UI. The trace follows a tree format in the UI, where processes resulting from successful execs are represented as slices and exec failures are represented as instant events.

The following video shows analyzing the build process of tracexec with itself:

The shape of the traces in the Perfetto UI could give you a rough idea of how parallel the build is at process-level. The trace tree and details of slices enable identification of bottlenecks, troubleshooting, and a deep understanding of how the build works.

Start collecting a perfetto trace with the following command:

tracexec collect --format=perfetto -o out.pftrace -- cmd

See Perfetto Trace Export for instructions on collecting and interpreting a trace.

TUI mode with pseudo terminal

TUI mode allocates a pseudo terminal by default, allowing you to view the details of exec events and interact with the processes within the pseudo terminal. Use --no-tty when a pseudo terminal is not wanted; the tracee’s stdin, stdout, and stderr will be redirected to /dev/null.

Tracing setuid binaries

With root privileges, you can also trace setuid binaries and see how they work. But do note that this is not compatible with seccomp-bpf optimization so it is much less performant. You can use eBPF mode which is more performant in such scenarios.

sudo tracexec --user $(whoami) tui -- sudo ls

Nested setuid binary tracing is also possible: A real world use case is to trace extra-x86_64-build(Arch Linux’s build tool that requires sudo):

In this real world example, we can easily see that _FORTIFY_SOURCE is redefined from 2 to 3, which led to a compiler error.

Use tracexec as a debugger launcher

tracexec can also be used as a debugger launcher to make debugging programs easier. For example, it’s not trivial or convenient to debug a program executed by a shell/python script(which can use pipes as stdio for the program). The following video shows how to use tracexec to launch GDB to attach to two simple programs piped together by a shell script.

See the debugger-launcher tutorial for the complete example.

eBPF mode

Please check platform support status before using the eBPF backend.

The following examples show how to use eBPF in TUI mode. The ebpf command also supports regular log and collect subcommands.

System-wide Exec Tracing

System-wide tracing has no command to attach to a pseudo terminal, so it runs without one automatically:

sudo -E tracexec ebpf tui

Follow Fork mode with eBPF

sudo -E tracexec --user $(whoami) ebpf tui -- bash

Log mode

In log mode, by default, tracexec will print filename, argv and the diff of the environment variables and file descriptors.

example: tracexec log -- bash (In an interactive bash shell)

asciicast

Reconstruct the command line with --show-cmdline

$ tracexec log --show-cmdline -- <command>
# example:
$ tracexec log --show-cmdline -- firefox

asciicast

Try to reproduce stdio in the reconstructed command line

--stdio-in-cmdline and --fd-in-cmdline can be used to reproduce(hopefully) the stdio used by a process.

But do note that the result might be inaccurate when pipes, sockets, etc are involved.

tracexec log --show-cmdline --stdio-in-cmdline -- bash

asciicast

Show the interpreter indicated by shebang with --show-interpreter

And show the cwd with --show-cwd.

$ tracexec log --show-interpreter --show-cwd -- <command>
# example: Running Arch Linux makepkg
$ tracexec log --show-interpreter --show-cwd -- makepkg -f

asciicast