Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging project with root in PyDev/LiClipse

For a project I'm doing, which uses scapy and therefore sockets, I need to be able to debug as root.

I have already figured out how to start the interpreter as root without the system asking for permission. I added:

user     ALL=(root) NOPASSWD:/home/user/git/Project/bin/python2.7

to /etc/sudoers.tmp. The path I used leads to the python interpreter of the virtual environment which I'm using for this project. The LiClipse project is also using this path. Now I only need to make LiClipse run the interpreter as root, but I don't want to start LiClipse as root. I just want it to use this interpreter as root when debugging. How can I do that?

like image 288
vicco Avatar asked Jan 18 '16 09:01

vicco


Video Answer


2 Answers

In this case, I suggest using remote debugging. You can then have the process running as whichever user it needs to, and the IDE can run independently as another user, or even on another server.

Assuming you're using PyDev in LiClipse, you can configure remote debugging by following the documentation for remote debugging.

The basic premise is that you add the pydev debugger library to your Python path and include the following where you need a breakpoint:

import pydevd
pydevd.settrace('localhost', port=7788, stdoutToServer=True, stderrToServer=True)

Then you configure your IDE with a pydev instance listening at that server (7788) in this case.

If you want to use breakpoints from the IDE, you can add the argument suspend=False, and the debugger will not suspend until it encounters your breakpoints.

like image 155
Dag Høidahl Avatar answered Oct 05 '22 22:10

Dag Høidahl


In PyDev you can actually select a shell script which in turn executes the actual Python to do the run... then, you can configure your shell script to first do any special setup.

I.e.: your script could be a file named python_on_root.sh with contents such as:

#!/bin/bash
source setup_env.bash
sudo python "$@"

Then, in the interpreter configuration, select the python_on_root.sh to create an interpreter that'll execute as root.

Note that the same could be done for other interesting things -- such as running in a docker container or activating a conda environment first -- sky is the limit ;)

like image 38
Fabio Zadrozny Avatar answered Oct 06 '22 00:10

Fabio Zadrozny