views:

288

answers:

2

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.

A: 

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.

nategoose
A: 

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

David Alfonso