summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-05-31 08:47:00 +0000
committerPavel Labath <labath@google.com>2018-05-31 08:47:00 +0000
commit59870af66f015c13105bbb865fb30a5b22e5548b (patch)
treee0a1d3968174e91c0bb6a31df186adcf2e4f50cd /llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
parent2e09995d425ae69aa0f20cf4a5c5db881d71fbf1 (diff)
downloadbcm5719-llvm-59870af66f015c13105bbb865fb30a5b22e5548b.tar.gz
bcm5719-llvm-59870af66f015c13105bbb865fb30a5b22e5548b.zip
DWARFAcceleratorTable: fix equal_range iterators
Summary: Both (Apple and DWARF5) implementations of the iterators had bugs which resulted in crashes if one attempted to iterate through the accelerator tables all the way. For the Apple tables, the issue was that we did not clear the DataOffset field when we reached the end, which made our iterator compare unequal to the "end" iterator. For the Dwarf5 tables, the problem was that we incremented the CurrentIndex pointer and then used the incremented (possibly invalid) pointer to check whether we have reached the end of the index list. The reason these bugs went undetected is because their only user (dwarfdump) only ever searched for the first match. Besides allowing us to test this fix, changing llvm-dwarfdump --find to display all matches seems like a good improvement (it makes the behavior consistent with the --name option), so I change llvm-dwarfdump to do that. The existing tests would be sufficient to test this fix with the new llvm-dwarfdump behavior, but I add a special test that demonstrates that the tool indeed displays multiple results. The find.test test needed to be tweaked a bit as the tool now does not print the ".debug_info contents" header (also consistent with how --name works). Reviewers: JDevlieghere, aprantl, dblaikie Subscribers: mgrang, llvm-commits Differential Revision: https://reviews.llvm.org/D47543 llvm-svn: 333635
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp')
-rw-r--r--llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp54
1 files changed, 29 insertions, 25 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 300a00b01be..433c681a108 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -309,6 +309,33 @@ 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);
+}
+
+/// 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;
+ 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);
+ }
+ llvm::sort(Offsets.begin(), Offsets.end());
+ Offsets.erase(std::unique(Offsets.begin(), Offsets.end()), Offsets.end());
+
+ for (uint64_t Off: Offsets) {
+ DWARFDie Die = DICtx.getDIEForOffset(Off);
+ Die.dump(OS, 0, getDumpOpts());
+ }
+}
+
/// Handle the --lookup option and dump the DIEs and line info for the given
/// address.
static bool lookup(DWARFContext &DICtx, uint64_t Address, raw_ostream &OS) {
@@ -335,15 +362,6 @@ static bool lookup(DWARFContext &DICtx, uint64_t Address, raw_ostream &OS) {
bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
Twine Filename, raw_ostream &OS);
-template <typename AccelTable>
-static llvm::Optional<uint64_t> getDIEOffset(const AccelTable &Accel,
- StringRef Name) {
- for (const auto &Entry : Accel.equal_range(Name))
- if (llvm::Optional<uint64_t> Off = Entry.getDIESectionOffset())
- return *Off;
- return None;
-}
-
static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
raw_ostream &OS) {
logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
@@ -369,22 +387,8 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
// Handle the --find option and lower it to --debug-info=<offset>.
if (!Find.empty()) {
- DumpOffsets[DIDT_ID_DebugInfo] = [&]() -> llvm::Optional<uint64_t> {
- for (auto Name : Find) {
- if (auto Offset = getDIEOffset(DICtx.getAppleNames(), Name))
- return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
- if (auto Offset = getDIEOffset(DICtx.getAppleTypes(), Name))
- return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
- if (auto Offset = getDIEOffset(DICtx.getAppleNamespaces(), Name))
- return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
- if (auto Offset = getDIEOffset(DICtx.getDebugNames(), Name))
- return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
- }
- return None;
- }();
- // Early exit if --find was specified but the current file doesn't have it.
- if (!DumpOffsets[DIDT_ID_DebugInfo])
- return true;
+ filterByAccelName(Find, DICtx, OS);
+ return true;
}
// Dump the complete DWARF structure.
OpenPOWER on IntegriCloud