Skip to content

Commit

Permalink
gdb: Fix pretty-printing special-cased Rust types
Browse files Browse the repository at this point in the history
gdb trunk now reports fully qualified type names, just like lldb. Move
lldb code for extracting unqualified names to shared file.
  • Loading branch information
Kha committed Aug 11, 2016
1 parent 080e0e0 commit 4714072
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
17 changes: 17 additions & 0 deletions src/etc/debugger_pretty_printers_common.py
Expand Up @@ -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:]
2 changes: 1 addition & 1 deletion src/etc/gdb_rust_pretty_printing.py
Expand Up @@ -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:
Expand Down
21 changes: 2 additions & 19 deletions src/etc/lldb_rust_formatters.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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 + "<invalid value>"

Expand Down Expand Up @@ -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.'''
Expand Down

0 comments on commit 4714072

Please sign in to comment.