Index: llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp @@ -867,8 +867,10 @@ continue; // Verify prologue. + bool isDWARF5 = LineTable->Prologue.getVersion() >= 5; + uint32_t MinFileIndex = isDWARF5 ? 0 : 1; uint32_t MaxDirIndex = LineTable->Prologue.IncludeDirectories.size(); - uint32_t FileIndex = 1; + uint32_t FileIndex = MinFileIndex; StringMap FullPathMap; for (const auto &FileName : LineTable->Prologue.FileNames) { // Verify directory index. @@ -926,12 +928,11 @@ // Verify file index. if (!LineTable->hasFileAtIndex(Row.File)) { ++NumDebugLineErrors; - bool isDWARF5 = LineTable->Prologue.getVersion() >= 5; error() << ".debug_line[" << format("0x%08" PRIx64, *toSectionOffset(Die.find(DW_AT_stmt_list))) << "][" << RowIndex << "] has invalid file index " << Row.File - << " (valid values are [" << (isDWARF5 ? "0," : "1,") + << " (valid values are [" << MinFileIndex << ',' << LineTable->Prologue.FileNames.size() << (isDWARF5 ? ")" : "]") << "):\n"; DWARFDebugLine::Row::dumpTableHeader(OS, 0); Index: llvm/test/tools/llvm-dwarfdump/X86/verify_dwarf5_debug_line.yaml =================================================================== --- /dev/null +++ llvm/test/tools/llvm-dwarfdump/X86/verify_dwarf5_debug_line.yaml @@ -0,0 +1,200 @@ +# RUN: yaml2obj %s -o %t.out +# RUN: llvm-dwarfdump --verbose -verify %t.out | FileCheck %s + +# CHECK: Verifying .debug_line... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + SectionHeaderStringTable: .strtab +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x10 + Content: 554889E5C745FC00000000897DF8488975F031C05DC3 + - Name: .debug_abbrev + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 011100252513050325721710171B25111B12067317000000 + - Name: .debug_info + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 1F000000050001080000000001001D0001000000000000000002001600000000000000 + - Name: .debug_str_offsets + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: '1000000005000000000000000000000000000000' + - Name: .comment + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x1 + EntSize: 0x1 + Content: 00636C616E672076657273696F6E2031372E302E302028676974406769746875622E636F6D3A6C6C766D2F6C6C766D2D70726F6A6563742E67697420663166366361353832653232393534363565323761373936363264363830373334326162643964642900 + - Name: .note.GNU-stack + Type: SHT_PROGBITS + AddressAlign: 0x1 + - Name: .eh_frame + Type: SHT_X86_64_UNWIND + Flags: [ SHF_ALLOC ] + AddressAlign: 0x8 + Content: 1400000000000000017A5200017810011B0C0708900100001C0000001C000000000000001600000000410E108602430D06510C0708000000 + - Name: .debug_line + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: 5A0000000500080037000000010101FB0E0D00010101010000000100000101011F010000000003011F020F051E010000000000A6F6C381B31C93C579BEAC58181F5D01040000090200000000000000000105030A0821060B2E0202000101 + - Name: .debug_line_str + Type: SHT_PROGBITS + Flags: [ SHF_MERGE, SHF_STRINGS ] + AddressAlign: 0x1 + EntSize: 0x1 + Content: 2F746D70006477617266352E6300 + - Name: .rela.debug_info + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + AddressAlign: 0x8 + Info: .debug_info + Relocations: + - Offset: 0x8 + Symbol: .debug_abbrev + Type: R_X86_64_32 + - Offset: 0x11 + Symbol: .debug_str_offsets + Type: R_X86_64_32 + Addend: 8 + - Offset: 0x15 + Symbol: .debug_line + Type: R_X86_64_32 + - Offset: 0x1F + Symbol: .debug_addr + Type: R_X86_64_32 + Addend: 8 + - Name: .rela.debug_str_offsets + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + AddressAlign: 0x8 + Info: .debug_str_offsets + Relocations: + - Offset: 0x8 + Symbol: .debug_str + Type: R_X86_64_32 + - Offset: 0xC + Symbol: .debug_str + Type: R_X86_64_32 + Addend: 101 + - Offset: 0x10 + Symbol: .debug_str + Type: R_X86_64_32 + Addend: 110 + - Name: .rela.debug_addr + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + AddressAlign: 0x8 + Info: .debug_addr + Relocations: + - Offset: 0x8 + Symbol: .text + Type: R_X86_64_64 + - Name: .rela.eh_frame + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + AddressAlign: 0x8 + Info: .eh_frame + Relocations: + - Offset: 0x20 + Symbol: .text + Type: R_X86_64_PC32 + - Name: .rela.debug_line + Type: SHT_RELA + Flags: [ SHF_INFO_LINK ] + Link: .symtab + AddressAlign: 0x8 + Info: .debug_line + Relocations: + - Offset: 0x22 + Symbol: .debug_line_str + Type: R_X86_64_32 + - Offset: 0x2E + Symbol: .debug_line_str + Type: R_X86_64_32 + Addend: 5 + - Offset: 0x48 + Symbol: .text + Type: R_X86_64_64 + - Name: .llvm_addrsig + Type: SHT_LLVM_ADDRSIG + Flags: [ SHF_EXCLUDE ] + Link: .symtab + AddressAlign: 0x1 + Offset: 0x448 + Symbols: [ ] + - Type: SectionHeaderTable + Sections: + - Name: .strtab + - Name: .text + - Name: .debug_abbrev + - Name: .debug_info + - Name: .rela.debug_info + - Name: .debug_str_offsets + - Name: .rela.debug_str_offsets + - Name: .debug_str + - Name: .debug_addr + - Name: .rela.debug_addr + - Name: .comment + - Name: .note.GNU-stack + - Name: .eh_frame + - Name: .rela.eh_frame + - Name: .debug_line + - Name: .rela.debug_line + - Name: .debug_line_str + - Name: .llvm_addrsig + - Name: .symtab +Symbols: + - Name: dwarf5.c + Type: STT_FILE + Index: SHN_ABS + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .debug_abbrev + Type: STT_SECTION + Section: .debug_abbrev + - Name: .debug_str_offsets + Type: STT_SECTION + Section: .debug_str_offsets + - Name: .debug_str + Type: STT_SECTION + Section: .debug_str + - Name: .debug_addr + Type: STT_SECTION + Section: .debug_addr + - Name: .debug_line + Type: STT_SECTION + Section: .debug_line + - Name: .debug_line_str + Type: STT_SECTION + Section: .debug_line_str + - Name: main + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + Size: 0x16 +DWARF: + debug_str: + - 'clang version 17.0.0 (git@github.com:llvm/llvm-project.git f1f6ca582e2295465e27a79662d6807342abd9dd)' + - dwarf5.c + - '/tmp' + debug_addr: + - Length: 0xC + Version: 0x5 + AddressSize: 0x8 + Entries: + - {} +...