Howto debug program that needs to run as root from gdb (Eclipse) as user (set gdb suid root?)

IanH picture IanH · Aug 6, 2010 · Viewed 15.4k times · Source

I need to debug a program on Linux with Eclipse (gdb). The program run as root and is quite large. The binary with debug symbols is about 250MB large and has more than 60 running threads after startup.

I'm thinking about the best solution:

  1. Use gdbserver
  2. Run Eclipse as root
  3. Set gdb suid

I think number 1 (gdbserver) would be the best solution, unfortunately it's not working reliable. The connection between gdb and gdbserver is lost. I think there is a problem with the huge amount of data transferred between eclipse <-> gdb <-> gdbserver.

Number 2 (run eclipse as root) means to run every process as root and so interferes also with the version control system, because the Eclipse plugin would use the root user instead of mine to change version-controlled files.

I didn't try number 3 (suid gdb). What do you think about it? Does it work at all? I'm aware that a suid root gdb is as safe as having no root-Password at all, but the machine is used for development and debugging by me only. And of course there could be an "enable/disable" script that sets the suid bit only when necessary.

Do you have any other suggestions?

Answer

necode picture necode · Dec 2, 2010

The less intrusive (no need to mess with suid) is to configure yourself to run gdb as root in /etc/sudoers and then just run:

sudo xauth merge ~/.Xauthority

sudo gdb

where the first command is needed to allow root open connection to X server