Skip to content

Commit 98d43cc

Browse files
dhly-etcEvergreen Agent
authored and
Evergreen Agent
committed
SERVER-75613 Add GDB pretty printers for immutable data structures
1 parent 80f7c41 commit 98d43cc

File tree

7 files changed

+572
-5
lines changed

7 files changed

+572
-5
lines changed

.gdbinit

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ source buildscripts/gdb/mongo_lock.py
1313

1414
# Load methods for printing in-memory contents of WT tables.
1515
source buildscripts/gdb/wt_dump_table.py
16+
17+
# Load third-party pretty printers
18+
source src/third_party/immer/dist/tools/gdb_pretty_printers/autoload.py

buildscripts/gdb/mongo_printers.py

+62-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
import gdb
1010
import gdb.printing
1111

12+
ROOT_PATH = str(Path(os.path.abspath(__file__)).parent.parent.parent)
13+
if ROOT_PATH not in sys.path:
14+
sys.path.insert(0, ROOT_PATH)
15+
from src.third_party.immer.dist.tools.gdb_pretty_printers.printers import ListIter as ImmerListIter # pylint: disable=wrong-import-position
16+
1217
if not gdb:
13-
sys.path.insert(0, str(Path(os.path.abspath(__file__)).parent.parent.parent))
1418
from buildscripts.gdb.mongo import get_boost_optional
1519
from buildscripts.gdb.optimizer_printers import register_abt_printers
1620

@@ -589,6 +593,61 @@ def children(self):
589593
yield ('value', kvp['value'])
590594

591595

596+
class ImmutableMapIter(ImmerListIter):
597+
def __init__(self, val):
598+
super().__init__(val)
599+
self.max = (1 << 64) - 1
600+
self.pair = None
601+
self.curr = (None, self.max, self.max)
602+
603+
def __next__(self):
604+
if self.pair:
605+
result = ('value', self.pair['second'])
606+
self.pair = None
607+
self.i += 1
608+
return result
609+
if self.i == self.size:
610+
raise StopIteration
611+
if self.i < self.curr[1] or self.i >= self.curr[2]:
612+
self.curr = self.region()
613+
self.pair = self.curr[0][self.i - self.curr[1]].cast(
614+
gdb.lookup_type(self.v.type.template_argument(0).name))
615+
result = ('key', self.pair['first'])
616+
return result
617+
618+
619+
class ImmutableMapPrinter:
620+
"""Pretty-printer for mongo::immutable::map<>."""
621+
622+
def __init__(self, val):
623+
self.val = val
624+
625+
def to_string(self):
626+
return '%s of size %d' % (self.val.type, int(self.val['_storage']['impl_']['size']))
627+
628+
def children(self):
629+
return ImmutableMapIter(self.val['_storage'])
630+
631+
def display_hint(self):
632+
return 'map'
633+
634+
635+
class ImmutableSetPrinter:
636+
"""Pretty-printer for mongo::immutable::set<>."""
637+
638+
def __init__(self, val):
639+
self.val = val
640+
641+
def to_string(self):
642+
return '%s of size %d' % (self.val.type, int(self.val['_storage']['impl_']['size']))
643+
644+
def children(self):
645+
return ImmerListIter(self.val['_storage'])
646+
647+
def display_hint(self):
648+
return 'array'
649+
650+
592651
def find_match_brackets(search, opening='<', closing='>'):
593652
"""Return the index of the closing bracket that matches the first opening bracket.
594653
@@ -914,6 +973,8 @@ def build_pretty_printer():
914973
pp.add('__wt_update', '__wt_update', False, WtUpdateToBsonPrinter)
915974
pp.add('CodeFragment', 'mongo::sbe::vm::CodeFragment', False, SbeCodeFragmentPrinter)
916975
pp.add('boost::optional', 'boost::optional', True, BoostOptionalPrinter)
976+
pp.add('immutable::map', 'mongo::immutable::map', True, ImmutableMapPrinter)
977+
pp.add('immutable::set', 'mongo::immutable::set', True, ImmutableSetPrinter)
917978

918979
# Optimizer/ABT related pretty printers that can be used only with a running process.
919980
register_abt_printers(pp)

src/third_party/immer/dist/README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. image:: https://github.com/arximboldi/immer/workflows/test/badge.svg
22
:target: https://github.com/arximboldi/immer/actions?query=workflow%3Atest+branch%3Amaster
3-
:alt: Github Actions Badge
3+
:alt: GitHub Actions Badge
44

55
.. image:: https://codecov.io/gh/arximboldi/immer/branch/master/graph/badge.svg
66
:target: https://codecov.io/gh/arximboldi/immer
@@ -74,7 +74,7 @@ Example
7474
For a **complete example** check `Ewig, a simple didactic
7575
text-editor <https://github.com/arximboldi/ewig>`_ built with this
7676
library. You may also wanna check `Lager, a Redux-like library
77-
<https://github.com/arximboldi/lager>`_ for writting interactive
77+
<https://github.com/arximboldi/lager>`_ for writing interactive
7878
software in C++ using a value-oriented design.
7979

8080

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import gdb.printing
2+
import os
3+
4+
path = os.path.dirname(__file__)
5+
if not path in sys.path:
6+
sys.path.append(path)
7+
from printers import immer_lookup_function
8+
9+
gdb.printing.register_pretty_printer(gdb.current_objfile(), immer_lookup_function)
10+
11+
print("immer gdb pretty-printers loaded")

0 commit comments

Comments
 (0)