GDBmongo
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.
Warnings
- gotcha 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.
- gotcha 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.
- gotcha 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.
- gotcha 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.
Install
-
pip install gdbmongo
Imports
- gdbmongo
import gdbmongo
- register_printers
gdbmongo.register_printers()
Quickstart
# In your ~/.gdbinit file:
python
try:
import gdbmongo
except ImportError:
import sys
# Example: Attempt to install gdbmongo if not found (e.g., in a specific toolchain Python)
if sys.prefix.startswith('/opt/mongodbtoolchain/'): # Adjust path as needed for your environment
import subprocess
subprocess.run([sys.prefix + '/bin/python3', '-m', 'pip', 'install', 'gdbmongo'], check=True)
import gdbmongo
else:
import warnings
warnings.warn("Not attempting to install gdbmongo into non-MongoDB toolchain Python")
# Register printers if gdbmongo was successfully imported
if 'gdbmongo' in dir():
gdbmongo.register_printers(essentials=True, stdlib=False, abseil=False, boost=False, mongo_extras=False)
end