Skip to content

Commit 98a0f91

Browse files
debuginfo: Don't mark struct fields as artificial.
LLDB doesn't allow for reading 'artifical' fields (fields that are generated by the compiler). So do not mark, slice fields, enum discriminants, and GcBox value fields as artificial.
1 parent 895aac9 commit 98a0f91

13 files changed

+57
-45
lines changed

src/etc/gdb_rust_pretty_printing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def classify_struct(type):
196196
if field_count == 0:
197197
return STRUCT_KIND_REGULAR_STRUCT
198198

199-
if fields[0].artificial:
199+
if fields[0].name == "RUST$ENUM$DISR":
200200
if field_count == 1:
201201
return STRUCT_KIND_CSTYLE_VARIANT
202202
elif fields[1].name == None:

src/etc/lldb_rust_formatters.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,19 @@ def print_enum_val(val, internal_dict):
117117

118118
assert val.GetType().GetTypeClass() == lldb.eTypeClassUnion
119119

120+
120121
if val.num_children == 1:
122+
# This is either an enum with just one variant, or it is an Option-like enum
123+
# where the discriminant is encoded in a non-nullable pointer field. We find
124+
# out which one it is by looking at the member name of the sole union
125+
# variant. If it starts with "RUST$ENCODED$ENUM$" then we have an
126+
# Option-like enum.
121127
first_variant_name = val.GetChildAtIndex(0).GetName()
122128
if first_variant_name and first_variant_name.startswith("RUST$ENCODED$ENUM$"):
123-
# Try to extract the
124129

130+
# This is an Option-like enum. The position of the discriminator field is
131+
# encoded in the name which has the format:
132+
# RUST$ENCODED$ENUM$<index of discriminator field>$<name of null variant>
125133
last_separator_index = first_variant_name.rfind("$")
126134
if last_separator_index == -1:
127135
return "<invalid enum encoding: %s>" % first_variant_name
@@ -130,25 +138,30 @@ def print_enum_val(val, internal_dict):
130138
if second_last_separator_index == -1:
131139
return "<invalid enum encoding: %s>" % first_variant_name
132140

141+
# Extract index of the discriminator field
133142
try:
134143
disr_field_index = first_variant_name[second_last_separator_index + 1 :
135144
last_separator_index]
136145
disr_field_index = int(disr_field_index)
137146
except:
138147
return "<invalid enum encoding: %s>" % first_variant_name
139148

149+
# Read the discriminant
140150
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
141151

142152
if disr_val == 0:
153+
# Null case: Print the name of the null-variant
143154
null_variant_name = first_variant_name[last_separator_index + 1:]
144155
return null_variant_name
145156
else:
157+
# Non-null case: Interpret the data as a value of the non-null variant type
146158
return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
147159
else:
160+
# This is just a regular uni-variant enum without discriminator field
148161
return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
149162

150-
# extract the discriminator value by
151-
disr_val = val.GetChildAtIndex(0).GetChildAtIndex(0)
163+
# If we are here, this is a regular enum with more than one variant
164+
disr_val = val.GetChildAtIndex(0).GetChildMemberWithName("RUST$ENUM$DISR")
152165
disr_type = disr_val.GetType()
153166

154167
if disr_type.GetTypeClass() != lldb.eTypeClassEnumeration:

src/librustc/middle/trans/debuginfo.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ static UNKNOWN_FILE_METADATA: DIFile = (0 as DIFile);
242242
static UNKNOWN_SCOPE_METADATA: DIScope = (0 as DIScope);
243243

244244
static FLAGS_NONE: c_uint = 0;
245-
static FLAGS_ARTIFICAL: c_uint = llvm::debuginfo::FlagArtificial as c_uint;
246245

247246
//=-----------------------------------------------------------------------------
248247
// Public Interface of debuginfo module
@@ -2276,11 +2275,7 @@ impl VariantMemberDescriptionFactory {
22762275
_ => type_metadata(cx, ty, self.span)
22772276
},
22782277
offset: ComputedMemberOffset,
2279-
flags: if self.discriminant_type_metadata.is_some() && i == 0 {
2280-
FLAGS_ARTIFICAL
2281-
} else {
2282-
FLAGS_NONE
2283-
}
2278+
flags: FLAGS_NONE
22842279
}
22852280
}).collect()
22862281
}
@@ -2339,9 +2334,9 @@ fn describe_enum_variant(cx: &CrateContext,
23392334
None => variant_info.args.iter().map(|_| "".to_string()).collect()
23402335
};
23412336

2342-
// If this is not a univariant enum, there is also the (unnamed) discriminant field.
2337+
// If this is not a univariant enum, there is also the discriminant field.
23432338
match discriminant_info {
2344-
RegularDiscriminant(_) => arg_names.insert(0, "".to_string()),
2339+
RegularDiscriminant(_) => arg_names.insert(0, "RUST$ENUM$DISR".to_string()),
23452340
_ => { /* do nothing */ }
23462341
};
23472342

@@ -2713,14 +2708,14 @@ fn vec_slice_metadata(cx: &CrateContext,
27132708
llvm_type: *member_llvm_types.get(0),
27142709
type_metadata: element_type_metadata,
27152710
offset: ComputedMemberOffset,
2716-
flags: FLAGS_ARTIFICAL
2711+
flags: FLAGS_NONE
27172712
},
27182713
MemberDescription {
27192714
name: "length".to_string(),
27202715
llvm_type: *member_llvm_types.get(1),
27212716
type_metadata: type_metadata(cx, ty::mk_uint(), span),
27222717
offset: ComputedMemberOffset,
2723-
flags: FLAGS_ARTIFICAL
2718+
flags: FLAGS_NONE
27242719
},
27252720
];
27262721

src/test/debuginfo/borrowed-enum.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
1112
// ignore-android: FIXME(#10381)
1213

1314
// compile-flags:-g
@@ -19,10 +20,10 @@
1920
// gdb-command:finish
2021

2122
// gdb-command:print *the_a_ref
22-
// gdb-check:$1 = {{TheA, x = 0, y = 8970181431921507452}, {TheA, 0, 2088533116, 2088533116}}
23+
// gdb-check:$1 = {{RUST$ENUM$DISR = TheA, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = TheA, 0, 2088533116, 2088533116}}
2324

2425
// gdb-command:print *the_b_ref
25-
// gdb-check:$2 = {{TheB, x = 0, y = 1229782938247303441}, {TheB, 0, 286331153, 286331153}}
26+
// gdb-check:$2 = {{RUST$ENUM$DISR = TheB, x = 0, y = 1229782938247303441}, {RUST$ENUM$DISR = TheB, 0, 286331153, 286331153}}
2627

2728
// gdb-command:print *univariant_ref
2829
// gdb-check:$3 = {{4820353753753434}}

src/test/debuginfo/by-value-non-immediate-argument.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
1112
// ignore-android: FIXME(#10381)
1213

1314
// compile-flags:-g
@@ -43,7 +44,7 @@
4344

4445
// gdb-command:finish
4546
// gdb-command:print x
46-
// gdb-check:$7 = {{Case1, x = 0, y = 8970181431921507452}, {Case1, 0, 2088533116, 2088533116}}
47+
// gdb-check:$7 = {{RUST$ENUM$DISR = Case1, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = Case1, 0, 2088533116, 2088533116}}
4748
// gdb-command:continue
4849

4950

src/test/debuginfo/generic-struct-style-enum.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
// gdb-command:finish
1919

2020
// gdb-command:print case1
21-
// gdb-check:$1 = {{Case1, a = 0, b = 31868, c = 31868, d = 31868, e = 31868}, {Case1, a = 0, b = 2088533116, c = 2088533116}, {Case1, a = 0, b = 8970181431921507452}}
21+
// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, a = 0, b = 31868, c = 31868, d = 31868, e = 31868}, {RUST$ENUM$DISR = Case1, a = 0, b = 2088533116, c = 2088533116}, {RUST$ENUM$DISR = Case1, a = 0, b = 8970181431921507452}}
2222

2323
// gdb-command:print case2
24-
// gdb-check:$2 = {{Case2, a = 0, b = 4369, c = 4369, d = 4369, e = 4369}, {Case2, a = 0, b = 286331153, c = 286331153}, {Case2, a = 0, b = 1229782938247303441}}
24+
// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, a = 0, b = 4369, c = 4369, d = 4369, e = 4369}, {RUST$ENUM$DISR = Case2, a = 0, b = 286331153, c = 286331153}, {RUST$ENUM$DISR = Case2, a = 0, b = 1229782938247303441}}
2525

2626
// gdb-command:print case3
27-
// gdb-check:$3 = {{Case3, a = 0, b = 22873, c = 22873, d = 22873, e = 22873}, {Case3, a = 0, b = 1499027801, c = 1499027801}, {Case3, a = 0, b = 6438275382588823897}}
27+
// gdb-check:$3 = {{RUST$ENUM$DISR = Case3, a = 0, b = 22873, c = 22873, d = 22873, e = 22873}, {RUST$ENUM$DISR = Case3, a = 0, b = 1499027801, c = 1499027801}, {RUST$ENUM$DISR = Case3, a = 0, b = 6438275382588823897}}
2828

2929
// gdb-command:print univariant
3030
// gdb-check:$4 = {{a = -1}}

src/test/debuginfo/generic-tuple-style-enum.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
// gdb-command:finish
2222

2323
// gdb-command:print case1
24-
// gdb-check:$1 = {{Case1, 0, 31868, 31868, 31868, 31868}, {Case1, 0, 2088533116, 2088533116}, {Case1, 0, 8970181431921507452}}
24+
// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, 0, 31868, 31868, 31868, 31868}, {RUST$ENUM$DISR = Case1, 0, 2088533116, 2088533116}, {RUST$ENUM$DISR = Case1, 0, 8970181431921507452}}
2525

2626
// gdb-command:print case2
27-
// gdb-check:$2 = {{Case2, 0, 4369, 4369, 4369, 4369}, {Case2, 0, 286331153, 286331153}, {Case2, 0, 1229782938247303441}}
27+
// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, 0, 4369, 4369, 4369, 4369}, {RUST$ENUM$DISR = Case2, 0, 286331153, 286331153}, {RUST$ENUM$DISR = Case2, 0, 1229782938247303441}}
2828

2929
// gdb-command:print case3
30-
// gdb-check:$3 = {{Case3, 0, 22873, 22873, 22873, 22873}, {Case3, 0, 1499027801, 1499027801}, {Case3, 0, 6438275382588823897}}
30+
// gdb-check:$3 = {{RUST$ENUM$DISR = Case3, 0, 22873, 22873, 22873, 22873}, {RUST$ENUM$DISR = Case3, 0, 1499027801, 1499027801}, {RUST$ENUM$DISR = Case3, 0, 6438275382588823897}}
3131

3232
// gdb-command:print univariant
3333
// gdb-check:$4 = {{-1}}

src/test/debuginfo/method-on-enum.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
1112
// ignore-android: FIXME(#10381)
1213

1314
// compile-flags:-g
@@ -20,7 +21,7 @@
2021
// STACK BY REF
2122
// gdb-command:finish
2223
// gdb-command:print *self
23-
// gdb-check:$1 = {{Variant2, [...]}, {Variant2, 117901063}}
24+
// gdb-check:$1 = {{RUST$ENUM$DISR = Variant2, [...]}, {RUST$ENUM$DISR = Variant2, 117901063}}
2425
// gdb-command:print arg1
2526
// gdb-check:$2 = -1
2627
// gdb-command:print arg2
@@ -30,7 +31,7 @@
3031
// STACK BY VAL
3132
// gdb-command:finish
3233
// gdb-command:print self
33-
// gdb-check:$4 = {{Variant2, [...]}, {Variant2, 117901063}}
34+
// gdb-check:$4 = {{RUST$ENUM$DISR = Variant2, [...]}, {RUST$ENUM$DISR = Variant2, 117901063}}
3435
// gdb-command:print arg1
3536
// gdb-check:$5 = -3
3637
// gdb-command:print arg2
@@ -40,7 +41,7 @@
4041
// OWNED BY REF
4142
// gdb-command:finish
4243
// gdb-command:print *self
43-
// gdb-check:$7 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
44+
// gdb-check:$7 = {{RUST$ENUM$DISR = Variant1, x = 1799, y = 1799}, {RUST$ENUM$DISR = Variant1, [...]}}
4445
// gdb-command:print arg1
4546
// gdb-check:$8 = -5
4647
// gdb-command:print arg2
@@ -50,7 +51,7 @@
5051
// OWNED BY VAL
5152
// gdb-command:finish
5253
// gdb-command:print self
53-
// gdb-check:$10 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
54+
// gdb-check:$10 = {{RUST$ENUM$DISR = Variant1, x = 1799, y = 1799}, {RUST$ENUM$DISR = Variant1, [...]}}
5455
// gdb-command:print arg1
5556
// gdb-check:$11 = -7
5657
// gdb-command:print arg2
@@ -60,7 +61,7 @@
6061
// OWNED MOVED
6162
// gdb-command:finish
6263
// gdb-command:print *self
63-
// gdb-check:$13 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
64+
// gdb-check:$13 = {{RUST$ENUM$DISR = Variant1, x = 1799, y = 1799}, {RUST$ENUM$DISR = Variant1, [...]}}
6465
// gdb-command:print arg1
6566
// gdb-check:$14 = -9
6667
// gdb-command:print arg2

src/test/debuginfo/struct-in-enum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
// gdb-command:finish
2222

2323
// gdb-command:print case1
24-
// gdb-check:$1 = {{Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {Case1, 0, 8970181431921507452, 31868}}
24+
// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {RUST$ENUM$DISR = Case1, 0, 8970181431921507452, 31868}}
2525

2626
// gdb-command:print case2
27-
// gdb-check:$2 = {{Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {Case2, 0, 1229782938247303441, 4369}}
27+
// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {RUST$ENUM$DISR = Case2, 0, 1229782938247303441, 4369}}
2828

2929
// gdb-command:print univariant
3030
// gdb-check:$3 = {{{x = 123, y = 456, z = 789}}}

src/test/debuginfo/struct-style-enum.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
// gdb-command:finish
2222

2323
// gdb-command:print case1
24-
// gdb-check:$1 = {{Case1, a = 0, b = 31868, c = 31868, d = 31868, e = 31868}, {Case1, a = 0, b = 2088533116, c = 2088533116}, {Case1, a = 0, b = 8970181431921507452}}
24+
// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, a = 0, b = 31868, c = 31868, d = 31868, e = 31868}, {RUST$ENUM$DISR = Case1, a = 0, b = 2088533116, c = 2088533116}, {RUST$ENUM$DISR = Case1, a = 0, b = 8970181431921507452}}
2525

2626
// gdb-command:print case2
27-
// gdb-check:$2 = {{Case2, a = 0, b = 4369, c = 4369, d = 4369, e = 4369}, {Case2, a = 0, b = 286331153, c = 286331153}, {Case2, a = 0, b = 1229782938247303441}}
27+
// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, a = 0, b = 4369, c = 4369, d = 4369, e = 4369}, {RUST$ENUM$DISR = Case2, a = 0, b = 286331153, c = 286331153}, {RUST$ENUM$DISR = Case2, a = 0, b = 1229782938247303441}}
2828

2929
// gdb-command:print case3
30-
// gdb-check:$3 = {{Case3, a = 0, b = 22873, c = 22873, d = 22873, e = 22873}, {Case3, a = 0, b = 1499027801, c = 1499027801}, {Case3, a = 0, b = 6438275382588823897}}
30+
// gdb-check:$3 = {{RUST$ENUM$DISR = Case3, a = 0, b = 22873, c = 22873, d = 22873, e = 22873}, {RUST$ENUM$DISR = Case3, a = 0, b = 1499027801, c = 1499027801}, {RUST$ENUM$DISR = Case3, a = 0, b = 6438275382588823897}}
3131

3232
// gdb-command:print univariant
3333
// gdb-check:$4 = {{a = -1}}

src/test/debuginfo/tuple-style-enum.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
// gdb-command:finish
2222

2323
// gdb-command:print case1
24-
// gdb-check:$1 = {{Case1, 0, 31868, 31868, 31868, 31868}, {Case1, 0, 2088533116, 2088533116}, {Case1, 0, 8970181431921507452}}
24+
// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, 0, 31868, 31868, 31868, 31868}, {RUST$ENUM$DISR = Case1, 0, 2088533116, 2088533116}, {RUST$ENUM$DISR = Case1, 0, 8970181431921507452}}
2525

2626
// gdb-command:print case2
27-
// gdb-check:$2 = {{Case2, 0, 4369, 4369, 4369, 4369}, {Case2, 0, 286331153, 286331153}, {Case2, 0, 1229782938247303441}}
27+
// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, 0, 4369, 4369, 4369, 4369}, {RUST$ENUM$DISR = Case2, 0, 286331153, 286331153}, {RUST$ENUM$DISR = Case2, 0, 1229782938247303441}}
2828

2929
// gdb-command:print case3
30-
// gdb-check:$3 = {{Case3, 0, 22873, 22873, 22873, 22873}, {Case3, 0, 1499027801, 1499027801}, {Case3, 0, 6438275382588823897}}
30+
// gdb-check:$3 = {{RUST$ENUM$DISR = Case3, 0, 22873, 22873, 22873, 22873}, {RUST$ENUM$DISR = Case3, 0, 1499027801, 1499027801}, {RUST$ENUM$DISR = Case3, 0, 6438275382588823897}}
3131

3232
// gdb-command:print univariant
3333
// gdb-check:$4 = {{-1}}

src/test/debuginfo/unique-enum.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
1112
// ignore-android: FIXME(#10381)
1213

1314
// compile-flags:-g
@@ -19,10 +20,10 @@
1920
// gdb-command:finish
2021

2122
// gdb-command:print *the_a
22-
// gdb-check:$1 = {{TheA, x = 0, y = 8970181431921507452}, {TheA, 0, 2088533116, 2088533116}}
23+
// gdb-check:$1 = {{RUST$ENUM$DISR = TheA, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = TheA, 0, 2088533116, 2088533116}}
2324

2425
// gdb-command:print *the_b
25-
// gdb-check:$2 = {{TheB, x = 0, y = 1229782938247303441}, {TheB, 0, 286331153, 286331153}}
26+
// gdb-check:$2 = {{RUST$ENUM$DISR = TheB, x = 0, y = 1229782938247303441}, {RUST$ENUM$DISR = TheB, 0, 286331153, 286331153}}
2627

2728
// gdb-command:print *univariant
2829
// gdb-check:$3 = {{123234}}

src/test/debuginfo/var-captured-in-nested-closure.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@
6363
// lldb-command:print *owned
6464
// lldb-check:[...]$4 = 6
6565
// lldb-command:print closure_local
66-
// lldb-check:[...]$6 = 8
66+
// lldb-check:[...]$5 = 8
6767
// lldb-command:continue
6868

6969
// lldb-command:print variable
70-
// lldb-check:[...]$7 = 1
70+
// lldb-check:[...]$6 = 1
7171
// lldb-command:print constant
72-
// lldb-check:[...]$8 = 2
72+
// lldb-check:[...]$7 = 2
7373
// lldb-command:print a_struct
74-
// lldb-check:[...]$9 = Struct { a: -3, b: 4.5, c: 5 }
74+
// lldb-check:[...]$8 = Struct { a: -3, b: 4.5, c: 5 }
7575
// lldb-command:print *struct_ref
76-
// lldb-check:[...]$10 = Struct { a: -3, b: 4.5, c: 5 }
76+
// lldb-check:[...]$9 = Struct { a: -3, b: 4.5, c: 5 }
7777
// lldb-command:print *owned
78-
// lldb-check:[...]$11 = 6
78+
// lldb-check:[...]$10 = 6
7979
// lldb-command:print closure_local
80-
// lldb-check:[...]$13 = 8
80+
// lldb-check:[...]$11 = 8
8181
// lldb-command:continue
8282

8383
#![allow(unused_variable)]

0 commit comments

Comments
 (0)