summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2016-05-23 21:58:58 +0000
committerDavid Blaikie <dblaikie@gmail.com>2016-05-23 21:58:58 +0000
commit16017f941b43b180f669aa0ed9b64fab8d065e8b (patch)
tree6ca2f8fe3e656d9226eb65b08260dfada827e6a8
parent312768009eb545e2f4c760b2426311cd3959f7b4 (diff)
llvm-dwp: Pull out compression handling helper
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270496 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--tools/llvm-dwp/llvm-dwp.cpp37
1 files 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<SmallString<32>, 4> &UncompressedSections, StringRef &Name,
+ StringRef &Contents) {
+ if (!Name.startswith("zdebug_"))
+ return Error();
+ UncompressedSections.emplace_back();
+ uint64_t OriginalSize;
+ if (!zlib::isAvailable())
+ return make_error<DWPError>("zlib not available");
+ if (!consumeCompressedDebugSectionHeader(Contents, OriginalSize) ||
+ zlib::uncompress(Contents, UncompressedSections.back(), OriginalSize) !=
+ zlib::StatusOK)
+ return make_error<DWPError>(
+ ("failure while decompressing compressed section: '" + Name + "\'")
+ .str());
+ Name = Name.substr(1);
+ Contents = UncompressedSections.back();
+ return Error();
+}
Error buildDuplicateError(const std::pair<uint64_t, UnitIndexEntry> &PrevE,
const CompileUnitIdentifiers &ID, StringRef DWPName) {
return make_error<DWPError>(
@@ -431,21 +450,9 @@ static Error write(MCStreamer &Out, ArrayRef<std::string> 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<DWPError>("zlib not available");
- if (!consumeCompressedDebugSectionHeader(Contents, OriginalSize) ||
- zlib::uncompress(Contents, UncompressedSections.back(),
- OriginalSize) != zlib::StatusOK)
- return make_error<DWPError>(
- ("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())