summaryrefslogtreecommitdiff
path: root/lib/DebugInfo/DWARF
diff options
context:
space:
mode:
Diffstat (limited to 'lib/DebugInfo/DWARF')
-rw-r--r--lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp5
-rw-r--r--lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp5
-rw-r--r--lib/DebugInfo/DWARF/DWARFCompileUnit.cpp4
-rw-r--r--lib/DebugInfo/DWARF/DWARFContext.cpp149
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugFrame.cpp8
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp2
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugLine.cpp2
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugLoc.cpp4
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugMacro.cpp4
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugPubTable.cpp4
-rw-r--r--lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp2
-rw-r--r--lib/DebugInfo/DWARF/DWARFDie.cpp41
-rw-r--r--lib/DebugInfo/DWARF/DWARFFormValue.cpp10
-rw-r--r--lib/DebugInfo/DWARF/DWARFGdbIndex.cpp2
-rw-r--r--lib/DebugInfo/DWARF/DWARFTypeUnit.cpp2
-rw-r--r--lib/DebugInfo/DWARF/DWARFUnit.cpp60
-rw-r--r--lib/DebugInfo/DWARF/DWARFUnitIndex.cpp4
-rw-r--r--lib/DebugInfo/DWARF/LLVMBuild.txt2
18 files changed, 231 insertions, 79 deletions
diff --git a/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp b/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
index e7b4b777b43f..57eac91f8c19 100644
--- a/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
+++ b/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
@@ -7,13 +7,14 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
+
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
-#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/DataExtractor.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
diff --git a/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index a12f8adfafe5..97b52f0fbdd6 100644
--- a/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -7,12 +7,13 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/SmallVector.h"
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp b/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp
index 6e550f2e9ec9..358e9bf43d00 100644
--- a/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp
+++ b/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp
@@ -15,7 +15,7 @@
using namespace llvm;
-void DWARFCompileUnit::dump(raw_ostream &OS) {
+void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
OS << format("0x%08x", getOffset()) << ": Compile Unit:"
<< " length = " << format("0x%08x", getLength())
<< " version = " << format("0x%04x", getVersion());
@@ -27,7 +27,7 @@ void DWARFCompileUnit::dump(raw_ostream &OS) {
<< ")\n";
if (DWARFDie CUDie = getUnitDIE(false))
- CUDie.dump(OS, -1U);
+ CUDie.dump(OS, -1U, 0, DumpOpts);
else
OS << "<compile unit can't be parsed!>\n\n";
}
diff --git a/lib/DebugInfo/DWARF/DWARFContext.cpp b/lib/DebugInfo/DWARF/DWARFContext.cpp
index 1be156d6ea9b..42ab48808f9a 100644
--- a/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -84,6 +84,123 @@ static void dumpAccelSection(raw_ostream &OS, StringRef Name,
Accel.dump(OS);
}
+static void
+dumpDWARFv5StringOffsetsSection(raw_ostream &OS, StringRef SectionName,
+ const DWARFSection &StringOffsetsSection,
+ StringRef StringSection, bool LittleEndian) {
+ DataExtractor StrOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
+ uint32_t Offset = 0;
+ uint64_t SectionSize = StringOffsetsSection.Data.size();
+
+ while (Offset < SectionSize) {
+ unsigned Version = 0;
+ DwarfFormat Format = DWARF32;
+ unsigned EntrySize = 4;
+ // Perform validation and extract the segment size from the header.
+ if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, 4)) {
+ OS << "error: invalid contribution to string offsets table in section ."
+ << SectionName << ".\n";
+ return;
+ }
+ uint32_t ContributionStart = Offset;
+ uint64_t ContributionSize = StrOffsetExt.getU32(&Offset);
+ // A contribution size of 0xffffffff indicates DWARF64, with the actual size
+ // in the following 8 bytes. Otherwise, the DWARF standard mandates that
+ // the contribution size must be at most 0xfffffff0.
+ if (ContributionSize == 0xffffffff) {
+ if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, 8)) {
+ OS << "error: invalid contribution to string offsets table in section ."
+ << SectionName << ".\n";
+ return;
+ }
+ Format = DWARF64;
+ EntrySize = 8;
+ ContributionSize = StrOffsetExt.getU64(&Offset);
+ } else if (ContributionSize > 0xfffffff0) {
+ OS << "error: invalid contribution to string offsets table in section ."
+ << SectionName << ".\n";
+ return;
+ }
+
+ // We must ensure that we don't read a partial record at the end, so we
+ // validate for a multiple of EntrySize. Also, we're expecting a version
+ // number and padding, which adds an additional 4 bytes.
+ uint64_t ValidationSize =
+ 4 + ((ContributionSize + EntrySize - 1) & (-(uint64_t)EntrySize));
+ if (!StrOffsetExt.isValidOffsetForDataOfSize(Offset, ValidationSize)) {
+ OS << "error: contribution to string offsets table in section ."
+ << SectionName << " has invalid length.\n";
+ return;
+ }
+
+ Version = StrOffsetExt.getU16(&Offset);
+ Offset += 2;
+ OS << format("0x%8.8x: ", ContributionStart);
+ OS << "Contribution size = " << ContributionSize
+ << ", Version = " << Version << "\n";
+
+ uint32_t ContributionBase = Offset;
+ DataExtractor StrData(StringSection, LittleEndian, 0);
+ while (Offset - ContributionBase < ContributionSize) {
+ OS << format("0x%8.8x: ", Offset);
+ // FIXME: We can only extract strings in DWARF32 format at the moment.
+ uint64_t StringOffset = getRelocatedValue(
+ StrOffsetExt, EntrySize, &Offset, &StringOffsetsSection.Relocs);
+ if (Format == DWARF32) {
+ OS << format("%8.8x ", StringOffset);
+ uint32_t StringOffset32 = (uint32_t)StringOffset;
+ const char *S = StrData.getCStr(&StringOffset32);
+ if (S)
+ OS << format("\"%s\"", S);
+ } else
+ OS << format("%16.16x ", StringOffset);
+ OS << "\n";
+ }
+ }
+}
+
+// Dump a DWARF string offsets section. This may be a DWARF v5 formatted
+// string offsets section, where each compile or type unit contributes a
+// number of entries (string offsets), with each contribution preceded by
+// a header containing size and version number. Alternatively, it may be a
+// monolithic series of string offsets, as generated by the pre-DWARF v5
+// implementation of split DWARF.
+static void dumpStringOffsetsSection(raw_ostream &OS, StringRef SectionName,
+ const DWARFSection &StringOffsetsSection,
+ StringRef StringSection, bool LittleEndian,
+ unsigned MaxVersion) {
+ if (StringOffsetsSection.Data.empty())
+ return;
+ OS << "\n." << SectionName << " contents:\n";
+ // If we have at least one (compile or type) unit with DWARF v5 or greater,
+ // we assume that the section is formatted like a DWARF v5 string offsets
+ // section.
+ if (MaxVersion >= 5)
+ dumpDWARFv5StringOffsetsSection(OS, SectionName, StringOffsetsSection,
+ StringSection, LittleEndian);
+ else {
+ DataExtractor strOffsetExt(StringOffsetsSection.Data, LittleEndian, 0);
+ uint32_t offset = 0;
+ uint64_t size = StringOffsetsSection.Data.size();
+ // Ensure that size is a multiple of the size of an entry.
+ if (size & ((uint64_t)(sizeof(uint32_t) - 1))) {
+ OS << "error: size of ." << SectionName << " is not a multiple of "
+ << sizeof(uint32_t) << ".\n";
+ size &= -(uint64_t)sizeof(uint32_t);
+ }
+ DataExtractor StrData(StringSection, LittleEndian, 0);
+ while (offset < size) {
+ OS << format("0x%8.8x: ", offset);
+ uint32_t StringOffset = strOffsetExt.getU32(&offset);
+ OS << format("%8.8x ", StringOffset);
+ const char *S = StrData.getCStr(&StringOffset);
+ if (S)
+ OS << format("\"%s\"", S);
+ OS << "\n";
+ }
+ }
+}
+
void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts){
DIDumpType DumpType = DumpOpts.DumpType;
@@ -104,14 +221,14 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts){
if (DumpType == DIDT_All || DumpType == DIDT_Info) {
OS << "\n.debug_info contents:\n";
for (const auto &CU : compile_units())
- CU->dump(OS);
+ CU->dump(OS, DumpOpts);
}
if ((DumpType == DIDT_All || DumpType == DIDT_InfoDwo) &&
getNumDWOCompileUnits()) {
OS << "\n.debug_info.dwo contents:\n";
for (const auto &DWOCU : dwo_compile_units())
- DWOCU->dump(OS);
+ DWOCU->dump(OS, DumpOpts);
}
if ((DumpType == DIDT_All || DumpType == DIDT_Types) && getNumTypeUnits()) {
@@ -258,17 +375,15 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpOptions DumpOpts){
true /* GnuStyle */)
.dump("debug_gnu_pubtypes", OS);
- if ((DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo) &&
- !getStringOffsetDWOSection().empty()) {
- OS << "\n.debug_str_offsets.dwo contents:\n";
- DataExtractor strOffsetExt(getStringOffsetDWOSection(), isLittleEndian(),
- 0);
- offset = 0;
- uint64_t size = getStringOffsetDWOSection().size();
- while (offset < size) {
- OS << format("0x%8.8x: ", offset);
- OS << format("%8.8x\n", strOffsetExt.getU32(&offset));
- }
+ if (DumpType == DIDT_All || DumpType == DIDT_StrOffsets)
+ dumpStringOffsetsSection(OS, "debug_str_offsets", getStringOffsetSection(),
+ getStringSection(), isLittleEndian(),
+ getMaxVersion());
+
+ if (DumpType == DIDT_All || DumpType == DIDT_StrOffsetsDwo) {
+ dumpStringOffsetsSection(OS, "debug_str_offsets.dwo",
+ getStringOffsetDWOSection(), getStringDWOSection(),
+ isLittleEndian(), getMaxVersion());
}
if ((DumpType == DIDT_All || DumpType == DIDT_GdbIndex) &&
@@ -1109,6 +1224,10 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
TypesDWOSections[Section].Data = data;
}
+ // Map platform specific debug section names to DWARF standard section
+ // names.
+ name = Obj.mapDebugSectionName(name);
+
if (RelocatedSection == Obj.section_end())
continue;
@@ -1141,6 +1260,7 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
.Case("debug_loc", &LocSection.Relocs)
.Case("debug_info.dwo", &InfoDWOSection.Relocs)
.Case("debug_line", &LineSection.Relocs)
+ .Case("debug_str_offsets", &StringOffsetSection.Relocs)
.Case("debug_ranges", &RangeSection.Relocs)
.Case("debug_addr", &AddrSection.Relocs)
.Case("apple_names", &AppleNamesSection.Relocs)
@@ -1211,6 +1331,7 @@ StringRef *DWARFContextInMemory::MapSectionToMember(StringRef Name) {
.Case("debug_frame", &DebugFrameSection)
.Case("eh_frame", &EHFrameSection)
.Case("debug_str", &StringSection)
+ .Case("debug_str_offsets", &StringOffsetSection.Data)
.Case("debug_ranges", &RangeSection.Data)
.Case("debug_macinfo", &MacinfoSection)
.Case("debug_pubnames", &PubNamesSection)
@@ -1222,7 +1343,7 @@ StringRef *DWARFContextInMemory::MapSectionToMember(StringRef Name) {
.Case("debug_loc.dwo", &LocDWOSection.Data)
.Case("debug_line.dwo", &LineDWOSection.Data)
.Case("debug_str.dwo", &StringDWOSection)
- .Case("debug_str_offsets.dwo", &StringOffsetDWOSection)
+ .Case("debug_str_offsets.dwo", &StringOffsetDWOSection.Data)
.Case("debug_addr", &AddrSection.Data)
.Case("apple_names", &AppleNamesSection.Data)
.Case("apple_types", &AppleTypesSection.Data)
diff --git a/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
index b55ed6a46849..e6e007896cc8 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -7,18 +7,19 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
+
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataExtractor.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
@@ -584,6 +585,7 @@ void DWARFDebugFrame::parse(DataExtractor Data) {
switch (AugmentationString[i]) {
default:
ReportError("Unknown augmentation character in entry at %lx");
+ llvm_unreachable("ReportError should not return.");
case 'L':
LSDAPointerEncoding = Data.getU8(&Offset);
break;
diff --git a/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp b/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
index 35f673c7acc6..dbcc64fc0832 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
#include "llvm/ADT/Optional.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
-#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/DataExtractor.h"
diff --git a/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index f32e8fe76357..cda3e75fbc3e 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -9,10 +9,10 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp b/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
index d5c34216ed53..2178bef65d1d 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp
@@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
-#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
diff --git a/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp b/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
index e0a9adde8e58..1b77be6192dd 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugMacro.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "SyntaxHighlighting.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugMacro.h"
-#include "llvm/Support/Dwarf.h"
+#include "SyntaxHighlighting.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdint>
diff --git a/lib/DebugInfo/DWARF/DWARFDebugPubTable.cpp b/lib/DebugInfo/DWARF/DWARFDebugPubTable.cpp
index daded255f8c7..5a4e39f3c2af 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugPubTable.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugPubTable.cpp
@@ -7,10 +7,10 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/DataExtractor.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdint>
diff --git a/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp b/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
index 6b5e1d3c931b..43201293fe60 100644
--- a/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDebugRangeList.cpp
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp
index fd45c77d3745..b4b682dd11b5 100644
--- a/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -7,18 +7,18 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "SyntaxHighlighting.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
-#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/DataExtractor.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
@@ -67,7 +67,8 @@ static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector& Ranges,
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
uint32_t *OffsetPtr, dwarf::Attribute Attr,
- dwarf::Form Form, unsigned Indent) {
+ dwarf::Form Form, unsigned Indent,
+ DIDumpOptions DumpOpts) {
if (!Die.isValid())
return;
const char BaseIndent[] = " ";
@@ -78,13 +79,15 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
WithColor(OS, syntax::Attribute) << attrString;
else
WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", Attr);
-
- auto formString = FormEncodingString(Form);
- if (!formString.empty())
- OS << " [" << formString << ']';
- else
- OS << format(" [DW_FORM_Unknown_%x]", Form);
-
+
+ if (!DumpOpts.Brief) {
+ auto formString = FormEncodingString(Form);
+ if (!formString.empty())
+ OS << " [" << formString << ']';
+ else
+ OS << format(" [DW_FORM_Unknown_%x]", Form);
+ }
+
DWARFUnit *U = Die.getDwarfUnit();
DWARFFormValue formValue(Form);
@@ -301,8 +304,8 @@ void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
}
-void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth,
- unsigned Indent) const {
+void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, unsigned Indent,
+ DIDumpOptions DumpOpts) const {
if (!isValid())
return;
DataExtractor debug_info_data = U->getDebugInfoExtractor();
@@ -322,10 +325,12 @@ void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth,
else
WithColor(OS, syntax::Tag).get().indent(Indent)
<< format("DW_TAG_Unknown_%x", getTag());
-
- OS << format(" [%u] %c\n", abbrCode,
- AbbrevDecl->hasChildren() ? '*' : ' ');
-
+
+ if (!DumpOpts.Brief)
+ OS << format(" [%u] %c", abbrCode,
+ AbbrevDecl->hasChildren() ? '*' : ' ');
+ OS << '\n';
+
// Dump all data in the DIE for the attributes.
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
if (AttrSpec.Form == DW_FORM_implicit_const) {
@@ -335,13 +340,13 @@ void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth,
continue;
}
dumpAttribute(OS, *this, &offset, AttrSpec.Attr, AttrSpec.Form,
- Indent);
+ Indent, DumpOpts);
}
DWARFDie child = getFirstChild();
if (RecurseDepth > 0 && child) {
while (child) {
- child.dump(OS, RecurseDepth-1, Indent+2);
+ child.dump(OS, RecurseDepth-1, Indent+2, DumpOpts);
child = child.getSibling();
}
}
diff --git a/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/lib/DebugInfo/DWARF/DWARFFormValue.cpp
index 0963d7bfd713..ed1f5f46dcfb 100644
--- a/lib/DebugInfo/DWARF/DWARFFormValue.cpp
+++ b/lib/DebugInfo/DWARF/DWARFFormValue.cpp
@@ -13,10 +13,10 @@
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
-#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
@@ -301,6 +301,7 @@ bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
return (FC == FC_Address);
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_strp_alt:
+ case DW_FORM_strx:
return (FC == FC_String);
case DW_FORM_implicit_const:
return (FC == FC_Constant);
@@ -415,6 +416,7 @@ bool DWARFFormValue::extractValue(const DataExtractor &Data,
break;
case DW_FORM_GNU_addr_index:
case DW_FORM_GNU_str_index:
+ case DW_FORM_strx:
Value.uval = Data.getULEB128(OffsetPtr);
break;
default:
@@ -542,6 +544,7 @@ void DWARFFormValue::dump(raw_ostream &OS) const {
OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)UValue);
dumpString(OS);
break;
+ case DW_FORM_strx:
case DW_FORM_GNU_str_index:
OS << format(" indexed (%8.8x) string = ", (uint32_t)UValue);
dumpString(OS);
@@ -620,10 +623,11 @@ Optional<const char *> DWARFFormValue::getAsCString() const {
if (Form == DW_FORM_GNU_strp_alt || U == nullptr)
return None;
uint32_t Offset = Value.uval;
- if (Form == DW_FORM_GNU_str_index) {
- uint32_t StrOffset;
+ if (Form == DW_FORM_GNU_str_index || Form == DW_FORM_strx) {
+ uint64_t StrOffset;
if (!U->getStringOffsetSectionItem(Offset, StrOffset))
return None;
+ StrOffset += U->getStringOffsetSectionRelocation(Offset);
Offset = StrOffset;
}
if (const char *Str = U->getStringExtractor().getCStr(&Offset)) {
diff --git a/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp b/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp
index 0625d01097c9..ebd6104ab878 100644
--- a/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp
+++ b/lib/DebugInfo/DWARF/DWARFGdbIndex.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/DebugInfo/DWARF/DWARFGdbIndex.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
diff --git a/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp b/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
index 25824f6eb83b..fd1684d33a16 100644
--- a/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
+++ b/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
@@ -7,10 +7,10 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
-#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/lib/DebugInfo/DWARF/DWARFUnit.cpp b/lib/DebugInfo/DWARF/DWARFUnit.cpp
index c5add6a478b3..09e6a292e5fe 100644
--- a/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -7,8 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/SmallString.h"
+#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -16,7 +17,6 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
-#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DataExtractor.h"
@@ -33,8 +33,9 @@ using namespace dwarf;
void DWARFUnitSectionBase::parse(DWARFContext &C, const DWARFSection &Section) {
parseImpl(C, Section, C.getDebugAbbrev(), &C.getRangeSection(),
- C.getStringSection(), StringRef(), &C.getAddrSection(),
- C.getLineSection().Data, C.isLittleEndian(), false);
+ C.getStringSection(), C.getStringOffsetSection(),
+ &C.getAddrSection(), C.getLineSection().Data, C.isLittleEndian(),
+ false);
}
void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
@@ -48,19 +49,14 @@ void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
const DWARFDebugAbbrev *DA, const DWARFSection *RS,
- StringRef SS, StringRef SOS, const DWARFSection *AOS,
- StringRef LS, bool LE, bool IsDWO,
+ StringRef SS, const DWARFSection &SOS,
+ const DWARFSection *AOS, StringRef LS, bool LE, bool IsDWO,
const DWARFUnitSectionBase &UnitSection,
const DWARFUnitIndex::Entry *IndexEntry)
: Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS),
- LineSection(LS), StringSection(SS), StringOffsetSection([&]() {
- if (IndexEntry)
- if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
- return SOS.slice(C->Offset, C->Offset + C->Length);
- return SOS;
- }()),
- AddrOffsetSection(AOS), isLittleEndian(LE), isDWO(IsDWO),
- UnitSection(UnitSection), IndexEntry(IndexEntry) {
+ LineSection(LS), StringSection(SS), StringOffsetSection(SOS),
+ StringOffsetSectionBase(0), AddrOffsetSection(AOS), isLittleEndian(LE),
+ isDWO(IsDWO), UnitSection(UnitSection), IndexEntry(IndexEntry) {
clear();
}
@@ -77,17 +73,25 @@ bool DWARFUnit::getAddrOffsetSectionItem(uint32_t Index,
}
bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index,
- uint32_t &Result) const {
- // FIXME: string offset section entries are 8-byte for DWARF64.
- const uint32_t ItemSize = 4;
- uint32_t Offset = Index * ItemSize;
- if (StringOffsetSection.size() < Offset + ItemSize)
+ uint64_t &Result) const {
+ unsigned ItemSize = getFormat() == DWARF64 ? 8 : 4;
+ uint32_t Offset = StringOffsetSectionBase + Index * ItemSize;
+ if (StringOffsetSection.Data.size() < Offset + ItemSize)
return false;
- DataExtractor DA(StringOffsetSection, isLittleEndian, 0);
- Result = DA.getU32(&Offset);
+ DataExtractor DA(StringOffsetSection.Data, isLittleEndian, 0);
+ Result = ItemSize == 4 ? DA.getU32(&Offset) : DA.getU64(&Offset);
return true;
}
+uint64_t DWARFUnit::getStringOffsetSectionRelocation(uint32_t Index) const {
+ unsigned ItemSize = getFormat() == DWARF64 ? 8 : 4;
+ uint64_t ByteOffset = StringOffsetSectionBase + Index * ItemSize;
+ RelocAddrMap::const_iterator AI = getStringOffsetsRelocMap().find(ByteOffset);
+ if (AI != getStringOffsetsRelocMap().end())
+ return AI->second.Value;
+ return 0;
+}
+
bool DWARFUnit::extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) {
Length = debug_info.getU32(offset_ptr);
Version = debug_info.getU16(offset_ptr);
@@ -119,6 +123,9 @@ bool DWARFUnit::extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) {
if (!LengthOK || !VersionOK || !AddrSizeOK)
return false;
+ // Keep track of the highest DWARF version we encounter across all units.
+ Context.setMaxVersionIfGreater(Version);
+
Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
return Abbrevs != nullptr;
}
@@ -242,6 +249,17 @@ size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
setBaseAddress(*BaseAddr);
AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0);
RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
+
+ // In general, we derive the offset of the unit's contibution to the
+ // debug_str_offsets{.dwo} section from the unit DIE's
+ // DW_AT_str_offsets_base attribute. In dwp files we add to it the offset
+ // we get from the index table.
+ StringOffsetSectionBase =
+ toSectionOffset(UnitDie.find(DW_AT_str_offsets_base), 0);
+ if (IndexEntry)
+ if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
+ StringOffsetSectionBase += C->Offset;
+
// Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
// skeleton CU DIE, so that DWARF users not aware of it are not broken.
}
diff --git a/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp b/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
index 0981a4dfdfa5..59b3d0ca55a6 100644
--- a/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
+++ b/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/lib/DebugInfo/DWARF/LLVMBuild.txt b/lib/DebugInfo/DWARF/LLVMBuild.txt
index 9f8b1047ef6b..8242a7f2e7f7 100644
--- a/lib/DebugInfo/DWARF/LLVMBuild.txt
+++ b/lib/DebugInfo/DWARF/LLVMBuild.txt
@@ -19,4 +19,4 @@
type = Library
name = DebugInfoDWARF
parent = DebugInfo
-required_libraries = Object Support
+required_libraries = BinaryFormat Object Support