I don't use Eclipse for Ghidra myself, but as far as I just checked it should also support this. I can confirm that this approach (remote debugging plus Python stubs) works well with PyCharm.
Remote Debugging with pydevd
The basic idea is to use remote debugging with pydevd
or similar. https://stackoverflow.com/a/41492711/13220684 explains the basic usage.
The issue with this is that you will have to install pydevd
inside the Ghidra Jython environment. The following is adapted from https://github.com/VDOO-Connected-Trust/ghidra-pyi-generator#python-packages
# Create a virtualenv for Ghidra packages.
# It is important to use Python2.7 for this venv!
# If you want, you can skip this step and use your default Python installation.
mkvirtualenv ghidra
# Create Jython's site-pacakges directory.
jython_site_packages="~/.local/lib/jython2.7/site-packages"
mkdir -p $jython_site_packages
# Create a PTH file to point Jython to Python's site-packages directories.
# Again, this has to be Python2.7.
# Outside a virtualenv, use
python -c "import site; print(site.getusersitepackages()); print(site.getsitepackages()[-1])" > $jython_site_packages/python.pth
# If using virtualenv, use the following instead
python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" > $jython_site_packages/python.pth
# Use pip to install packages for Ghidra
pip install pydevd
It should now be possible to import pydevd
inside a Ghidra Python script (or even the integrated REPL).
I don't remember if the GhidraDev plugin for eclipse provides tab completion for the ghidra
module inside Python scripts, but this setup is generic enough that you are not required to use Eclipse anymore if you prefer another IDE for Python.
The IDE only needs to support remote debugging via pydevd
. I also strongly recommend using https://github.com/VDOO-Connected-Trust/ghidra-pyi-generator if you are using another IDE to provide the type information, method signatures and docstrings of the Ghidra API to the IDE.
Another Workaround
Personally I use mostly ghidra_bridge
and the previously mentioned type stubs for Python with Ghidra. Because ghidra_bridge
is a full RPC interface, you can write a Python 3 script with full IDE support and run it via the IDE. ghidra_bridge
then handles the connection to the Ghidra Python environment and proxies all the relevant objects. With the type stubs the IDE just treats the script as generic Python script and the ghidra
module like any Python 3 module.