[llvm-commits] [llvm] r128801 - in /llvm/trunk: include/llvm/Object/MachOObject.h lib/Object/MachOObject.cpp tools/macho-dump/macho-dump.cpp
Eric Christopher
echristo at apple.com
Sun Apr 3 16:51:48 PDT 2011
Author: echristo
Date: Sun Apr 3 18:51:47 2011
New Revision: 128801
URL: http://llvm.org/viewvc/llvm-project?rev=128801&view=rev
Log:
Start migrating mach-o dumping facilities to the object file out of a
separate executable.
Modified:
llvm/trunk/include/llvm/Object/MachOObject.h
llvm/trunk/lib/Object/MachOObject.cpp
llvm/trunk/tools/macho-dump/macho-dump.cpp
Modified: llvm/trunk/include/llvm/Object/MachOObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOObject.h?rev=128801&r1=128800&r2=128801&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (original)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Sun Apr 3 18:51:47 2011
@@ -19,6 +19,7 @@
namespace llvm {
class MemoryBuffer;
+class raw_ostream;
namespace object {
@@ -172,7 +173,26 @@
InMemoryStruct<macho::Symbol64TableEntry> &Res) const;
/// @}
+
+ /// @name Object Dump Facilities
+ /// @{
+ /// dump - Support for debugging, callable in GDB: V->dump()
+ //
+ void dump() const;
+ void dumpHeader() const;
+
+ /// print - Implement operator<< on Value.
+ ///
+ void print(raw_ostream &O) const;
+ void printHeader(raw_ostream &O) const;
+
+ /// @}
};
+
+inline raw_ostream &operator<<(raw_ostream &OS, const MachOObject &V) {
+ V.print(OS);
+ return OS;
+}
} // end namespace object
} // end namespace llvm
Modified: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=128801&r1=128800&r2=128801&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (original)
+++ llvm/trunk/lib/Object/MachOObject.cpp Sun Apr 3 18:51:47 2011
@@ -12,6 +12,8 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Debug.h"
using namespace llvm;
using namespace llvm::object;
@@ -340,3 +342,29 @@
Index * sizeof(macho::Symbol64TableEntry));
ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res);
}
+
+/* ** */
+// Object Dumping Facilities
+void MachOObject::dump() const { print(dbgs()); dbgs() << '\n'; }
+void MachOObject::dumpHeader() const { printHeader(dbgs()); dbgs() << '\n'; }
+
+void MachOObject::printHeader(raw_ostream &O) const {
+ O << "('cputype', " << Header.CPUType << ")\n";
+ O << "('cpusubtype', " << Header.CPUSubtype << ")\n";
+ O << "('filetype', " << Header.FileType << ")\n";
+ O << "('num_load_commands', " << Header.NumLoadCommands << ")\n";
+ O << "('load_commands_size', " << Header.SizeOfLoadCommands << ")\n";
+ O << "('flag', " << Header.Flags << ")\n";
+
+ // Print extended header if 64-bit.
+ if (is64Bit())
+ O << "('reserved', " << Header64Ext.Reserved << ")\n";
+}
+
+void MachOObject::print(raw_ostream &O) const {
+ O << "Header:\n";
+ printHeader(O);
+ O << "Load Commands:\n";
+
+ O << "Buffer:\n";
+}
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=128801&r1=128800&r2=128801&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Sun Apr 3 18:51:47 2011
@@ -376,8 +376,8 @@
if (!InputObject)
return Error("unable to load object: '" + ErrorStr + "'");
- if (int Res = DumpHeader(*InputObject))
- return Res;
+ // Print the header
+ InputObject->printHeader(outs());
// Print the load commands.
int Res = 0;
More information about the llvm-commits
mailing list