[Lldb-commits] [lldb] r231504 - A few improvements to our vector types formatting story:
Enrico Granata
egranata at apple.com
Fri Mar 6 11:37:57 PST 2015
Author: enrico
Date: Fri Mar 6 13:37:57 2015
New Revision: 231504
URL: http://llvm.org/viewvc/llvm-project?rev=231504&view=rev
Log:
A few improvements to our vector types formatting story:
- use a hardcoded formatter to match all vector types, and make it so that their element type is taken into account when doing default formatting
- special case a vector of char to display byte values instead of characters by default
Fixes the test failures Ilia was seeing
Modified:
lldb/trunk/source/DataFormatters/FormatManager.cpp
lldb/trunk/source/DataFormatters/VectorType.cpp
lldb/trunk/source/Symbol/ClangASTType.cpp
lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py
lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp
Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=231504&r1=231503&r2=231504&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Fri Mar 6 13:37:57 2015
@@ -477,7 +477,7 @@ FormatManager::GetValidatorForType (lldb
lldb::TypeCategoryImplSP
FormatManager::GetCategory (const ConstString& category_name,
- bool can_create)
+ bool can_create)
{
if (!category_name)
return GetCategory(m_default_category_name);
@@ -1215,16 +1215,6 @@ FormatManager::LoadSystemFormatters()
fourchar_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(true);
AddFormat(sys_category_sp, lldb::eFormatOSType, ConstString("FourCharCode"), fourchar_flags);
-
- SyntheticChildren::Flags synth_flags;
- synth_flags.SetCascades(true).SetSkipPointers(true).SetSkipReferences(true);
-
- AddCXXSynthetic(sys_category_sp,
- lldb_private::formatters::VectorTypeSyntheticFrontEndCreator,
- "vector_type synthetic children",
- ConstString("unsigned char __attribute__\\(\\(ext_vector_type\\([0-9]+\\)\\)\\)"),
- synth_flags,
- true);
#endif
}
@@ -1615,6 +1605,20 @@ FormatManager::LoadHardcodedFormatters()
}
{
// insert code to load synthetics here
+ m_hardcoded_synthetics.push_back(
+ [](lldb_private::ValueObject& valobj,
+ lldb::DynamicValueType,
+ FormatManager& fmt_mgr) -> SyntheticChildren::SharedPointer {
+ static CXXSyntheticChildren::SharedPointer formatter_sp(new CXXSyntheticChildren(SyntheticChildren::Flags().SetCascades(true).SetSkipPointers(true).SetSkipReferences(true),
+ "vector_type synthetic children",
+ lldb_private::formatters::VectorTypeSyntheticFrontEndCreator));
+ if (valobj.GetClangType().IsVectorType(nullptr, nullptr))
+ {
+ if (fmt_mgr.GetCategory(fmt_mgr.m_vectortypes_category_name)->IsEnabled())
+ return formatter_sp;
+ }
+ return nullptr;
+ });
}
{
// insert code to load validators here
Modified: lldb/trunk/source/DataFormatters/VectorType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/VectorType.cpp?rev=231504&r1=231503&r2=231504&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/VectorType.cpp (original)
+++ lldb/trunk/source/DataFormatters/VectorType.cpp Fri Mar 6 13:37:57 2015
@@ -21,6 +21,7 @@ using namespace lldb_private::formatters
static ClangASTType
GetClangTypeForFormat (lldb::Format format,
+ ClangASTType element_type,
ClangASTContext *ast_ctx)
{
lldbassert(ast_ctx && "ast_ctx needs to be not NULL");
@@ -100,10 +101,12 @@ GetClangTypeForFormat (lldb::Format form
case lldb::eFormatVectorOfUInt8:
return ast_ctx->GetIntTypeFromBitSize(8, false);
+ case lldb::eFormatDefault:
+ return element_type;
+
case lldb::eFormatBinary:
case lldb::eFormatComplexInteger:
case lldb::eFormatDecimal:
- case lldb::eFormatDefault:
case lldb::eFormatEnum:
case lldb::eFormatInstruction:
case lldb::eFormatOSType:
@@ -114,7 +117,8 @@ GetClangTypeForFormat (lldb::Format form
}
static lldb::Format
-GetItemFormatForFormat (lldb::Format format)
+GetItemFormatForFormat (lldb::Format format,
+ ClangASTType element_type)
{
switch (format)
{
@@ -141,13 +145,23 @@ GetItemFormatForFormat (lldb::Format for
case lldb::eFormatBinary:
case lldb::eFormatComplexInteger:
case lldb::eFormatDecimal:
- case lldb::eFormatDefault:
case lldb::eFormatEnum:
case lldb::eFormatInstruction:
case lldb::eFormatOSType:
case lldb::eFormatVoid:
return eFormatHex;
+ case lldb::eFormatDefault:
+ {
+ // special case the (default, char) combination to actually display as an integer value
+ // most often, you won't want to see the ASCII characters... (and if you do, eFormatChar is a keystroke away)
+ bool is_char = element_type.IsCharType();
+ bool is_signed = false;
+ element_type.IsIntegerType(is_signed);
+ return is_char ? (is_signed ? lldb::eFormatDecimal : eFormatHex) : format;
+ }
+ break;
+
default:
return format;
}
@@ -215,10 +229,13 @@ namespace lldb_private {
{
m_parent_format = m_backend.GetFormat();
ClangASTType parent_type(m_backend.GetClangType());
- m_child_type = ::GetClangTypeForFormat(m_parent_format, ClangASTContext::GetASTContext(parent_type.GetASTContext()));
+ ClangASTType element_type;
+ parent_type.IsVectorType(&element_type, nullptr);
+ m_child_type = ::GetClangTypeForFormat(m_parent_format, element_type, ClangASTContext::GetASTContext(parent_type.GetASTContext()));
m_num_children = ::CalculateNumChildren(parent_type,
m_child_type);
- m_item_format = GetItemFormatForFormat(m_parent_format);
+ m_item_format = GetItemFormatForFormat(m_parent_format,
+ m_child_type);
return false;
}
Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=231504&r1=231503&r2=231504&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Fri Mar 6 13:37:57 2015
@@ -315,6 +315,18 @@ ClangASTType::IsVectorType (ClangASTType
return true;
}
break;
+ case clang::Type::ExtVector:
+ {
+ const clang::ExtVectorType *ext_vector_type = qual_type->getAs<clang::ExtVectorType>();
+ if (ext_vector_type)
+ {
+ if (size)
+ *size = ext_vector_type->getNumElements();
+ if (element_type)
+ *element_type = ClangASTType(m_ast, ext_vector_type->getElementType().getAsOpaquePtr());
+ }
+ return true;
+ }
default:
break;
}
Modified: lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py?rev=231504&r1=231503&r2=231504&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/rdar-10642615/Test-rdar-10642615.py Fri Mar 6 13:37:57 2015
@@ -55,14 +55,14 @@ class Radar10642615DataFormatterTestCase
self.addTearDownHook(cleanup)
self.expect('frame variable',
- substrs = ['(vFloat) valueFL = (1, 0, 4, 0)',
+ substrs = ['(vFloat) valueFL = (1.25, 0, 0.25, 0)',
'(int16_t [8]) valueI16 = (1, 0, 4, 0, 0, 1, 0, 4)',
'(int32_t [4]) valueI32 = (1, 0, 4, 0)',
- '(vDouble) valueDL = (1, 4)',
+ '(vDouble) valueDL = (1.25, 2.25)',
'(vUInt8) valueU8 = (0x01, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)',
'(vUInt16) valueU16 = (1, 0, 4, 0, 0, 1, 0, 4)',
'(vUInt32) valueU32 = (1, 2, 3, 4)',
- "(vSInt8) valueS8 = ('\\x01', '\\0', '\\x04', '\\0', '\\0', '\\x01', '\\0', '\\x04', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0', '\\0')",
+ "(vSInt8) valueS8 = (1, 0, 4, 0, 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0)",
'(vSInt16) valueS16 = (1, 0, 4, 0, 0, 1, 0, 4)',
'(vSInt32) valueS32 = (4, 3, 2, 1)',
'(vBool32) valueBool32 = (0, 1, 0, 1)'])
Modified: lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp?rev=231504&r1=231503&r2=231504&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp (original)
+++ lldb/trunk/test/functionalities/data-formatter/rdar-10642615/main.cpp Fri Mar 6 13:37:57 2015
@@ -1,4 +1,4 @@
-//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+ //===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -11,8 +11,8 @@
int main()
{
- vFloat valueFL = {1,0,4,0};
- vDouble valueDL = {1,4};
+ vFloat valueFL = {1.25,0,0.25,0};
+ vDouble valueDL = {1.25,2.25};
int16_t valueI16[8] = {1,0,4,0,0,1,0,4};
int32_t valueI32[4] = {1,0,4,0};
vUInt8 valueU8 = {1,0,4,0,0,1,0,4};
More information about the lldb-commits
mailing list