summaryrefslogtreecommitdiff
path: root/tools/macho-dump/macho-dump.cpp
blob: 945406a501977f7ef693840315994b23422693f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//===-- macho-dump.cpp - Mach Object Dumping Tool -------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This is a testing tool for use with the MC/Mach-O LLVM components.
//
//===----------------------------------------------------------------------===//

#include "llvm/Object/MachOObject.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::object;

static cl::opt<std::string>
InputFile(cl::Positional, cl::desc("<input file>"), cl::init("-"));

static cl::opt<bool>
DumpSectionData("dump-section-data", cl::desc("Dump the contents of sections"),
                cl::init(false));

int main(int argc, char **argv) {
  const char *ProgramName = argv[0];
  llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.

  cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n");

  // Load the input file.
  std::string ErrorStr;
  OwningPtr<MemoryBuffer> InputBuffer(
    MemoryBuffer::getFileOrSTDIN(InputFile, &ErrorStr));
  if (!InputBuffer) {
    errs() << ProgramName << ": " << "unable to read input: '"
           << ErrorStr << "'\n";
    return 1;
  }

  // Construct the Mach-O wrapper object.
  OwningPtr<MachOObject> InputObject(
    MachOObject::LoadFromBuffer(InputBuffer.take(), &ErrorStr));
  if (!InputObject) {
    errs() << ProgramName << ": " << "unable to load object: '"
           << ErrorStr << "'\n";
    return 1;
  }

  errs() << "ok\n";
  return 0;
}