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

llvm-svn: 192323
This commit is contained in:
Ed Maste
2013-10-09 20:34:25 +00:00
parent 9715936d9e
commit b0e33d4165
3 changed files with 38 additions and 1 deletions

View File

@@ -467,6 +467,27 @@ public:
return ptr;
}
//------------------------------------------------------------------
/// 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

View File

@@ -949,6 +949,21 @@ DataExtractor::ExtractBytes (offset_t offset, offset_t length, ByteOrder dst_byt
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,

View File

@@ -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);
}