[llvm-commits] [llvm] r120217 - in /llvm/trunk: include/llvm/Object/MachOObject.h lib/Object/MachOObject.cpp tools/macho-dump/macho-dump.cpp

Daniel Dunbar daniel at zuster.org
Sat Nov 27 05:46:11 PST 2010


Author: ddunbar
Date: Sat Nov 27 07:46:11 2010
New Revision: 120217

URL: http://llvm.org/viewvc/llvm-project?rev=120217&view=rev
Log:
macho-dump: Add support for dumping string table data.

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=120217&r1=120216&r2=120217&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOObject.h (original)
+++ llvm/trunk/include/llvm/Object/MachOObject.h Sat Nov 27 07:46:11 2010
@@ -13,6 +13,7 @@
 #include <string>
 #include "llvm/ADT/InMemoryStruct.h"
 #include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/Object/MachOFormat.h"
 
 namespace llvm {
@@ -59,6 +60,8 @@
   bool Is64Bit;
   /// Whether the object is swapped endianness from the host.
   bool IsSwappedEndian;
+  /// Whether the string table has been registered.
+  bool HasStringTable;
 
   /// The cached information on the load commands.
   LoadCommandInfo *LoadCommands;
@@ -68,6 +71,9 @@
   macho::Header Header;
   macho::Header64Ext Header64Ext;
 
+  /// Cache string table information.
+  StringRef StringTable;
+
 private:
   MachOObject(MemoryBuffer *Buffer, bool IsLittleEndian, bool Is64Bit);
 
@@ -97,6 +103,17 @@
   }
 
   /// @}
+  /// @name String Table Data
+  /// @{
+
+  StringRef getStringTableData() const {
+    assert(HasStringTable && "String table has not been registered!");
+    return StringTable;
+  }
+
+  void RegisterStringTable(macho::SymtabLoadCommand &SLC);
+
+  /// @}
   /// @name Object Header Access
   /// @{
 

Modified: llvm/trunk/lib/Object/MachOObject.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObject.cpp?rev=120217&r1=120216&r2=120217&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObject.cpp (original)
+++ llvm/trunk/lib/Object/MachOObject.cpp Sat Nov 27 07:46:11 2010
@@ -57,7 +57,7 @@
                          bool Is64Bit_)
   : Buffer(Buffer_), IsLittleEndian(IsLittleEndian_), Is64Bit(Is64Bit_),
     IsSwappedEndian(IsLittleEndian != sys::isLittleEndianHost()),
-    LoadCommands(0), NumLoadedCommands(0) {
+    HasStringTable(false), LoadCommands(0), NumLoadedCommands(0) {
   // Load the common header.
   memcpy(&Header, Buffer->getBuffer().data(), sizeof(Header));
   if (IsSwappedEndian) {
@@ -125,6 +125,12 @@
   return Object.take();
 }
 
+void MachOObject::RegisterStringTable(macho::SymtabLoadCommand &SLC) {
+  HasStringTable = true;
+  StringTable = Buffer->getBuffer().substr(SLC.StringTableOffset,
+                                           SLC.StringTableSize);
+}
+
 const MachOObject::LoadCommandInfo &
 MachOObject::getLoadCommandInfo(unsigned Index) const {
   assert(Index < getHeader().NumLoadCommands && "Invalid index!");

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=120217&r1=120216&r2=120217&view=diff
==============================================================================
--- llvm/trunk/tools/macho-dump/macho-dump.cpp (original)
+++ llvm/trunk/tools/macho-dump/macho-dump.cpp Sat Nov 27 07:46:11 2010
@@ -213,6 +213,14 @@
   outs() << "  ('stroff', " << SLC->StringTableOffset << ")\n";
   outs() << "  ('strsize', " << SLC->StringTableSize << ")\n";
 
+  // Cache the string table data.
+  Obj.RegisterStringTable(*SLC);
+
+  // Dump the string data.
+  outs() << "  ('_string_data', '";
+  outs().write_escaped(Obj.getStringTableData(),
+                       /*UseHexEscapes=*/true) << "')\n";
+
   return 0;
 }
 





More information about the llvm-commits mailing list