summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump/COFFDump.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-21 11:07:31 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-21 11:07:31 +0000
commitf0f38d9b9deea950659756ddd490c6673199e4aa (patch)
treecef89ff401156ea39c0664d21dc25f844c96a56f /llvm/tools/llvm-objdump/COFFDump.cpp
parent65c58a902d00d8523cbe55d6218ba8d23b6dd185 (diff)
downloadbcm5719-llvm-f0f38d9b9deea950659756ddd490c6673199e4aa.tar.gz
bcm5719-llvm-f0f38d9b9deea950659756ddd490c6673199e4aa.zip
[llvm-objdump] - Cleanup the error reporting.
The error reporting function are not consistent. Before this change: * They had inconsistent naming (e.g. 'error' vs 'report_error'). * Some of them reported the object name, others - dont. * Some of them accepted the case when there was no error. (i.e. error code or Error had a success value). This patch tries to cleanup it a bit. It also renames report_error -> reportError, report_warning -> reportWarning and removes a full stop from messages. Differential revision: https://reviews.llvm.org/D66418 llvm-svn: 369515
Diffstat (limited to 'llvm/tools/llvm-objdump/COFFDump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/COFFDump.cpp61
1 files changed, 43 insertions, 18 deletions
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index 584467bcf5b..60b0f5a3cbd 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -234,13 +234,14 @@ printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) {
if (Count == 0)
return;
- uint32_t ImageBase = Obj->getPE32Header()->ImageBase;
uintptr_t IntPtr = 0;
- error(Obj->getVaPtr(TableVA, IntPtr));
+ if (std::error_code EC = Obj->getVaPtr(TableVA, IntPtr))
+ reportError(errorCodeToError(EC), Obj->getFileName());
+
const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
outs() << "SEH Table:";
for (int I = 0; I < Count; ++I)
- outs() << format(" 0x%x", P[I] + ImageBase);
+ outs() << format(" 0x%x", P[I] + Obj->getPE32Header()->ImageBase);
outs() << "\n\n";
}
@@ -274,11 +275,16 @@ static void printTLSDirectory(const COFFObjectFile *Obj) {
return;
const data_directory *DataDir;
- error(Obj->getDataDirectory(COFF::TLS_TABLE, DataDir));
- uintptr_t IntPtr = 0;
+ if (std::error_code EC = Obj->getDataDirectory(COFF::TLS_TABLE, DataDir))
+ reportError(errorCodeToError(EC), Obj->getFileName());
+
if (DataDir->RelativeVirtualAddress == 0)
return;
- error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr));
+
+ uintptr_t IntPtr = 0;
+ if (std::error_code EC =
+ Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
+ reportError(errorCodeToError(EC), Obj->getFileName());
if (PE32Header) {
auto *TLSDir = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
@@ -301,11 +307,18 @@ static void printLoadConfiguration(const COFFObjectFile *Obj) {
return;
const data_directory *DataDir;
- error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir));
+
+ if (std::error_code EC =
+ Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir))
+ reportError(errorCodeToError(EC), Obj->getFileName());
+
uintptr_t IntPtr = 0;
if (DataDir->RelativeVirtualAddress == 0)
return;
- error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr));
+
+ if (std::error_code EC =
+ Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
+ reportError(errorCodeToError(EC), Obj->getFileName());
auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
outs() << "Load configuration:"
@@ -447,7 +460,9 @@ static bool getPDataSection(const COFFObjectFile *Obj,
llvm::sort(Rels, isRelocAddressLess);
ArrayRef<uint8_t> Contents;
- error(Obj->getSectionContents(Pdata, Contents));
+ if (Error E = Obj->getSectionContents(Pdata, Contents))
+ reportError(std::move(E), Obj->getFileName());
+
if (Contents.empty())
continue;
@@ -563,10 +578,12 @@ static void printRuntimeFunctionRels(const COFFObjectFile *Obj,
ArrayRef<uint8_t> XContents;
uint64_t UnwindInfoOffset = 0;
- error(getSectionContents(
- Obj, Rels, SectionOffset +
- /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
- XContents, UnwindInfoOffset));
+ if (Error E = getSectionContents(
+ Obj, Rels,
+ SectionOffset +
+ /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
+ XContents, UnwindInfoOffset))
+ reportError(std::move(E), Obj->getFileName());
if (XContents.empty())
return;
@@ -642,9 +659,12 @@ void printCOFFSymbolTable(const object::COFFImportFile *i) {
void printCOFFSymbolTable(const COFFObjectFile *coff) {
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
+ if (!Symbol)
+ reportError(Symbol.takeError(), coff->getFileName());
+
StringRef Name;
- error(Symbol.takeError());
- error(coff->getSymbolName(*Symbol, Name));
+ if (std::error_code EC = coff->getSymbolName(*Symbol, Name))
+ reportError(errorCodeToError(EC), coff->getFileName());
outs() << "[" << format("%2d", SI) << "]"
<< "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
@@ -674,7 +694,9 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
if (Symbol->isSectionDefinition()) {
const coff_aux_section_definition *asd;
- error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd));
+ if (std::error_code EC =
+ coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd))
+ reportError(errorCodeToError(EC), coff->getFileName());
int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
@@ -689,7 +711,8 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
, unsigned(asd->Selection));
} else if (Symbol->isFileRecord()) {
const char *FileName;
- error(coff->getAuxSymbol<char>(SI + 1, FileName));
+ if (std::error_code EC = coff->getAuxSymbol<char>(SI + 1, FileName))
+ reportError(errorCodeToError(EC), coff->getFileName());
StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
coff->getSymbolTableEntrySize());
@@ -699,7 +722,9 @@ void printCOFFSymbolTable(const COFFObjectFile *coff) {
break;
} else if (Symbol->isWeakExternal()) {
const coff_aux_weak_external *awe;
- error(coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe));
+ if (std::error_code EC =
+ coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe))
+ reportError(errorCodeToError(EC), coff->getFileName());
outs() << "AUX " << format("indx %d srch %d\n",
static_cast<uint32_t>(awe->TagIndex),
OpenPOWER on IntegriCloud