diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2015-04-06 11:39:51 -0700 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2015-04-12 20:44:25 +0200 |
| commit | 03f92694966259ee156bb8f3a7ef9d4dc587ecb9 (patch) | |
| tree | 9363dd3d1538fa2984f99607ce4fc5af72de6962 /src/etc | |
| parent | feeb23d42e0b1bc6f0466d4c6f035cfc3a4e9718 (diff) | |
| download | rust-03f92694966259ee156bb8f3a7ef9d4dc587ecb9.tar.gz rust-03f92694966259ee156bb8f3a7ef9d4dc587ecb9.zip | |
Add a name for tuple fields in debuginfo so that they can be accessed in debuggers.
Diffstat (limited to 'src/etc')
| -rwxr-xr-x | src/etc/gdb_rust_pretty_printing.py | 12 | ||||
| -rw-r--r-- | src/etc/lldb_rust_formatters.py | 28 |
2 files changed, 24 insertions, 16 deletions
diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index 4e489df7dd7..fc4d15a5168 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -9,6 +9,7 @@ # except according to those terms. import gdb +import re #=============================================================================== # GDB Pretty Printing Module for Rust @@ -299,12 +300,12 @@ def classify_struct(type): if fields[0].name == "RUST$ENUM$DISR": if field_count == 1: return STRUCT_KIND_CSTYLE_VARIANT - elif fields[1].name is None: + elif all_fields_conform_to_tuple_field_naming(fields, 1): return STRUCT_KIND_TUPLE_VARIANT else: return STRUCT_KIND_STRUCT_VARIANT - if fields[0].name is None: + if all_fields_conform_to_tuple_field_naming(fields, 0): if type.tag.startswith("("): return STRUCT_KIND_TUPLE else: @@ -325,7 +326,6 @@ def first_field(val): for field in val.type.fields(): return field - def get_field_at_index(val, index): i = 0 for field in val.type.fields(): @@ -334,6 +334,12 @@ def get_field_at_index(val, index): i += 1 return None +def all_fields_conform_to_tuple_field_naming(fields, start_index): + for i in range(start_index, len(fields)): + if (fields[i].name is None) or (re.match(r"__\d+$", fields[i].name) is None): + return False + return True + def extract_length_and_data_ptr_from_std_vec(vec_val): length = int(vec_val["len"]) vec_ptr_val = vec_val["ptr"] diff --git a/src/etc/lldb_rust_formatters.py b/src/etc/lldb_rust_formatters.py index 20f9b1ce66c..2aaa1588758 100644 --- a/src/etc/lldb_rust_formatters.py +++ b/src/etc/lldb_rust_formatters.py @@ -9,7 +9,7 @@ # except according to those terms. import lldb - +import re def print_val(val, internal_dict): '''Prints the given value with Rust syntax''' @@ -61,14 +61,14 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict): # The only field of this struct is the enum discriminant return type_name - has_field_names = type_has_field_names(t) + is_tuple_like = type_is_tuple_like(t) - if has_field_names: - template = "%(type_name)s {\n%(body)s\n}" - separator = ", \n" - else: + if is_tuple_like: template = "%(type_name)s(%(body)s)" separator = ", " + else: + template = "%(type_name)s {\n%(body)s\n}" + separator = ", \n" if type_name.startswith("("): # this is a tuple, so don't print the type name @@ -76,7 +76,7 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict): def render_child(child_index): this = "" - if has_field_names: + if not is_tuple_like: field_name = t.GetFieldAtIndex(child_index).GetName() this += field_name + ": " @@ -233,13 +233,15 @@ def extract_type_name(qualified_type_name): return qualified_type_name[index + 2:] -def type_has_field_names(ty): +def type_is_tuple_like(ty): '''Returns true of this is a type with field names (struct, struct-like enum variant)''' - # This may also be an enum variant where the first field doesn't have a name but the rest has - if ty.GetNumberOfFields() > 1: - return ty.GetFieldAtIndex(1).GetName() is not None - else: - return ty.GetFieldAtIndex(0).GetName() is not None + for field in ty.fields: + if field.GetName() == "RUST$ENUM$DISR": + # Ignore the enum discriminant field if there is one. + continue + if (field.GetName() is None) or (re.match(r"__\d+$", field.GetName()) is None): + return False + return True def is_vec_slice(val): |
