Skip to content

Commit e7d52db

Browse files
Michael137miguelcsx
authored andcommitted
[lldb][DWARF] Support retrieving DW_FORM_implicit_const value with DWARFDebugInfoEntry::GetAttributeValue (llvm#145328)
`DWARFFormValue::ExtractValue` has nothing to extract for `DW_FORM_implicit_const` since the value is stored in the abbreviation. `DWARFFormValue` expects the user to have set the value of the implicit_const. This patch does so in `GetAttributeValue`.
1 parent 65cbc81 commit e7d52db

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
403403
const dw_offset_t attr_offset = offset;
404404
form_value.SetUnit(cu);
405405
form_value.SetForm(abbrevDecl->getFormByIndex(idx));
406+
if (abbrevDecl->getAttrIsImplicitConstByIndex(idx))
407+
form_value.SetValue(abbrevDecl->getAttrImplicitConstValueByIndex(idx));
408+
406409
if (form_value.ExtractValue(data, &offset)) {
407410
if (end_attr_offset_ptr)
408411
*end_attr_offset_ptr = offset;

lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,64 @@ TEST(DWARFDIETest, GetContextInFunction) {
395395
testing::ElementsAre(make_struct("struct_t")));
396396
}
397397

398+
TEST(DWARFDIETest, GetAttributeValue_ImplicitConst) {
399+
// Make sure we can correctly retrieve the value of an attribute
400+
// that has a DW_FORM_implicit_const form.
401+
402+
const char *yamldata = R"(
403+
--- !ELF
404+
FileHeader:
405+
Class: ELFCLASS64
406+
Data: ELFDATA2LSB
407+
Type: ET_EXEC
408+
Machine: EM_386
409+
DWARF:
410+
debug_str:
411+
- ''
412+
debug_abbrev:
413+
- ID: 0
414+
Table:
415+
- Code: 0x1
416+
Tag: DW_TAG_compile_unit
417+
Children: DW_CHILDREN_yes
418+
- Code: 0x2
419+
Tag: DW_TAG_subprogram
420+
Children: DW_CHILDREN_no
421+
Attributes:
422+
- Attribute: DW_AT_name
423+
Form: DW_FORM_string
424+
- Attribute: DW_AT_object_pointer
425+
Form: DW_FORM_implicit_const
426+
Value: 5
427+
debug_info:
428+
- Version: 5
429+
UnitType: DW_UT_compile
430+
AddrSize: 8
431+
Entries:
432+
- AbbrCode: 0x1
433+
- AbbrCode: 0x2
434+
Values:
435+
- Value: 0xDEADBEEFDEADBEEF
436+
CStr: func
437+
- AbbrCode: 0x0)";
438+
439+
YAMLModuleTester t(yamldata);
440+
auto *symbol_file =
441+
llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile());
442+
DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0);
443+
ASSERT_TRUE(unit);
444+
445+
DWARFDIE subprogram = unit->DIE().GetFirstChild();
446+
ASSERT_TRUE(subprogram);
447+
dw_offset_t end_attr_offset;
448+
DWARFFormValue form_value;
449+
dw_offset_t offset = subprogram.GetDIE()->GetAttributeValue(
450+
unit, DW_AT_object_pointer, form_value, &end_attr_offset);
451+
EXPECT_EQ(form_value.Unsigned(), 5U);
452+
EXPECT_GT(offset, 0U);
453+
EXPECT_GT(end_attr_offset, 0U);
454+
}
455+
398456
struct GetAttributesTestFixture : public testing::TestWithParam<dw_attr_t> {};
399457

400458
TEST_P(GetAttributesTestFixture, TestGetAttributes_IterationOrder) {

0 commit comments

Comments
 (0)