Skip to content

Instantly share code, notes, and snippets.

@tyhoff
Last active March 17, 2025 17:13
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
@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