From e13b89dd20f9270d6733f67e85bc711485945f3b Mon Sep 17 00:00:00 2001 From: Sebastian Zaha Date: Fri, 4 Aug 2023 19:31:38 +0200 Subject: [PATCH] Meta: Implement support for the new String in the gdb formatter The pretty-print gdb helpers were not updated since the DeprecatedString change. This commit introduces a new printer for String and renames the old one to DeprecatedString. --- Meta/serenity_gdb.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Meta/serenity_gdb.py b/Meta/serenity_gdb.py index 7e1273987e..0a74b12741 100644 --- a/Meta/serenity_gdb.py +++ b/Meta/serenity_gdb.py @@ -38,6 +38,8 @@ def handler_class_for_type(type, re=re.compile('^([^<]+)(<.*>)?$')): return AKSinglyLinkedList elif klass == 'AK::String': return AKString + elif klass == 'AK::DeprecatedString': + return AKDeprecatedString elif klass == 'AK::StringView': return AKStringView elif klass == 'AK::StringImpl': @@ -149,6 +151,24 @@ class AKString: def __init__(self, val): self.val = val + def to_string(self): + # Using the internal structure directly is quite convoluted here because of the packing optimizations + # of AK::String (could be a short string, a substring, or a normal string). + # This workaround was described in the gdb bugzilla on a discussion of supporting direct method calls + # on values: https://sourceware.org/bugzilla/show_bug.cgi?id=13326 + gdb.set_convenience_variable('_tmp', self.val.reference_value()) + string_view = gdb.parse_and_eval('$_tmp.bytes_as_string_view()') + return AKStringView(string_view).to_string() + + @classmethod + def prettyprint_type(cls, type): + return 'AK::String' + + +class AKDeprecatedString: + def __init__(self, val): + self.val = val + def to_string(self): if int(self.val["m_impl"]["m_ptr"]) == 0: return '""' @@ -158,7 +178,7 @@ class AKString: @classmethod def prettyprint_type(cls, type): - return 'AK::String' + return 'AK::DeprecatedString' class AKStringView: