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

Use tracexec as debugger launcher

Without tracexec, it’s not trivial or convenient to debug a program that gets executed by other programs or debug programs with pipes:

This example demonstrates how to use tracexec as a gdb launcher to debug programs under complex setup. The following video demonstrates the whole process:

To run this example, first ensure that tracexec and rust is installed on your system.

Clone the tracexec repository and enter the directory for this example:

git clone https://github.com/kxxt/tracexec
cd tracexec/book/tutorials/debugger-launcher

Then run make to compile the two simple rust programs.

In order to allow gdb to attach to the detached and stopped tracees, you probably need to run:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

On a machine with Wayland/X11 display, assuming you have konsole installed(if not, please change the default-external-command), run

tracexec tui -t \
    -b sysexit:in-filename:/a \
    -b sysexit:in-filename:/b \
    --default-external-command "konsole -e gdb -ex cont -ex cont -p {{PID}}" \
    -- ./shell-script

or on a headless server, inside a tmux session, run:

tracexec tui -t \
    -b sysexit:in-filename:/a \
    -b sysexit:in-filename:/b \
    --default-external-command "tmux split-window 'gdb -ex cont -ex cont -p {{PID}}'" \
    -- ./shell-script

Alternatively, launch tracexec tui with a bash session and set the breakpoints in the TUI then run ./shell-script in it.

When the breakpoint get hit, open the Hit Manager and launch the external command for the two stopped tracees. Then two gdb session will open.

To restart the tracees in gdb, Send command c twice.