Skip to main content

About

The gdbmongo package contains GDB pretty printers and commands for debugging the MongoDB Server. Its primary target audience is MongoDB employees.

Motivation

The gdbmongo package is mostly born out of joy from tinkering with low-level constructs while writing GDB pretty printers. There are some explicit areas for what it aims to achieve:

  1. GDB pretty printers and commands which only work against live MongoDB processes are of limited value. This is because the hang analyzer is only granted enough time in Evergreen to save a core file for each of the lingering processes. Further analysis is deferred until later by making use of these saved core files. GDB pretty printers and commands which are implemented by walking in-memory data structures and not by executing C++ code can run against core dumps and are therefore more widely applicable.

  2. New versions of the MongoDB Server are released regularly. Each new git branch fragments the tooling for testing the server. This can cause development on older branches to feel foreign and awkward because so many new enhancements were made in the meantime. Flipping the model so there’s a single version which attempts to work with all supported MongoDB versions can potentially enable more things to “just work.” Another way to think about it is that the new GDB pretty printers and commands may not be getting built for new MongoDB Server functionality and instead may be getting built for a newly-recognized debugging need.

Installation

The gdbmongo package must be loaded into the Python installation that the GDB process is running. In particular, launching gdb from within a Python virtual environment won’t give the GDB process access to the Python packages defined within the virtual environment. This is because gdb is dynamically linked against libpython and therefore always uses the site-packages of the base installation.

Adding the following snippet to a .gdbinit file will cause gdb at launch time to attempt to install the gdbmongo package if it isn’t already installed.

# In your ~/.gdbinit:
python
try:
    import gdbmongo
except ImportError:
    import sys
    if sys.prefix.startswith("/opt/mongodbtoolchain/"):
        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")

if "gdbmongo" in dir():
    gdbmongo.register_printers()
end

If you don’t plan to use the GDB pretty printers defined in the mongodb/mongo repository then you may want to consider enabling some of the other printers defined by the gdbmongo package by default.

register_printers(*, essentials=True, stdlib=False, abseil=False, boost=False, mongo_extras=False)

Register the pretty printers defined by the gdbmongo package with GDB itself.

The pretty printer collections other than gdbmongo-essentials are defaulted to off to avoid conflicting with the pretty printers defined in the mongodb/mongo repository.

Regardless of whether you choose to enable these other pretty printers by default, each of the gdbmongo-* pretty printer collections can still be enabled later on within GDB. For example, the gdbmongo-mongo-extras pretty printer collection can be enabled with the following command:

(gdb) enable pretty-printer global gdbmongo-mongo-extras

Tip: Use info pretty-printer, enable pretty-printer, disable pretty-printer, and print /r to inspect and toggle the state of any GDB pretty printers.

Usage

The gdbmongo package is a nascent GDB extension and quite limited in what it can do right now. But, if you’re looking to dump the contents of the global LockManager in a core dump, then you can run the following commands:

(gdb) python lock_mgr = gdbmongo.LockManagerPrinter.from_global()
(gdb) python print(lock_mgr.val)

Changelog

0.16.0 (2025-02-13)

  • Support binaries built with MongoDB v5 toolchain.

0.15.2 (2025-02-02)

  • Fix listing decorations of upcoming MongoDB 8.1. This includes accessing LockManager on global ServiceContext.

0.15.1 (2024-05-19)

  • Fix detecting libstdc++ version for Clang sanitizer builds.

  • Fix listing decorations of MongoDB 8.0. This includes accessing LockManager on global ServiceContext.

0.15.0 (2024-04-29)

  • Support dumping LockManager from core dump of MongoDB 8.0.

  • Fix mongo::StringData pretty printer and mongo::BSONObj pretty printer which consumes it.

0.14.0 (2023-09-30)

  • Include OperationContext* in output for LockManager dump.

0.13.0 (2023-09-29)

  • Include thread’s name and number in output for LockManager dump.

  • Fix detecting compiler version when cross-platform debugging.

0.12.0 (2023-09-22)

  • Support displaying thread names in core dump of MongoDB 4.4, 5.0, and 6.0.

0.11.0 (2023-09-16)

  • Support displaying contents of partitions within CursorManager.

0.10.0 (2023-09-03)

  • Support dumping LockManager from core dump of MongoDB 7.1.

0.9.0 (2023-08-26)

  • Support dumping LockManager from core dump of MongoDB 7.0.

0.8.1 (2023-03-04)

  • Fix two Python exceptions from thread names logic when no program or core dump was loaded.

  • Fix boost::optional pretty printer for scalar types.

0.8.0 (2023-02-04)

  • Always register gdbmongo pretty printers with GDB itself but continue defaulting them to off.

  • Support displaying thread names in core dump of MongoDB 6.2.

0.7.0 (2022-12-24)

  • Support binaries built with MongoDB v4 toolchain.

0.6.0 (2022-11-18)

  • Support dumping LockManager from core dump of MongoDB 6.2.

  • Fix resource type names in output of MongoDB 4.4.15, 5.0.10, and 6.0.0.

0.5.1 (2022-08-25)

  • Fix detecting MongoDB toolchain from –install-action=hardlink executables.

0.5.0 (2022-07-31)

  • Format BSON binary subtype 4 as UUID.

  • Include ErrorExtraInfo in output for Status and StatusWith<T>.

0.4.0 (2022-04-09)

  • Support detecting libstdc++ version in MongoDB binaries back to 4.2.0 and 4.4.0.

  • Support decoding BSONObjs even when they contain dates exceeding datetime.MAXYEAR (= 9999).

0.3.0 (2022-03-26)

  • Include database name in dump of DatabaseShardingState ResourceMutexes.

  • Avoid truncating namespace strings in LockManager dump.

0.2.0 (2022-03-05)

  • Support dumping LockManager from core dump of MongoDB 4.2, 4.4, and 5.0.

0.1.0 (2022-02-26)

  • Initial release.

  • Support dumping LockManager from core dump of MongoDB 5.3.

Metadata

Release files for gdbmongo 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gdbmongo 0.16.0
File Size Uploaded
gdbmongo-0.16.0.tar.gz 59.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gdbmongo 0.16.0
File Interpreter ABI Platform
gdbmongo-0.16.0-py3-none-any.whl Python 3 none any Details

Total release size: 125.8 kB

Release files / gdbmongo-0.16.0.tar.gz

Download URL gdbmongo-0.16.0.tar.gz
Size 59.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5bab61e2ec5b52b7f8374ee1834fc9cf0c7bf628acb1fda1132969073cd64660
BLAKE2b-256 checksum
How to use checksums
ad4a84b59862e49d3a959a7177446debc501bfdef8c1e8ea4c78e9647128f459
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.4

Release files / gdbmongo-0.16.0-py3-none-any.whl

Download URL gdbmongo-0.16.0-py3-none-any.whl
Size 66.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bafacaf8a0930010f495ae708bfe7e47420eca4d767bf2dc053307109065ae5
BLAKE2b-256 checksum
How to use checksums
71a802c3fa500597482ca74912bac433761984d5becd6b0a47bea45839eda9e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

0.16.0 This release

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page