llvm.org GIT mirror llvm / bc67646
Fix llvm-symbolizer to navigate both DW_AT_abstract_origin and DW_AT_specification in a single chain In a recent refactoring (r291959) this regressed to only following one or the other, not both, in a single chain. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297676 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 3 years ago
3 changed file(s) with 28 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
145145 /// exist in this DIE.
146146 Optional find(ArrayRef Attrs) const;
147147
148 /// Extract an attribute value from this DIE and recurse into any
149 /// DW_AT_specification or DW_AT_abstract_origin referenced DIEs.
150 ///
151 /// \param Attr the attribute to extract.
152 /// \returns an optional DWARFFormValue that will have the form value if the
153 /// attribute was successfully extracted.
154 Optional findRecursively(dwarf::Attribute Attr) const;
155
156148 /// Extract the first value of any attribute in Attrs from this DIE and
157149 /// recurse into any DW_AT_specification or DW_AT_abstract_origin referenced
158150 /// DIEs.
149149 }
150150
151151 Optional
152 DWARFDie::findRecursively(dwarf::Attribute Attr) const {
153 if (!isValid())
154 return None;
155 if (auto Value = find(Attr))
156 return Value;
157 if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
158 if (auto Value = Die.find(Attr))
159 return Value;
160 if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification))
161 if (auto Value = Die.find(Attr))
162 return Value;
163 return None;
164 }
165
166 Optional
167152 DWARFDie::find(ArrayRef Attrs) const {
168153 if (!isValid())
169154 return None;
181166 DWARFDie::findRecursively(ArrayRef Attrs) const {
182167 if (!isValid())
183168 return None;
184 if (auto Value = find(Attrs))
169 auto Die = *this;
170 if (auto Value = Die.find(Attrs))
185171 return Value;
186 if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
187 if (auto Value = Die.find(Attrs))
188 return Value;
189 if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification))
190 if (auto Value = Die.find(Attrs))
191 return Value;
172 if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
173 Die = D;
174 if (auto Value = Die.find(Attrs))
175 return Value;
176 if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
177 Die = D;
178 if (auto Value = Die.find(Attrs))
179 return Value;
192180 return None;
193181 }
194182
12781278 dwarfgen::Generator *DG = ExpectedDG.get().get();
12791279 dwarfgen::CompileUnit &CU = DG->addCompileUnit();
12801280
1281 StringRef SpecDieName("spec");
1282 StringRef AbsDieName("abs");
1281 StringRef SpecDieName = "spec";
1282 StringRef SpecLinkageName = "spec_linkage";
1283 StringRef AbsDieName = "abs";
12831284 // Scope to allow us to re-use the same DIE names
12841285 {
12851286 auto CUDie = CU.getUnitDIE();
12861287 auto FuncSpecDie = CUDie.addChild(DW_TAG_subprogram);
1288 auto FuncAbsDie = CUDie.addChild(DW_TAG_subprogram);
12871289 auto FuncDie = CUDie.addChild(DW_TAG_subprogram);
12881290 auto VarAbsDie = CUDie.addChild(DW_TAG_variable);
12891291 auto VarDie = CUDie.addChild(DW_TAG_variable);
12901292 FuncSpecDie.addAttribute(DW_AT_name, DW_FORM_strp, SpecDieName);
1291 FuncDie.addAttribute(DW_AT_specification, DW_FORM_ref4, FuncSpecDie);
1293 FuncAbsDie.addAttribute(DW_AT_linkage_name, DW_FORM_strp, SpecLinkageName);
1294 FuncAbsDie.addAttribute(DW_AT_specification, DW_FORM_ref4, FuncSpecDie);
1295 FuncDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, FuncAbsDie);
12921296 VarAbsDie.addAttribute(DW_AT_name, DW_FORM_strp, AbsDieName);
12931297 VarDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, VarAbsDie);
12941298 }
13081312 EXPECT_TRUE(CUDie.isValid());
13091313
13101314 auto FuncSpecDie = CUDie.getFirstChild();
1311 auto FuncDie = FuncSpecDie.getSibling();
1315 auto FuncAbsDie = FuncSpecDie.getSibling();
1316 auto FuncDie = FuncAbsDie.getSibling();
13121317 auto VarAbsDie = FuncDie.getSibling();
13131318 auto VarDie = VarAbsDie.getSibling();
13141319
13151320 // Make sure we can't extract the name from the specification die when using
13161321 // DWARFDie::find() since it won't check the DW_AT_specification DIE.
1317 EXPECT_FALSE(FuncDie.find(DW_AT_name).hasValue());
1322 EXPECT_FALSE(FuncDie.find(DW_AT_name));
13181323
13191324 // Make sure we can extract the name from the specification die when using
13201325 // DWARFDie::findRecursively() since it should recurse through the
13211326 // DW_AT_specification DIE.
13221327 auto NameOpt = FuncDie.findRecursively(DW_AT_name);
1323 EXPECT_TRUE(NameOpt.hasValue());
1328 EXPECT_TRUE(NameOpt);
13241329 // Test the dwarf::toString() helper function.
13251330 auto StringOpt = toString(NameOpt);
1326 EXPECT_TRUE(StringOpt.hasValue());
1331 EXPECT_TRUE(StringOpt);
13271332 EXPECT_EQ(SpecDieName, StringOpt.getValueOr(nullptr));
13281333 // Test the dwarf::toString() helper function with a default value specified.
13291334 EXPECT_EQ(SpecDieName, toString(NameOpt, nullptr));
1335
1336 auto LinkageNameOpt = FuncDie.findRecursively(DW_AT_linkage_name);
1337 EXPECT_EQ(SpecLinkageName, toString(LinkageNameOpt).getValueOr(nullptr));
13301338
13311339 // Make sure we can't extract the name from the abstract origin die when using
13321340 // DWARFDie::find() since it won't check the DW_AT_abstract_origin DIE.
1333 EXPECT_FALSE(VarDie.find(DW_AT_name).hasValue());
1341 EXPECT_FALSE(VarDie.find(DW_AT_name));
13341342
13351343 // Make sure we can extract the name from the abstract origin die when using
13361344 // DWARFDie::findRecursively() since it should recurse through the
13371345 // DW_AT_abstract_origin DIE.
13381346 NameOpt = VarDie.findRecursively(DW_AT_name);
1339 EXPECT_TRUE(NameOpt.hasValue());
1347 EXPECT_TRUE(NameOpt);
13401348 // Test the dwarf::toString() helper function.
13411349 StringOpt = toString(NameOpt);
1342 EXPECT_TRUE(StringOpt.hasValue());
1350 EXPECT_TRUE(StringOpt);
13431351 EXPECT_EQ(AbsDieName, StringOpt.getValueOr(nullptr));
1344 // Test the dwarf::toString() helper function with a default value specified.
1345 EXPECT_EQ(AbsDieName, toString(NameOpt, nullptr));
13461352 }
13471353
13481354 TEST(DWARFDebugInfo, TestDwarfToFunctions) {