summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/DataExtractor.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-08-15 02:24:40 +0000
committerGreg Clayton <gclayton@apple.com>2011-08-15 02:24:40 +0000
commit8753c1e057616534af175a4ee41bf90c18702c2b (patch)
tree5c78340882186c0d2f2051cf4aa45771bc93298f /lldb/source/Core/DataExtractor.cpp
parentff5f5ff963a46dfe70c091ee6032e5ddbd0d8b6e (diff)
downloadbcm5719-llvm-8753c1e057616534af175a4ee41bf90c18702c2b.tar.gz
bcm5719-llvm-8753c1e057616534af175a4ee41bf90c18702c2b.zip
Added the ability to use llvm::APInt class to view
any integers that are larger than a 8 bytes. We can now display signed decimal, unsigned decimal, octal, and binary (we could already view hex before this fix). llvm-svn: 137602
Diffstat (limited to 'lldb/source/Core/DataExtractor.cpp')
-rw-r--r--lldb/source/Core/DataExtractor.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/lldb/source/Core/DataExtractor.cpp b/lldb/source/Core/DataExtractor.cpp
index f8be9a421e0..e1fda0c9373 100644
--- a/lldb/source/Core/DataExtractor.cpp
+++ b/lldb/source/Core/DataExtractor.cpp
@@ -13,6 +13,7 @@
#include <bitset>
#include <string>
+#include "llvm/ADT/APInt.h"
#include "llvm/Support/MathExtras.h"
#include "lldb/Core/DataExtractor.h"
@@ -1306,6 +1307,76 @@ DataExtractor::Skip_LEB128 (uint32_t *offset_ptr) const
return bytes_consumed;
}
+static uint32_t
+DumpAPInt (Stream *s, const DataExtractor &data, uint32_t offset, uint32_t byte_size, bool is_signed, unsigned radix)
+{
+ llvm::SmallVector<uint64_t, 2> uint64_array;
+ uint32_t bytes_left = byte_size;
+ uint64_t u64;
+ const lldb::ByteOrder byte_order = data.GetByteOrder();
+ if (byte_order == lldb::eByteOrderLittle)
+ {
+ while (bytes_left > 0)
+ {
+ if (bytes_left >= 8)
+ {
+ u64 = data.GetU64(&offset);
+ bytes_left -= 8;
+ }
+ else
+ {
+ u64 = data.GetMaxU64(&offset, bytes_left);
+ bytes_left = 0;
+ }
+ uint64_array.push_back(u64);
+ }
+ }
+ else if (byte_order == lldb::eByteOrderBig)
+ {
+ uint32_t be_offset = offset + byte_size;
+ uint32_t temp_offset;
+ while (bytes_left > 0)
+ {
+ if (bytes_left >= 8)
+ {
+ be_offset -= 8;
+ temp_offset = be_offset;
+ u64 = data.GetU64(&temp_offset);
+ bytes_left -= 8;
+ }
+ else
+ {
+ be_offset -= bytes_left;
+ temp_offset = be_offset;
+ u64 = data.GetMaxU64(&temp_offset, bytes_left);
+ bytes_left = 0;
+ }
+ uint64_array.push_back(u64);
+ }
+ }
+ else
+ return offset;
+
+ llvm::APInt apint (byte_size * 8,
+ uint64_array.size(),
+ uint64_array.data());
+
+ std::string apint_str(apint.toString(radix, is_signed));
+ switch (radix)
+ {
+ case 2:
+ s->Write ("0b", 2);
+ break;
+ case 8:
+ s->Write ("0", 1);
+ break;
+ case 10:
+ break;
+ }
+ s->Write(apint_str.c_str(), apint_str.size());
+ return offset;
+}
+
uint32_t
DataExtractor::Dump
(
@@ -1370,6 +1441,7 @@ DataExtractor::Dump
break;
case eFormatBinary:
+ if (item_byte_size <= 8)
{
uint64_t uval64 = GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset);
// Avoid std::bitset<64>::to_string() since it is missing in
@@ -1384,6 +1456,12 @@ DataExtractor::Dump
else if (item_byte_size > 0 && item_byte_size <= 8)
s->Printf("0b%s", binary_value.c_str() + 64 - item_byte_size * 8);
}
+ else
+ {
+ const bool is_signed = false;
+ const unsigned radix = 2;
+ offset = DumpAPInt (s, *this, offset, item_byte_size, is_signed, radix);
+ }
break;
case eFormatBytes:
@@ -1445,16 +1523,34 @@ DataExtractor::Dump
case eFormatDecimal:
if (item_byte_size <= 8)
s->Printf ("%lld", GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset));
+ else
+ {
+ const bool is_signed = true;
+ const unsigned radix = 10;
+ offset = DumpAPInt (s, *this, offset, item_byte_size, is_signed, radix);
+ }
break;
case eFormatUnsigned:
if (item_byte_size <= 8)
s->Printf ("%llu", GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset));
+ else
+ {
+ const bool is_signed = false;
+ const unsigned radix = 10;
+ offset = DumpAPInt (s, *this, offset, item_byte_size, is_signed, radix);
+ }
break;
case eFormatOctal:
if (item_byte_size <= 8)
s->Printf ("0%llo", GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset));
+ else
+ {
+ const bool is_signed = false;
+ const unsigned radix = 8;
+ offset = DumpAPInt (s, *this, offset, item_byte_size, is_signed, radix);
+ }
break;
case eFormatOSType:
OpenPOWER on IntegriCloud