aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DWP/DWP.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DWP/DWP.cpp')
-rw-r--r--llvm/lib/DWP/DWP.cpp108
1 files changed, 61 insertions, 47 deletions
diff --git a/llvm/lib/DWP/DWP.cpp b/llvm/lib/DWP/DWP.cpp
index 346f4dfd290d..50447042bbb8 100644
--- a/llvm/lib/DWP/DWP.cpp
+++ b/llvm/lib/DWP/DWP.cpp
@@ -175,7 +175,7 @@ static StringRef getSubsection(StringRef Section,
const auto *Off = Entry.getContribution(Kind);
if (!Off)
return StringRef();
- return Section.substr(Off->Offset, Off->Length);
+ return Section.substr(Off->getOffset(), Off->getLength());
}
static void
@@ -200,16 +200,17 @@ addAllTypesFromDWP(MCStreamer &Out,
continue;
auto &C =
Entry.Contributions[getContributionIndex(Kind, TUIndex.getVersion())];
- C.Offset += I->Offset;
- C.Length = I->Length;
+ C.setOffset(C.getOffset() + I->getOffset());
+ C.setLength(I->getLength());
++I;
}
auto &C = Entry.Contributions[TypesContributionIndex];
Out.emitBytes(Types.substr(
- C.Offset - TUEntry.Contributions[TypesContributionIndex].Offset,
- C.Length));
- C.Offset = TypesOffset;
- TypesOffset += C.Length;
+ C.getOffset() -
+ TUEntry.Contributions[TypesContributionIndex].getOffset(),
+ C.getLength()));
+ C.setOffset(TypesOffset);
+ TypesOffset += C.getLength();
}
}
@@ -226,23 +227,23 @@ static void addAllTypesFromTypesSection(
// Zero out the debug_info contribution
Entry.Contributions[0] = {};
auto &C = Entry.Contributions[getContributionIndex(DW_SECT_EXT_TYPES, 2)];
- C.Offset = TypesOffset;
+ C.setOffset(TypesOffset);
auto PrevOffset = Offset;
// Length of the unit, including the 4 byte length field.
- C.Length = Data.getU32(&Offset) + 4;
+ C.setLength(Data.getU32(&Offset) + 4);
Data.getU16(&Offset); // Version
Data.getU32(&Offset); // Abbrev offset
Data.getU8(&Offset); // Address size
auto Signature = Data.getU64(&Offset);
- Offset = PrevOffset + C.Length;
+ Offset = PrevOffset + C.getLength32();
auto P = TypeIndexEntries.insert(std::make_pair(Signature, Entry));
if (!P.second)
continue;
- Out.emitBytes(Types.substr(PrevOffset, C.Length));
- TypesOffset += C.Length;
+ Out.emitBytes(Types.substr(PrevOffset, C.getLength32()));
+ TypesOffset += C.getLength32();
}
}
}
@@ -252,16 +253,23 @@ static std::string buildDWODescription(StringRef Name, StringRef DWPName,
std::string Text = "\'";
Text += Name;
Text += '\'';
- if (!DWPName.empty()) {
+ bool HasDWO = !DWOName.empty();
+ bool HasDWP = !DWPName.empty();
+ if (HasDWO || HasDWP) {
Text += " (from ";
- if (!DWOName.empty()) {
+ if (HasDWO) {
Text += '\'';
Text += DWOName;
- Text += "' in ";
+ Text += '\'';
}
- Text += '\'';
- Text += DWPName;
- Text += "')";
+ if (HasDWO && HasDWP)
+ Text += " in ";
+ if (!DWPName.empty()) {
+ Text += '\'';
+ Text += DWPName;
+ Text += '\'';
+ }
+ Text += ")";
}
return Text;
}
@@ -395,14 +403,17 @@ void writeStringsAndOffsets(MCStreamer &Out, DWPStringPool &Strings,
}
}
-void writeIndexTable(
- MCStreamer &Out, ArrayRef<unsigned> ContributionOffsets,
- const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
- uint32_t DWARFUnitIndex::Entry::SectionContribution::*Field) {
+enum AccessField { Offset, Length };
+void writeIndexTable(MCStreamer &Out, ArrayRef<unsigned> ContributionOffsets,
+ const MapVector<uint64_t, UnitIndexEntry> &IndexEntries,
+ const AccessField &Field) {
for (const auto &E : IndexEntries)
- for (size_t I = 0; I != array_lengthof(E.second.Contributions); ++I)
+ for (size_t I = 0; I != std::size(E.second.Contributions); ++I)
if (ContributionOffsets[I])
- Out.emitIntValue(E.second.Contributions[I].*Field, 4);
+ Out.emitIntValue((Field == AccessField::Offset
+ ? E.second.Contributions[I].getOffset32()
+ : E.second.Contributions[I].getLength32()),
+ 4);
}
void writeIndex(MCStreamer &Out, MCSection *Section,
@@ -453,12 +464,10 @@ void writeIndex(MCStreamer &Out, MCSection *Section,
Out.emitIntValue(getOnDiskSectionId(I), 4);
// Write the offsets.
- writeIndexTable(Out, ContributionOffsets, IndexEntries,
- &DWARFUnitIndex::Entry::SectionContribution::Offset);
+ writeIndexTable(Out, ContributionOffsets, IndexEntries, AccessField::Offset);
// Write the lengths.
- writeIndexTable(Out, ContributionOffsets, IndexEntries,
- &DWARFUnitIndex::Entry::SectionContribution::Length);
+ writeIndexTable(Out, ContributionOffsets, IndexEntries, AccessField::Length);
}
Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
@@ -579,8 +588,12 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
for (const auto &Input : Inputs) {
auto ErrOrObj = object::ObjectFile::createObjectFile(Input);
- if (!ErrOrObj)
- return ErrOrObj.takeError();
+ if (!ErrOrObj) {
+ return handleErrors(ErrOrObj.takeError(),
+ [&](std::unique_ptr<ECError> EC) -> Error {
+ return createFileError(Input, Error(std::move(EC)));
+ });
+ }
auto &Obj = *ErrOrObj->getBinary();
Objects.push_back(std::move(*ErrOrObj));
@@ -631,9 +644,9 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
for (auto Pair : SectionLength) {
auto Index = getContributionIndex(Pair.first, IndexVersion);
- CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
- ContributionOffsets[Index] +=
- (CurEntry.Contributions[Index].Length = Pair.second);
+ CurEntry.Contributions[Index].setOffset(ContributionOffsets[Index]);
+ CurEntry.Contributions[Index].setLength(Pair.second);
+ ContributionOffsets[Index] += CurEntry.Contributions[Index].getLength32();
}
uint32_t &InfoSectionOffset =
@@ -653,21 +666,21 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
UnitIndexEntry Entry = CurEntry;
auto &C = Entry.Contributions[getContributionIndex(DW_SECT_INFO,
IndexVersion)];
- C.Offset = InfoSectionOffset;
- C.Length = Header.Length + 4;
+ C.setOffset(InfoSectionOffset);
+ C.setLength(Header.Length + 4);
if (std::numeric_limits<uint32_t>::max() - InfoSectionOffset <
- C.Length)
+ C.getLength32())
return make_error<DWPError>(
"debug information section offset is greater than 4GB");
- UnitOffset += C.Length;
+ UnitOffset += C.getLength32();
if (Header.Version < 5 ||
Header.UnitType == dwarf::DW_UT_split_compile) {
- Expected<CompileUnitIdentifiers> EID =
- getCUIdentifiers(Header, AbbrevSection,
- Info.substr(UnitOffset - C.Length, C.Length),
- CurStrOffsetSection, CurStrSection);
+ Expected<CompileUnitIdentifiers> EID = getCUIdentifiers(
+ Header, AbbrevSection,
+ Info.substr(UnitOffset - C.getLength32(), C.getLength32()),
+ CurStrOffsetSection, CurStrSection);
if (!EID)
return createFileError(Input, EID.takeError());
@@ -685,8 +698,9 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
if (!P.second)
continue;
}
- Out.emitBytes(Info.substr(UnitOffset - C.Length, C.Length));
- InfoSectionOffset += C.Length;
+ Out.emitBytes(
+ Info.substr(UnitOffset - C.getLength32(), C.getLength32()));
+ InfoSectionOffset += C.getLength32();
}
}
@@ -749,15 +763,15 @@ Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
continue;
auto &C =
NewEntry.Contributions[getContributionIndex(Kind, IndexVersion)];
- C.Offset += I->Offset;
- C.Length = I->Length;
+ C.setOffset(C.getOffset() + I->getOffset());
+ C.setLength(I->getLength());
++I;
}
unsigned Index = getContributionIndex(DW_SECT_INFO, IndexVersion);
auto &C = NewEntry.Contributions[Index];
Out.emitBytes(CUInfoSection);
- C.Offset = InfoSectionOffset;
- InfoSectionOffset += C.Length;
+ C.setOffset(InfoSectionOffset);
+ InfoSectionOffset += C.getLength32();
}
if (!CurTUIndexSection.empty()) {