Take the 2-minute tour ×

I'm programming application using libpcap. when I debug the application in normal mode, pcap cannot get the network device. it seems that I have to debug the application in root. How can I debug the application in root? I have the root password. I think eclipse has such an option that can add root for the debugging application,but I don't know how to do it. please help.

share|improve this question
Basically, run your debugger as root. Are you trying to use a debugger through an IDE? –  Artelius May 23 '10 at 10:33
Can you tell me how to run debugger as root? yes, I use eclipse IDE. –  futang May 23 '10 at 12:37
Unless you are also running your IDE as root there is probably no easy or straight forward way to run your debugger as root. –  nategoose May 23 '10 at 21:50
hi, are you still active and might want to consider accepting an answer if there was any helpful? –  xmoex Oct 22 '13 at 12:24

6 Answers 6

  1. Enable your user to run as root without being asked for any password:
    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

share|improve this answer
This is a lifesaver. THANKS! –  Ziyao Wei Dec 7 '11 at 6:08
Thanks, now I can debug normally –  Guy L Jan 28 '13 at 14:19
I changed the debugger from gdb to sudo gdb and it works. –  Shahensha Nov 25 '13 at 11:19
This should come with a warning that when gdb is run as root then the user can do lots of nasty stuff, like attach to process 0 or make any other program do just about anything by issuing print system("be_evil.sh"); –  nategoose Jul 9 at 13:35
@nategoose thanks for your comment, you're absolutely right. I added a warning and referenced a possible alternative... –  xmoex Jul 10 at 17:06

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.

share|improve this answer

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

share|improve this answer

Another solution is to grant you (or the gdb executable) the rights to make some pcap captures as mentioned here. With something like this :

setcap cap_net_raw,cap_net_admin=eip /usr/bin/gdb

you should be able to allow to capture packets to gdb without being root.

share|improve this answer

this question was asked a long time ago but if this will help to anybody I open a bug in bugzilla and this short thread solved the problem: bugzilla bug

share|improve this answer

From the console in the directory with your executable:

sudo gdb ./my_program

If eclipse supports remote debugging then you could do that even though it is running locally.

From the console:

sudo gdbserver localhost:<port_number> ./my_program

And then tell Eclipse the address (localhost and the port number you chose).

Oh yeah, you said the reason you were doing this was because you were using libpcap, so you may not want to use remote debugging over TCP because you may end up capturing your debugging connection packets in addition to your other network traffic.

In that case you do your remote (but really local) debugging over a serial port. I have never done this on a local machine, but you could use two actual serial ports (attaching them though a null modem) or try using a psudoterminal:

sudo gdbserver /dev/ptmx ./my_program

This will create the psudo-terminal under /dev/pts/ but you'll have to figure out the name of it, and it might also create it with restrictive permissions. You can get around those. Unless you are running lots of terminal windows as root, it is not likely that you have many entries under /dev/pts that belong to root, so take note of the one that does after running the above command and then sudo chmod or sudo chown it to make it usable for your normal user and then tell your debugger to use that as your serial connection to your remote debugging target.

share|improve this answer

Your Answer


