[llvm-commits] [llvm] r120192 - /llvm/trunk/tools/macho-dump/macho-dump.cpp

Daniel Dunbar daniel at zuster.org
Fri Nov 26 22:19:17 PST 2010


Author: ddunbar
Date: Sat Nov 27 00:19:17 2010
New Revision: 120192

URL: http://llvm.org/viewvc/llvm-project?rev=120192&view=rev
Log:
macho-dump: More sketching.

Modified:
    llvm/trunk/tools/macho-dump/macho-dump.cpp

Modified: llvm/trunk/tools/macho-dump/macho-dump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/macho-dump/macho-dump.cpp?rev=120192&r1=120191&r2=120192&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Sat Nov 27 00:19:17 2010
@@ -11,20 +11,46 @@
 //
 //===----------------------------------------------------------------------===//
 
+#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");
 
-  errs() << ProgramName << ": " << "not yet implemented!" << "\n";
-  return 1;
+  // 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;
 }





More information about the llvm-commits mailing list