[Lldb-commits] [lldb] r192323 - Fix endianness in ObjectFile::CopyData

Ed Maste emaste at freebsd.org
Wed Oct 9 13:34:26 PDT 2013


Author: emaste
Date: Wed Oct  9 15:34:25 2013
New Revision: 192323

URL: http://llvm.org/viewvc/llvm-project?rev=192323&view=rev
Log:
Fix endianness in ObjectFile::CopyData

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().

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

Modified: lldb/trunk/include/lldb/Core/DataExtractor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DataExtractor.h?rev=192323&r1=192322&r2=192323&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/DataExtractor.h (original)
+++ lldb/trunk/include/lldb/Core/DataExtractor.h Wed Oct  9 15:34:25 2013
@@ -468,6 +468,27 @@ public:
     }
     
     //------------------------------------------------------------------
+    /// 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.

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=192323&r1=192322&r2=192323&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Wed Oct  9 15:34:25 2013
@@ -949,6 +949,21 @@ DataExtractor::ExtractBytes (offset_t of
     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,

Modified: lldb/trunk/source/Symbol/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=192323&r1=192322&r2=192323&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ObjectFile.cpp (original)
+++ lldb/trunk/source/Symbol/ObjectFile.cpp Wed Oct  9 15:34:25 2013
@@ -459,7 +459,8 @@ size_t
 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);
 }
 
 





More information about the lldb-commits mailing list