conda-forge / gdb-feedstock

A conda-smithy repository for gdb.
BSD 3-Clause "New" or "Revised" License
17 stars 62 forks source link

How to `import gdb` #62

Open AntoinePrv opened 1 year ago

AntoinePrv commented 1 year ago

Comment:

I'm trying to set up the pretty printing function from the following in my ~/.gdbinit to find the gdb and libstdcxx modules.

import sys
import shutil
import pathlib

gdb_path = pathlib.Path(shutil.which("gdb")).resolve()
share_path = gdb_path.parent.parent / "share"

sys.path.insert(0, str(share_path / "gdb/python"))

for p in share_path.glob("gcc*"):
    if p.is_dir() and (p / "python").exists():
        sys.path.insert(0, str(p / "python"))
        from libstdcxx.v6.printers import register_libstdcxx_printers
        register_libstdcxx_printers(None)
        break

However, I do get the error:

File $CONDA_PREFIX/share/gdb/python/gdb/__init__.py:19
     17 import os
     18 import sys
---> 19 import _gdb
     20 from contextlib import contextmanager
     22 # Python 3 moved "reload"

ModuleNotFoundError: No module named '_gdb'

Looking around, it seems like _gdb is a Python extension module. Is it shipping with gdb? I cannot find any such module in the gdb conda-forge package.

phil-blain commented 9 months ago

Hi!

I'm trying to set up the pretty printing function from the following in my ~/.gdbinit to find the gdb and libstdcxx modules.

Usually if everything is configured correctly, the libstdcxx pretty printers should "work outside the box".

How are you installing GCC ?

phil-blain commented 9 months ago

Also, providing the conda list and conda info as the issue template asks would help pinpoint where the issue is :)