gdbserver

Extending gdbserver to support an strace client

Extending gdbserver to support an strace client

The strace command traces system calls and signals, deciding them and their corresponding arguments into a symbolic form. A frequent debugging request from developers is the ability to allow strace to trace system calls for a program that is also being debugged by GDB, like this:

% gdb --args test-program
(gdb) b main
Breakpoint 1 at 0x40128e: file test-program.c, line 22.
(gdb) run
Starting program: test-program
Breakpoint 1, main (argc=3, argv=0x7fffffffdb98) at test-program.c:22
22 int thread_count = 2;
(gdb)

In another terminal window, we invoke strace on the same process GDB is debugging:

% strace -p $(pgrep -f test-program)
strace: attach: ptrace(PTRACE_SEIZE, 27882): Operation not permitted

The culprit here is that the ptrace system call, which is used by both GDB and strace to control the execution of programs, and does not allow both strace and GDB to control the same process.

Continue reading “Extending gdbserver to support an strace client”

Share