From 25b15777df42d5d608810f6881b6c98107481d69 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Sat, 25 Jun 2011 17:55:23 +0000 Subject: Object: Add proper error handling. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133872 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/llvm-objdump.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'tools/llvm-objdump/llvm-objdump.cpp') diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index a17624a..c971e49 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -69,6 +69,14 @@ namespace { "see -version for available targets")); StringRef ToolName; + + bool error(error_code ec) { + if (!ec) return false; + + outs() << ToolName << ": error reading file: " << ec.message() << ".\n"; + outs().flush(); + return true; + } } static const Target *GetTarget(const ObjectFile *Obj = NULL) { @@ -161,12 +169,18 @@ static void DisassembleInput(const StringRef &Filename) { outs() << Filename << ":\tfile format " << Obj->getFileFormatName() << "\n\n\n"; + error_code ec; for (ObjectFile::section_iterator i = Obj->begin_sections(), e = Obj->end_sections(); - i != e; ++i) { - if (!i->isText()) - continue; - outs() << "Disassembly of section " << i->getName() << ":\n\n"; + i != e; i.increment(ec)) { + if (error(ec)) break; + bool text; + if (error(i->isText(text))) break; + if (!text) continue; + + StringRef name; + if (error(i->getName(name))) break; + outs() << "Disassembly of section " << name << ":\n\n"; // Set up disassembler. OwningPtr AsmInfo(TheTarget->createAsmInfo(TripleName)); @@ -202,7 +216,8 @@ static void DisassembleInput(const StringRef &Filename) { return; } - StringRef Bytes = i->getContents(); + StringRef Bytes; + if (error(i->getContents(Bytes))) break; StringRefMemoryObject memoryObject(Bytes); uint64_t Size; uint64_t Index; @@ -217,7 +232,9 @@ static void DisassembleInput(const StringRef &Filename) { # endif if (DisAsm->getInstruction(Inst, Size, memoryObject, Index, DebugOut)) { - outs() << format("%8x:\t", i->getAddress() + Index); + uint64_t addr; + if (error(i->getAddress(addr))) break; + outs() << format("%8x:\t", addr + Index); DumpBytes(StringRef(Bytes.data() + Index, Size)); IP->printInst(&Inst, outs()); outs() << "\n"; -- cgit v1.1 From 276365dd4bc0c2160f91fd8062ae1fc90c86c324 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 30 Jun 2011 01:53:36 +0000 Subject: Fix the ridiculous SubtargetFeatures API where it implicitly expects CPU name to be the first encoded as the first feature. It then uses the CPU name to look up features / scheduling itineray even though clients know full well the CPU name being used to query these properties. The fix is to just have the clients explictly pass the CPU name! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134127 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/llvm-objdump.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools/llvm-objdump/llvm-objdump.cpp') diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index c971e49..a125c91 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -201,7 +201,8 @@ static void DisassembleInput(const StringRef &Filename) { // it straightforward to switch subtargets on the fly (.e.g, // the .cpu and .code16 directives). std::string FeaturesStr; - OwningPtr TM(TheTarget->createTargetMachine(TripleName, + std::string CPU; + OwningPtr TM(TheTarget->createTargetMachine(TripleName, CPU, FeaturesStr)); if (!TM) { errs() << "error: could not create target for triple " << TripleName << "\n"; -- cgit v1.1