Skip to content

Commit e8a3972

Browse files
jankratochviltstellar
authored andcommitted
llvm-dwarfdump: Fix DWARF-5 DW_FORM_implicit_const (used by GCC)
Differential Revision: https://reviews.llvm.org/D98195 (cherry picked from commit 4289a7f)
1 parent 02b775a commit e8a3972

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ class DWARFAbbreviationDeclaration {
111111
return AttributeSpecs[idx].Attr;
112112
}
113113

114+
bool getAttrIsImplicitConstByIndex(uint32_t idx) const {
115+
assert(idx < AttributeSpecs.size());
116+
return AttributeSpecs[idx].isImplicitConst();
117+
}
118+
119+
int64_t getAttrImplicitConstValueByIndex(uint32_t idx) const {
120+
assert(idx < AttributeSpecs.size());
121+
return AttributeSpecs[idx].getImplicitConstValue();
122+
}
123+
114124
/// Get the index of the specified attribute.
115125
///
116126
/// Searches the this abbreviation declaration for the index of the specified

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,8 @@ void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
632632
OS << '\n';
633633

634634
// Dump all data in the DIE for the attributes.
635-
for (const DWARFAttribute &AttrValue : attributes()) {
636-
if (AttrValue.Value.getForm() == DW_FORM_implicit_const) {
637-
// We are dumping .debug_info section ,
638-
// implicit_const attribute values are not really stored here,
639-
// but in .debug_abbrev section. So we just skip such attrs.
640-
continue;
641-
}
635+
for (const DWARFAttribute &AttrValue : attributes())
642636
dumpAttribute(OS, *this, AttrValue, Indent, DumpOpts);
643-
}
644637

645638
DWARFDie child = getFirstChild();
646639
if (DumpOpts.ShowChildren && DumpOpts.ChildRecurseDepth > 0 && child) {
@@ -723,10 +716,16 @@ void DWARFDie::attribute_iterator::updateForIndex(
723716
// Add the previous byte size of any previous attribute value.
724717
AttrValue.Offset += AttrValue.ByteSize;
725718
uint64_t ParseOffset = AttrValue.Offset;
726-
auto U = Die.getDwarfUnit();
727-
assert(U && "Die must have valid DWARF unit");
728-
AttrValue.Value = DWARFFormValue::createFromUnit(
729-
AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
719+
if (AbbrDecl.getAttrIsImplicitConstByIndex(Index))
720+
AttrValue.Value = DWARFFormValue::createFromSValue(
721+
AbbrDecl.getFormByIndex(Index),
722+
AbbrDecl.getAttrImplicitConstValueByIndex(Index));
723+
else {
724+
auto U = Die.getDwarfUnit();
725+
assert(U && "Die must have valid DWARF unit");
726+
AttrValue.Value = DWARFFormValue::createFromUnit(
727+
AbbrDecl.getFormByIndex(Index), U, &ParseOffset);
728+
}
730729
AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
731730
} else {
732731
assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");

llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
168168
case DW_FORM_line_strp:
169169
case DW_FORM_GNU_ref_alt:
170170
case DW_FORM_GNU_strp_alt:
171+
case DW_FORM_implicit_const:
171172
if (Optional<uint8_t> FixedSize =
172173
dwarf::getFixedFormByteSize(Form, Params)) {
173174
*OffsetPtr += *FixedSize;
@@ -345,6 +346,9 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
345346
case DW_FORM_ref_sig8:
346347
Value.uval = Data.getU64(OffsetPtr, &Err);
347348
break;
349+
case DW_FORM_implicit_const:
350+
// Value has been already set by DWARFFormValue::createFromSValue.
351+
break;
348352
default:
349353
// DWARFFormValue::skipValue() will have caught this and caused all
350354
// DWARF DIEs to fail to be parsed, so this code is not be reachable.
@@ -482,6 +486,7 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
482486
break;
483487

484488
case DW_FORM_sdata:
489+
case DW_FORM_implicit_const:
485490
OS << Value.sval;
486491
break;
487492
case DW_FORM_udata:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# REQUIRES: x86-registered-target
2+
3+
# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g
4+
5+
# RUN: llvm-dwarfdump -v %t.o | FileCheck %s
6+
7+
# CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_no
8+
# CHECK-NEXT: DW_AT_language DW_FORM_implicit_const 29
9+
10+
# CHECK: 0x0000000c: DW_TAG_compile_unit [1]
11+
# CHECK-NEXT: DW_AT_language [DW_FORM_implicit_const] (DW_LANG_C11)
12+
13+
.section .debug_info,"",@progbits
14+
.Ldebug_info0:
15+
.long .Ldebug_info0_end - .Ldebug_info0_start # Length of Compilation Unit Info
16+
.Ldebug_info0_start:
17+
.value 0x5 # DWARF version number
18+
.byte 0x1 # DW_UT_compile
19+
.byte 0x8 # Pointer Size (in bytes)
20+
.long .Ldebug_abbrev0 # Offset Into Abbrev. Section
21+
.uleb128 0x1 # (DIE DW_TAG_compile_unit)
22+
# DW_AT_language
23+
.Ldebug_info0_end:
24+
.section .debug_abbrev,"",@progbits
25+
.Ldebug_abbrev0:
26+
.uleb128 0x1 # (abbrev code)
27+
.uleb128 0x11 # (TAG: DW_TAG_compile_unit)
28+
.byte 0x0 # DW_children_no
29+
.uleb128 0x13 # (DW_AT_language)
30+
.uleb128 0x21 # (DW_FORM_implicit_const)
31+
.sleb128 0x1d
32+
.byte 0
33+
.byte 0
34+
.byte 0

0 commit comments

Comments
 (0)