3

I want to debug the very initial startup of a daemon started as a service under linux (centos 7).

My service is started as: "service mydaemon start"

I know about attaching gdb to a running process, but, unfortunately that technique is too slow, the initial execution of mydaemon is important.

mydaemon is written in C++ and full debug info is available.

J. Curtis
  • 41
  • 5

1 Answers1

3

unfortunately that technique is too slow

There are two general solutions to this problem.

The first one is described here: you make your target executable wait for GDB to attach (this requires building a special version of the daemon).

The second is to "wrap" your daemon in gdbserver (as root):

mv mydaemon mydaemon.exe
echo > mydaemon <<EOF
#!/bin/sh
exec gdbserver :1234 /path/to/mydaemon.exe "$@"
EOF
chmod +x mydaemon

Now execute service mydaemon start, and your process will be stopped by gdbserver and will wait for connection from GDB.

gdb /path/to/mydaemon.exe
(gdb) target remote :1234
# You should now be looking at the mydaemon process stopped in `_start`.

At that point you can set beakpoints, and use continue or next or step as appropriate.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362