Index: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h =================================================================== --- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h +++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h @@ -15,6 +15,7 @@ #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h" +#include "llvm/Support/MD5.h" #include #include #include @@ -34,6 +35,7 @@ uint64_t DirIdx = 0; uint64_t ModTime = 0; uint64_t Length = 0; + MD5::MD5Result Checksum; }; struct Prologue { @@ -46,11 +48,11 @@ /// parameters affect interpretation of forms (used in the directory and /// file tables starting with v5). DWARFFormParams FormParams; - /// In v5, size in bytes of a segment selector. - uint8_t SegSelectorSize; /// The number of bytes following the prologue_length field to the beginning /// of the first byte of the statement program itself. uint64_t PrologueLength; + /// In v5, size in bytes of a segment selector. + uint8_t SegSelectorSize; /// The size in bytes of the smallest target machine instruction. Statement /// program opcodes that alter the address register first multiply their /// operands by this value. @@ -66,6 +68,8 @@ uint8_t LineRange; /// The number assigned to the first special opcode. uint8_t OpcodeBase; + /// For v5, whether filename entries provide an MD5 checksum. + bool HasMD5; std::vector StandardOpcodeLengths; std::vector IncludeDirectories; std::vector FileNames; Index: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp @@ -777,6 +777,7 @@ case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break; case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break; case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break; + case dwarf::DW_FORM_data16: break; } for (const auto &V : values()) @@ -791,6 +792,7 @@ case dwarf::DW_FORM_block2: return Size + sizeof(int16_t); case dwarf::DW_FORM_block4: return Size + sizeof(int32_t); case dwarf::DW_FORM_block: return Size + getULEB128Size(Size); + case dwarf::DW_FORM_data16: return 16; default: llvm_unreachable("Improper form for block"); } } Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -48,6 +48,7 @@ MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0; OpcodeBase = 0; FormParams = DWARFFormParams({0, 0, DWARF32}); + HasMD5 = false; StandardOpcodeLengths.clear(); IncludeDirectories.clear(); FileNames.clear(); @@ -78,15 +79,23 @@ << IncludeDirectories[I] << "'\n"; if (!FileNames.empty()) { - OS << " Dir Mod Time File Len File Name\n" - << " ---- ---------- ---------- -----------" - "----------------\n"; + if (HasMD5) + OS << " Dir MD5 Checksum File Name\n" + << " ---- -------------------------------- -----------" + "---------------\n"; + else + OS << " Dir Mod Time File Len File Name\n" + << " ---- ---------- ---------- -----------" + "----------------\n"; for (uint32_t I = 0; I != FileNames.size(); ++I) { const FileNameEntry &FileEntry = FileNames[I]; - OS << format("file_names[%3u] %4" PRIu64 " ", I + 1, FileEntry.DirIdx) - << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64 " ", FileEntry.ModTime, - FileEntry.Length) - << FileEntry.Name << '\n'; + OS << format("file_names[%3u] %4" PRIu64 " ", I + 1, FileEntry.DirIdx); + if (HasMD5) + OS << FileEntry.Checksum.digest(); + else + OS << format("0x%8.8" PRIx64 " 0x%8.8" PRIx64, FileEntry.ModTime, + FileEntry.Length); + OS << ' ' << FileEntry.Name << '\n'; } } } @@ -122,7 +131,7 @@ // ran off the end of the prologue. static ContentDescriptors parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, - uint64_t EndPrologueOffset) { + uint64_t EndPrologueOffset, bool *HasMD5) { ContentDescriptors Descriptors; int FormatCount = DebugLineData.getU8(OffsetPtr); bool HasPath = false; @@ -135,6 +144,8 @@ Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr)); if (Descriptor.Type == dwarf::DW_LNCT_path) HasPath = true; + else if (Descriptor.Type == dwarf::DW_LNCT_MD5 && HasMD5) + *HasMD5 = true; Descriptors.push_back(Descriptor); } return HasPath ? Descriptors : ContentDescriptors(); @@ -144,11 +155,11 @@ parseV5DirFileTables(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr, uint64_t EndPrologueOffset, const DWARFFormParams &FormParams, const DWARFUnit *U, - std::vector &IncludeDirectories, + bool &HasMD5, std::vector &IncludeDirectories, std::vector &FileNames) { // Get the directory entry description. ContentDescriptors DirDescriptors = - parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset); + parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, nullptr); if (DirDescriptors.empty()) return false; @@ -174,7 +185,7 @@ // Get the file entry description. ContentDescriptors FileDescriptors = - parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset); + parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, &HasMD5); if (FileDescriptors.empty()) return false; @@ -201,7 +212,11 @@ case DW_LNCT_size: FileEntry.Length = Value.getAsUnsignedConstant().getValue(); break; - // FIXME: Add MD5 + case DW_LNCT_MD5: + assert(Value.getAsBlock().getValue().size() == 16); + std::uninitialized_copy_n(Value.getAsBlock().getValue().begin(), 16, + FileEntry.Checksum.Bytes.begin()); + break; default: break; } @@ -253,7 +268,7 @@ if (getVersion() >= 5) { if (!parseV5DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset, - getFormParams(), U, IncludeDirectories, + getFormParams(), U, HasMD5, IncludeDirectories, FileNames)) { fprintf(stderr, "warning: parsing line table prologue at 0x%8.8" PRIx64 Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -186,6 +186,7 @@ case DW_FORM_data2: case DW_FORM_data4: case DW_FORM_data8: + case DW_FORM_data16: case DW_FORM_flag: case DW_FORM_ref1: case DW_FORM_ref2: @@ -339,6 +340,11 @@ case DW_FORM_ref_sup8: Value.uval = Data.getU64(OffsetPtr); break; + case DW_FORM_data16: + // Treat this like a 16-byte block. + Value.uval = 16; + IsBlock = true; + break; case DW_FORM_sdata: Value.sval = Data.getSLEB128(OffsetPtr); break; @@ -432,6 +438,9 @@ case DW_FORM_data8: OS << format("0x%016" PRIx64, UValue); break; + case DW_FORM_data16: + OS << format_bytes(ArrayRef(Value.data, 16), None, 16, 16); + break; case DW_FORM_string: OS << '"'; OS.write_escaped(Value.cstr); @@ -651,7 +660,8 @@ } Optional> DWARFFormValue::getAsBlock() const { - if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc)) + if (!isFormClass(FC_Block) && !isFormClass(FC_Exprloc) && + Form != DW_FORM_data16) return None; return makeArrayRef(Value.data, Value.uval); } Index: llvm/trunk/test/DebugInfo/X86/dwarfdump-header.s =================================================================== --- llvm/trunk/test/DebugInfo/X86/dwarfdump-header.s +++ llvm/trunk/test/DebugInfo/X86/dwarfdump-header.s @@ -298,25 +298,23 @@ .long str_LT_5a .long str_LT_5b # File table format - .byte 4 # Four elements per file entry + .byte 3 # Three elements per file entry .byte 1 # DW_LNCT_path .byte 0x08 # DW_FORM_string .byte 2 # DW_LNCT_directory_index .byte 0x0b # DW_FORM_data1 - .byte 3 # DW_LNCT_timestamp - .byte 0x0f # DW_FORM_udata - .byte 4 # DW_LNCT_size - .byte 0x0f # DW_FORM_udata + .byte 5 # DW_LNCT_MD5 + .byte 0x1e # DW_FORM_data16 # File table entries .byte 2 # Two files .asciz "File5a" .byte 1 - .byte 0x51 - .byte 0x52 + .quad 0x7766554433221100 + .quad 0xffeeddccbbaa9988 .asciz "File5b" .byte 2 - .byte 0x53 - .byte 0x54 + .quad 0x8899aabbccddeeff + .quad 0x0011223344556677 LH_5_header_end: # Line number program, which is empty. LH_5_end: @@ -329,8 +327,9 @@ # CHECK: include_directories[ 1] = 'Directory5a' # CHECK: include_directories[ 2] = 'Directory5b' # CHECK-NOT: include_directories -# CHECK: file_names[ 1] 1 0x00000051 0x00000052 File5a{{$}} -# CHECK: file_names[ 2] 2 0x00000053 0x00000054 File5b{{$}} +# CHECK: MD5 Checksum +# CHECK: file_names[ 1] 1 00112233445566778899aabbccddeeff File5a{{$}} +# CHECK: file_names[ 2] 2 ffeeddccbbaa99887766554433221100 File5b{{$}} # CHECK-NOT: file_names .section .debug_line.dwo,"",@progbits Index: llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp =================================================================== --- llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -82,6 +82,8 @@ const uint32_t Data4 = 0x6789abcdU; const uint64_t Data8 = 0x0011223344556677ULL; const uint64_t Data8_2 = 0xAABBCCDDEEFF0011ULL; + const uint8_t Data16[16] = {1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16}; const int64_t SData = INT64_MIN; const int64_t ICSData = INT64_MAX; // DW_FORM_implicit_const SData const uint64_t UData[] = {UINT64_MAX - 1, UINT64_MAX - 2, UINT64_MAX - 3, @@ -120,6 +122,11 @@ const auto Attr_DW_FORM_block4 = static_cast(Attr++); CUDie.addAttribute(Attr_DW_FORM_block4, DW_FORM_block4, BlockData, BlockSize); + // We handle data16 as a block form. + const auto Attr_DW_FORM_data16 = static_cast(Attr++); + if (Version >= 5) + CUDie.addAttribute(Attr_DW_FORM_data16, DW_FORM_data16, Data16, 16); + //---------------------------------------------------------------------- // Test data forms //---------------------------------------------------------------------- @@ -276,6 +283,17 @@ EXPECT_EQ(ExtractedBlockData.size(), BlockSize); EXPECT_TRUE(memcmp(ExtractedBlockData.data(), BlockData, BlockSize) == 0); + // Data16 is handled like a block. + if (Version >= 5) { + FormValue = DieDG.find(Attr_DW_FORM_data16); + EXPECT_TRUE((bool)FormValue); + BlockDataOpt = FormValue->getAsBlock(); + EXPECT_TRUE(BlockDataOpt.hasValue()); + ExtractedBlockData = BlockDataOpt.getValue(); + EXPECT_EQ(ExtractedBlockData.size(), 16u); + EXPECT_TRUE(memcmp(ExtractedBlockData.data(), Data16, 16) == 0); + } + //---------------------------------------------------------------------- // Test data forms //---------------------------------------------------------------------- Index: llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp =================================================================== --- llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -160,6 +160,15 @@ EXPECT_EQ(LEBMax.getAsSignedConstant().getValue(), LLONG_MAX); EXPECT_EQ(LEB1.getAsSignedConstant().getValue(), -42); EXPECT_EQ(LEB2.getAsSignedConstant().getValue(), 42); + + // Data16 is a little tricky. + using uint128_t = std::array; + uint128_t Item16({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}); + auto Data16 = createDataXFormValue(DW_FORM_data16, Item16); + SmallString<32> Str; + raw_svector_ostream Res(Str); + Data16.dump(Res, DIDumpOptions()); + EXPECT_EQ(memcmp(Str.data(), "000102030405060708090a0b0c0d0e0f", 32), 0); } } // end anonymous namespace