Skip to content

Commit 824000a

Browse files
authored
Auto merge of #35585 - Kha:gdb-qualified, r=michaelwoerister
gdb: Fix pretty-printing special-cased Rust types gdb trunk now reports fully qualified type names, just like lldb. Move lldb code for extracting unqualified names to shared file. For current releases of gdb, `extract_type_name` should just be a no-op. Fixes #35155
2 parents 603d9cc + 4714072 commit 824000a

3 files changed

+20
-20
lines changed

src/etc/debugger_pretty_printers_common.py

+17
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,20 @@ def extract_length_and_ptr_from_slice(slice_val):
324324

325325
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
326326
return (length, data_ptr)
327+
328+
UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"])
329+
330+
def extract_type_name(qualified_type_name):
331+
'''Extracts the type name from a fully qualified path'''
332+
if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS:
333+
return qualified_type_name
334+
335+
end_of_search = qualified_type_name.find("<")
336+
if end_of_search < 0:
337+
end_of_search = len(qualified_type_name)
338+
339+
index = qualified_type_name.rfind("::", 0, end_of_search)
340+
if index < 0:
341+
return qualified_type_name
342+
else:
343+
return qualified_type_name[index + 2:]

src/etc/gdb_rust_pretty_printing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_unqualified_type_name(self):
3636
if tag is None:
3737
return tag
3838

39-
return tag.replace("&'static ", "&")
39+
return rustpp.extract_type_name(tag).replace("&'static ", "&")
4040

4141
def get_dwarf_type_kind(self):
4242
if self.ty.code == gdb.TYPE_CODE_STRUCT:

src/etc/lldb_rust_formatters.py

+2-19
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_unqualified_type_name(self):
2929
if qualified_name is None:
3030
return qualified_name
3131

32-
return extract_type_name(qualified_name).replace("&'static ", "&")
32+
return rustpp.extract_type_name(qualified_name).replace("&'static ", "&")
3333

3434
def get_dwarf_type_kind(self):
3535
type_class = self.ty.GetTypeClass()
@@ -204,7 +204,7 @@ def render_child(child_index):
204204
# LLDB is not good at handling zero-sized values, so we have to help
205205
# it a little
206206
if field.GetType().GetByteSize() == 0:
207-
return this + extract_type_name(field.GetType().GetName())
207+
return this + rustpp.extract_type_name(field.GetType().GetName())
208208
else:
209209
return this + "<invalid value>"
210210

@@ -274,23 +274,6 @@ def print_std_string_val(val, internal_dict):
274274
# Helper Functions
275275
#=--------------------------------------------------------------------------------------------------
276276

277-
UNQUALIFIED_TYPE_MARKERS = frozenset(["(", "[", "&", "*"])
278-
279-
def extract_type_name(qualified_type_name):
280-
'''Extracts the type name from a fully qualified path'''
281-
if qualified_type_name[0] in UNQUALIFIED_TYPE_MARKERS:
282-
return qualified_type_name
283-
284-
end_of_search = qualified_type_name.find("<")
285-
if end_of_search < 0:
286-
end_of_search = len(qualified_type_name)
287-
288-
index = qualified_type_name.rfind("::", 0, end_of_search)
289-
if index < 0:
290-
return qualified_type_name
291-
else:
292-
return qualified_type_name[index + 2:]
293-
294277
def print_array_of_values(array_name, data_ptr_val, length, internal_dict):
295278
'''Prints a contigous memory range, interpreting it as values of the
296279
pointee-type of data_ptr_val.'''

0 commit comments

Comments
 (0)