summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-readobj
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-readobj')
-rw-r--r--llvm/tools/llvm-readobj/COFFDumper.cpp26
-rw-r--r--llvm/tools/llvm-readobj/MachODumper.cpp14
-rw-r--r--llvm/tools/llvm-readobj/ObjDumper.cpp6
3 files changed, 13 insertions, 33 deletions
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index 62f2fc56b56..21ceb002857 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -933,8 +933,7 @@ void COFFDumper::initializeFileAndStringTables(BinaryStreamReader &Reader) {
void COFFDumper::printCodeViewSymbolSection(StringRef SectionName,
const SectionRef &Section) {
- StringRef SectionContents;
- error(Section.getContents(SectionContents));
+ StringRef SectionContents = unwrapOrError(Section.getContents());
StringRef Data = SectionContents;
SmallVector<StringRef, 10> FunctionNames;
@@ -1218,8 +1217,7 @@ void COFFDumper::mergeCodeViewTypes(MergingTypeTableBuilder &CVIDs,
StringRef SectionName;
error(S.getName(SectionName));
if (SectionName == ".debug$T") {
- StringRef Data;
- error(S.getContents(Data));
+ StringRef Data = unwrapOrError(S.getContents());
uint32_t Magic;
error(consume(Data, Magic));
if (Magic != 4)
@@ -1255,8 +1253,7 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName,
ListScope D(W, "CodeViewTypes");
W.printNumber("Section", SectionName, Obj->getSectionID(Section));
- StringRef Data;
- error(Section.getContents(Data));
+ StringRef Data = unwrapOrError(Section.getContents());
if (opts::CodeViewSubsectionBytes)
W.printBinaryBlock("Data", Data);
@@ -1316,9 +1313,7 @@ void COFFDumper::printSectionHeaders() {
if (opts::SectionData &&
!(Section->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)) {
- StringRef Data;
- error(Sec.getContents(Data));
-
+ StringRef Data = unwrapOrError(Sec.getContents());
W.printBinaryBlock("SectionData", Data);
}
}
@@ -1660,15 +1655,13 @@ void COFFDumper::printCOFFExports() {
void COFFDumper::printCOFFDirectives() {
for (const SectionRef &Section : Obj->sections()) {
- StringRef Contents;
StringRef Name;
error(Section.getName(Name));
if (Name != ".drectve")
continue;
- error(Section.getContents(Contents));
-
+ StringRef Contents = unwrapOrError(Section.getContents());
W.printString("Directive(s)", Contents);
}
}
@@ -1707,8 +1700,7 @@ void COFFDumper::printCOFFResources() {
if (!Name.startswith(".rsrc"))
continue;
- StringRef Ref;
- error(S.getContents(Ref));
+ StringRef Ref = unwrapOrError(S.getContents());
if ((Name == ".rsrc") || (Name == ".rsrc$01")) {
ResourceSectionRef RSF(Ref);
@@ -1834,8 +1826,7 @@ void COFFDumper::printStackMap() const {
if (StackMapSection == object::SectionRef())
return;
- StringRef StackMapContents;
- StackMapSection.getContents(StackMapContents);
+ StringRef StackMapContents = unwrapOrError(StackMapSection.getContents());
ArrayRef<uint8_t> StackMapContentsArray =
arrayRefFromStringRef(StackMapContents);
@@ -1861,8 +1852,7 @@ void COFFDumper::printAddrsig() {
if (AddrsigSection == object::SectionRef())
return;
- StringRef AddrsigContents;
- AddrsigSection.getContents(AddrsigContents);
+ StringRef AddrsigContents = unwrapOrError(AddrsigSection.getContents());
ArrayRef<uint8_t> AddrsigContentsArray(AddrsigContents.bytes_begin(),
AddrsigContents.size());
diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp
index 5e82f1c38f7..5149f469aa1 100644
--- a/llvm/tools/llvm-readobj/MachODumper.cpp
+++ b/llvm/tools/llvm-readobj/MachODumper.cpp
@@ -483,15 +483,8 @@ void MachODumper::printSectionHeaders(const MachOObjectFile *Obj) {
}
}
- if (opts::SectionData) {
- bool IsBSS = Section.isBSS();
- if (!IsBSS) {
- StringRef Data;
- error(Section.getContents(Data));
-
- W.printBinaryBlock("SectionData", Data);
- }
- }
+ if (opts::SectionData && !Section.isBSS())
+ W.printBinaryBlock("SectionData", unwrapOrError(Section.getContents()));
}
}
@@ -660,8 +653,7 @@ void MachODumper::printStackMap() const {
if (StackMapSection == object::SectionRef())
return;
- StringRef StackMapContents;
- StackMapSection.getContents(StackMapContents);
+ StringRef StackMapContents = unwrapOrError(StackMapSection.getContents());
ArrayRef<uint8_t> StackMapContentsArray =
arrayRefFromStringRef(StackMapContents);
diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp
index 15facefaddf..4f73cbdf281 100644
--- a/llvm/tools/llvm-readobj/ObjDumper.cpp
+++ b/llvm/tools/llvm-readobj/ObjDumper.cpp
@@ -73,8 +73,7 @@ void ObjDumper::printSectionAsString(const object::ObjectFile *Obj,
error(E);
W.startLine() << "String dump of section '" << SectionName << "':\n";
- StringRef SectionContent;
- Section.getContents(SectionContent);
+ StringRef SectionContent = unwrapOrError(Section.getContents());
const uint8_t *SecContent = SectionContent.bytes_begin();
const uint8_t *CurrentWord = SecContent;
@@ -107,8 +106,7 @@ void ObjDumper::printSectionAsHex(const object::ObjectFile *Obj,
error(E);
W.startLine() << "Hex dump of section '" << SectionName << "':\n";
- StringRef SectionContent;
- Section.getContents(SectionContent);
+ StringRef SectionContent = unwrapOrError(Section.getContents());
const uint8_t *SecContent = SectionContent.bytes_begin();
const uint8_t *SecEnd = SecContent + SectionContent.size();
OpenPOWER on IntegriCloud