summaryrefslogtreecommitdiff
path: root/source/Core/DataExtractor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Core/DataExtractor.cpp')
-rw-r--r--source/Core/DataExtractor.cpp97
1 files changed, 64 insertions, 33 deletions
diff --git a/source/Core/DataExtractor.cpp b/source/Core/DataExtractor.cpp
index 861bece98da96..dc7857fe9cb77 100644
--- a/source/Core/DataExtractor.cpp
+++ b/source/Core/DataExtractor.cpp
@@ -14,6 +14,7 @@
#include <limits>
#include <sstream>
#include <string>
+#include <math.h>
#include "clang/AST/ASTContext.h"
@@ -130,8 +131,8 @@ ReadSwapInt64(const void* ptr)
DataExtractor::DataExtractor () :
m_start (NULL),
m_end (NULL),
- m_byte_order(lldb::endian::InlHostByteOrder()),
- m_addr_size (4),
+ m_byte_order(endian::InlHostByteOrder()),
+ m_addr_size (sizeof(void *)),
m_data_sp (),
m_target_byte_size(1)
{
@@ -142,13 +143,16 @@ DataExtractor::DataExtractor () :
// The data must stay around as long as this object is valid.
//----------------------------------------------------------------------
DataExtractor::DataExtractor (const void* data, offset_t length, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size/*=1*/) :
- m_start ((uint8_t*)data),
- m_end ((uint8_t*)data + length),
+ m_start (const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(data))),
+ m_end (const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(data)) + length),
m_byte_order(endian),
m_addr_size (addr_size),
m_data_sp (),
m_target_byte_size(target_byte_size)
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (addr_size == 4 || addr_size == 8);
+#endif
}
//----------------------------------------------------------------------
@@ -166,6 +170,9 @@ DataExtractor::DataExtractor (const DataBufferSP& data_sp, ByteOrder endian, uin
m_data_sp (),
m_target_byte_size(target_byte_size)
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (addr_size == 4 || addr_size == 8);
+#endif
SetData (data_sp);
}
@@ -184,6 +191,9 @@ DataExtractor::DataExtractor (const DataExtractor& data, offset_t offset, offset
m_data_sp(),
m_target_byte_size(target_byte_size)
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (m_addr_size == 4 || m_addr_size == 8);
+#endif
if (data.ValidOffset(offset))
{
offset_t bytes_available = data.GetByteSize() - offset;
@@ -201,6 +211,9 @@ DataExtractor::DataExtractor (const DataExtractor& rhs) :
m_data_sp (rhs.m_data_sp),
m_target_byte_size(rhs.m_target_byte_size)
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (m_addr_size == 4 || m_addr_size == 8);
+#endif
}
//----------------------------------------------------------------------
@@ -237,8 +250,8 @@ DataExtractor::Clear ()
{
m_start = NULL;
m_end = NULL;
- m_byte_order = lldb::endian::InlHostByteOrder();
- m_addr_size = 4;
+ m_byte_order = endian::InlHostByteOrder();
+ m_addr_size = sizeof(void *);
m_data_sp.reset();
}
@@ -287,7 +300,7 @@ DataExtractor::SetData (const void *bytes, offset_t length, ByteOrder endian)
}
else
{
- m_start = (uint8_t *)bytes;
+ m_start = const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(bytes));
m_end = m_start + length;
}
return GetByteSize();
@@ -311,6 +324,9 @@ lldb::offset_t
DataExtractor::SetData (const DataExtractor& data, offset_t data_offset, offset_t data_length)
{
m_addr_size = data.m_addr_size;
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (m_addr_size == 4 || m_addr_size == 8);
+#endif
// If "data" contains shared pointer to data, then we can use that
if (data.m_data_sp.get())
{
@@ -427,7 +443,7 @@ DataExtractor::GetU16 (offset_t *offset_ptr) const
const uint8_t *data = (const uint8_t *)GetData (offset_ptr, sizeof(val));
if (data)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
val = ReadSwapInt16(data);
else
val = ReadInt16 (data);
@@ -439,7 +455,7 @@ uint16_t
DataExtractor::GetU16_unchecked (offset_t *offset_ptr) const
{
uint16_t val;
- if (m_byte_order == lldb::endian::InlHostByteOrder())
+ if (m_byte_order == endian::InlHostByteOrder())
val = ReadInt16 (m_start, *offset_ptr);
else
val = ReadSwapInt16(m_start, *offset_ptr);
@@ -451,7 +467,7 @@ uint32_t
DataExtractor::GetU32_unchecked (offset_t *offset_ptr) const
{
uint32_t val;
- if (m_byte_order == lldb::endian::InlHostByteOrder())
+ if (m_byte_order == endian::InlHostByteOrder())
val = ReadInt32 (m_start, *offset_ptr);
else
val = ReadSwapInt32 (m_start, *offset_ptr);
@@ -463,7 +479,7 @@ uint64_t
DataExtractor::GetU64_unchecked (offset_t *offset_ptr) const
{
uint64_t val;
- if (m_byte_order == lldb::endian::InlHostByteOrder())
+ if (m_byte_order == endian::InlHostByteOrder())
val = ReadInt64 (m_start, *offset_ptr);
else
val = ReadSwapInt64 (m_start, *offset_ptr);
@@ -488,7 +504,7 @@ DataExtractor::GetU16 (offset_t *offset_ptr, void *void_dst, uint32_t count) con
const uint16_t *src = (const uint16_t *)GetData (offset_ptr, src_size);
if (src)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
uint16_t *dst_pos = (uint16_t *)void_dst;
uint16_t *dst_end = dst_pos + count;
@@ -523,7 +539,7 @@ DataExtractor::GetU32 (offset_t *offset_ptr) const
const uint8_t *data = (const uint8_t *)GetData (offset_ptr, sizeof(val));
if (data)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
val = ReadSwapInt32 (data);
}
@@ -551,7 +567,7 @@ DataExtractor::GetU32 (offset_t *offset_ptr, void *void_dst, uint32_t count) con
const uint32_t *src = (const uint32_t *)GetData (offset_ptr, src_size);
if (src)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
uint32_t *dst_pos = (uint32_t *)void_dst;
uint32_t *dst_end = dst_pos + count;
@@ -586,7 +602,7 @@ DataExtractor::GetU64 (offset_t *offset_ptr) const
const uint8_t *data = (const uint8_t *)GetData (offset_ptr, sizeof(val));
if (data)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
val = ReadSwapInt64 (data);
}
@@ -612,7 +628,7 @@ DataExtractor::GetU64 (offset_t *offset_ptr, void *void_dst, uint32_t count) con
const uint64_t *src = (const uint64_t *)GetData (offset_ptr, src_size);
if (src)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
uint64_t *dst_pos = (uint64_t *)void_dst;
uint64_t *dst_end = dst_pos + count;
@@ -653,7 +669,7 @@ DataExtractor::GetMaxU32 (offset_t *offset_ptr, size_t byte_size) const
case 2: return GetU16(offset_ptr); break;
case 4: return GetU32(offset_ptr); break;
default:
- assert("GetMaxU32 unhandled case!" == NULL);
+ assert(false && "GetMaxU32 unhandled case!");
break;
}
return 0;
@@ -679,7 +695,7 @@ DataExtractor::GetMaxU64 (offset_t *offset_ptr, size_t size) const
case 4: return GetU32(offset_ptr); break;
case 8: return GetU64(offset_ptr); break;
default:
- assert("GetMax64 unhandled case!" == NULL);
+ assert(false && "GetMax64 unhandled case!");
break;
}
return 0;
@@ -695,7 +711,7 @@ DataExtractor::GetMaxU64_unchecked (offset_t *offset_ptr, size_t size) const
case 4: return GetU32_unchecked (offset_ptr); break;
case 8: return GetU64_unchecked (offset_ptr); break;
default:
- assert("GetMax64 unhandled case!" == NULL);
+ assert(false && "GetMax64 unhandled case!");
break;
}
return 0;
@@ -711,7 +727,7 @@ DataExtractor::GetMaxS64 (offset_t *offset_ptr, size_t size) const
case 4: return (int32_t)GetU32(offset_ptr); break;
case 8: return (int64_t)GetU64(offset_ptr); break;
default:
- assert("GetMax64 unhandled case!" == NULL);
+ assert(false && "GetMax64 unhandled case!");
break;
}
return 0;
@@ -760,7 +776,7 @@ DataExtractor::GetFloat (offset_t *offset_ptr) const
const float_type *src = (const float_type *)GetData (offset_ptr, src_size);
if (src)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
const uint8_t *src_data = (const uint8_t *)src;
uint8_t *dst_data = (uint8_t *)&val;
@@ -784,7 +800,7 @@ DataExtractor::GetDouble (offset_t *offset_ptr) const
const float_type *src = (const float_type *)GetData (offset_ptr, src_size);
if (src)
{
- if (m_byte_order != lldb::endian::InlHostByteOrder())
+ if (m_byte_order != endian::InlHostByteOrder())
{
const uint8_t *src_data = (const uint8_t *)src;
uint8_t *dst_data = (uint8_t *)&val;
@@ -805,9 +821,9 @@ DataExtractor::GetLongDouble (offset_t *offset_ptr) const
{
long double val = 0.0;
#if defined (__i386__) || defined (__amd64__) || defined (__x86_64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_X64)
- *offset_ptr += CopyByteOrderedData (*offset_ptr, 10, &val, sizeof(val), lldb::endian::InlHostByteOrder());
+ *offset_ptr += CopyByteOrderedData (*offset_ptr, 10, &val, sizeof(val), endian::InlHostByteOrder());
#else
- *offset_ptr += CopyByteOrderedData (*offset_ptr, sizeof(val), &val, sizeof(val), lldb::endian::InlHostByteOrder());
+ *offset_ptr += CopyByteOrderedData (*offset_ptr, sizeof(val), &val, sizeof(val), endian::InlHostByteOrder());
#endif
return val;
}
@@ -824,12 +840,18 @@ DataExtractor::GetLongDouble (offset_t *offset_ptr) const
uint64_t
DataExtractor::GetAddress (offset_t *offset_ptr) const
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (m_addr_size == 4 || m_addr_size == 8);
+#endif
return GetMaxU64 (offset_ptr, m_addr_size);
}
uint64_t
DataExtractor::GetAddress_unchecked (offset_t *offset_ptr) const
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (m_addr_size == 4 || m_addr_size == 8);
+#endif
return GetMaxU64_unchecked (offset_ptr, m_addr_size);
}
@@ -844,6 +866,9 @@ DataExtractor::GetAddress_unchecked (offset_t *offset_ptr) const
uint64_t
DataExtractor::GetPointer (offset_t *offset_ptr) const
{
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (m_addr_size == 4 || m_addr_size == 8);
+#endif
return GetMaxU64 (offset_ptr, m_addr_size);
}
@@ -863,6 +888,9 @@ DataExtractor::GetGNUEHPointer (offset_t *offset_ptr, uint32_t eh_ptr_enc, lldb:
uint64_t baseAddress = 0;
uint64_t addressValue = 0;
const uint32_t addr_size = GetAddressByteSize();
+#ifdef LLDB_CONFIGURATION_DEBUG
+ assert (addr_size == 4 || addr_size == 8);
+#endif
bool signExtendValue = false;
// Decode the base part or adjust our offset
@@ -1378,24 +1406,21 @@ DumpAPInt (Stream *s, const DataExtractor &data, lldb::offset_t offset, lldb::of
return offset;
}
-static float half2float (uint16_t half)
+static float
+half2float (uint16_t half)
{
-#ifdef _MSC_VER
- llvm_unreachable("half2float not implemented for MSVC");
-#else
- union{ float f; uint32_t u;}u;
+ union { float f; uint32_t u; } u;
int32_t v = (int16_t) half;
-
- if( 0 == (v & 0x7c00))
+
+ if (0 == (v & 0x7c00))
{
u.u = v & 0x80007FFFU;
return u.f * ldexpf(1, 125);
}
-
+
v <<= 13;
u.u = v | 0x70000000U;
return u.f * ldexpf(1, -112);
-#endif
}
lldb::offset_t
@@ -2012,6 +2037,12 @@ DataExtractor::Dump (Stream *s,
s->PutChar('}');
break;
+ case eFormatVectorOfFloat16:
+ s->PutChar('{');
+ offset = Dump (s, offset, eFormatFloat, 2, item_byte_size / 2, item_byte_size / 2, LLDB_INVALID_ADDRESS, 0, 0);
+ s->PutChar('}');
+ break;
+
case eFormatVectorOfFloat32:
s->PutChar('{');
offset = Dump (s, offset, eFormatFloat, 4, item_byte_size / 4, item_byte_size / 4, LLDB_INVALID_ADDRESS, 0, 0);