GDB
此存储库包含一个 .gdbinit文件,其中包含有助于调试数据结构的辅助函数。如果您已将包含 文件的目录添加到.gdbinit GDB 的自动加载安全路径中,并且从包含 .gdbinit文件的目录启动 GDB,GDB 将自动加载此文件 。
您可以在 GDB 提示符下使用show auto-load safe-path查看安全路径。 您可以通过在~/.gdbinit中设置来进行配置:
add-auto-load-safe-path /path/to/mongo-c-driver 
如果您尚未将路径添加到自动加载安全路径中,或在其他目录中启动 GDB,请使用以下命令加载文件:
source path/to/mongo-c-driver/.gdbinit 
.gdbinit文件定义了printbson函数,该函数显示bson_t *变量的内容。 如果您有本地bson_t ,则必须在变量前加上&作为前缀。
GDB 会话示例如下:
(gdb) printbson bson ALLOC [0x555556cd7310 + 0] (len=475) {     'bool' : true,     'int32' : NumberInt("42"),     'int64' : NumberLong("3000000042"),     'string' : "Stŕìñg",     'objectId' : ObjectID("5A1442F3122D331C3C6757E1"),     'utcDateTime' : UTCDateTime(1511277299031),     'arrayOfInts' : [         '0' : NumberInt("1"),         '1' : NumberInt("2")     ],     'embeddedDocument' : {         'arrayOfStrings' : [             '0' : "one",             '1' : "two"         ],         'double' : 2.718280,         'notherDoc' : {             'true' : NumberInt("1"),             'false' : false         }     },     'binary' : Binary("02", "3031343532333637"),     'regex' : Regex("@[a-z]+@", "im"),     'null' : null,     'js' : JavaScript("print foo"),     'jsws' : JavaScript("print foo") with scope: {         'f' : NumberInt("42"),         'a' : [             '0' : 3.141593,             '1' : 2.718282         ]     },     'timestamp' : Timestamp(4294967295, 4294967295),     'double' : 3.141593 } 
LLDB
mongo-c-driver存储库包含一个脚本lldb_bson.py ,可以导入到 LLDB 会话中,并允许对BSON值进行丰富的检查。
注意
lldb_bson.py模块需要使用 Python 3.8或更高版本的 LLDB。
要激活脚本,请从 LLDB命令行其导入:
(lldb) command script import /path/to/mongo-c-driver/lldb_bson.py 
成功后,消息lldb_bson is ready将打印到 LLDB 控制台。
通过将该命令添加到.lldbinit文件,可以自动导入该脚本。 示例:创建文件~/.lldbinit ,其中包含:
command script import /path/to/mongo-c-driver/lldb_bson.py 
lldb_bson.py文件顶部的文档字符串包含有关该模块功能的更多信息。
调试断言
要启用运行时调试断言,请使用-DENABLE_DEBUG_ASSERTIONS=ON进行配置。