Adds missing support for DW_FORM_data16.
Update of r320852/r320886, fixing the unittest again, this time use a
raw char string for the test data.
Differential Revision: https://reviews.llvm.org/D41090
llvm-svn: 321011
#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>
uint64_t DirIdx = 0;
uint64_t ModTime = 0;
uint64_t Length = 0;
+ MD5::MD5Result Checksum;
};
struct Prologue {
/// 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.
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;
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())
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");
}
}
MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
OpcodeBase = 0;
FormParams = DWARFFormParams({0, 0, DWARF32});
+ HasMD5 = false;
StandardOpcodeLengths.clear();
IncludeDirectories.clear();
FileNames.clear();
<< 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';
}
}
}
// 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;
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();
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;
// Get the file entry description.
ContentDescriptors FileDescriptors =
- parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset);
+ parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, &HasMD5);
if (FileDescriptors.empty())
return false;
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;
}
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
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:
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;
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);
}
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);
}
.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:
# 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
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,
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
//----------------------------------------------------------------------
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
//----------------------------------------------------------------------
EXPECT_EQ(LEBMax.getAsSignedConstant().getValue(), LLONG_MAX);
EXPECT_EQ(LEB1.getAsSignedConstant().getValue(), -42);
EXPECT_EQ(LEB2.getAsSignedConstant().getValue(), 42);
+
+ // Data16 is a little tricky.
+ char Cksum[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+ DWARFFormValue Data16(DW_FORM_data16);
+ DWARFDataExtractor DE16(StringRef(Cksum, 16), sys::IsLittleEndianHost,
+ sizeof(void *));
+ uint32_t Offset = 0;
+ Data16.extractValue(DE16, &Offset, {0, 0, dwarf::DwarfFormat::DWARF32});
+ SmallString<32> Str;
+ raw_svector_ostream Res(Str);
+ Data16.dump(Res, DIDumpOptions());
+ EXPECT_EQ(memcmp(Str.data(), "000102030405060708090a0b0c0d0e0f", 32), 0);
}
} // end anonymous namespace