diff --git a/src/etc/debugger_pretty_printers_common.py b/src/etc/debugger_pretty_printers_common.py index b2bb7859661ab..e713c7c8387fc 100644 --- a/src/etc/debugger_pretty_printers_common.py +++ b/src/etc/debugger_pretty_printers_common.py @@ -324,3 +324,20 @@ def extract_length_and_ptr_from_slice(slice_val): assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR return (length, data_ptr) + +UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"]) + +def extract_type_name(qualified_type_name): + '''Extracts the type name from a fully qualified path''' + if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS: + return qualified_type_name + + end_of_search = qualified_type_name.find("<") + if end_of_search < 0: + end_of_search = len(qualified_type_name) + + index = qualified_type_name.rfind("::", 0, end_of_search) + if index < 0: + return qualified_type_name + else: + return qualified_type_name[index + 2:] diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index cc5f621cb6be0..9b163c835c650 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -36,7 +36,7 @@ def get_unqualified_type_name(self): if tag is None: return tag - return tag.replace("&'static ", "&") + return rustpp.extract_type_name(tag).replace("&'static ", "&") def get_dwarf_type_kind(self): if self.ty.code == gdb.TYPE_CODE_STRUCT: diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py index c22a60abf3f76..c0a4c3e9ece93 100644 --- a/src/etc/lldb_rust_formatters.py +++ b/src/etc/lldb_rust_formatters.py @@ -29,7 +29,7 @@ def get_unqualified_type_name(self): if qualified_name is None: return qualified_name - return extract_type_name(qualified_name).replace("&'static ", "&") + return rustpp.extract_type_name(qualified_name).replace("&'static ", "&") def get_dwarf_type_kind(self): type_class = self.ty.GetTypeClass() @@ -204,7 +204,7 @@ def render_child(child_index): # LLDB is not good at handling zero-sized values, so we have to help # it a little if field.GetType().GetByteSize() == 0: - return this + extract_type_name(field.GetType().GetName()) + return this + rustpp.extract_type_name(field.GetType().GetName()) else: return this + "" @@ -274,23 +274,6 @@ def print_std_string_val(val, internal_dict): # Helper Functions #=-------------------------------------------------------------------------------------------------- -UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"]) - -def extract_type_name(qualified_type_name): - '''Extracts the type name from a fully qualified path''' - if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS: - return qualified_type_name - - end_of_search = qualified_type_name.find("<") - if end_of_search < 0: - end_of_search = len(qualified_type_name) - - index = qualified_type_name.rfind("::", 0, end_of_search) - if index < 0: - return qualified_type_name - else: - return qualified_type_name[index + 2:] - def print_array_of_values(array_name, data_ptr_val, length, internal_dict): '''Prints a contigous memory range, interpreting it as values of the pointee-type of data_ptr_val.'''