|
26 | 26 | import gdb
|
27 | 27 |
|
28 | 28 | from gdbmongo.objectid_printer import MongoOID
|
| 29 | +from gdbmongo.printer_protocol import SupportsToString |
29 | 30 | from gdbmongo.string_data_printer import MongoStringData
|
30 | 31 |
|
31 | 32 |
|
@@ -212,3 +213,62 @@ def to_value(self) -> gdb.Value:
|
212 | 213 |
|
213 | 214 | setattr(MongoBSONSymbol, "_fields_",
|
214 | 215 | [(field.name, field.type) for field in dataclasses.fields(MongoBSONSymbol)])
|
| 216 | + |
| 217 | + |
| 218 | +# pylint: disable-next=too-few-public-methods |
| 219 | +class UndefinedLabelerPrinter(SupportsToString): |
| 220 | + # pylint: disable=missing-function-docstring |
| 221 | + """Pretty-printer for literal undefined value.""" |
| 222 | + |
| 223 | + def __init__(self, val: gdb.Value, /) -> None: |
| 224 | + self.val = val |
| 225 | + |
| 226 | + def to_string(self) -> str: |
| 227 | + return "undefined" |
| 228 | + |
| 229 | + |
| 230 | +# pylint: disable-next=too-few-public-methods |
| 231 | +class NullLabelerPrinter(SupportsToString): |
| 232 | + # pylint: disable=missing-function-docstring |
| 233 | + """Pretty-printer for literal null value.""" |
| 234 | + |
| 235 | + def __init__(self, val: gdb.Value, /) -> None: |
| 236 | + self.val = val |
| 237 | + |
| 238 | + def to_string(self) -> str: |
| 239 | + return "null" |
| 240 | + |
| 241 | + |
| 242 | +# pylint: disable-next=too-few-public-methods |
| 243 | +class MinKeyLabelerPrinter(SupportsToString): |
| 244 | + # pylint: disable=missing-function-docstring |
| 245 | + """Pretty-printer for literal MinKey value.""" |
| 246 | + |
| 247 | + def __init__(self, val: gdb.Value, /) -> None: |
| 248 | + self.val = val |
| 249 | + |
| 250 | + def to_string(self) -> str: |
| 251 | + return "MinKey()" |
| 252 | + |
| 253 | + |
| 254 | +# pylint: disable-next=too-few-public-methods |
| 255 | +class MaxKeyLabelerPrinter(SupportsToString): |
| 256 | + # pylint: disable=missing-function-docstring |
| 257 | + """Pretty-printer for literal MaxKey value.""" |
| 258 | + |
| 259 | + def __init__(self, val: gdb.Value, /) -> None: |
| 260 | + self.val = val |
| 261 | + |
| 262 | + def to_string(self) -> str: |
| 263 | + return "MaxKey()" |
| 264 | + |
| 265 | + |
| 266 | +def add_printers(pretty_printer: gdb.printing.RegexpCollectionPrettyPrinter, /) -> None: |
| 267 | + """Add the BSON-related printers to the pretty printer collection given.""" |
| 268 | + pretty_printer.add_printer("mongo::MaxKeyLabeler", "^mongo::MaxKeyLabeler$", |
| 269 | + MaxKeyLabelerPrinter) |
| 270 | + pretty_printer.add_printer("mongo::MinKeyLabeler", "^mongo::MinKeyLabeler$", |
| 271 | + MinKeyLabelerPrinter) |
| 272 | + pretty_printer.add_printer("mongo::NullLabeler", "^mongo::NullLabeler$", NullLabelerPrinter) |
| 273 | + pretty_printer.add_printer("mongo::UndefinedLabeler", "^mongo::UndefinedLabeler$", |
| 274 | + UndefinedLabelerPrinter) |
0 commit comments