Author: enrico Date: Tue Sep 8 20:10:46 2015 New Revision: 247112 URL: http://llvm.org/viewvc/llvm-project?rev=247112&view=rev Log: Data formatter candidate matches can be generated in a number of ways; language-based dynamic type discovery being one of them (for instance, this is what takes an 'id' and discovers that it truly is an __NSArrayI, so it should probably use the NSArray formatter)
This used to be hardcoded in the FormatManager, but in a pluginized world that is not the right way to go So, move this step to the Language plugin such that appropriate language plugins for a type get a say about adding candidates to the formatters lookup tables Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h lldb/trunk/include/lldb/Target/Language.h lldb/trunk/include/lldb/lldb-private-enumerations.h lldb/trunk/source/DataFormatters/FormatManager.cpp lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.h lldb/trunk/source/Target/Language.cpp Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/include/lldb/DataFormatters/FormatManager.h (original) +++ lldb/trunk/include/lldb/DataFormatters/FormatManager.h Tue Sep 8 20:10:46 2015 @@ -264,6 +264,9 @@ public: private: + static std::vector<lldb::LanguageType> + GetCandidateLanguages (ValueObject& valobj); + static void GetPossibleMatches (ValueObject& valobj, CompilerType clang_type, Modified: lldb/trunk/include/lldb/Target/Language.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Language.h?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Language.h (original) +++ lldb/trunk/include/lldb/Target/Language.h Tue Sep 8 20:10:46 2015 @@ -13,6 +13,7 @@ // C Includes // C++ Includes #include <functional> +#include <vector> // Other libraries and framework includes // Project includes @@ -22,11 +23,10 @@ namespace lldb_private { - class Language : - public PluginInterface - { - public: - +class Language : +public PluginInterface +{ +public: ~Language() override; static Language* @@ -42,6 +42,9 @@ namespace lldb_private { virtual lldb::TypeCategoryImplSP GetFormatters (); + virtual std::vector<ConstString> + GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic); + // These are accessors for general information about the Languages lldb knows about: static lldb::LanguageType @@ -70,16 +73,16 @@ namespace lldb_private { LanguageIsPascal (lldb::LanguageType language); - protected: - //------------------------------------------------------------------ - // Classes that inherit from Language can see and modify these - //------------------------------------------------------------------ - - Language(); - private: - - DISALLOW_COPY_AND_ASSIGN (Language); - }; +protected: + //------------------------------------------------------------------ + // Classes that inherit from Language can see and modify these + //------------------------------------------------------------------ + + Language(); +private: + + DISALLOW_COPY_AND_ASSIGN (Language); +}; } // namespace lldb_private Modified: lldb/trunk/include/lldb/lldb-private-enumerations.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-enumerations.h?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/include/lldb/lldb-private-enumerations.h (original) +++ lldb/trunk/include/lldb/lldb-private-enumerations.h Tue Sep 8 20:10:46 2015 @@ -188,7 +188,7 @@ typedef enum FormatterChoiceCriterion eFormatterChoiceCriterionNavigatedTypedefs = 0x00000002, eFormatterChoiceCriterionRegularExpressionSummary = 0x00000004, eFormatterChoiceCriterionRegularExpressionFilter = 0x00000004, - eFormatterChoiceCriterionDynamicObjCDiscovery = 0x00000008, + eFormatterChoiceCriterionLanguagePlugin = 0x00000008, eFormatterChoiceCriterionStrippedBitField = 0x00000010, eFormatterChoiceCriterionWentToStaticValue = 0x00000020 } FormatterChoiceCriterion; Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/source/DataFormatters/FormatManager.cpp (original) +++ lldb/trunk/source/DataFormatters/FormatManager.cpp Tue Sep 8 20:10:46 2015 @@ -270,41 +270,22 @@ FormatManager::GetPossibleMatches (Value true); // this is not exactly the usual meaning of stripping typedefs } } - bool canBeObjCDynamic = clang_type.IsPossibleDynamicType (NULL, - false, // no C - true); // yes ObjC - if (canBeObjCDynamic) + for (lldb::LanguageType language_type : GetCandidateLanguages(valobj)) { - if (use_dynamic != lldb::eNoDynamicValues) + if (Language* language = Language::FindPlugin(language_type)) { - do + for (ConstString candidate : language->GetPossibleFormattersMatches(valobj, use_dynamic)) { - lldb::ProcessSP process_sp = valobj.GetProcessSP(); - if (!process_sp) - break; - ObjCLanguageRuntime* runtime = process_sp->GetObjCLanguageRuntime(); - if (runtime == nullptr) - break; - ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetClassDescriptor(valobj)); - if (!objc_class_sp) - break; - ConstString name (objc_class_sp->GetClassName()); - entries.push_back({name,reason | lldb_private::eFormatterChoiceCriterionDynamicObjCDiscovery,did_strip_ptr,did_strip_ref,did_strip_typedef}); - } while (false); + entries.push_back({candidate, + reason | lldb_private::eFormatterChoiceCriterionLanguagePlugin, + did_strip_ptr, + did_strip_ref, + did_strip_typedef}); + } } - - CompilerType non_ptr_type = clang_type.GetPointeeType(); - GetPossibleMatches(valobj, - non_ptr_type, - reason | lldb_private::eFormatterChoiceCriterionStrippedPointerReference, - use_dynamic, - entries, - true, - did_strip_ref, - did_strip_typedef); } - + // try to strip typedef chains if (clang_type.IsTypedefType()) { @@ -666,8 +647,8 @@ FormatManager::GetTypeForCache (ValueObj return ConstString(); } -static std::vector<lldb::LanguageType> -GetCandidateLanguages (ValueObject& valobj) +std::vector<lldb::LanguageType> +FormatManager::GetCandidateLanguages (ValueObject& valobj) { lldb::LanguageType lang_type = valobj.GetObjectRuntimeLanguage(); switch (lang_type) Modified: lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp (original) +++ lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.cpp Tue Sep 8 20:10:46 2015 @@ -12,6 +12,9 @@ #include "lldb/Core/ConstString.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/StreamString.h" +#include "lldb/Core/ValueObject.h" +#include "lldb/Symbol/CompilerType.h" +#include "lldb/Target/ObjCLanguageRuntime.h" using namespace lldb; using namespace lldb_private; @@ -298,3 +301,37 @@ ObjCLanguage::MethodName::GetFullNames ( } return names.size(); } + +std::vector<ConstString> +ObjCLanguage::GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic) +{ + std::vector<ConstString> result; + + if (use_dynamic == lldb::eNoDynamicValues) + return result; + + CompilerType compiler_type(valobj.GetCompilerType()); + + const bool check_cpp = false; + const bool check_objc = true; + bool canBeObjCDynamic = compiler_type.IsPossibleDynamicType(nullptr, check_cpp, check_objc); + + if (canBeObjCDynamic) + { + do { + lldb::ProcessSP process_sp = valobj.GetProcessSP(); + if (!process_sp) + break; + ObjCLanguageRuntime* runtime = process_sp->GetObjCLanguageRuntime(); + if (runtime == nullptr) + break; + ObjCLanguageRuntime::ClassDescriptorSP objc_class_sp (runtime->GetClassDescriptor(valobj)); + if (!objc_class_sp) + break; + if (ConstString name = objc_class_sp->GetClassName()) + result.push_back(name); + } while (false); + } + + return result; +} Modified: lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.h?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.h (original) +++ lldb/trunk/source/Plugins/Language/ObjC/ObjCLanguage.h Tue Sep 8 20:10:46 2015 @@ -135,11 +135,14 @@ public: ObjCLanguage () = default; lldb::LanguageType - GetLanguageType () const + GetLanguageType () const override { return lldb::eLanguageTypeObjC; } + std::vector<ConstString> + GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic) override; + //------------------------------------------------------------------ // Static Functions //------------------------------------------------------------------ @@ -183,10 +186,10 @@ public: // PluginInterface protocol //------------------------------------------------------------------ virtual ConstString - GetPluginName(); + GetPluginName() override; virtual uint32_t - GetPluginVersion(); + GetPluginVersion() override; }; } // namespace lldb_private Modified: lldb/trunk/source/Target/Language.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Language.cpp?rev=247112&r1=247111&r2=247112&view=diff ============================================================================== --- lldb/trunk/source/Target/Language.cpp (original) +++ lldb/trunk/source/Target/Language.cpp Tue Sep 8 20:10:46 2015 @@ -94,6 +94,12 @@ Language::GetFormatters () return nullptr; } +std::vector<ConstString> +Language::GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic) +{ + return {}; +} + struct language_name_pair { const char *name; LanguageType type; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits