forked from OSchip/llvm-project
<rdar://problem/10546739>
Fixed SBValue::GetValueAsUnsigned() and SBValue::GetValueAsSigned() calls to work for bitfields. llvm-svn: 147332
This commit is contained in:
parent
714296cb31
commit
dcad5021d4
|
@ -57,6 +57,10 @@ public:
|
|||
bool
|
||||
SignExtend (uint32_t bit_pos);
|
||||
|
||||
bool
|
||||
ExtractBitfield (uint32_t bit_size,
|
||||
uint32_t bit_offset);
|
||||
|
||||
size_t
|
||||
GetByteSize() const;
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include "lldb/Core/DataExtractor.h"
|
||||
#include "lldb/Host/Endian.h"
|
||||
|
||||
#include "Plugins/Process/Utility/InstructionUtils.h"
|
||||
|
||||
using namespace lldb;
|
||||
using namespace lldb_private;
|
||||
|
||||
|
@ -2017,6 +2019,85 @@ Scalar::GetAsMemoryData (void *dst,
|
|||
return bytes_copied;
|
||||
}
|
||||
|
||||
bool
|
||||
Scalar::ExtractBitfield (uint32_t bit_size,
|
||||
uint32_t bit_offset)
|
||||
{
|
||||
if (bit_size == 0)
|
||||
return true;
|
||||
|
||||
uint32_t msbit = bit_offset + bit_size - 1;
|
||||
uint32_t lsbit = bit_offset;
|
||||
switch (m_type)
|
||||
{
|
||||
default:
|
||||
case Scalar::e_void:
|
||||
break;
|
||||
|
||||
case e_float:
|
||||
if (sizeof(m_data.flt) == sizeof(int))
|
||||
m_data.sint = SignedBits (m_data.sint, msbit, lsbit);
|
||||
else if (sizeof(m_data.flt) == sizeof(unsigned long))
|
||||
m_data.slong = SignedBits (m_data.slong, msbit, lsbit);
|
||||
else if (sizeof(m_data.flt) == sizeof(unsigned long long))
|
||||
m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
|
||||
case e_double:
|
||||
if (sizeof(m_data.dbl) == sizeof(int))
|
||||
m_data.sint = SignedBits (m_data.sint, msbit, lsbit);
|
||||
else if (sizeof(m_data.dbl) == sizeof(unsigned long))
|
||||
m_data.slong = SignedBits (m_data.slong, msbit, lsbit);
|
||||
else if (sizeof(m_data.dbl) == sizeof(unsigned long long))
|
||||
m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
|
||||
case e_long_double:
|
||||
if (sizeof(m_data.ldbl) == sizeof(int))
|
||||
m_data.sint = SignedBits (m_data.sint, msbit, lsbit);
|
||||
else if (sizeof(m_data.ldbl) == sizeof(unsigned long))
|
||||
m_data.slong = SignedBits (m_data.slong, msbit, lsbit);
|
||||
else if (sizeof(m_data.ldbl) == sizeof(unsigned long long))
|
||||
m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
|
||||
case Scalar::e_sint:
|
||||
m_data.sint = SignedBits (m_data.sint, msbit, lsbit);
|
||||
return true;
|
||||
|
||||
case Scalar::e_uint:
|
||||
m_data.uint = UnsignedBits (m_data.uint, msbit, lsbit);
|
||||
return true;
|
||||
|
||||
case Scalar::e_slong:
|
||||
m_data.slong = SignedBits (m_data.slong, msbit, lsbit);
|
||||
return true;
|
||||
|
||||
case Scalar::e_ulong:
|
||||
m_data.ulong = SignedBits (m_data.ulong, msbit, lsbit);
|
||||
return true;
|
||||
|
||||
case Scalar::e_slonglong:
|
||||
m_data.slonglong = SignedBits (m_data.slonglong, msbit, lsbit);
|
||||
return true;
|
||||
|
||||
case Scalar::e_ulonglong:
|
||||
m_data.ulonglong = SignedBits (m_data.ulonglong, msbit, lsbit);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool
|
||||
lldb_private::operator== (const Scalar& lhs, const Scalar& rhs)
|
||||
{
|
||||
|
|
|
@ -359,10 +359,15 @@ ValueObject::ResolveValue (Scalar &scalar)
|
|||
exe_scope->CalculateExecutionContext(exe_ctx);
|
||||
Value tmp_value(m_value);
|
||||
scalar = tmp_value.ResolveValue(&exe_ctx, GetClangAST ());
|
||||
return scalar.IsValid();
|
||||
if (scalar.IsValid())
|
||||
{
|
||||
const uint32_t bitfield_bit_size = GetBitfieldBitSize();
|
||||
if (bitfield_bit_size)
|
||||
return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -80,9 +80,9 @@ class TestObjCIvarOffsets(TestBase):
|
|||
self.assertTrue (flag2_value == 7)
|
||||
|
||||
# GetValueAsUnsigned fails for bit-fields:
|
||||
# flag2_value = mine_flag2.GetValueAsUnsigned (error)
|
||||
# self.assertTrue (error.Success())
|
||||
# self.assertTrue (flag2_value == 7)
|
||||
flag2_value = mine_flag2.GetValueAsUnsigned (error)
|
||||
self.assertTrue (error.Success())
|
||||
self.assertTrue (flag2_value == 7)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import atexit
|
||||
|
|
Loading…
Reference in New Issue