Skip to content

Instantly share code, notes, and snippets.

@tyhoff
Last active February 10, 2021 21:20
Show Gist options
  • Save tyhoff/060e480b6cf9ad35dfd2ba9d01cad4b6 to your computer and use it in GitHub Desktop.
Save tyhoff/060e480b6cf9ad35dfd2ba9d01cad4b6 to your computer and use it in GitHub Desktop.
.gdbinit modifications for using a Virtual/Conda environment with GDB Python scripts
# All of your normal .gdbinit commands, functions, and setup tasks
# Update GDB's Python paths with the `sys.path` values of the local Python installation,
# whether that is brew'ed Python, a virtualenv, or another system python.
# Convert GDB to interpret in Python
python
import os,subprocess,sys
# Execute a Python using the user's shell and pull out the sys.path (for site-packages)
paths = subprocess.check_output('python -c "import os,sys;print(os.linesep.join(sys.path).strip())"',shell=True).decode("utf-8").split()
# Extend GDB's Python's search path
sys.path.extend(paths)
end
@tyhoff
Copy link
Author

tyhoff commented Apr 12, 2020

This was created for users to get around GDB not loading the activated virtual environments Python modules

If you are looking for an equivalent .lldbinit version, check out the other Gist:
https://gist.github.com/tyhoff/7a286945ef75947ad49a347dbc8708ca

@phil-blain
Copy link

Hi @tyhoff ! thanks for providing this workaround.

Just a quick note: if you use conda, you can also simply install GDB through conda (from the conda-forge channel). The conda-forge GDB is built with the Python from conda-forge and so will automatically look for packages in the conda environment, so you would not need the above workaround. LLDB is also available from conda-forge, but I did not succeed in using it to debug on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment