summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-06-15 13:28:11 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-16 15:33:37 +0000
commit3fae1b46947a58618e1f1f68e0ca8ba85d499ef8 (patch)
treeaa21be0c691746d71402a75dc7ff7055a7b42e03
parent2aca88acdf18714923961fdfd6c99915f56570a5 (diff)
downloadmongo-3fae1b46947a58618e1f1f68e0ca8ba85d499ef8.tar.gz
SERVER-56626 RecordId GDB pretty printer
(cherry picked from commit 6abf79a4a8ae87059fb6a1fdc14d34a4bc59d1ff)
-rw-r--r--buildscripts/gdb/mongo_printers.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/buildscripts/gdb/mongo_printers.py b/buildscripts/gdb/mongo_printers.py
index 6adf0f3b3b0..7f75e42c891 100644
--- a/buildscripts/gdb/mongo_printers.py
+++ b/buildscripts/gdb/mongo_printers.py
@@ -188,6 +188,37 @@ class UUIDPrinter(object):
return str(uuid.UUID("".join(uuid_hex_bytes)))
+class RecordIdPrinter(object):
+ """Pretty-printer for mongo::RecordId."""
+
+ def __init__(self, val):
+ """Initialize RecordIdPrinter."""
+ self.val = val
+
+ @staticmethod
+ def display_hint():
+ """Display hint."""
+ return 'string'
+
+ def to_string(self):
+ """Return RecordId for printing."""
+ buf_size = 16
+ rid_format = self.val["_buffer"][buf_size - 1]
+ if rid_format == 0:
+ return "null"
+ elif rid_format == 1:
+ hex_bytes = [int(self.val['_buffer'][i]) for i in range(8)]
+ raw_bytes = bytes(hex_bytes)
+ return struct.unpack('l', raw_bytes)[0]
+ elif rid_format == 2:
+ str_len = int(self.val["_buffer"][0])
+ raw_bytes = [int(self.val['_buffer'][i]) for i in range(1, str_len + 1)]
+ hex_bytes = [hex(b & 0xFF)[2:].zfill(2) for b in raw_bytes]
+ return str("".join(hex_bytes))
+ else:
+ return "invalid RecordId format"
+
+
class DecorablePrinter(object):
"""Pretty-printer for mongo::Decorable<>."""
@@ -578,6 +609,7 @@ def build_pretty_printer():
pp.add('node_hash_set', 'absl::node_hash_set', True, AbslNodeHashSetPrinter)
pp.add('flat_hash_map', 'absl::flat_hash_map', True, AbslFlatHashMapPrinter)
pp.add('flat_hash_set', 'absl::flat_hash_set', True, AbslFlatHashSetPrinter)
+ pp.add('RecordId', 'mongo::RecordId', False, RecordIdPrinter)
pp.add('UUID', 'mongo::UUID', False, UUIDPrinter)
pp.add('__wt_cursor', '__wt_cursor', False, WtCursorPrinter)
pp.add('__wt_session_impl', '__wt_session_impl', False, WtSessionImplPrinter)