From 2122ff64c6ef776d37592a7fc3f4029cdef46fe2 Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 5 May 2017 10:52:39 +0000 Subject: [PATCH] [llvm-dwarfdump] - Print an error message if section decompression failed. 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. Differential revision: https://reviews.llvm.org/D32865 llvm-svn: 302221 --- llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | 3 ++ llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | 35 +++++++++++++++------ .../dwarfdump-decompression-error.elf-x86-64 | Bin 0 -> 7096 bytes .../DebugInfo/dwarfdump-decompression-error.test | 15 +++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 create mode 100644 llvm/test/DebugInfo/dwarfdump-decompression-error.test diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h index b9f3425..d42c477 100644 --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -310,6 +310,9 @@ class DWARFContextInMemory : public DWARFContext { StringRef *MapSectionToMember(StringRef Name); + Error maybeDecompress(const object::SectionRef &Sec, StringRef Name, + StringRef &Data); + public: DWARFContextInMemory(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr); diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp index 179d6af..246899a 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -957,6 +957,26 @@ static bool isRelocScattered(const object::ObjectFile &Obj, return MachObj->isRelocationScattered(RelocInfo); } +Error DWARFContextInMemory::maybeDecompress(const SectionRef &Sec, + StringRef Name, StringRef &Data) { + if (!Decompressor::isCompressed(Sec)) + return Error::success(); + + Expected 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()), @@ -980,16 +1000,11 @@ DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj, if (!L || !L->getLoadedSectionContents(*RelocatedSection,data)) Section.getContents(data); - if (Decompressor::isCompressed(Section)) { - Expected 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", diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 b/llvm/test/DebugInfo/Inputs/dwarfdump-decompression-error.elf-x86-64 new file mode 100644 index 0000000000000000000000000000000000000000..ba352f51123d5cfc94808025c2870fdf25914e64 GIT binary patch literal 7096 zcmcgwZ)_CT5ud&FKXPzB^Vfh|t_i44z=r_`Ob}tuV6%=4xWp7!jk7-At?iS1ch=or zVydKdN)yEj6k1hkRpkTy)(@2u3TWym^23z5Q12Kwro(Kqv%H18K9Sr6B(e@XzH+Wvm;Tz=Fph1`UYR z<7253;=UyO0*4mf#C9g~I+8;Sge+fR-sWo{oWrQxsJ;cVSoHY;N(f0fV2(uOPenGD z+YO_rk?!+W&LbxIupg=9GR%I%Y%lynPE5G8kJ?608^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