[PATCH] D32865: [llvm-dwarfdump] - Print an error message if section decompression failed.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 4 07:47:23 PDT 2017
grimar created this revision.
llvm-dwarfdump currently prints no message if decompression fails
for some reason. I noticed that during work on one of LLD patches
where LLD produced an broken output. It was a bit confusing to see
no output for section dumped and no any error message at all.
Patch adds error message for such cases.
https://reviews.llvm.org/D32865
Files:
include/llvm/DebugInfo/DWARF/DWARFContext.h
lib/DebugInfo/DWARF/DWARFContext.cpp
test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64
test/DebugInfo/dwarfdump-decompression-error.test
Index: test/DebugInfo/dwarfdump-decompression-error.test
===================================================================
--- test/DebugInfo/dwarfdump-decompression-error.test
+++ test/DebugInfo/dwarfdump-decompression-error.test
@@ -0,0 +1,15 @@
+REQUIRES: zlib
+
+// dwarfdump-decompression-error.elf-x86-64 is prepared using following
+// source code and invocation:
+// test.cpp:
+// int main() { return 0; }
+//
+// gcc test.cpp -o out -g -Wl,--compress-debug-sections,zlib
+//
+// After that result object was modified manually. One random byte in compressed
+// content of .debug_info section was changed to 0xff. That breaks normal
+// decompression flow in runtime.
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-decompression-error.elf-x86-64 2>&1 | FileCheck %s
+
+CHECK: error: failed to decompress '.debug_info', zlib error: Z_DATA_ERROR
Index: lib/DebugInfo/DWARF/DWARFContext.cpp
===================================================================
--- lib/DebugInfo/DWARF/DWARFContext.cpp
+++ lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -935,6 +935,26 @@
return MachObj->isRelocationScattered(RelocInfo);
}
+Error DWARFContextInMemory::maybeDecompress(const SectionRef &Sec,
+ StringRef Name, StringRef &Data) {
+ if (!Decompressor::isCompressed(Sec))
+ return Error::success();
+
+ Expected<Decompressor> Decompressor =
+ Decompressor::create(Name, Data, IsLittleEndian, AddressSize == 8);
+ if (!Decompressor)
+ return Decompressor.takeError();
+
+ SmallString<32> Out;
+ if (auto Err = Decompressor->decompress(Out))
+ return Err;
+
+ UncompressedSections.emplace_back(std::move(Out));
+ Data = UncompressedSections.back();
+
+ return Error::success();
+}
+
DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
const LoadedObjectInfo *L)
: IsLittleEndian(Obj.isLittleEndian()),
@@ -958,16 +978,11 @@
if (!L || !L->getLoadedSectionContents(*RelocatedSection,data))
Section.getContents(data);
- if (Decompressor::isCompressed(Section)) {
- Expected<Decompressor> Decompressor =
- Decompressor::create(name, data, IsLittleEndian, AddressSize == 8);
- if (!Decompressor)
- continue;
- SmallString<32> Out;
- if (auto Err = Decompressor->decompress(Out))
- continue;
- UncompressedSections.emplace_back(std::move(Out));
- data = UncompressedSections.back();
+ if (auto Err = maybeDecompress(Section, name, data)) {
+ errs() << "error: failed to decompress '" + name + "', " +
+ toString(std::move(Err))
+ << '\n';
+ continue;
}
// Compressed sections names in GNU style starts from ".z",
Index: include/llvm/DebugInfo/DWARF/DWARFContext.h
===================================================================
--- include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -310,6 +310,9 @@
StringRef *MapSectionToMember(StringRef Name);
+ Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
+ StringRef &Data);
+
public:
DWARFContextInMemory(const object::ObjectFile &Obj,
const LoadedObjectInfo *L = nullptr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32865.97827.patch
Type: text/x-patch
Size: 3237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170504/10c11e47/attachment.bin>
More information about the llvm-commits
mailing list