summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-06-13 08:14:27 +0000
committerPavel Labath <labath@google.com>2018-06-13 08:14:27 +0000
commit4adc88ed25b313b1dc6594f3b00d1a206f5449b6 (patch)
treebe04e2b6d57a26947082c18f4564d8a77fbab2d5 /llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
parent2527c378c67bc274c0a93bb0fabbbabd95405699 (diff)
downloadbcm5719-llvm-4adc88ed25b313b1dc6594f3b00d1a206f5449b6.tar.gz
bcm5719-llvm-4adc88ed25b313b1dc6594f3b00d1a206f5449b6.zip
[DWARF/AccelTable] Remove getDIESectionOffset for DWARF v5 entries
Summary: This method was not correct for entries in DWO files as it assumed it could just add up the CU and DIE offsets to get the absolute DIE offset. This is not correct for the DWO files, as here the CU offset will reference the skeleton unit, whereas the DIE offset will be the offset in the full unit in the DWO file. Unfortunately, this means that we are not able to determine the absolute DIE offset using the information in the .debug_names section alone, which means we have to offload some of this work to the users of this class. To demonstrate how this can be done, I've added/fixed the ability to lookup entries using accelerator tables in DWO files in llvm-dwarfdump. To make this happen, I've needed to make two extra changes in other classes: - made the DWARFContext method to lookup a CU based on the section offset public. I've needed this functionality to lookup a CU, and this seems like a useful thing in general. - made DWARFUnit::getDWOId call extractDIEsIfNeeded. Before this, the DWOId was filled in only if the root DIE happened to be parsed before we called the accessor. Since the lazy parsing is supposed to happen under the hood, calling extractDIEsIfNeeded seems appropriate. Reviewers: JDevlieghere, aprantl, dblaikie Subscribers: mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D48009 llvm-svn: 334578
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp')
-rw-r--r--llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp61
1 files changed, 45 insertions, 16 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 433c681a108..d9d36625083 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -309,31 +309,60 @@ static void filterByName(const StringSet<> &Names,
}
-template <typename AccelTable>
-static void getDIEOffset(const AccelTable &Accel, StringRef Name,
- SmallVectorImpl<uint64_t> &Offsets) {
- for (const auto &Entry : Accel.equal_range(Name))
- if (llvm::Optional<uint64_t> Off = Entry.getDIESectionOffset())
- Offsets.push_back(*Off);
+static void getDies(DWARFContext &DICtx, const AppleAcceleratorTable &Accel,
+ StringRef Name, SmallVectorImpl<DWARFDie> &Dies) {
+ for (const auto &Entry : Accel.equal_range(Name)) {
+ if (llvm::Optional<uint64_t> Off = Entry.getDIESectionOffset()) {
+ if (DWARFDie Die = DICtx.getDIEForOffset(*Off))
+ Dies.push_back(Die);
+ }
+ }
+}
+
+static DWARFDie toDie(const DWARFDebugNames::Entry &Entry,
+ DWARFContext &DICtx) {
+ llvm::Optional<uint64_t> CUOff = Entry.getCUOffset();
+ llvm::Optional<uint64_t> Off = Entry.getDIEUnitOffset();
+ if (!CUOff || !Off)
+ return DWARFDie();
+
+ DWARFCompileUnit *CU = DICtx.getCompileUnitForOffset(*CUOff);
+ if (!CU)
+ return DWARFDie();
+
+ if (Optional<uint64_t> DWOId = CU->getDWOId()) {
+ // This is a skeleton unit. Look up the DIE in the DWO unit.
+ CU = DICtx.getDWOCompileUnitForHash(*DWOId);
+ if (!CU)
+ return DWARFDie();
+ }
+
+ return CU->getDIEForOffset(CU->getOffset() + *Off);
+}
+
+static void getDies(DWARFContext &DICtx, const DWARFDebugNames &Accel,
+ StringRef Name, SmallVectorImpl<DWARFDie> &Dies) {
+ for (const auto &Entry : Accel.equal_range(Name)) {
+ if (DWARFDie Die = toDie(Entry, DICtx))
+ Dies.push_back(Die);
+ }
}
/// Print only DIEs that have a certain name.
static void filterByAccelName(ArrayRef<std::string> Names, DWARFContext &DICtx,
raw_ostream &OS) {
- SmallVector<uint64_t, 4> Offsets;
+ SmallVector<DWARFDie, 4> Dies;
for (const auto &Name : Names) {
- getDIEOffset(DICtx.getAppleNames(), Name, Offsets);
- getDIEOffset(DICtx.getAppleTypes(), Name, Offsets);
- getDIEOffset(DICtx.getAppleNamespaces(), Name, Offsets);
- getDIEOffset(DICtx.getDebugNames(), Name, Offsets);
+ getDies(DICtx, DICtx.getAppleNames(), Name, Dies);
+ getDies(DICtx, DICtx.getAppleTypes(), Name, Dies);
+ getDies(DICtx, DICtx.getAppleNamespaces(), Name, Dies);
+ getDies(DICtx, DICtx.getDebugNames(), Name, Dies);
}
- llvm::sort(Offsets.begin(), Offsets.end());
- Offsets.erase(std::unique(Offsets.begin(), Offsets.end()), Offsets.end());
+ llvm::sort(Dies.begin(), Dies.end());
+ Dies.erase(std::unique(Dies.begin(), Dies.end()), Dies.end());
- for (uint64_t Off: Offsets) {
- DWARFDie Die = DICtx.getDIEForOffset(Off);
+ for (DWARFDie Die : Dies)
Die.dump(OS, 0, getDumpOpts());
- }
}
/// Handle the --lookup option and dump the DIEs and line info for the given
OpenPOWER on IntegriCloud