From dbfa9e5cd498d63ab0e17a4c6c5a890bc14a88dc Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 23 May 2016 21:58:58 +0000 Subject: [PATCH] llvm-dwp: Pull out compression handling helper llvm-svn: 270496 --- tools/llvm-dwp/llvm-dwp.cpp | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/llvm-dwp/llvm-dwp.cpp b/tools/llvm-dwp/llvm-dwp.cpp index 1ce6a14d37b..ab66c7168fa 100644 --- a/tools/llvm-dwp/llvm-dwp.cpp +++ b/tools/llvm-dwp/llvm-dwp.cpp @@ -359,6 +359,25 @@ std::string buildDWODescription(StringRef Name, StringRef DWPName, StringRef DWO return Text; } +static Error handleCompressedSection( + SmallVector, 4> &UncompressedSections, StringRef &Name, + StringRef &Contents) { + if (!Name.startswith("zdebug_")) + return Error(); + UncompressedSections.emplace_back(); + uint64_t OriginalSize; + if (!zlib::isAvailable()) + return make_error("zlib not available"); + if (!consumeCompressedDebugSectionHeader(Contents, OriginalSize) || + zlib::uncompress(Contents, UncompressedSections.back(), OriginalSize) != + zlib::StatusOK) + return make_error( + ("failure while decompressing compressed section: '" + Name + "\'") + .str()); + Name = Name.substr(1); + Contents = UncompressedSections.back(); + return Error(); +} Error buildDuplicateError(const std::pair &PrevE, const CompileUnitIdentifiers &ID, StringRef DWPName) { return make_error( @@ -431,21 +450,9 @@ static Error write(MCStreamer &Out, ArrayRef Inputs) { if (auto Err = Section.getContents(Contents)) return errorCodeToError(Err); - if (Name.startswith("zdebug_")) { - UncompressedSections.emplace_back(); - uint64_t OriginalSize; - if (!zlib::isAvailable()) - return make_error("zlib not available"); - if (!consumeCompressedDebugSectionHeader(Contents, OriginalSize) || - zlib::uncompress(Contents, UncompressedSections.back(), - OriginalSize) != zlib::StatusOK) - return make_error( - ("failure while decompressing compressed section: '" + Name + - "\'") - .str()); - Name = Name.substr(1); - Contents = UncompressedSections.back(); - } + if (auto Err = + handleCompressedSection(UncompressedSections, Name, Contents)) + return Err; auto SectionPair = KnownSections.find(Name); if (SectionPair == KnownSections.end())