diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index 96c546250974c..33f79baf483da 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -136,23 +136,31 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, auto Color = HighlightColor::Enumerator; if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) { Color = HighlightColor::String; - if (const auto *LT = U->getContext().getLineTableForUnit(U)) - if (LT->getFileNameByIndex( - *FormValue.getAsUnsignedConstant(), U->getCompilationDir(), - DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) { - File = '"' + File + '"'; - Name = File; + if (const auto *LT = U->getContext().getLineTableForUnit(U)) { + if (Optional Val = FormValue.getAsUnsignedConstant()) { + if (LT->getFileNameByIndex( + *Val, U->getCompilationDir(), + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, + File)) { + File = '"' + File + '"'; + Name = File; + } } + } } else if (Optional Val = FormValue.getAsUnsignedConstant()) Name = AttributeValueString(Attr, *Val); if (!Name.empty()) WithColor(OS, Color) << Name; - else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line) - OS << *FormValue.getAsUnsignedConstant(); - else if (Attr == DW_AT_low_pc && - (FormValue.getAsAddress() == - dwarf::computeTombstoneAddress(U->getAddressByteSize()))) { + else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line) { + if (Optional Val = FormValue.getAsUnsignedConstant()) { + OS << *Val; + } else { + FormValue.dump(OS, DumpOpts); + } + } else if (Attr == DW_AT_low_pc && + (FormValue.getAsAddress() == + dwarf::computeTombstoneAddress(U->getAddressByteSize()))) { if (DumpOpts.Verbose) { FormValue.dump(OS, DumpOpts); OS << " ("; diff --git a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp index c704f8f583af8..2be2a12aa0256 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -704,6 +704,14 @@ unsigned DWARFVerifier::verifyDebugInfoAttribute(const DWARFDie &Die, } break; } + case DW_AT_call_line: + case DW_AT_decl_line: { + if (!AttrValue.Value.getAsUnsignedConstant()) { + ReportError("DIE has " + AttributeString(Attr) + + " with invalid encoding"); + } + break; + } default: break; } diff --git a/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml b/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml index f9029952cf585..af55a3a7d1034 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml +++ b/llvm/test/tools/llvm-dwarfdump/X86/verify_file_encoding.yaml @@ -14,6 +14,42 @@ # CHECK-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000100) # CHECK-NEXT: DW_AT_call_file [DW_FORM_strp] ( .debug_str[0x00000012] = "") # CHECK-NEXT: DW_AT_call_line [DW_FORM_data1] (10){{[[:space:]]}} +# CHECK-NEXT: error: DIE has DW_AT_decl_file with invalid encoding{{[[:space:]]}} +# CHECK-NEXT: 0x0000004a: DW_TAG_subprogram +# CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000001b] = "foo") +# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000002000) +# CHECK-NEXT: DW_AT_high_pc [DW_FORM_addr] (0x0000000000003000) +# CHECK-NEXT: DW_AT_decl_file [DW_FORM_sdata] (2) +# CHECK-NEXT: DW_AT_decl_line [DW_FORM_sdata] (3) +# CHECK-NEXT: DW_AT_call_file [DW_FORM_sdata] (4) +# CHECK-NEXT: DW_AT_call_line [DW_FORM_sdata] (5){{[[:space:]]}} +# CHECK-NEXT: error: DIE has DW_AT_decl_line with invalid encoding{{[[:space:]]}} +# CHECK-NEXT: 0x0000004a: DW_TAG_subprogram +# CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000001b] = "foo") +# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000002000) +# CHECK-NEXT: DW_AT_high_pc [DW_FORM_addr] (0x0000000000003000) +# CHECK-NEXT: DW_AT_decl_file [DW_FORM_sdata] (2) +# CHECK-NEXT: DW_AT_decl_line [DW_FORM_sdata] (3) +# CHECK-NEXT: DW_AT_call_file [DW_FORM_sdata] (4) +# CHECK-NEXT: DW_AT_call_line [DW_FORM_sdata] (5){{[[:space:]]}} +# CHECK-NEXT: error: DIE has DW_AT_call_file with invalid encoding{{[[:space:]]}} +# CHECK-NEXT: 0x0000004a: DW_TAG_subprogram +# CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000001b] = "foo") +# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000002000) +# CHECK-NEXT: DW_AT_high_pc [DW_FORM_addr] (0x0000000000003000) +# CHECK-NEXT: DW_AT_decl_file [DW_FORM_sdata] (2) +# CHECK-NEXT: DW_AT_decl_line [DW_FORM_sdata] (3) +# CHECK-NEXT: DW_AT_call_file [DW_FORM_sdata] (4) +# CHECK-NEXT: DW_AT_call_line [DW_FORM_sdata] (5){{[[:space:]]}} +# CHECK-NEXT: error: DIE has DW_AT_call_line with invalid encoding{{[[:space:]]}} +# CHECK-NEXT: 0x0000004a: DW_TAG_subprogram +# CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x0000001b] = "foo") +# CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x0000000000002000) +# CHECK-NEXT: DW_AT_high_pc [DW_FORM_addr] (0x0000000000003000) +# CHECK-NEXT: DW_AT_decl_file [DW_FORM_sdata] (2) +# CHECK-NEXT: DW_AT_decl_line [DW_FORM_sdata] (3) +# CHECK-NEXT: DW_AT_call_file [DW_FORM_sdata] (4) +# CHECK-NEXT: DW_AT_call_line [DW_FORM_sdata] (5){{[[:space:]]}} --- !ELF FileHeader: @@ -28,6 +64,7 @@ DWARF: - main - '' - inline1 + - foo debug_abbrev: - Table: - Code: 0x0000000000000001 @@ -68,8 +105,26 @@ DWARF: Form: DW_FORM_strp - Attribute: DW_AT_call_line Form: DW_FORM_data1 + - Code: 0x0000000000000004 + Tag: DW_TAG_subprogram + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_name + Form: DW_FORM_strp + - Attribute: DW_AT_low_pc + Form: DW_FORM_addr + - Attribute: DW_AT_high_pc + Form: DW_FORM_addr + - Attribute: DW_AT_decl_file + Form: DW_FORM_sdata + - Attribute: DW_AT_decl_line + Form: DW_FORM_sdata + - Attribute: DW_AT_call_file + Form: DW_FORM_sdata + - Attribute: DW_AT_call_line + Form: DW_FORM_sdata debug_info: - - Length: 0x0000000000000048 + - Length: 0x0000000000000061 Version: 4 AbbrOffset: 0x0000000000000000 AddrSize: 8 @@ -93,6 +148,15 @@ DWARF: - Value: 0x0000000000000100 - Value: 0x0000000000000012 - Value: 0x000000000000000A + - AbbrCode: 0x00000004 + Values: + - Value: 0x000000000000001B + - Value: 0x0000000000002000 + - Value: 0x0000000000003000 + - Value: 0x0000000000000002 + - Value: 0x0000000000000003 + - Value: 0x0000000000000004 + - Value: 0x0000000000000005 - AbbrCode: 0x00000000 Values: [] - AbbrCode: 0x00000000