Daniel Dunbar | 75373ac | 2010-11-27 05:58:44 +0000 | [diff] [blame] | 1 | //===-- macho-dump.cpp - Mach Object Dumping Tool -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is a testing tool for use with the MC/Mach-O LLVM components. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Daniel Dunbar | ad12524 | 2010-11-27 06:19:17 +0000 | [diff] [blame^] | 14 | #include "llvm/Object/MachOObject.h" |
Daniel Dunbar | 75373ac | 2010-11-27 05:58:44 +0000 | [diff] [blame] | 15 | #include "llvm/Support/CommandLine.h" |
| 16 | #include "llvm/Support/ManagedStatic.h" |
Daniel Dunbar | ad12524 | 2010-11-27 06:19:17 +0000 | [diff] [blame^] | 17 | #include "llvm/Support/MemoryBuffer.h" |
Daniel Dunbar | 75373ac | 2010-11-27 05:58:44 +0000 | [diff] [blame] | 18 | #include "llvm/Support/raw_ostream.h" |
| 19 | using namespace llvm; |
Daniel Dunbar | ad12524 | 2010-11-27 06:19:17 +0000 | [diff] [blame^] | 20 | using namespace llvm::object; |
Daniel Dunbar | 75373ac | 2010-11-27 05:58:44 +0000 | [diff] [blame] | 21 | |
| 22 | static cl::opt<std::string> |
| 23 | InputFile(cl::Positional, cl::desc("<input file>"), cl::init("-")); |
| 24 | |
Daniel Dunbar | ad12524 | 2010-11-27 06:19:17 +0000 | [diff] [blame^] | 25 | static cl::opt<bool> |
| 26 | DumpSectionData("dump-section-data", cl::desc("Dump the contents of sections"), |
| 27 | cl::init(false)); |
| 28 | |
Daniel Dunbar | 75373ac | 2010-11-27 05:58:44 +0000 | [diff] [blame] | 29 | int main(int argc, char **argv) { |
| 30 | const char *ProgramName = argv[0]; |
| 31 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 32 | |
| 33 | cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n"); |
| 34 | |
Daniel Dunbar | ad12524 | 2010-11-27 06:19:17 +0000 | [diff] [blame^] | 35 | // Load the input file. |
| 36 | std::string ErrorStr; |
| 37 | OwningPtr<MemoryBuffer> InputBuffer( |
| 38 | MemoryBuffer::getFileOrSTDIN(InputFile, &ErrorStr)); |
| 39 | if (!InputBuffer) { |
| 40 | errs() << ProgramName << ": " << "unable to read input: '" |
| 41 | << ErrorStr << "'\n"; |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | // Construct the Mach-O wrapper object. |
| 46 | OwningPtr<MachOObject> InputObject( |
| 47 | MachOObject::LoadFromBuffer(InputBuffer.take(), &ErrorStr)); |
| 48 | if (!InputObject) { |
| 49 | errs() << ProgramName << ": " << "unable to load object: '" |
| 50 | << ErrorStr << "'\n"; |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | errs() << "ok\n"; |
| 55 | return 0; |
Daniel Dunbar | 75373ac | 2010-11-27 05:58:44 +0000 | [diff] [blame] | 56 | } |