mirror of https://github.com/mongodb/mongo
SERVER-87668 Implement pretty printers for MatchExpression (#44297)
GitOrigin-RevId: 3409cc9e8eaeca6465710a1552060cfe90311588
This commit is contained in:
parent
540027140c
commit
2992f11709
|
|
@ -807,6 +807,25 @@ class ImmutableSetPrinter:
|
|||
return "array"
|
||||
|
||||
|
||||
class MatchExpressionPrinter:
|
||||
"""Pretty-printer for mongo::MatchExpression."""
|
||||
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def to_string(self):
|
||||
gdb.set_convenience_variable("_mep_tmp", self.val.reference_value())
|
||||
return (
|
||||
gdb.parse_and_eval("$_mep_tmp.toString()")
|
||||
.format_string()
|
||||
.encode()
|
||||
.decode("unicode_escape")[1:-1]
|
||||
)
|
||||
|
||||
def display_hint(self):
|
||||
return "map"
|
||||
|
||||
|
||||
def find_match_brackets(search, opening="<", closing=">"):
|
||||
"""Return the index of the closing bracket that matches the first opening bracket.
|
||||
|
||||
|
|
@ -1177,6 +1196,7 @@ def build_pretty_printer():
|
|||
pp.add("boost::optional", "boost::optional", True, BoostOptionalPrinter)
|
||||
pp.add("immutable::map", "mongo::immutable::map", True, ImmutableMapPrinter)
|
||||
pp.add("immutable::set", "mongo::immutable::set", True, ImmutableSetPrinter)
|
||||
pp.add("MatchExpression", "mongo::MatchExpression", False, MatchExpressionPrinter)
|
||||
|
||||
# Optimizer/ABT related pretty printers that can be used only with a running process.
|
||||
register_optimizer_printers(pp)
|
||||
|
|
|
|||
|
|
@ -29,10 +29,6 @@ except ImportError:
|
|||
|
||||
def __lldb_init_module(debugger, *_args):
|
||||
"""Register pretty printers."""
|
||||
debugger.HandleCommand(
|
||||
"type summary add -s 'A${*var.__ptr_.__value_}' -x '^std::__1::unique_ptr<.+>$'"
|
||||
)
|
||||
|
||||
debugger.HandleCommand("type summary add -s '${var._value}' -x '^mongo::AtomicWord<.+>$'")
|
||||
debugger.HandleCommand("type summary add -s '${var._M_base._M_i}' 'std::atomic<bool>'")
|
||||
debugger.HandleCommand("type summary add -s '${var._M_i}' -x '^std::atomic<.+>$'")
|
||||
|
|
@ -61,9 +57,6 @@ def __lldb_init_module(debugger, *_args):
|
|||
debugger.HandleCommand(
|
||||
"type synthetic add -x '^boost::optional<.+>$' --python-class lldb_printers.OptionalPrinter"
|
||||
)
|
||||
debugger.HandleCommand(
|
||||
"type synthetic add -x '^std::unique_ptr<.+>$' --python-class lldb_printers.UniquePtrPrinter"
|
||||
)
|
||||
|
||||
debugger.HandleCommand(
|
||||
"type summary add -x '^boost::optional<.+>$' -F lldb_printers.OptionalSummaryPrinter"
|
||||
|
|
@ -79,6 +72,10 @@ def __lldb_init_module(debugger, *_args):
|
|||
"type synthetic add -x '^mongo::stdx::unordered_map<.+>$' --python-class lldb_printers.AbslHashSetPrinter"
|
||||
)
|
||||
|
||||
debugger.HandleCommand(
|
||||
"type summary add mongo::MatchExpression -F lldb_printers.MatchExpressionPrinter"
|
||||
)
|
||||
|
||||
|
||||
#############################
|
||||
# Pretty Printer Defintions #
|
||||
|
|
@ -223,48 +220,6 @@ def Decimal128Printer(valobj, *_args):
|
|||
return Decimal128((high64, low64))
|
||||
|
||||
|
||||
class UniquePtrPrinter:
|
||||
"""Pretty printer for std::unique_ptr."""
|
||||
|
||||
def __init__(self, valobj, *_args):
|
||||
"""Store valobj and retrieve object held at the unique_ptr."""
|
||||
self.valobj = valobj
|
||||
self.update()
|
||||
|
||||
def num_children(self):
|
||||
"""Match LLDB's expected API."""
|
||||
return 1
|
||||
|
||||
def get_child_index(self, name):
|
||||
"""Match LLDB's expected API."""
|
||||
if name == "ptr":
|
||||
return 0
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_child_at_index(self, index):
|
||||
"""Match LLDB's expected API.
|
||||
|
||||
Always prints object pointed at by the ptr.
|
||||
"""
|
||||
if index == 0:
|
||||
return (
|
||||
self.valobj.GetChildMemberWithName("__ptr_")
|
||||
.GetChildMemberWithName("__value_")
|
||||
.Dereference()
|
||||
)
|
||||
else:
|
||||
return None
|
||||
|
||||
def has_children(self):
|
||||
"""Match LLDB's expected API."""
|
||||
return True
|
||||
|
||||
def update(self):
|
||||
"""Match LLDB's expected API."""
|
||||
pass
|
||||
|
||||
|
||||
class OptionalPrinter:
|
||||
"""Pretty printer for boost::optional."""
|
||||
|
||||
|
|
@ -537,3 +492,9 @@ def dump_value(value):
|
|||
print("value.value: %s" % (value.value))
|
||||
print("value.value_type: %s" % (value.value_type))
|
||||
print("----------------------------------------")
|
||||
|
||||
|
||||
def MatchExpressionPrinter(valobj, *_args):
|
||||
return (
|
||||
valobj.EvaluateExpression("toString()").GetSummary().encode().decode("unicode_escape")[1:-1]
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue