{"id":4950,"library":"gdbmongo","title":"GDBmongo","description":"GDBmongo provides GDB pretty printers and commands specifically designed for debugging the MongoDB Server. It enhances GDB's capabilities to better inspect complex MongoDB data structures. The library is actively maintained, with version 0.16.0 being the latest as of the last verification, and typically follows a periodic release cadence to keep up with MongoDB Server developments.","status":"active","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/visemet/gdb-mongodb-server","tags":["gdb","mongodb","debugging","pretty-printer","developer-tools"],"install":[{"cmd":"pip install gdbmongo","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Required Python version for the GDB's embedded interpreter.","package":"python","optional":false}],"imports":[{"note":"The 'gdb' module is only available within GDB's embedded Python interpreter. For gdbmongo, you import 'gdbmongo' which then registers its functionality with GDB.","wrong":"import gdb","symbol":"gdbmongo","correct":"import gdbmongo"},{"note":"Call this function within GDB's Python context (e.g., from .gdbinit) to enable the pretty printers.","symbol":"register_printers","correct":"gdbmongo.register_printers()"}],"quickstart":{"code":"# In your ~/.gdbinit file:\npython\ntry:\n    import gdbmongo\nexcept ImportError:\n    import sys\n    # Example: Attempt to install gdbmongo if not found (e.g., in a specific toolchain Python)\n    if sys.prefix.startswith('/opt/mongodbtoolchain/'): # Adjust path as needed for your environment\n        import subprocess\n        subprocess.run([sys.prefix + '/bin/python3', '-m', 'pip', 'install', 'gdbmongo'], check=True)\n        import gdbmongo\n    else:\n        import warnings\n        warnings.warn(\"Not attempting to install gdbmongo into non-MongoDB toolchain Python\")\n\n# Register printers if gdbmongo was successfully imported\nif 'gdbmongo' in dir():\n    gdbmongo.register_printers(essentials=True, stdlib=False, abseil=False, boost=False, mongo_extras=False)\nend","lang":"python","description":"To quickly integrate `gdbmongo` with GDB, add the provided Python snippet to your `~/.gdbinit` file. This script attempts to import `gdbmongo` and, if it fails, can optionally try to install it using `pip` within the GDB's Python environment (especially useful for specific toolchains). After import, it registers the essential pretty printers. You can then launch GDB and use commands like `(gdb) enable pretty-printer global gdbmongo-mongo-extras` to activate other collections."},"warnings":[{"fix":"Ensure `gdbmongo` is installed in the Python environment GDB is linked against (typically the base system Python), or explicitly manage `sys.path` within your `.gdbinit` to include the virtual environment's site-packages. The provided quickstart snippet includes a conditional install attempt for specific toolchains.","message":"GDB's embedded Python interpreter often uses the system's base Python installation, not necessarily a virtual environment from which GDB was launched. This can lead to `ImportError` if `gdbmongo` is installed only in a virtual environment.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To enable additional pretty printers (e.g., `mongo_extras`), explicitly pass `True` to `gdbmongo.register_printers()` (e.g., `gdbmongo.register_printers(mongo_extras=True)`), or enable them later within GDB using `(gdb) enable pretty-printer global gdbmongo-mongo-extras`.","message":"By default, `gdbmongo` pretty printer collections other than `gdbmongo-essentials` are disabled to prevent conflicts with pretty printers defined in the official `mongodb/mongo` repository.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always execute Python code that interacts with GDB's API (like `gdbmongo`) within GDB, typically by sourcing a Python script (`(gdb) source your_script.py`) or including it in your `.gdbinit` file.","message":"Directly `import gdb` or attempting to use GDB-specific Python functionality from a standard Python script outside of the GDB process will fail with an `ImportError`. The `gdb` module is part of GDB's embedded Python interpreter.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the `gdbmongo` project's documentation or changelog for specific compatibility notes regarding MongoDB Server versions. Regularly update `gdbmongo` to match the version of the MongoDB Server you are debugging to ensure optimal and correct functionality.","message":"As a debugging tool closely tied to the MongoDB Server's internal structures, `gdbmongo`'s functionality can be sensitive to major changes in MongoDB Server versions. Unforeseen behavior or incorrect pretty printing may occur if `gdbmongo` is used with a significantly different MongoDB Server version than it was developed for.","severity":"gotcha","affected_versions":"Inter-version compatibility"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}