Skip to content

Instantly share code, notes, and snippets.

@tyhoff
Last active March 17, 2025 17:13
Show Gist options
  • Select an option

  • Save tyhoff/060e480b6cf9ad35dfd2ba9d01cad4b6 to your computer and use it in GitHub Desktop.

Select an option

Save tyhoff/060e480b6cf9ad35dfd2ba9d01cad4b6 to your computer and use it in GitHub Desktop.

Revisions

  1. tyhoff revised this gist Apr 13, 2020. No changes.
  2. tyhoff revised this gist Apr 13, 2020. No changes.
  3. tyhoff revised this gist Apr 12, 2020. 1 changed file with 4 additions and 6 deletions.
    10 changes: 4 additions & 6 deletions .gdbinit
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,9 @@

    # Convert GDB to interpret in Python
    python
    import sys
    import os
    import subprocess
    # Execute a Python using the user's shell and pull out the sys.path from that version
    paths = eval(subprocess.check_output('python -c "import sys;print(sys.path)"', shell=True).strip())
    # Extend the current GDB instance's Python paths
    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
  4. tyhoff revised this gist Jul 25, 2019. No changes.
  5. tyhoff created this gist Jul 15, 2019.
    15 changes: 15 additions & 0 deletions .gdbinit
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    # 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 sys
    import os
    import subprocess
    # Execute a Python using the user's shell and pull out the sys.path from that version
    paths = eval(subprocess.check_output('python -c "import sys;print(sys.path)"', shell=True).strip())
    # Extend the current GDB instance's Python paths
    sys.path.extend(paths)
    end