aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-dwp/llvm-dwp.cpp
diff options
context:
space:
mode:
authorIgor Kudrin <ikudrin@accesssoftek.com>2020-03-11 21:54:51 +0700
committerIgor Kudrin <ikudrin@accesssoftek.com>2020-04-06 13:28:05 +0700
commitf9cd90837bdced66c933349b402c322f7198ddfe (patch)
treea64c06db785b330db1f52e3c6131044e8a619367 /llvm/tools/llvm-dwp/llvm-dwp.cpp
parent6163aa96799cbad7f2f58e02c5bebee9647056a5 (diff)
downloadllvm-f9cd90837bdced66c933349b402c322f7198ddfe.zip
llvm-f9cd90837bdced66c933349b402c322f7198ddfe.tar.gz
llvm-f9cd90837bdced66c933349b402c322f7198ddfe.tar.bz2
[llvm-dwp] Refactor handling of section identifiers. NFCI.
There is a number of places in llvm-dwp.cpp where a section identifier is translated into an index of an internal array of section contributions, and another place where the index is converted to an on-disk value. All these places use direct expressions like "<id> - DW_SECT_INFO" or "<index> + DW_SECT_INFO", exploiting the fact that DW_SECT_INFO is the minimum valid value of that kind. The patch adds distinct functions for that translation. The goal is to make the code more readable and to prepare it to support index sections of new versions, where the numeric scheme of section indexes is changed. Differential Revision: https://reviews.llvm.org/D76067
Diffstat (limited to 'llvm/tools/llvm-dwp/llvm-dwp.cpp')
-rw-r--r--llvm/tools/llvm-dwp/llvm-dwp.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/llvm/tools/llvm-dwp/llvm-dwp.cpp b/llvm/tools/llvm-dwp/llvm-dwp.cpp
index 2a17819..cd7048b 100644
--- a/llvm/tools/llvm-dwp/llvm-dwp.cpp
+++ b/llvm/tools/llvm-dwp/llvm-dwp.cpp
@@ -216,6 +216,19 @@ struct UnitIndexEntry {
StringRef DWPName;
};
+// Convert a section identifier into the index to use with
+// UnitIndexEntry::Contributions.
+static unsigned getContributionIndex(DWARFSectionKind Kind) {
+ assert(Kind >= DW_SECT_INFO);
+ return Kind - DW_SECT_INFO;
+}
+
+// Convert a UnitIndexEntry::Contributions index to the corresponding on-disk
+// value of the section identifier.
+static unsigned getOnDiskSectionId(unsigned Index) {
+ return Index + DW_SECT_INFO;
+}
+
static StringRef getSubsection(StringRef Section,
const DWARFUnitIndex::Entry &Entry,
DWARFSectionKind Kind) {
@@ -241,15 +254,15 @@ static void addAllTypesFromDWP(
// Zero out the debug_info contribution
Entry.Contributions[0] = {};
for (auto Kind : TUIndex.getColumnKinds()) {
- auto &C = Entry.Contributions[Kind - DW_SECT_INFO];
+ auto &C = Entry.Contributions[getContributionIndex(Kind)];
C.Offset += I->Offset;
C.Length = I->Length;
++I;
}
- auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO];
+ unsigned TypesIndex = getContributionIndex(DW_SECT_TYPES);
+ auto &C = Entry.Contributions[TypesIndex];
Out.emitBytes(Types.substr(
- C.Offset - TUEntry.Contributions[DW_SECT_TYPES - DW_SECT_INFO].Offset,
- C.Length));
+ C.Offset - TUEntry.Contributions[TypesIndex].Offset, C.Length));
C.Offset = TypesOffset;
TypesOffset += C.Length;
}
@@ -268,7 +281,7 @@ static void addAllTypes(MCStreamer &Out,
UnitIndexEntry Entry = CUEntry;
// Zero out the debug_info contribution
Entry.Contributions[0] = {};
- auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO];
+ auto &C = Entry.Contributions[getContributionIndex(DW_SECT_TYPES)];
C.Offset = TypesOffset;
auto PrevOffset = Offset;
// Length of the unit, including the 4 byte length field.
@@ -345,7 +358,7 @@ writeIndex(MCStreamer &Out, MCSection *Section,
// Write the column headers (which sections will appear in the table)
for (size_t i = 0; i != ContributionOffsets.size(); ++i)
if (ContributionOffsets[i])
- Out.emitIntValue(i + DW_SECT_INFO, 4);
+ Out.emitIntValue(getOnDiskSectionId(i), 4);
// Write the offsets.
writeIndexTable(Out, ContributionOffsets, IndexEntries,
@@ -438,7 +451,7 @@ static Error handleSection(
return Error::success();
if (DWARFSectionKind Kind = SectionPair->second.second) {
- auto Index = Kind - DW_SECT_INFO;
+ auto Index = getContributionIndex(Kind);
if (Kind != DW_SECT_TYPES) {
CurEntry.Contributions[Index].Offset = ContributionOffsets[Index];
ContributionOffsets[Index] +=
@@ -589,7 +602,8 @@ static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
P.first->second.Name = ID.Name;
P.first->second.DWOName = ID.DWOName;
addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection,
- CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
+ CurEntry,
+ ContributionOffsets[getContributionIndex(DW_SECT_TYPES)]);
continue;
}
@@ -618,7 +632,7 @@ static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
NewEntry.DWOName = ID.DWOName;
NewEntry.DWPName = Input;
for (auto Kind : CUIndex.getColumnKinds()) {
- auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO];
+ auto &C = NewEntry.Contributions[getContributionIndex(Kind)];
C.Offset += I->Offset;
C.Length = I->Length;
++I;
@@ -632,9 +646,9 @@ static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
DataExtractor TUIndexData(CurTUIndexSection, Obj.isLittleEndian(), 0);
if (!TUIndex.parse(TUIndexData))
return make_error<DWPError>("failed to parse tu_index");
- addAllTypesFromDWP(Out, TypeIndexEntries, TUIndex, TypesSection,
- CurTypesSection.front(), CurEntry,
- ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
+ addAllTypesFromDWP(
+ Out, TypeIndexEntries, TUIndex, TypesSection, CurTypesSection.front(),
+ CurEntry, ContributionOffsets[getContributionIndex(DW_SECT_TYPES)]);
}
}
@@ -645,7 +659,7 @@ static Error write(MCStreamer &Out, ArrayRef<std::string> Inputs) {
TypeIndexEntries);
// Lie about the type contribution
- ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO] = 0;
+ ContributionOffsets[getContributionIndex(DW_SECT_TYPES)] = 0;
// Unlie about the info contribution
ContributionOffsets[0] = 1;