[Lldb-commits] [lldb] r122895 - in /lldb/trunk: include/lldb/API/SBValue.h include/lldb/Core/ValueObject.h include/lldb/lldb-enumerations.h source/API/SBValue.cpp source/Core/DataExtractor.cpp source/Symbol/ClangASTType.cpp
Greg Clayton
gclayton at apple.com
Wed Jan 5 10:43:15 PST 2011
Author: gclayton
Date: Wed Jan 5 12:43:15 2011
New Revision: 122895
URL: http://llvm.org/viewvc/llvm-project?rev=122895&view=rev
Log:
Added the ability to get an set the desired format for SBValue objects.
Fixed the display of complex numbers in lldb_private::DataExtractor::Dump(...)
and also fixed other edge display cases in lldb_private::ClangASTType::DumpTypeValue(...).
Modified:
lldb/trunk/include/lldb/API/SBValue.h
lldb/trunk/include/lldb/Core/ValueObject.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/source/API/SBValue.cpp
lldb/trunk/source/Core/DataExtractor.cpp
lldb/trunk/source/Symbol/ClangASTType.cpp
Modified: lldb/trunk/include/lldb/API/SBValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBValue.h?rev=122895&r1=122894&r2=122895&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBValue.h (original)
+++ lldb/trunk/include/lldb/API/SBValue.h Wed Jan 5 12:43:15 2011
@@ -48,6 +48,12 @@
bool
IsInScope (const lldb::SBFrame &frame);
+ lldb::Format
+ GetFormat () const;
+
+ void
+ SetFormat (lldb::Format format);
+
const char *
GetValue (const lldb::SBFrame &frame);
Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=122895&r1=122894&r2=122895&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Wed Jan 5 12:43:15 2011
@@ -260,6 +260,8 @@
void
SetFormat (lldb::Format format)
{
+ if (format != m_format)
+ m_value_str.clear();
m_format = format;
}
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=122895&r1=122894&r2=122895&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Wed Jan 5 12:43:15 2011
@@ -155,6 +155,7 @@
eFormatHex,
eFormatFloat,
eFormatOctal,
+ eFormatOSType, // OS character codes encoded into an integer 'PICT' 'text' etc...
eFormatUnicode16,
eFormatUnicode32,
eFormatUnsigned,
Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=122895&r1=122894&r2=122895&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Wed Jan 5 12:43:15 2011
@@ -489,3 +489,19 @@
return true;
}
+
+lldb::Format
+SBValue::GetFormat () const
+{
+ if (m_opaque_sp)
+ return m_opaque_sp->GetFormat();
+ return eFormatDefault;
+}
+
+void
+SBValue::SetFormat (lldb::Format format)
+{
+ if (m_opaque_sp)
+ m_opaque_sp->SetFormat(format);
+}
+
Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=122895&r1=122894&r2=122895&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Wed Jan 5 12:43:15 2011
@@ -1210,6 +1210,9 @@
if (item_byte_size != 4 && item_byte_size != 8)
item_byte_size = s->GetAddressByteSize();
}
+
+ if (item_format == eFormatOSType && item_byte_size > 8)
+ item_format = eFormatHex;
for (offset = start_offset, line_start_offset = start_offset, count = 0; ValidOffset(offset) && count < item_count; ++count)
{
@@ -1280,7 +1283,7 @@
if (item_count == 1 && item_format == eFormatChar)
s->PutChar('\'');
- uint8_t ch = GetU8(&offset);
+ uint32_t ch = GetMaxU64(&offset, item_byte_size);
if (isprint(ch))
s->Printf ("%c", ch);
else if (item_format == eFormatChar)
@@ -1296,7 +1299,12 @@
case '\t': s->Printf ("\\t", ch); break;
case '\v': s->Printf ("\\v", ch); break;
case '\0': s->Printf ("\\0", ch); break;
- default: s->Printf ("\\x%2.2x", ch); break;
+ default:
+ if (item_byte_size == 1)
+ s->Printf ("\\x%2.2x", ch);
+ else
+ s->Printf ("\\u%x", ch);
+ break;
}
}
else
@@ -1310,29 +1318,6 @@
}
break;
- case eFormatComplex:
- if (sizeof(float) * 2 == item_byte_size)
- {
- uint32_t a32 = GetU32(&offset);
- uint32_t b32 = GetU32(&offset);
-
- s->Printf ("%g + %gi", a32, b32);
- }
- else if (sizeof(double) * 2 == item_byte_size)
- {
- uint64_t a64 = GetU64(&offset);
- uint64_t b64 = GetU64(&offset);
-
- s->Printf ("%lg + %lgi", a64, b64);
- }
- else if (sizeof(long double) * 2 == item_byte_size && sizeof(long double) <= sizeof(uint64_t))
- {
- uint64_t a64 = GetU64(&offset);
- uint64_t b64 = GetU64(&offset);
- s->Printf ("%Lg + %Lgi", a64, b64);
- }
- break;
-
case eFormatDecimal:
if (item_byte_size <= 8)
s->Printf ("%lld", GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset));
@@ -1348,6 +1333,40 @@
s->Printf ("0%llo", GetMaxS64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset));
break;
+ case eFormatOSType:
+ {
+ uint64_t uval64 = GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset);
+ s->PutChar('\'');
+ for (i=0; i<item_byte_size; ++i)
+ {
+ uint8_t ch;
+ if (i > 0)
+ ch = (uint8_t)(uval64 >> ((item_byte_size - i - 1) * 8));
+ else
+ ch = (uint8_t)uval64;
+ if (isprint(ch))
+ s->Printf ("%c", ch);
+ else
+ {
+ switch (ch)
+ {
+ case '\e': s->Printf ("\\e", (uint8_t)ch); break;
+ case '\a': s->Printf ("\\a", ch); break;
+ case '\b': s->Printf ("\\b", ch); break;
+ case '\f': s->Printf ("\\f", ch); break;
+ case '\n': s->Printf ("\\n", ch); break;
+ case '\r': s->Printf ("\\r", ch); break;
+ case '\t': s->Printf ("\\t", ch); break;
+ case '\v': s->Printf ("\\v", ch); break;
+ case '\0': s->Printf ("\\0", ch); break;
+ default: s->Printf ("\\x%2.2x", ch); break;
+ }
+ }
+ }
+ s->PutChar('\'');
+ }
+ break;
+
case eFormatEnum:
// Print enum value as a signed integer when we don't get the enum type
s->Printf ("%lld", GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset));
@@ -1371,6 +1390,34 @@
s->Address(GetMaxU64Bitfield(&offset, item_byte_size, item_bit_size, item_bit_offset), sizeof (addr_t));
break;
+ case eFormatComplex:
+ if (sizeof(float) * 2 == item_byte_size)
+ {
+ float f32_1 = GetFloat (&offset);
+ float f32_2 = GetFloat (&offset);
+
+ s->Printf ("%g + %gi", f32_1, f32_2);
+ break;
+ }
+ else if (sizeof(double) * 2 == item_byte_size)
+ {
+ double d64_1 = GetDouble (&offset);
+ double d64_2 = GetDouble (&offset);
+
+ s->Printf ("%lg + %lgi", d64_1, d64_2);
+ break;
+ }
+ else if (sizeof(long double) * 2 == item_byte_size)
+ {
+ long double ld64_1 = GetLongDouble (&offset);
+ long double ld64_2 = GetLongDouble (&offset);
+ s->Printf ("%Lg + %Lgi", ld64_1, ld64_2);
+ break;
+ }
+
+ // Fall through to hex for any other sizes
+ item_format = eFormatHex;
+
default:
case eFormatDefault:
case eFormatHex:
Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=122895&r1=122894&r2=122895&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Wed Jan 5 12:43:15 2011
@@ -646,9 +646,33 @@
else
{
const clang::Type::TypeClass type_class = qual_type->getTypeClass();
+
switch (type_class)
{
+ case clang::Type::Typedef:
+ {
+ clang::QualType typedef_qual_type = cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
+ if (format == eFormatDefault)
+ format = ClangASTType::GetFormat(typedef_qual_type.getAsOpaquePtr());
+ std::pair<uint64_t, unsigned> typedef_type_info = ast_context->getTypeInfo(typedef_qual_type);
+ uint64_t typedef_byte_size = typedef_type_info.first / 8;
+
+ return ClangASTType::DumpTypeValue (ast_context, // The clang AST context for this type
+ typedef_qual_type.getAsOpaquePtr(), // The clang type we want to dump
+ s,
+ format, // The format with which to display the element
+ data, // Data buffer containing all bytes for this type
+ byte_offset, // Offset into "data" where to grab value from
+ typedef_byte_size, // Size of this type in bytes
+ bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
+ bitfield_bit_offset); // Offset in bits of a bitfield value if bitfield_bit_size != 0
+ }
+ break;
+
case clang::Type::Enum:
+ // If our format is enum or default, show the enumeration value as
+ // its enumeration string value, else just display it as requested.
+ if (format == eFormatEnum || format == eFormatDefault)
{
const clang::EnumType *enum_type = cast<clang::EnumType>(qual_type.getTypePtr());
const clang::EnumDecl *enum_decl = enum_type->getDecl();
@@ -666,43 +690,75 @@
}
// If we have gotten here we didn't get find the enumerator in the
// enum decl, so just print the integer.
-
+
s->Printf("%lli", enum_value);
return true;
}
- break;
-
- case clang::Type::Typedef:
- {
- clang::QualType typedef_qual_type = cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType();
- lldb::Format typedef_format = ClangASTType::GetFormat(typedef_qual_type.getAsOpaquePtr());
- std::pair<uint64_t, unsigned> typedef_type_info = ast_context->getTypeInfo(typedef_qual_type);
- uint64_t typedef_byte_size = typedef_type_info.first / 8;
-
- return ClangASTType::DumpTypeValue(
- ast_context, // The clang AST context for this type
- typedef_qual_type.getAsOpaquePtr(), // The clang type we want to dump
- s,
- typedef_format, // The format with which to display the element
- data, // Data buffer containing all bytes for this type
- byte_offset, // Offset into "data" where to grab value from
- typedef_byte_size, // Size of this type in bytes
- bitfield_bit_size, // Size in bits of a bitfield value, if zero don't treat as a bitfield
- bitfield_bit_offset); // Offset in bits of a bitfield value if bitfield_bit_size != 0
- }
- break;
-
+ // format was not enum, just fall through and dump the value as requested....
+
default:
// We are down the a scalar type that we just need to display.
- return data.Dump(s,
- byte_offset,
- format,
- byte_size,
- 1,
- UINT32_MAX,
- LLDB_INVALID_ADDRESS,
- bitfield_bit_size,
- bitfield_bit_offset);
+ {
+ uint32_t item_count = 1;
+ // A few formats, we might need to modify our size and count for depending
+ // on how we are trying to display the value...
+ switch (format)
+ {
+ default:
+ case eFormatBoolean:
+ case eFormatBinary:
+ case eFormatComplex:
+ case eFormatCString: // NULL terminated C strings
+ case eFormatDecimal:
+ case eFormatEnum:
+ case eFormatHex:
+ case eFormatFloat:
+ case eFormatOctal:
+ case eFormatOSType:
+ case eFormatUnsigned:
+ case eFormatPointer:
+ case eFormatVectorOfChar:
+ case eFormatVectorOfSInt8:
+ case eFormatVectorOfUInt8:
+ case eFormatVectorOfSInt16:
+ case eFormatVectorOfUInt16:
+ case eFormatVectorOfSInt32:
+ case eFormatVectorOfUInt32:
+ case eFormatVectorOfSInt64:
+ case eFormatVectorOfUInt64:
+ case eFormatVectorOfFloat32:
+ case eFormatVectorOfFloat64:
+ case eFormatVectorOfUInt128:
+ break;
+
+ case eFormatChar:
+ case eFormatCharPrintable:
+ case eFormatBytes:
+ case eFormatBytesWithASCII:
+ item_count = (byte_size * item_count);
+ byte_size = 1;
+ break;
+
+ case eFormatUnicode16:
+ item_count = (byte_size * item_count) / 2;
+ byte_size = 2;
+ break;
+
+ case eFormatUnicode32:
+ item_count = (byte_size * item_count) / 4;
+ byte_size = 4;
+ break;
+ }
+ return data.Dump (s,
+ byte_offset,
+ format,
+ byte_size,
+ item_count,
+ UINT32_MAX,
+ LLDB_INVALID_ADDRESS,
+ bitfield_bit_size,
+ bitfield_bit_offset);
+ }
break;
}
}
More information about the lldb-commits
mailing list