-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaligned_printer.py
46 lines (36 loc) · 1.66 KB
/
aligned_printer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
###
# Copyright 2023-present MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
"""Pretty-printer for the mongo::Aligned<T> type."""
import gdb
from gdbmongo.boost_printers import SingletonPrinterBase
from gdbmongo.gdbutil import gdb_resolve_type
from gdbmongo.printer_protocol import PrettyPrinterProtocol
class AlignedPrinter(PrettyPrinterProtocol, SingletonPrinterBase):
# pylint: disable=missing-function-docstring
"""Pretty-printer for mongo::Aligned<T>."""
def __init__(self, val: gdb.Value, /) -> None:
self.element_type = val.type.template_argument(0)
self.val = val
gdb_resolve_type(self.element_type)
def to_string(self) -> str:
return f"mongo::Aligned<{self.element_type}>"
def value(self) -> gdb.Value:
storage = self.val["_storage"]["__data"]
contained_value = storage.cast(self.element_type.pointer()).dereference()
return contained_value
def add_printers(pretty_printer: gdb.printing.RegexpCollectionPrettyPrinter, /) -> None:
"""Add the AlignedPrinter to the pretty printer collection given."""
pretty_printer.add_printer("mongo::Aligned", "^mongo::Aligned<.*>$", AlignedPrinter)