#trace #ptrace #strace #utility

app tracexec

A small utility for tracing execve{,at}

12 releases

0.0.4 Nov 10, 2023
0.0.3 Nov 5, 2023
0.0.2 Oct 27, 2023

#144 in Debugging

Download history 27/week @ 2023-10-28 74/week @ 2023-11-04 16/week @ 2023-11-11 5/week @ 2023-11-18 38/week @ 2023-11-25 22/week @ 2023-12-02 24/week @ 2023-12-09 12/week @ 2023-12-16 25/week @ 2023-12-23 12/week @ 2023-12-30 2/week @ 2024-01-06 1/week @ 2024-01-13 24/week @ 2024-01-27 28/week @ 2024-02-10

52 downloads per month

GPL-2.0 license

415KB
1.5K SLoC

tracexec

A small utility for tracing execve{,at}.

Status:

  • Proof of concept.
  • Experimental quality.
  • Not ready for production use.
  • Performance is not a focus right now.

Showcases

Default mode

By default, tracexec will print filename, argv and the diff of the environment variables.

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

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

Installation

From source

Via cargo:

cargo install tracexec

You can also install tracexec from AUR.

Binary

You can download the binary from the release page

You can also install tracexec-bin from AUR.

Usage

Run tracexec in logging mode

Usage: tracexec log [OPTIONS] -- <CMD>...

Arguments:
  <CMD>...  command to be executed

Options:
      --successful-only   Only show successful calls
      --show-cmdline      Print commandline that reproduces what was executed. Note that when filename and argv[0] differs, it probably won't give you the correct commandline for now. Implies --successful-only
      --show-interpreter  Try to show script interpreter indicated by shebang
      --more-colors       More colors
      --less-colors       Less colors
      --show-children     Print a message when a child is created
      --diff-env          Diff environment variables with the original environment
      --no-diff-env       Do not diff environment variables
      --show-env          Show environment variables
      --no-show-env       Do not trace environment variables
      --show-comm         Show comm
      --no-show-comm      Do not show comm
      --show-argv         Show argv
      --no-show-argv      Do not show argv
      --show-filename     Show filename
      --no-show-filename  Do not show filename
      --show-cwd          Show cwd
      --no-show-cwd       Do not show cwd
      --decode-errno      Decode errno values
      --no-decode-errno   
  -o, --output <OUTPUT>   Output, stderr by default. A single hyphen '-' represents stdout.
  -h, --help              Print help

The recommended way to use tracexec is to create an alias with your favorite options in your bashrc:

alias tracex='tracexec log --show-cmdline --show-interpreter --show-children --show-filename --'
# Now you can use
tracex <command>

Known issues

  • Non UTF-8 strings are converted to UTF-8 in a lossy way, which means that the output may be inaccurate.
  • The output is not stable yet, which means that the output may change in the future.
  • No tests yet.

Origin

This project was born out of the need to trace the execution of programs.

Initially I simply use strace -Y -f -qqq -s99999 -e trace=execve,execveat <command>.

But the output is still too verbose so that's why I created this project.

Credits

This project takes inspiration from strace and lurk.

Dependencies

~9–21MB
~261K SLoC