how to debug application as root in eclipse in Ubuntu? how to debug application as root in eclipse in Ubuntu? c c

how to debug application as root in eclipse in Ubuntu?


  1. Enable your user to run as root without being asked for anypassword:
    sudo visudo
    Add the following line after all other rules:
    <youruser> ALL=(root) NOPASSWD:/usr/bin/gdb
  2. Create or modify a debug configuration in to run gdb as root
    e.g. in Run > Debug Configurations > C/C++ Application > YourProject Debug:
    change Debugger > Main > GDB debugger from gdb to sudo -u <youruser> gdb

Update (and warning!):

In his comment nategoose pointed out that this answer should come with a warning:

Enabling a user to use sudo for gdb like suggested in my answer in fact gives admin privileges to him/her which in many cases might be an undesired side effect. I therefore consider the answer appropriate in an environment where it's not assumed that the user would try to harm the system (e.g. it's your own personal computer or a virtual machine)

For a multi-(non-trusted)-user environment I think it might be a better idead to utilize unix' file capabilities to enable gdb to debug an application without the need of admin privileges


You can use gdbserver on localhost to attach a existing process, the following is the command line:

sudo gdbserver :<listening port> --attach <pid>

Or you can create a new process using gdbserver:

sudo gdbserver :<listening port> <process executable>

Then you can create a debugging configuration in Eclipse, in the debugger tab, the debugger item, select gdbserver, and input the listening port in the connection tab in the bellow.


Launch Eclipse with sudo (just for completeness: http://www.eclipse.org/forums/index.php?t=msg&goto=516838&)

Update: Follow xmoex solution. If you run Eclipse as root (ie. using sudo) your files will be root-owned... which you probably don't want.