blob: 945406a501977f7ef693840315994b23422693f5 [file] [log] [blame]
Daniel Dunbar75373ac2010-11-27 05:58:44 +00001//===-- 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 Dunbarad125242010-11-27 06:19:17 +000014#include "llvm/Object/MachOObject.h"
Daniel Dunbar75373ac2010-11-27 05:58:44 +000015#include "llvm/Support/CommandLine.h"
16#include "llvm/Support/ManagedStatic.h"
Daniel Dunbarad125242010-11-27 06:19:17 +000017#include "llvm/Support/MemoryBuffer.h"
Daniel Dunbar75373ac2010-11-27 05:58:44 +000018#include "llvm/Support/raw_ostream.h"
19using namespace llvm;
Daniel Dunbarad125242010-11-27 06:19:17 +000020using namespace llvm::object;
Daniel Dunbar75373ac2010-11-27 05:58:44 +000021
22static cl::opt<std::string>
23InputFile(cl::Positional, cl::desc("<input file>"), cl::init("-"));
24
Daniel Dunbarad125242010-11-27 06:19:17 +000025static cl::opt<bool>
26DumpSectionData("dump-section-data", cl::desc("Dump the contents of sections"),
27 cl::init(false));
28
Daniel Dunbar75373ac2010-11-27 05:58:44 +000029int 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 Dunbarad125242010-11-27 06:19:17 +000035 // 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 Dunbar75373ac2010-11-27 05:58:44 +000056}