aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-nm
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-06-25 17:55:23 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-06-25 17:55:23 +0000
commit25b15777df42d5d608810f6881b6c98107481d69 (patch)
tree0fabbe893ff5c2dd78381c8b9c3ac7b2fb257832 /tools/llvm-nm
parent76fb9b0e5f553f03321777ff634eb245dd8a821e (diff)
Object: Add proper error handling.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-nm')
-rw-r--r--tools/llvm-nm/llvm-nm.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp
index f6eb33c9e6..014cb29650 100644
--- a/tools/llvm-nm/llvm-nm.cpp
+++ b/tools/llvm-nm/llvm-nm.cpp
@@ -143,6 +143,14 @@ namespace {
StringRef CurrentFilename;
typedef std::vector<NMSymbol> SymbolListT;
SymbolListT SymbolList;
+
+ bool error(error_code ec) {
+ if (!ec) return false;
+
+ outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
+ outs().flush();
+ return true;
+ }
}
static void SortAndPrintSymbolList() {
@@ -261,19 +269,25 @@ static void DumpSymbolNamesFromModule(Module *M) {
}
static void DumpSymbolNamesFromObject(ObjectFile *obj) {
+ error_code ec;
for (ObjectFile::symbol_iterator i = obj->begin_symbols(),
- e = obj->end_symbols(); i != e; ++i) {
- if (!DebugSyms && i->isInternal())
+ e = obj->end_symbols();
+ i != e; i.increment(ec)) {
+ if (error(ec)) break;
+ bool internal;
+ if (error(i->isInternal(internal))) break;
+ if (!DebugSyms && internal)
continue;
NMSymbol s;
s.Size = object::UnknownAddressOrSize;
s.Address = object::UnknownAddressOrSize;
- if (PrintSize || SizeSort)
- s.Size = i->getSize();
+ if (PrintSize || SizeSort) {
+ if (error(i->getSize(s.Size))) break;
+ }
if (PrintAddress)
- s.Address = i->getAddress();
- s.TypeChar = i->getNMTypeChar();
- s.Name = i->getName();
+ if (error(i->getAddress(s.Address))) break;
+ if (error(i->getNMTypeChar(s.TypeChar))) break;
+ if (error(i->getName(s.Name))) break;
SymbolList.push_back(s);
}