[Lldb-commits] [lldb] r137602 - /lldb/trunk/source/Core/DataExtractor.cpp
Greg Clayton
gclayton at apple.com
Sun Aug 14 19:24:40 PDT 2011
Author: gclayton
Date: Sun Aug 14 21:24:40 2011
New Revision: 137602
URL: http://llvm.org/viewvc/llvm-project?rev=137602&view=rev
Log:
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).
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=137602&r1=137601&r2=137602&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Sun Aug 14 21:24:40 2011
@@ -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 @@
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 @@
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 @@
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 @@
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:
More information about the lldb-commits
mailing list