[DWARFv5] Dump an MD5 checksum in the line-table header.

Adds missing support for DW_FORM_data16.

Differential Revision: https://reviews.llvm.org/D41090

llvm-svn: 320852
This commit is contained in:
Paul Robinson 2017-12-15 19:52:34 +00:00
parent 22e5551ed7
commit 72546fe87b
7 changed files with 84 additions and 27 deletions

View File

@ -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 <cstdint>
#include <map>
#include <string>
@ -34,6 +35,7 @@ public:
uint64_t DirIdx = 0;
uint64_t ModTime = 0;
uint64_t Length = 0;
MD5::MD5Result Checksum;
};
struct Prologue {
@ -46,11 +48,11 @@ public:
/// 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 @@ public:
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<uint8_t> StandardOpcodeLengths;
std::vector<StringRef> IncludeDirectories;
std::vector<FileNameEntry> FileNames;

View File

@ -777,6 +777,7 @@ void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
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 @@ unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
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");
}
}

View File

@ -48,6 +48,7 @@ void DWARFDebugLine::Prologue::clear() {
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 @@ void DWARFDebugLine::Prologue::dump(raw_ostream &OS) const {
<< 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 @@ parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,
// 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 @@ parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint32_t *OffsetPtr,
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 @@ static bool
parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
uint32_t *OffsetPtr, uint64_t EndPrologueOffset,
const DWARFFormParams &FormParams, const DWARFUnit *U,
std::vector<StringRef> &IncludeDirectories,
bool &HasMD5, std::vector<StringRef> &IncludeDirectories,
std::vector<DWARFDebugLine::FileNameEntry> &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 @@ parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
// 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 @@ parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
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 @@ bool DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
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

View File

@ -186,6 +186,7 @@ bool DWARFFormValue::skipValue(dwarf::Form Form, DataExtractor DebugInfoData,
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 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data,
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 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
case DW_FORM_data8:
OS << format("0x%016" PRIx64, UValue);
break;
case DW_FORM_data16:
OS << format_bytes(ArrayRef<uint8_t>(Value.data, 16), None, 16, 16);
break;
case DW_FORM_string:
OS << '"';
OS.write_escaped(Value.cstr);
@ -651,7 +660,8 @@ Optional<int64_t> DWARFFormValue::getAsSignedConstant() const {
}
Optional<ArrayRef<uint8_t>> 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);
}

View File

@ -298,25 +298,23 @@ LH_5_params:
.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 @@ LH_5_end:
# 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

View File

@ -82,6 +82,8 @@ void TestAllForms() {
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 @@ void TestAllForms() {
const auto Attr_DW_FORM_block4 = static_cast<dwarf::Attribute>(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<dwarf::Attribute>(Attr++);
if (Version >= 5)
CUDie.addAttribute(Attr_DW_FORM_data16, DW_FORM_data16, Data16, 16);
//----------------------------------------------------------------------
// Test data forms
//----------------------------------------------------------------------
@ -276,6 +283,17 @@ void TestAllForms() {
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
//----------------------------------------------------------------------

View File

@ -160,6 +160,15 @@ TEST(DWARFFormValue, SignedConstantForms) {
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<uint8_t, 16>;
uint128_t Item16({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
auto Data16 = createDataXFormValue<uint128_t>(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