[llvm] r254489 - [llvm-dwp] Emit a rather fictional debug_cu_index
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 1 22:21:34 PST 2015
Author: dblaikie
Date: Wed Dec 2 00:21:34 2015
New Revision: 254489
URL: http://llvm.org/viewvc/llvm-project?rev=254489&view=rev
Log:
[llvm-dwp] Emit a rather fictional debug_cu_index
This is very rudimentary support for debug_cu_index, but it is enough to
allow llvm-dwarfdump to find the offsets for contributions and
correctly dump debug_info.
It will need to actually find the real signature of the unit and build
the real hash table with the right number of buckets, as per the DWP
specification.
It will also need to be expanded to cover the tu_index as well.
Modified:
llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
llvm/trunk/include/llvm/MC/MCObjectFileInfo.h
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
llvm/trunk/lib/MC/MCObjectFileInfo.cpp
llvm/trunk/test/tools/llvm-dwp/X86/simple.test
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h Wed Dec 2 00:21:34 2015
@@ -41,12 +41,15 @@ class DWARFUnitIndex {
public:
class Entry {
- const DWARFUnitIndex *Index;
- uint64_t Signature;
+ public:
struct SectionContribution {
uint32_t Offset;
uint32_t Length;
};
+
+ private:
+ const DWARFUnitIndex *Index;
+ uint64_t Signature;
std::unique_ptr<SectionContribution[]> Contributions;
friend class DWARFUnitIndex;
@@ -58,14 +61,18 @@ public:
private:
struct Header Header;
+ DWARFSectionKind InfoColumnKind;
int InfoColumn = -1;
std::unique_ptr<DWARFSectionKind[]> ColumnKinds;
std::unique_ptr<Entry[]> Rows;
static StringRef getColumnHeader(DWARFSectionKind DS);
+ bool parseImpl(DataExtractor IndexData);
public:
bool parse(DataExtractor IndexData);
+ DWARFUnitIndex(DWARFSectionKind InfoColumnKind)
+ : InfoColumnKind(InfoColumnKind) {}
void dump(raw_ostream &OS) const;
const Entry *getFromOffset(uint32_t Offset) const;
};
Modified: llvm/trunk/include/llvm/MC/MCObjectFileInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectFileInfo.h?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectFileInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectFileInfo.h Wed Dec 2 00:21:34 2015
@@ -116,6 +116,9 @@ protected:
MCSection *DwarfStrOffDWOSection;
MCSection *DwarfAddrSection;
+ // These are for Fission DWP files.
+ MCSection *DwarfCUIndexSection;
+
/// Section for newer gnu pubnames.
MCSection *DwarfGnuPubNamesSection;
/// Section for newer gnu pubtypes.
@@ -262,6 +265,7 @@ public:
MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
+ MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
MCSection *getCOFFDebugSymbolsSection() const {
return COFFDebugSymbolsSection;
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Wed Dec 2 00:21:34 2015
@@ -163,20 +163,12 @@ void DWARFContext::dump(raw_ostream &OS,
if (DumpType == DIDT_All || DumpType == DIDT_CUIndex) {
OS << "\n.debug_cu_index contents:\n";
- DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(),
- savedAddressByteSize);
- DWARFUnitIndex CUIndex;
- if (CUIndex.parse(CUIndexData))
- CUIndex.dump(OS);
+ getCUIndex().dump(OS);
}
if (DumpType == DIDT_All || DumpType == DIDT_TUIndex) {
OS << "\n.debug_tu_index contents:\n";
- DataExtractor TUIndexData(getTUIndexSection(), isLittleEndian(),
- savedAddressByteSize);
- DWARFUnitIndex TUIndex;
- if (TUIndex.parse(TUIndexData))
- TUIndex.dump(OS);
+ getTUIndex().dump(OS);
}
if (DumpType == DIDT_All || DumpType == DIDT_LineDwo) {
@@ -280,7 +272,7 @@ const DWARFUnitIndex &DWARFContext::getC
DataExtractor CUIndexData(getCUIndexSection(), isLittleEndian(), 0);
- CUIndex = llvm::make_unique<DWARFUnitIndex>();
+ CUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_INFO);
CUIndex->parse(CUIndexData);
return *CUIndex;
}
@@ -291,7 +283,7 @@ const DWARFUnitIndex &DWARFContext::getT
DataExtractor TUIndexData(getTUIndexSection(), isLittleEndian(), 0);
- TUIndex = llvm::make_unique<DWARFUnitIndex>();
+ TUIndex = llvm::make_unique<DWARFUnitIndex>(DW_SECT_TYPES);
TUIndex->parse(TUIndexData);
return *TUIndex;
}
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp Wed Dec 2 00:21:34 2015
@@ -30,6 +30,13 @@ void DWARFUnitIndex::Header::dump(raw_os
}
bool DWARFUnitIndex::parse(DataExtractor IndexData) {
+ bool b = parseImpl(IndexData);
+ if (!b)
+ *this = DWARFUnitIndex(InfoColumnKind);
+ return b;
+}
+
+bool DWARFUnitIndex::parseImpl(DataExtractor IndexData) {
uint32_t Offset = 0;
if (!Header.parse(IndexData, &Offset))
return false;
@@ -62,7 +69,7 @@ bool DWARFUnitIndex::parse(DataExtractor
// Read the Column Headers
for (unsigned i = 0; i != Header.NumColumns; ++i) {
ColumnKinds[i] = static_cast<DWARFSectionKind>(IndexData.getU32(&Offset));
- if (ColumnKinds[i] == DW_SECT_INFO || ColumnKinds[i] == DW_SECT_TYPES) {
+ if (ColumnKinds[i] == InfoColumnKind) {
if (InfoColumn != -1)
return false;
InfoColumn = i;
@@ -107,6 +114,9 @@ StringRef DWARFUnitIndex::getColumnHeade
}
void DWARFUnitIndex::dump(raw_ostream &OS) const {
+ if (!Header.NumBuckets)
+ return;
+
Header.dump(OS);
OS << "Index Signature ";
for (unsigned i = 0; i != Header.NumColumns; ++i)
Modified: llvm/trunk/lib/MC/MCObjectFileInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectFileInfo.cpp?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectFileInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectFileInfo.cpp Wed Dec 2 00:21:34 2015
@@ -259,6 +259,9 @@ void MCObjectFileInfo::initMachOMCObject
DwarfDebugInlineSection =
Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,
SectionKind::getMetadata());
+ DwarfCUIndexSection =
+ Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,
+ SectionKind::getMetadata());
StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",
0, SectionKind::getMetadata());
@@ -531,6 +534,10 @@ void MCObjectFileInfo::initELFMCObjectFi
DwarfAddrSection =
Ctx->getELFSection(".debug_addr", ELF::SHT_PROGBITS, 0, "addr_sec");
+ // DWP Sections
+ DwarfCUIndexSection =
+ Ctx->getELFSection(".debug_cu_index", ELF::SHT_PROGBITS, 0);
+
StackMapSection =
Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
@@ -713,6 +720,11 @@ void MCObjectFileInfo::initCOFFMCObjectF
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
COFF::IMAGE_SCN_MEM_READ,
SectionKind::getMetadata(), "addr_sec");
+ DwarfCUIndexSection = Ctx->getCOFFSection(
+ ".debug_cu_index",
+ COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+ COFF::IMAGE_SCN_MEM_READ,
+ SectionKind::getMetadata());
DwarfAccelNamesSection = Ctx->getCOFFSection(
".apple_names",
COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
Modified: llvm/trunk/test/tools/llvm-dwp/X86/simple.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/simple.test?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/simple.test (original)
+++ llvm/trunk/test/tools/llvm-dwp/X86/simple.test Wed Dec 2 00:21:34 2015
@@ -33,12 +33,13 @@ CHECK: DW_AT_name {{.*}} "a"
CHECK: DW_TAG_structure_type
CHECK: DW_AT_name {{.*}} "foo"
-FIXME: Using cu_index, identify that abbr_offset is 0x0031, not 0x0000
-CHECK: 0x00000029: Compile Unit: length = 0x00000031 version = 0x0004 abbr_offset = 0x0000 addr_size = 0x08 (next unit at 0x0000005e)
-FIXME: Using cu_index, use strings based on the right str index offset
-CHECK: DW_AT_name {{.*}} "a.cpp"
-FIXME: Using cu_index to find the right abbrevs at abbr_offset, this abbrevation should actually be structure_type
-CHECK: DW_TAG_variable
+CHECK: 0x00000029: Compile Unit: length = 0x00000031 version = 0x0004 abbr_offset = 0x0031 addr_size = 0x08 (next unit at 0x0000005e)
+CHECK: DW_AT_name {{.*}} "b.cpp"
+CHECK: DW_TAG_structure_type
+CHECK: DW_AT_name {{.*}} "bar"
+CHECK: DW_TAG_subprogram
+CHECK: DW_AT_name {{.*}} "b"
+CHECK: DW_TAG_formal_parameter
CHECK: .debug_cu_index contents:
FIXME: Emit and verify the cu_index contents
Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=254489&r1=254488&r2=254489&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Wed Dec 2 00:21:34 2015
@@ -17,6 +17,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Support/TargetSelect.h"
+#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
#include <memory>
#include <list>
#include <unordered_set>
@@ -85,48 +86,106 @@ static std::error_code write(MCStreamer
const auto &MCOFI = *Out.getContext().getObjectFileInfo();
MCSection *const StrSection = MCOFI.getDwarfStrDWOSection();
MCSection *const StrOffsetSection = MCOFI.getDwarfStrOffDWOSection();
- const StringMap<MCSection *> KnownSections = {
- {"debug_info.dwo", MCOFI.getDwarfInfoDWOSection()},
- {"debug_types.dwo", MCOFI.getDwarfTypesDWOSection()},
- {"debug_str_offsets.dwo", StrOffsetSection},
- {"debug_str.dwo", StrSection},
- {"debug_loc.dwo", MCOFI.getDwarfLocDWOSection()},
- {"debug_abbrev.dwo", MCOFI.getDwarfAbbrevDWOSection()}};
+ const StringMap<std::pair<MCSection *, DWARFSectionKind>> KnownSections = {
+ {"debug_info.dwo", {MCOFI.getDwarfInfoDWOSection(), DW_SECT_INFO}},
+ {"debug_types.dwo", {MCOFI.getDwarfTypesDWOSection(), DW_SECT_TYPES}},
+ {"debug_str_offsets.dwo", {StrOffsetSection, DW_SECT_STR_OFFSETS}},
+ {"debug_str.dwo", {StrSection, static_cast<DWARFSectionKind>(0)}},
+ {"debug_loc.dwo", {MCOFI.getDwarfLocDWOSection(), DW_SECT_LOC}},
+ {"debug_abbrev.dwo", {MCOFI.getDwarfAbbrevDWOSection(), DW_SECT_ABBREV}}};
+
+ struct UnitIndexEntry {
+ uint64_t Signature;
+ DWARFUnitIndex::Entry::SectionContribution Contributions[8];
+ };
+
+ std::vector<UnitIndexEntry> IndexEntries;
StringMap<uint32_t> Strings;
uint32_t StringOffset = 0;
+ uint64_t UnitIndex = 0;
+ uint32_t ContributionOffsets[8] = {};
+
for (const auto &Input : Inputs) {
auto ErrOrObj = object::ObjectFile::createObjectFile(Input);
if (!ErrOrObj)
return ErrOrObj.getError();
- const auto *Obj = ErrOrObj->getBinary();
+
+ IndexEntries.emplace_back();
+ UnitIndexEntry &CurEntry = IndexEntries.back();
+ CurEntry.Signature = UnitIndex++;
+
StringRef CurStrSection;
StringRef CurStrOffsetSection;
- for (const auto &Section : Obj->sections()) {
+
+ for (const auto &Section : ErrOrObj->getBinary()->sections()) {
StringRef Name;
if (std::error_code Err = Section.getName(Name))
return Err;
- if (MCSection *OutSection =
- KnownSections.lookup(Name.substr(Name.find_first_not_of("._")))) {
- StringRef Contents;
- if (auto Err = Section.getContents(Contents))
- return Err;
- if (OutSection == StrOffsetSection)
- CurStrOffsetSection = Contents;
- else if (OutSection == StrSection)
- CurStrSection = Contents;
- else {
- Out.SwitchSection(OutSection);
- Out.EmitBytes(Contents);
- }
+
+ auto SectionPair =
+ KnownSections.find(Name.substr(Name.find_first_not_of("._")));
+ if (SectionPair == KnownSections.end())
+ continue;
+
+ StringRef Contents;
+ if (auto Err = Section.getContents(Contents))
+ return Err;
+
+ if (DWARFSectionKind Kind = SectionPair->second.second) {
+ auto Index = Kind - DW_SECT_INFO;
+ CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
+ ContributionOffsets[Index] +=
+ (CurEntry.Contributions[Index].Length = Contents.size());
+ }
+
+ MCSection *OutSection = SectionPair->second.first;
+ if (OutSection == StrOffsetSection)
+ CurStrOffsetSection = Contents;
+ else if (OutSection == StrSection)
+ CurStrSection = Contents;
+ else {
+ Out.SwitchSection(OutSection);
+ Out.EmitBytes(Contents);
}
}
+
if (auto Err = writeStringsAndOffsets(Out, Strings, StringOffset,
StrSection, StrOffsetSection,
CurStrSection, CurStrOffsetSection))
return Err;
}
+
+ Out.SwitchSection(MCOFI.getDwarfCUIndexSection());
+ Out.EmitIntValue(2, 4); // Version
+ Out.EmitIntValue(8, 4); // Columns
+ Out.EmitIntValue(IndexEntries.size(), 4); // Num Units
+ // FIXME: This is not the right number of buckets for a real hash.
+ Out.EmitIntValue(IndexEntries.size(), 4); // Num Buckets
+
+ // Write the signatures.
+ for (const auto &E : IndexEntries)
+ Out.EmitIntValue(E.Signature, 8);
+
+ // Write the indexes.
+ for (size_t i = 0; i != IndexEntries.size(); ++i)
+ Out.EmitIntValue(i + 1, 4);
+
+ // Write the column headers (which sections will appear in the table)
+ for (size_t i = 1; i != 9; ++i)
+ Out.EmitIntValue(i, 4);
+
+ // Write the offsets.
+ for (const auto &E : IndexEntries)
+ for (const auto &C : E.Contributions)
+ Out.EmitIntValue(C.Offset, 4);
+
+ // Write the lengths.
+ for (const auto &E : IndexEntries)
+ for (const auto &C : E.Contributions)
+ Out.EmitIntValue(C.Length, 4);
+
return std::error_code();
}
More information about the llvm-commits
mailing list