[Object/COFF]: Expose getSectionName.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Mon, 19 Mar 2012 20:27:15 +0000 (20:27 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Mon, 19 Mar 2012 20:27:15 +0000 (20:27 +0000)
Also add some documentation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153050 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/Binary.h
include/llvm/Object/COFF.h
lib/Object/COFFObjectFile.cpp

index 81cdd32a73e3d32b2f8bf09b397dc4214e6766f2..77a08d597c4df534d1978b0c554bfc4f4bdce969 100644 (file)
@@ -88,7 +88,14 @@ public:
   }
 };
 
+/// @brief Create a Binary from Source, autodetecting the file type.
+///
+/// @param Source The data to create the Binary from. Ownership is transfered
+///        to Result if successful. If an error is returned, Source is destroyed
+///        by createBinary before returning.
+/// @param Result A pointer to the resulting Binary if no error occured.
 error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result);
+
 error_code createBinary(StringRef Path, OwningPtr<Binary> &Result);
 
 }
index fc33ab1035827fe47fbab75a9139f6cc76ea442a..f19ce6f19e8abd8c93ec34d1c63b74ed9477d995 100644 (file)
@@ -177,6 +177,7 @@ public:
     return ec;
   }
   error_code getSymbolName(const coff_symbol *symbol, StringRef &Res) const;
+  error_code getSectionName(const coff_section *Sec, StringRef &Res) const;
 
   static inline bool classof(const Binary *v) {
     return v->isCOFF();
index 22894a348cfa6dfac0ed7a838376bcb76fb32610..afe9e737f0e255cf6764ed2df5abdd9fdfc5b6de 100644 (file)
@@ -300,25 +300,7 @@ error_code COFFObjectFile::getSectionNext(DataRefImpl Sec,
 error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
                                           StringRef &Result) const {
   const coff_section *sec = toSec(Sec);
-  StringRef name;
-  if (sec->Name[7] == 0)
-    // Null terminated, let ::strlen figure out the length.
-    name = sec->Name;
-  else
-    // Not null terminated, use all 8 bytes.
-    name = StringRef(sec->Name, 8);
-
-  // Check for string table entry. First byte is '/'.
-  if (name[0] == '/') {
-    uint32_t Offset;
-    if (name.substr(1).getAsInteger(10, Offset))
-      return object_error::parse_failed;
-    if (error_code ec = getString(Offset, name))
-      return ec;
-  }
-
-  Result = name;
-  return object_error::success;
+  return getSectionName(sec, Result);
 }
 
 error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
@@ -631,6 +613,29 @@ error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
   return object_error::success;
 }
 
+error_code COFFObjectFile::getSectionName(const coff_section *Sec,
+                                          StringRef &Res) const {
+  StringRef Name;
+  if (Sec->Name[7] == 0)
+    // Null terminated, let ::strlen figure out the length.
+    Name = Sec->Name;
+  else
+    // Not null terminated, use all 8 bytes.
+    Name = StringRef(Sec->Name, 8);
+
+  // Check for string table entry. First byte is '/'.
+  if (Name[0] == '/') {
+    uint32_t Offset;
+    if (Name.substr(1).getAsInteger(10, Offset))
+      return object_error::parse_failed;
+    if (error_code ec = getString(Offset, Name))
+      return ec;
+  }
+
+  Res = Name;
+  return object_error::success;
+}
+
 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
   return reinterpret_cast<const coff_relocation*>(Rel.p);
 }