1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:27:45 +00:00

Meta: Add a gdb pretty-printer for Optional

This commit is contained in:
Lucas CHOLLET 2023-06-20 17:36:57 -04:00 committed by Andreas Kling
parent 5bd9f4c31c
commit e5685078c1

View file

@ -42,6 +42,8 @@ def handler_class_for_type(type, re=re.compile('^([^<]+)(<.*>)?$')):
return AKStringImpl return AKStringImpl
elif klass == 'AK::Variant': elif klass == 'AK::Variant':
return AKVariant return AKVariant
elif klass == 'AK::Optional':
return AKOptional
elif klass == 'AK::Vector': elif klass == 'AK::Vector':
return AKVector return AKVector
elif klass == 'VirtualAddress': elif klass == 'VirtualAddress':
@ -229,6 +231,27 @@ class AKVariant:
return f'AK::Variant<{names}>' return f'AK::Variant<{names}>'
class AKOptional:
def __init__(self, val):
self.val = val
self.has_value = bool(self.val["m_has_value"])
self.contained_type = self.val.type.strip_typedefs().template_argument(0)
def to_string(self):
return AKOptional.prettyprint_type(self.val.type)
def children(self):
if self.has_value:
data = self.val["m_storage"]
return [(self.contained_type.name, data.cast(self.contained_type.pointer()).referenced_value())]
return [("OptionalNone", "{}")]
@classmethod
def prettyprint_type(cls, type):
template_type = type.template_argument(0)
return f'AK::Optional<{template_type}>'
class AKVector: class AKVector:
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val