|
9 | 9 | import gdb
|
10 | 10 | import gdb.printing
|
11 | 11 |
|
| 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 | + |
12 | 17 | if not gdb:
|
13 |
| - sys.path.insert(0, str(Path(os.path.abspath(__file__)).parent.parent.parent)) |
14 | 18 | from buildscripts.gdb.mongo import get_boost_optional
|
15 | 19 | from buildscripts.gdb.optimizer_printers import register_abt_printers
|
16 | 20 |
|
@@ -589,6 +593,61 @@ def children(self):
|
589 | 593 | yield ('value', kvp['value'])
|
590 | 594 |
|
591 | 595 |
|
| 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 | + |
592 | 651 | def find_match_brackets(search, opening='<', closing='>'):
|
593 | 652 | """Return the index of the closing bracket that matches the first opening bracket.
|
594 | 653 |
|
@@ -914,6 +973,8 @@ def build_pretty_printer():
|
914 | 973 | pp.add('__wt_update', '__wt_update', False, WtUpdateToBsonPrinter)
|
915 | 974 | pp.add('CodeFragment', 'mongo::sbe::vm::CodeFragment', False, SbeCodeFragmentPrinter)
|
916 | 975 | 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) |
917 | 978 |
|
918 | 979 | # Optimizer/ABT related pretty printers that can be used only with a running process.
|
919 | 980 | register_abt_printers(pp)
|
|
0 commit comments