]> git.lizzy.rs Git - rust.git/commitdiff
debuginfo: Don't mark struct fields as artificial.
authorMichael Woerister <michaelwoerister@posteo>
Thu, 2 Oct 2014 13:59:22 +0000 (15:59 +0200)
committerMichael Woerister <michaelwoerister@posteo>
Wed, 8 Oct 2014 09:52:06 +0000 (11:52 +0200)
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.

13 files changed:
src/etc/gdb_rust_pretty_printing.py
src/etc/lldb_rust_formatters.py
src/librustc/middle/trans/debuginfo.rs
src/test/debuginfo/borrowed-enum.rs
src/test/debuginfo/by-value-non-immediate-argument.rs
src/test/debuginfo/generic-struct-style-enum.rs
src/test/debuginfo/generic-tuple-style-enum.rs
src/test/debuginfo/method-on-enum.rs
src/test/debuginfo/struct-in-enum.rs
src/test/debuginfo/struct-style-enum.rs
src/test/debuginfo/tuple-style-enum.rs
src/test/debuginfo/unique-enum.rs
src/test/debuginfo/var-captured-in-nested-closure.rs

index e8a6427c1d7317cb6590835cc1e2347e1a7d7f1c..1af649f0731766c2c3db3612c5c204c16559569e 100644 (file)
@@ -196,7 +196,7 @@ def classify_struct(type):
   if field_count == 0:
     return STRUCT_KIND_REGULAR_STRUCT
 
-  if fields[0].artificial:
+  if fields[0].name == "RUST$ENUM$DISR":
     if field_count == 1:
       return STRUCT_KIND_CSTYLE_VARIANT
     elif fields[1].name == None:
index aa223019b5481188a90ebbb2dd2140b9a203f2ef..ca895414635b6ae302186430a78bfa85698cd34d 100644 (file)
@@ -117,11 +117,19 @@ def print_enum_val(val, internal_dict):
 
   assert val.GetType().GetTypeClass() == lldb.eTypeClassUnion
 
+
   if val.num_children == 1:
+    # This is either an enum with just one variant, or it is an Option-like enum
+    # where the discriminant is encoded in a non-nullable pointer field. We find
+    # out which one it is by looking at the member name of the sole union
+    # variant. If it starts with "RUST$ENCODED$ENUM$" then we have an
+    # Option-like enum.
     first_variant_name = val.GetChildAtIndex(0).GetName()
     if first_variant_name and first_variant_name.startswith("RUST$ENCODED$ENUM$"):
-      # Try to extract the
 
+      # This is an Option-like enum. The position of the discriminator field is
+      # encoded in the name which has the format:
+      #  RUST$ENCODED$ENUM$<index of discriminator field>$<name of null variant>
       last_separator_index = first_variant_name.rfind("$")
       if last_separator_index == -1:
         return "<invalid enum encoding: %s>" % first_variant_name
@@ -130,6 +138,7 @@ def print_enum_val(val, internal_dict):
       if second_last_separator_index == -1:
         return "<invalid enum encoding: %s>" % first_variant_name
 
+      # Extract index of the discriminator field
       try:
         disr_field_index = first_variant_name[second_last_separator_index + 1 :
                                               last_separator_index]
@@ -137,18 +146,22 @@ def print_enum_val(val, internal_dict):
       except:
         return "<invalid enum encoding: %s>" % first_variant_name
 
+      # Read the discriminant
       disr_val = val.GetChildAtIndex(0).GetChildAtIndex(disr_field_index).GetValueAsUnsigned()
 
       if disr_val == 0:
+        # Null case: Print the name of the null-variant
         null_variant_name = first_variant_name[last_separator_index + 1:]
         return null_variant_name
       else:
+        # Non-null case: Interpret the data as a value of the non-null variant type
         return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
     else:
+      # This is just a regular uni-variant enum without discriminator field
       return print_struct_val_starting_from(0, val.GetChildAtIndex(0), internal_dict)
 
-  # extract the discriminator value by
-  disr_val = val.GetChildAtIndex(0).GetChildAtIndex(0)
+  # If we are here, this is a regular enum with more than one variant
+  disr_val = val.GetChildAtIndex(0).GetChildMemberWithName("RUST$ENUM$DISR")
   disr_type = disr_val.GetType()
 
   if disr_type.GetTypeClass() != lldb.eTypeClassEnumeration:
index 7fbfe43c208ffd008c16c459cd6348600d6f6283..a2b7cb159d9dc17705476f1602a236e56b450ad8 100644 (file)
@@ -242,7 +242,6 @@ struct List {
 static UNKNOWN_SCOPE_METADATA: DIScope = (0 as DIScope);
 
 static FLAGS_NONE: c_uint = 0;
-static FLAGS_ARTIFICAL: c_uint = llvm::debuginfo::FlagArtificial as c_uint;
 
 //=-----------------------------------------------------------------------------
 //  Public Interface of debuginfo module
@@ -2276,11 +2275,7 @@ fn create_member_descriptions(&self, cx: &CrateContext) -> Vec<MemberDescription
                     _ => type_metadata(cx, ty, self.span)
                 },
                 offset: ComputedMemberOffset,
-                flags: if self.discriminant_type_metadata.is_some() &&  i == 0 {
-                    FLAGS_ARTIFICAL
-                } else {
-                    FLAGS_NONE
-                }
+                flags: FLAGS_NONE
             }
         }).collect()
     }
@@ -2339,9 +2334,9 @@ fn describe_enum_variant(cx: &CrateContext,
         None => variant_info.args.iter().map(|_| "".to_string()).collect()
     };
 
-    // If this is not a univariant enum, there is also the (unnamed) discriminant field.
+    // If this is not a univariant enum, there is also the discriminant field.
     match discriminant_info {
-        RegularDiscriminant(_) => arg_names.insert(0, "".to_string()),
+        RegularDiscriminant(_) => arg_names.insert(0, "RUST$ENUM$DISR".to_string()),
         _ => { /* do nothing */ }
     };
 
@@ -2713,14 +2708,14 @@ fn vec_slice_metadata(cx: &CrateContext,
             llvm_type: *member_llvm_types.get(0),
             type_metadata: element_type_metadata,
             offset: ComputedMemberOffset,
-            flags: FLAGS_ARTIFICAL
+            flags: FLAGS_NONE
         },
         MemberDescription {
             name: "length".to_string(),
             llvm_type: *member_llvm_types.get(1),
             type_metadata: type_metadata(cx, ty::mk_uint(), span),
             offset: ComputedMemberOffset,
-            flags: FLAGS_ARTIFICAL
+            flags: FLAGS_NONE
         },
     ];
 
index b6f5096c726a5ec172cea6d922e298b6f7c0ffd8..f018bd4668bb6e76e7dea7c087e22632792cbf9f 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
 // ignore-android: FIXME(#10381)
 
 // compile-flags:-g
 // gdb-command:finish
 
 // gdb-command:print *the_a_ref
-// gdb-check:$1 = {{TheA, x = 0, y = 8970181431921507452}, {TheA, 0, 2088533116, 2088533116}}
+// gdb-check:$1 = {{RUST$ENUM$DISR = TheA, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = TheA, 0, 2088533116, 2088533116}}
 
 // gdb-command:print *the_b_ref
-// gdb-check:$2 = {{TheB, x = 0, y = 1229782938247303441}, {TheB, 0, 286331153, 286331153}}
+// gdb-check:$2 = {{RUST$ENUM$DISR = TheB, x = 0, y = 1229782938247303441}, {RUST$ENUM$DISR = TheB, 0, 286331153, 286331153}}
 
 // gdb-command:print *univariant_ref
 // gdb-check:$3 = {{4820353753753434}}
index 2e1c4c79af0b336887a6f964fd5f84ba3122f535..60986c316176f3273b949ec1b316cfa055215a24 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
 // ignore-android: FIXME(#10381)
 
 // compile-flags:-g
@@ -43,7 +44,7 @@
 
 // gdb-command:finish
 // gdb-command:print x
-// gdb-check:$7 = {{Case1, x = 0, y = 8970181431921507452}, {Case1, 0, 2088533116, 2088533116}}
+// gdb-check:$7 = {{RUST$ENUM$DISR = Case1, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = Case1, 0, 2088533116, 2088533116}}
 // gdb-command:continue
 
 
index 7fec116b8e58255a4dab5a1f4ec630a14b6b5e93..c0a07a0137488fc641a13efc471942b60e2dadd7 100644 (file)
 // gdb-command:finish
 
 // gdb-command:print case1
-// 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}}
+// 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}}
 
 // gdb-command:print case2
-// 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}}
+// 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}}
 
 // gdb-command:print case3
-// 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}}
+// 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}}
 
 // gdb-command:print univariant
 // gdb-check:$4 = {{a = -1}}
index 8638ae3b49d890c58bfb5571ed3ad73c323c8063..867303d08777fe2668f8fcf6a2fa56e7376b982b 100644 (file)
 // gdb-command:finish
 
 // gdb-command:print case1
-// gdb-check:$1 = {{Case1, 0, 31868, 31868, 31868, 31868}, {Case1, 0, 2088533116, 2088533116}, {Case1, 0, 8970181431921507452}}
+// 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}}
 
 // gdb-command:print case2
-// gdb-check:$2 = {{Case2, 0, 4369, 4369, 4369, 4369}, {Case2, 0, 286331153, 286331153}, {Case2, 0, 1229782938247303441}}
+// 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}}
 
 // gdb-command:print case3
-// gdb-check:$3 = {{Case3, 0, 22873, 22873, 22873, 22873}, {Case3, 0, 1499027801, 1499027801}, {Case3, 0, 6438275382588823897}}
+// 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}}
 
 // gdb-command:print univariant
 // gdb-check:$4 = {{-1}}
index 74f4882bd4bf494918a01cb3515fcf98735a90c5..3e6ea221f486a2a92650749f7b9addd43e76f392 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
 // ignore-android: FIXME(#10381)
 
 // compile-flags:-g
@@ -20,7 +21,7 @@
 // STACK BY REF
 // gdb-command:finish
 // gdb-command:print *self
-// gdb-check:$1 = {{Variant2, [...]}, {Variant2, 117901063}}
+// gdb-check:$1 = {{RUST$ENUM$DISR = Variant2, [...]}, {RUST$ENUM$DISR = Variant2, 117901063}}
 // gdb-command:print arg1
 // gdb-check:$2 = -1
 // gdb-command:print arg2
@@ -30,7 +31,7 @@
 // STACK BY VAL
 // gdb-command:finish
 // gdb-command:print self
-// gdb-check:$4 = {{Variant2, [...]}, {Variant2, 117901063}}
+// gdb-check:$4 = {{RUST$ENUM$DISR = Variant2, [...]}, {RUST$ENUM$DISR = Variant2, 117901063}}
 // gdb-command:print arg1
 // gdb-check:$5 = -3
 // gdb-command:print arg2
@@ -40,7 +41,7 @@
 // OWNED BY REF
 // gdb-command:finish
 // gdb-command:print *self
-// gdb-check:$7 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
+// gdb-check:$7 = {{RUST$ENUM$DISR = Variant1, x = 1799, y = 1799}, {RUST$ENUM$DISR = Variant1, [...]}}
 // gdb-command:print arg1
 // gdb-check:$8 = -5
 // gdb-command:print arg2
@@ -50,7 +51,7 @@
 // OWNED BY VAL
 // gdb-command:finish
 // gdb-command:print self
-// gdb-check:$10 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
+// gdb-check:$10 = {{RUST$ENUM$DISR = Variant1, x = 1799, y = 1799}, {RUST$ENUM$DISR = Variant1, [...]}}
 // gdb-command:print arg1
 // gdb-check:$11 = -7
 // gdb-command:print arg2
@@ -60,7 +61,7 @@
 // OWNED MOVED
 // gdb-command:finish
 // gdb-command:print *self
-// gdb-check:$13 = {{Variant1, x = 1799, y = 1799}, {Variant1, [...]}}
+// gdb-check:$13 = {{RUST$ENUM$DISR = Variant1, x = 1799, y = 1799}, {RUST$ENUM$DISR = Variant1, [...]}}
 // gdb-command:print arg1
 // gdb-check:$14 = -9
 // gdb-command:print arg2
index d01119bce05338ce3c618c8d8feddd3f8259b671..d193cb78941118b03a588fd5d538a51d599ea816 100644 (file)
 // gdb-command:finish
 
 // gdb-command:print case1
-// gdb-check:$1 = {{Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {Case1, 0, 8970181431921507452, 31868}}
+// gdb-check:$1 = {{RUST$ENUM$DISR = Case1, 0, {x = 2088533116, y = 2088533116, z = 31868}}, {RUST$ENUM$DISR = Case1, 0, 8970181431921507452, 31868}}
 
 // gdb-command:print case2
-// gdb-check:$2 = {{Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {Case2, 0, 1229782938247303441, 4369}}
+// gdb-check:$2 = {{RUST$ENUM$DISR = Case2, 0, {x = 286331153, y = 286331153, z = 4369}}, {RUST$ENUM$DISR = Case2, 0, 1229782938247303441, 4369}}
 
 // gdb-command:print univariant
 // gdb-check:$3 = {{{x = 123, y = 456, z = 789}}}
index c3a5abf2d389a67e25c5b431938c885d2a7e5fe0..79f0dc52190c17d04ee00d40d9fe501484f880eb 100644 (file)
 // gdb-command:finish
 
 // gdb-command:print case1
-// 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}}
+// 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}}
 
 // gdb-command:print case2
-// 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}}
+// 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}}
 
 // gdb-command:print case3
-// 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}}
+// 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}}
 
 // gdb-command:print univariant
 // gdb-check:$4 = {{a = -1}}
index 7cd0a8f6164e8102816c3951a09dd3feb99a386f..ab06367512ab583df5615c1f4f8d67dcb0e961ff 100644 (file)
 // gdb-command:finish
 
 // gdb-command:print case1
-// gdb-check:$1 = {{Case1, 0, 31868, 31868, 31868, 31868}, {Case1, 0, 2088533116, 2088533116}, {Case1, 0, 8970181431921507452}}
+// 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}}
 
 // gdb-command:print case2
-// gdb-check:$2 = {{Case2, 0, 4369, 4369, 4369, 4369}, {Case2, 0, 286331153, 286331153}, {Case2, 0, 1229782938247303441}}
+// 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}}
 
 // gdb-command:print case3
-// gdb-check:$3 = {{Case3, 0, 22873, 22873, 22873, 22873}, {Case3, 0, 1499027801, 1499027801}, {Case3, 0, 6438275382588823897}}
+// 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}}
 
 // gdb-command:print univariant
 // gdb-check:$4 = {{-1}}
index 4c945e62abcd8cb057b1848c57d968d446c484c8..6932676df58cde64aeb2d7248be40310d1507a09 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-tidy-linelength
 // ignore-android: FIXME(#10381)
 
 // compile-flags:-g
 // gdb-command:finish
 
 // gdb-command:print *the_a
-// gdb-check:$1 = {{TheA, x = 0, y = 8970181431921507452}, {TheA, 0, 2088533116, 2088533116}}
+// gdb-check:$1 = {{RUST$ENUM$DISR = TheA, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = TheA, 0, 2088533116, 2088533116}}
 
 // gdb-command:print *the_b
-// gdb-check:$2 = {{TheB, x = 0, y = 1229782938247303441}, {TheB, 0, 286331153, 286331153}}
+// gdb-check:$2 = {{RUST$ENUM$DISR = TheB, x = 0, y = 1229782938247303441}, {RUST$ENUM$DISR = TheB, 0, 286331153, 286331153}}
 
 // gdb-command:print *univariant
 // gdb-check:$3 = {{123234}}
index d72f9256883c4557e04ebd72372f0bdf32ecea69..c46b1aca3b4c6ed47c5b9679373ec8ce70234cbf 100644 (file)
 // lldb-command:print *owned
 // lldb-check:[...]$4 = 6
 // lldb-command:print closure_local
-// lldb-check:[...]$6 = 8
+// lldb-check:[...]$5 = 8
 // lldb-command:continue
 
 // lldb-command:print variable
-// lldb-check:[...]$7 = 1
+// lldb-check:[...]$6 = 1
 // lldb-command:print constant
-// lldb-check:[...]$8 = 2
+// lldb-check:[...]$7 = 2
 // lldb-command:print a_struct
-// lldb-check:[...]$9 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-check:[...]$8 = Struct { a: -3, b: 4.5, c: 5 }
 // lldb-command:print *struct_ref
-// lldb-check:[...]$10 = Struct { a: -3, b: 4.5, c: 5 }
+// lldb-check:[...]$9 = Struct { a: -3, b: 4.5, c: 5 }
 // lldb-command:print *owned
-// lldb-check:[...]$11 = 6
+// lldb-check:[...]$10 = 6
 // lldb-command:print closure_local
-// lldb-check:[...]$13 = 8
+// lldb-check:[...]$11 = 8
 // lldb-command:continue
 
 #![allow(unused_variable)]