[Lldb-commits] [PATCH] Fix endianness in ObjectFile::CopyData

Ed Maste emaste at freebsd.org
Thu Oct 3 08:23:58 PDT 2013


ObjectFile::CopyData is used to copy a block of target memory to the caller's buffer (e.g. for "memory read").  This should be a straight memcpy, and not byte-swapped if the target and host have different endianness.

Add a new DataExtractor::CopyData() method that performs this straight copy and use it in ObjectFile::CopyData().



http://llvm-reviews.chandlerc.com/D1820

Files:
  include/lldb/Core/DataExtractor.h
  source/Core/DataExtractor.cpp
  source/Symbol/ObjectFile.cpp

Index: include/lldb/Core/DataExtractor.h
===================================================================
--- include/lldb/Core/DataExtractor.h
+++ include/lldb/Core/DataExtractor.h
@@ -468,6 +468,27 @@
     }
     
     //------------------------------------------------------------------
+    /// Copy \a length bytes from \a *offset, without swapping bytes.
+    ///
+    /// @param[in] offset
+    ///     The offset into this data from which to start copying
+    ///
+    /// @param[in] length
+    ///     The length of the data to copy from this object
+    ///
+    /// @param[out] dst
+    ///     The buffer to place the output data.
+    ///
+    /// @return
+    ///     Returns the number of bytes that were copied, or zero if 
+    ///     anything goes wrong.
+    //------------------------------------------------------------------
+    lldb::offset_t
+    CopyData (lldb::offset_t offset,
+              lldb::offset_t length,
+              void *dst) const;
+
+    //------------------------------------------------------------------
     /// Copy \a dst_len bytes from \a *offset_ptr and ensure the copied
     /// data is treated as a value that can be swapped to match the
     /// specified byte order.
Index: source/Core/DataExtractor.cpp
===================================================================
--- source/Core/DataExtractor.cpp
+++ source/Core/DataExtractor.cpp
@@ -949,6 +949,21 @@
     return 0;
 }
 
+// Extract data as it exists in target memory
+lldb::offset_t
+DataExtractor::CopyData (offset_t offset,
+                         offset_t length,
+                         void *dst) const
+{
+    const uint8_t *src = PeekData (offset, length);
+    if (src)
+    {
+        ::memcpy (dst, src, length);
+        return length;
+    }
+    return 0;
+}
+
 // Extract data and swap if needed when doing the copy
 lldb::offset_t
 DataExtractor::CopyByteOrderedData (offset_t src_offset,
Index: source/Symbol/ObjectFile.cpp
===================================================================
--- source/Symbol/ObjectFile.cpp
+++ source/Symbol/ObjectFile.cpp
@@ -459,7 +459,8 @@
 ObjectFile::CopyData (off_t offset, size_t length, void *dst) const
 {
     // The entire file has already been mmap'ed into m_data, so just copy from there
-    return m_data.CopyByteOrderedData (offset, length, dst, length, lldb::endian::InlHostByteOrder());
+    // Note that the data remains in target byte order.
+    return m_data.CopyData (offset, length, dst);
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1820.1.patch
Type: text/x-patch
Size: 2500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20131003/cb0bfa56/attachment.bin>


More information about the lldb-commits mailing list