Skip to content

Commit 7191cd9

Browse files
committed
lldb: Clean up struct printing
1 parent 0ab0104 commit 7191cd9

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

src/etc/lldb_rust_formatters.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,33 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict):
7171
t = val.GetType()
7272
has_field_names = type_has_field_names(t)
7373
type_name = extract_type_name(t.GetName())
74-
output = ""
75-
76-
if not type_name.startswith("("):
77-
# this is a tuple, so don't print the type name
78-
output += type_name
7974

8075
if has_field_names:
81-
output += " { \n"
76+
template = "%(type_name)s {\n%(body)s\n}"
77+
separator = ", \n"
8278
else:
83-
output += "("
79+
template = "%(type_name)s(%(body)s)"
80+
separator = ", "
81+
82+
if type_name.startswith("("):
83+
# this is a tuple, so don't print the type name
84+
type_name = ""
8485

8586
num_children = val.num_children
8687

87-
for child_index in range(field_start_index, num_children):
88+
def render_child(child_index):
89+
this = ""
8890
if has_field_names:
8991
field_name = t.GetFieldAtIndex(child_index).GetName()
90-
output += field_name + ": "
92+
this += field_name + ": "
9193

9294
field_val = val.GetChildAtIndex(child_index)
93-
output += print_val(field_val, internal_dict)
95+
return this + print_val(field_val, internal_dict)
9496

95-
if child_index != num_children - 1:
96-
output += ", "
97+
body = separator.join([render_child(idx) for idx in range(field_start_index, num_children)])
9798

98-
if has_field_names:
99-
output += "\n"
100-
101-
if has_field_names:
102-
output += "}"
103-
else:
104-
output += ")"
105-
106-
return output
99+
return template % {"type_name": type_name,
100+
"body": body}
107101

108102

109103
def print_enum_val(val, internal_dict):

0 commit comments

Comments
 (0)