diff options
author | Enrico Granata <egranata@apple.com> | 2014-05-17 19:14:17 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2014-05-17 19:14:17 +0000 |
commit | e8daa2f843e280607db9e5c8ca1b72db1f62c21e (patch) | |
tree | 12ec14fab56f9bca8b93c56896f5e81daa11d9c6 | |
parent | 210e1aded709f6148f6d0a6c16eb5a16190c5e53 (diff) | |
download | bcm5719-llvm-e8daa2f843e280607db9e5c8ca1b72db1f62c21e.tar.gz bcm5719-llvm-e8daa2f843e280607db9e5c8ca1b72db1f62c21e.zip |
Introduce the concept of a "display name" for types
Rationale:
Pretty simply, the idea is that sometimes type names are way too long and contain way too many details for the average developer to care about. For instance, a plain ol' vector of int might be shown as
std::__1::vector<int, std::__1::allocator<....
rather than the much simpler std::vector<int> form, which is what most developers would actually type in their code
Proposed solution:
Introduce a notion of "display name" and a corresponding API GetDisplayTypeName() to return such a crafted for visual representation type name
Obviously, the display name and the fully qualified (or "true") name are not necessarily the same - that's the whole point
LLDB could choose to pick the "display name" as its one true notion of a type name, and if somebody really needs the fully qualified version of it, let them deal with the problem
Or, LLDB could rename what it currently calls the "type name" to be the "display name", and add new APIs for the fully qualified name, making the display name the default choice
The choice that I am making here is that the type name will keep meaning the same, and people who want a type name suited for display will explicitly ask for one
It is the less risky/disruptive choice - and it should eventually make it fairly obvious when someone is asking for the wrong type
Caveats:
- for now, GetDisplayTypeName() == GetTypeName(), there is no logic to produce customized display type names yet.
- while the fully-qualified type name is still the main key to the kingdom of data formatters, if we start showing custom names to people, those should match formatters
llvm-svn: 209072
28 files changed, 190 insertions, 33 deletions
diff --git a/lldb/include/lldb/API/SBType.h b/lldb/include/lldb/API/SBType.h index 2cd9b4459a3..40173af9332 100644 --- a/lldb/include/lldb/API/SBType.h +++ b/lldb/include/lldb/API/SBType.h @@ -161,6 +161,9 @@ public: const char* GetName(); + const char * + GetDisplayTypeName (); + lldb::TypeClass GetTypeClass (); diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h index 2b9a344b930..332ca50b85f 100644 --- a/lldb/include/lldb/API/SBValue.h +++ b/lldb/include/lldb/API/SBValue.h @@ -50,6 +50,9 @@ public: const char * GetTypeName (); + + const char * + GetDisplayTypeName (); size_t GetByteSize (); diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index 589b22f3a24..0a525451898 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -395,6 +395,9 @@ public: GetTypeName(); virtual ConstString + GetDisplayTypeName(); + + virtual ConstString GetQualifiedTypeName(); virtual lldb::LanguageType diff --git a/lldb/include/lldb/Core/ValueObjectChild.h b/lldb/include/lldb/Core/ValueObjectChild.h index 780529a4af1..40c40608887 100644 --- a/lldb/include/lldb/Core/ValueObjectChild.h +++ b/lldb/include/lldb/Core/ValueObjectChild.h @@ -62,6 +62,9 @@ public: virtual ConstString GetQualifiedTypeName(); + virtual ConstString + GetDisplayTypeName(); + virtual bool IsInScope (); diff --git a/lldb/include/lldb/Core/ValueObjectConstResult.h b/lldb/include/lldb/Core/ValueObjectConstResult.h index 4964d0589a0..dd87fc848ae 100644 --- a/lldb/include/lldb/Core/ValueObjectConstResult.h +++ b/lldb/include/lldb/Core/ValueObjectConstResult.h @@ -80,6 +80,9 @@ public: virtual ConstString GetTypeName(); + virtual ConstString + GetDisplayTypeName(); + virtual bool IsInScope (); diff --git a/lldb/include/lldb/Core/ValueObjectDynamicValue.h b/lldb/include/lldb/Core/ValueObjectDynamicValue.h index 68f88c96e54..7607bd38137 100644 --- a/lldb/include/lldb/Core/ValueObjectDynamicValue.h +++ b/lldb/include/lldb/Core/ValueObjectDynamicValue.h @@ -37,6 +37,9 @@ public: virtual ConstString GetQualifiedTypeName(); + + virtual ConstString + GetDisplayTypeName(); virtual size_t CalculateNumChildren(); diff --git a/lldb/include/lldb/Core/ValueObjectMemory.h b/lldb/include/lldb/Core/ValueObjectMemory.h index 627d73eb4b2..41b43188a46 100644 --- a/lldb/include/lldb/Core/ValueObjectMemory.h +++ b/lldb/include/lldb/Core/ValueObjectMemory.h @@ -47,6 +47,9 @@ public: virtual ConstString GetTypeName(); + virtual ConstString + GetDisplayTypeName(); + virtual size_t CalculateNumChildren(); diff --git a/lldb/include/lldb/Core/ValueObjectRegister.h b/lldb/include/lldb/Core/ValueObjectRegister.h index 6820629f08e..f7c7683d60b 100644 --- a/lldb/include/lldb/Core/ValueObjectRegister.h +++ b/lldb/include/lldb/Core/ValueObjectRegister.h @@ -45,6 +45,9 @@ public: virtual ConstString GetQualifiedTypeName(); + + virtual ConstString + GetDisplayTypeName(); virtual size_t CalculateNumChildren(); diff --git a/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h b/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h index f1d8c885c25..e12698f49bb 100644 --- a/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h +++ b/lldb/include/lldb/Core/ValueObjectSyntheticFilter.h @@ -41,6 +41,9 @@ public: virtual ConstString GetQualifiedTypeName(); + + virtual ConstString + GetDisplayTypeName(); virtual bool MightHaveChildren(); diff --git a/lldb/include/lldb/Core/ValueObjectVariable.h b/lldb/include/lldb/Core/ValueObjectVariable.h index 8a30b00f6bb..0e32d09057d 100644 --- a/lldb/include/lldb/Core/ValueObjectVariable.h +++ b/lldb/include/lldb/Core/ValueObjectVariable.h @@ -39,6 +39,9 @@ public: virtual ConstString GetQualifiedTypeName(); + + virtual ConstString + GetDisplayTypeName(); virtual size_t CalculateNumChildren(); diff --git a/lldb/include/lldb/Symbol/ClangASTType.h b/lldb/include/lldb/Symbol/ClangASTType.h index 0f2eb965ca6..7f136bd9573 100644 --- a/lldb/include/lldb/Symbol/ClangASTType.h +++ b/lldb/include/lldb/Symbol/ClangASTType.h @@ -264,6 +264,9 @@ public: ConstString GetTypeName () const; + ConstString + GetDisplayTypeName () const; + uint32_t GetTypeInfo (ClangASTType *pointee_or_element_clang_type = NULL) const; diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h index da327439936..a1034044c0d 100644 --- a/lldb/include/lldb/Symbol/Type.h +++ b/lldb/include/lldb/Symbol/Type.h @@ -368,6 +368,16 @@ public: return ConstString (); } + ConstString + GetDisplayTypeName () const + { + if (type_sp) + return type_sp->GetClangForwardType().GetDisplayTypeName(); + if (clang_type) + return clang_type.GetDisplayTypeName(); + return ConstString(); + } + void SetType (ClangASTType type) { @@ -511,6 +521,9 @@ public: ConstString GetName () const; + ConstString + GetDisplayTypeName () const; + TypeImpl GetPointerType () const; diff --git a/lldb/scripts/Python/interface/SBType.i b/lldb/scripts/Python/interface/SBType.i index 936bf2ccf27..8a0ad6e508b 100644 --- a/lldb/scripts/Python/interface/SBType.i +++ b/lldb/scripts/Python/interface/SBType.i @@ -27,7 +27,7 @@ public: const char * GetName (); - + lldb::SBType GetType (); @@ -216,6 +216,9 @@ public: const char* GetName(); + const char * + GetDisplayTypeName (); + lldb::TypeClass GetTypeClass (); diff --git a/lldb/scripts/Python/interface/SBValue.i b/lldb/scripts/Python/interface/SBValue.i index 4cfafa3f4d8..78e7605224e 100644 --- a/lldb/scripts/Python/interface/SBValue.i +++ b/lldb/scripts/Python/interface/SBValue.i @@ -81,6 +81,9 @@ public: const char * GetTypeName (); + + const char * + GetDisplayTypeName (); size_t GetByteSize (); diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index 5ca7ddf3d81..1e04841bfad 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -414,6 +414,14 @@ SBType::GetName() return m_opaque_sp->GetName().GetCString(); } +const char * +SBType::GetDisplayTypeName () +{ + if (!IsValid()) + return ""; + return m_opaque_sp->GetDisplayTypeName().GetCString(); +} + lldb::TypeClass SBType::GetTypeClass () { diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index f171d239913..3a9621b1e3b 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -378,6 +378,31 @@ SBValue::GetTypeName () return name; } +const char * +SBValue::GetDisplayTypeName () +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + const char *name = NULL; + ValueLocker locker; + lldb::ValueObjectSP value_sp(GetSP(locker)); + if (value_sp) + { + name = value_sp->GetDisplayTypeName().GetCString(); + } + + if (log) + { + if (name) + log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", + static_cast<void*>(value_sp.get()), name); + else + log->Printf ("SBValue(%p)::GetTypeName () => NULL", + static_cast<void*>(value_sp.get())); + } + + return name; +} + size_t SBValue::GetByteSize () { diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index f6a3d53032b..9fc4167f31b 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1953,6 +1953,12 @@ ValueObject::GetTypeName() } ConstString +ValueObject::GetDisplayTypeName() +{ + return GetTypeName(); +} + +ConstString ValueObject::GetQualifiedTypeName() { return GetClangType().GetConstQualifiedTypeName(); diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp index ccf87cd15b2..33b91f9e30d 100644 --- a/lldb/source/Core/ValueObjectChild.cpp +++ b/lldb/source/Core/ValueObjectChild.cpp @@ -66,25 +66,29 @@ ValueObjectChild::CalculateNumChildren() return GetClangType().GetNumChildren (true); } +static void +AdjustForBitfieldness(ConstString& name, + uint8_t bitfield_bit_size) +{ + if (name && bitfield_bit_size) + { + const char *clang_type_name = name.AsCString(); + if (clang_type_name) + { + std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0); + ::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, bitfield_bit_size); + name.SetCString(&bitfield_type_name.front()); + } + } +} + ConstString ValueObjectChild::GetTypeName() { if (m_type_name.IsEmpty()) { m_type_name = GetClangType().GetConstTypeName (); - if (m_type_name) - { - if (m_bitfield_bit_size > 0) - { - const char *clang_type_name = m_type_name.AsCString(); - if (clang_type_name) - { - std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0); - ::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, m_bitfield_bit_size); - m_type_name.SetCString(&bitfield_type_name.front()); - } - } - } + AdjustForBitfieldness(m_type_name, m_bitfield_bit_size); } return m_type_name; } @@ -93,22 +97,18 @@ ConstString ValueObjectChild::GetQualifiedTypeName() { ConstString qualified_name = GetClangType().GetConstTypeName(); - if (qualified_name) - { - if (m_bitfield_bit_size > 0) - { - const char *clang_type_name = qualified_name.AsCString(); - if (clang_type_name) - { - std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0); - ::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, m_bitfield_bit_size); - qualified_name.SetCString(&bitfield_type_name.front()); - } - } - } + AdjustForBitfieldness(qualified_name, m_bitfield_bit_size); return qualified_name; } +ConstString +ValueObjectChild::GetDisplayTypeName() +{ + ConstString display_name = GetClangType().GetDisplayTypeName(); + AdjustForBitfieldness(display_name, m_bitfield_bit_size); + return display_name; +} + bool ValueObjectChild::UpdateValue () { diff --git a/lldb/source/Core/ValueObjectConstResult.cpp b/lldb/source/Core/ValueObjectConstResult.cpp index d6d86381358..387e171e352 100644 --- a/lldb/source/Core/ValueObjectConstResult.cpp +++ b/lldb/source/Core/ValueObjectConstResult.cpp @@ -276,6 +276,12 @@ ValueObjectConstResult::GetTypeName() return m_type_name; } +ConstString +ValueObjectConstResult::GetDisplayTypeName() +{ + return GetClangType().GetDisplayTypeName(); +} + bool ValueObjectConstResult::UpdateValue () { diff --git a/lldb/source/Core/ValueObjectDynamicValue.cpp b/lldb/source/Core/ValueObjectDynamicValue.cpp index a9f2606212c..a6fad7a9b1f 100644 --- a/lldb/source/Core/ValueObjectDynamicValue.cpp +++ b/lldb/source/Core/ValueObjectDynamicValue.cpp @@ -71,8 +71,6 @@ ValueObjectDynamicValue::GetTypeName() { if (m_dynamic_type_info.HasName()) return m_dynamic_type_info.GetName(); - if (m_dynamic_type_info.HasType()) - return GetClangType().GetConstTypeName(); } return m_parent->GetTypeName(); } @@ -96,10 +94,22 @@ ValueObjectDynamicValue::GetQualifiedTypeName() { if (m_dynamic_type_info.HasName()) return m_dynamic_type_info.GetName(); + } + return m_parent->GetQualifiedTypeName(); +} + +ConstString +ValueObjectDynamicValue::GetDisplayTypeName() +{ + const bool success = UpdateValueIfNeeded(false); + if (success) + { if (m_dynamic_type_info.HasType()) - return GetClangType().GetConstQualifiedTypeName (); + return GetClangType().GetDisplayTypeName(); + if (m_dynamic_type_info.HasName()) + return m_dynamic_type_info.GetName(); } - return m_parent->GetTypeName(); + return m_parent->GetDisplayTypeName(); } size_t diff --git a/lldb/source/Core/ValueObjectMemory.cpp b/lldb/source/Core/ValueObjectMemory.cpp index 42fd0e8fffb..d2cbbfdda24 100644 --- a/lldb/source/Core/ValueObjectMemory.cpp +++ b/lldb/source/Core/ValueObjectMemory.cpp @@ -147,6 +147,14 @@ ValueObjectMemory::GetTypeName() return m_clang_type.GetConstTypeName(); } +ConstString +ValueObjectMemory::GetDisplayTypeName() +{ + if (m_type_sp) + return m_type_sp->GetClangForwardType().GetDisplayTypeName(); + return m_clang_type.GetDisplayTypeName(); +} + size_t ValueObjectMemory::CalculateNumChildren() { diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp index 4f21457519e..0db1f0cd45c 100644 --- a/lldb/source/Core/ValueObjectRegister.cpp +++ b/lldb/source/Core/ValueObjectRegister.cpp @@ -55,6 +55,12 @@ ValueObjectRegisterContext::GetTypeName() } ConstString +ValueObjectRegisterContext::GetDisplayTypeName() +{ + return ConstString(); +} + +ConstString ValueObjectRegisterContext::GetQualifiedTypeName() { return ConstString(); diff --git a/lldb/source/Core/ValueObjectSyntheticFilter.cpp b/lldb/source/Core/ValueObjectSyntheticFilter.cpp index a65b8f63e31..18d36164989 100644 --- a/lldb/source/Core/ValueObjectSyntheticFilter.cpp +++ b/lldb/source/Core/ValueObjectSyntheticFilter.cpp @@ -101,6 +101,12 @@ ValueObjectSynthetic::GetQualifiedTypeName() return m_parent->GetQualifiedTypeName(); } +ConstString +ValueObjectSynthetic::GetDisplayTypeName() +{ + return m_parent->GetDisplayTypeName(); +} + size_t ValueObjectSynthetic::CalculateNumChildren() { diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp index 2e5bb22a890..225dc02c8ad 100644 --- a/lldb/source/Core/ValueObjectVariable.cpp +++ b/lldb/source/Core/ValueObjectVariable.cpp @@ -73,6 +73,15 @@ ValueObjectVariable::GetTypeName() } ConstString +ValueObjectVariable::GetDisplayTypeName() +{ + Type * var_type = m_variable_sp->GetType(); + if (var_type) + return var_type->GetClangForwardType().GetDisplayTypeName(); + return ConstString(); +} + +ConstString ValueObjectVariable::GetQualifiedTypeName() { Type * var_type = m_variable_sp->GetType(); diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index 9fe89b187bf..f3146b99f0c 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -185,7 +185,11 @@ FormatManager::GetPossibleMatches (ValueObject& valobj, reason |= lldb_private::eFormatterChoiceCriterionStrippedBitField; } entries.push_back({type_name,reason,did_strip_ptr,did_strip_ref,did_strip_typedef}); - + + ConstString display_type_name(clang_type.GetDisplayTypeName()); + if (display_type_name != type_name) + entries.push_back({display_type_name,reason,did_strip_ptr,did_strip_ref,did_strip_typedef}); + for (bool is_rvalue_ref = true, j = true; j && clang_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false) { ClangASTType non_ref_type = clang_type.GetNonReferenceType(); diff --git a/lldb/source/DataFormatters/ValueObjectPrinter.cpp b/lldb/source/DataFormatters/ValueObjectPrinter.cpp index 565d4d419da..65e5e3f4582 100644 --- a/lldb/source/DataFormatters/ValueObjectPrinter.cpp +++ b/lldb/source/DataFormatters/ValueObjectPrinter.cpp @@ -222,7 +222,11 @@ ValueObjectPrinter::PrintTypeIfNeeded () { // Some ValueObjects don't have types (like registers sets). Only print // the type if there is one to print - ConstString qualified_type_name(m_valobj->GetQualifiedTypeName()); + ConstString qualified_type_name; + if (options.m_be_raw) + qualified_type_name = m_valobj->GetQualifiedTypeName(); + else + qualified_type_name = m_valobj->GetDisplayTypeName(); if (qualified_type_name) m_stream->Printf("(%s) ", qualified_type_name.GetCString()); else diff --git a/lldb/source/Symbol/ClangASTType.cpp b/lldb/source/Symbol/ClangASTType.cpp index 20ac65fe323..b864844625b 100644 --- a/lldb/source/Symbol/ClangASTType.cpp +++ b/lldb/source/Symbol/ClangASTType.cpp @@ -1243,6 +1243,11 @@ ClangASTType::GetTypeName () const return ConstString(type_name); } +ConstString +ClangASTType::GetDisplayTypeName () const +{ + return GetTypeName(); +} uint32_t ClangASTType::GetTypeInfo (ClangASTType *pointee_or_element_clang_type) const diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp index cabdbbafa71..e58cbc19b36 100644 --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -1053,6 +1053,14 @@ TypeImpl::GetName () const return m_static_type.GetName (); } +ConstString +TypeImpl::GetDisplayTypeName () const +{ + if (m_dynamic_type) + return m_dynamic_type.GetDisplayTypeName(); + return m_static_type.GetDisplayTypeName(); +} + TypeImpl TypeImpl::GetPointerType () const { |