[Lldb-commits] [lldb] r191005 - Assert that only reg- or word-sized values are byte swapped

Ed Maste emaste at freebsd.org
Thu Sep 19 08:12:37 PDT 2013


Author: emaste
Date: Thu Sep 19 10:12:36 2013
New Revision: 191005

URL: http://llvm.org/viewvc/llvm-project?rev=191005&view=rev
Log:
Assert that only reg- or word-sized values are byte swapped

Targets and hosts today are little-endian (arm, x86), so this change
should be a no-op as they will not encounter the byte swapping cases.

Byte swapping  will happen when cross debugging of big endian-targets
(e.g. MIPS, PPC) on a little-endian host (x86).  Register- or word-
sized data copies need to be swapped, but calls to ExtractBytes or
CopyByteOrderedData that would invoke the swapping case are presumably
in error.

Modified:
    lldb/trunk/source/Core/DataExtractor.cpp

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=191005&r1=191004&r2=191005&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Thu Sep 19 10:12:36 2013
@@ -935,6 +935,10 @@ DataExtractor::ExtractBytes (offset_t of
     {
         if (dst_byte_order != GetByteOrder())
         {
+            // Validate that only a word- or register-sized dst is byte swapped
+            assert (length == 1 || length == 2 || length == 4 || length == 8 ||
+                    length == 10 || length == 16 || length == 32);
+
             for (uint32_t i=0; i<length; ++i)
                 ((uint8_t*)dst)[i] = src[length - i - 1];
         }
@@ -963,7 +967,12 @@ DataExtractor::CopyByteOrderedData (offs
     assert (dst_void_ptr != NULL);
     assert (dst_len > 0);
     assert (dst_byte_order == eByteOrderBig || dst_byte_order == eByteOrderLittle);
-    
+
+    // Validate that only a word- or register-sized dst is byte swapped
+    assert (dst_byte_order == m_byte_order || dst_len == 1 || dst_len == 2 ||
+            dst_len == 4 || dst_len == 8 || dst_len == 10 || dst_len == 16 ||
+            dst_len == 32);
+
     // Must have valid byte orders set in this object and for destination
     if (!(dst_byte_order == eByteOrderBig || dst_byte_order == eByteOrderLittle) ||
         !(m_byte_order == eByteOrderBig || m_byte_order == eByteOrderLittle))





More information about the lldb-commits mailing list