[Lldb-commits] [lldb] r247872 - Add the ability for formatter categories to be bound to one or more languages
Enrico Granata via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 16 17:14:50 PDT 2015
Author: enrico
Date: Wed Sep 16 19:14:50 2015
New Revision: 247872
URL: http://llvm.org/viewvc/llvm-project?rev=247872&view=rev
Log:
Add the ability for formatter categories to be bound to one or more languages
What that does is it restricts formatters in those categories to only match to types coming from "compatible" source languages
Modified:
lldb/trunk/include/lldb/DataFormatters/FormatManager.h
lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
lldb/trunk/include/lldb/DataFormatters/TypeCategory.h
lldb/trunk/source/Commands/CommandObjectType.cpp
lldb/trunk/source/DataFormatters/DataVisualization.cpp
lldb/trunk/source/DataFormatters/FormatManager.cpp
lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
lldb/trunk/source/DataFormatters/TypeCategory.cpp
lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp
lldb/trunk/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py
lldb/trunk/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py
Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/FormatManager.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/FormatManager.h Wed Sep 16 19:14:50 2015
@@ -60,8 +60,33 @@ public:
EnableCategory (const ConstString& category_name,
TypeCategoryMap::Position pos = TypeCategoryMap::Default)
{
- m_categories_map.Enable(category_name,
- pos);
+ EnableCategory(category_name,
+ pos,
+ std::initializer_list<lldb::LanguageType>());
+ }
+
+ void
+ EnableCategory (const ConstString& category_name,
+ TypeCategoryMap::Position pos,
+ lldb::LanguageType lang)
+ {
+ EnableCategory(category_name,
+ pos,
+ {lang});
+ }
+
+ void
+ EnableCategory (const ConstString& category_name,
+ TypeCategoryMap::Position pos = TypeCategoryMap::Default,
+ std::initializer_list<lldb::LanguageType> langs = {})
+ {
+ TypeCategoryMap::ValueSP category_sp;
+ if (m_categories_map.Get(category_name, category_sp) && category_sp)
+ {
+ m_categories_map.Enable(category_sp, pos);
+ for (const lldb::LanguageType lang : langs)
+ category_sp->AddLanguage(lang);
+ }
}
void
Modified: lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/FormattersHelpers.h Wed Sep 16 19:14:50 2015
@@ -32,6 +32,12 @@ namespace lldb_private {
bool regex = false);
void
+ AddSummary(TypeCategoryImpl::SharedPointer category_sp,
+ lldb::TypeSummaryImplSP summary_sp,
+ ConstString type_name,
+ bool regex = false);
+
+ void
AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
const char* string,
ConstString type_name,
Modified: lldb/trunk/include/lldb/DataFormatters/TypeCategory.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeCategory.h?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/TypeCategory.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/TypeCategory.h Wed Sep 16 19:14:50 2015
@@ -99,7 +99,8 @@ namespace lldb_private {
typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP;
TypeCategoryImpl (IFormatChangeListener* clist,
- ConstString name);
+ ConstString name,
+ std::initializer_list<lldb::LanguageType> langs = {});
FormatContainerSP
GetTypeFormatsContainer ()
@@ -264,6 +265,21 @@ namespace lldb_private {
{
return m_name.GetCString();
}
+
+ size_t
+ GetNumLanguages ();
+
+ lldb::LanguageType
+ GetLanguageAtIndex (size_t idx);
+
+ void
+ AddLanguage (lldb::LanguageType lang);
+
+ bool
+ HasLanguage (lldb::LanguageType lang);
+
+ std::string
+ GetDescription ();
bool
AnyMatches (ConstString type_name,
@@ -291,6 +307,8 @@ namespace lldb_private {
ConstString m_name;
+ std::vector<lldb::LanguageType> m_languages;
+
uint32_t m_enabled_position;
void
@@ -302,6 +320,9 @@ namespace lldb_private {
Enable(false, UINT32_MAX);
}
+ bool
+ IsApplicable (ValueObject& valobj);
+
uint32_t
GetLastEnabledPosition ()
{
Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Wed Sep 16 19:14:50 2015
@@ -30,6 +30,8 @@
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Interpreter/OptionGroupFormat.h"
+#include "lldb/Interpreter/OptionValueBoolean.h"
+#include "lldb/Interpreter/OptionValueLanguage.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
@@ -1356,9 +1358,7 @@ private:
if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
return true;
- result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
- cate_name,
- (cate->IsEnabled() ? "enabled" : "disabled"));
+ result->GetOutputStream().Printf("-----------------------\nCategory: %s\n-----------------------\n", cate->GetDescription().c_str());
cate->GetTypeFormatsContainer()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
@@ -2398,10 +2398,8 @@ private:
if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
return true;
- result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
- cate_name,
- (cate->IsEnabled() ? "enabled" : "disabled"));
-
+ result->GetOutputStream().Printf("-----------------------\nCategory: %s\n-----------------------\n", cate->GetDescription().c_str());
+
cate->GetTypeSummariesContainer()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
@@ -2456,6 +2454,145 @@ CommandObjectTypeSummaryList::CommandOpt
};
//-------------------------------------------------------------------------
+// CommandObjectTypeCategoryDefine
+//-------------------------------------------------------------------------
+
+class CommandObjectTypeCategoryDefine : public CommandObjectParsed
+{
+
+ class CommandOptions : public Options
+ {
+ public:
+
+ CommandOptions (CommandInterpreter &interpreter) :
+ Options (interpreter),
+ m_define_enabled(false,false),
+ m_cate_language(eLanguageTypeUnknown,eLanguageTypeUnknown)
+ {
+ }
+
+ virtual
+ ~CommandOptions (){}
+
+ virtual Error
+ SetOptionValue (uint32_t option_idx, const char *option_arg)
+ {
+ Error error;
+ const int short_option = m_getopt_table[option_idx].val;
+
+ switch (short_option)
+ {
+ case 'e':
+ m_define_enabled.SetValueFromString("true");
+ break;
+ case 'l':
+ error = m_cate_language.SetValueFromString(option_arg);
+ break;
+ default:
+ error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
+ break;
+ }
+
+ return error;
+ }
+
+ void
+ OptionParsingStarting ()
+ {
+ m_define_enabled.Clear();
+ m_cate_language.Clear();
+ }
+
+ const OptionDefinition*
+ GetDefinitions ()
+ {
+ return g_option_table;
+ }
+
+ // Options table: Required for subclasses of Options.
+
+ static OptionDefinition g_option_table[];
+
+ // Instance variables to hold the values for command options.
+
+ OptionValueBoolean m_define_enabled;
+ OptionValueLanguage m_cate_language;
+
+
+ };
+
+ CommandOptions m_options;
+
+ virtual Options *
+ GetOptions ()
+ {
+ return &m_options;
+ }
+
+public:
+ CommandObjectTypeCategoryDefine (CommandInterpreter &interpreter) :
+ CommandObjectParsed (interpreter,
+ "type category define",
+ "Define a new category as a source of formatters.",
+ NULL),
+ m_options(interpreter)
+ {
+ CommandArgumentEntry type_arg;
+ CommandArgumentData type_style_arg;
+
+ type_style_arg.arg_type = eArgTypeName;
+ type_style_arg.arg_repetition = eArgRepeatPlus;
+
+ type_arg.push_back (type_style_arg);
+
+ m_arguments.push_back (type_arg);
+
+ }
+
+ ~CommandObjectTypeCategoryDefine ()
+ {
+ }
+
+protected:
+ bool
+ DoExecute (Args& command, CommandReturnObject &result)
+ {
+ const size_t argc = command.GetArgumentCount();
+
+ if (argc < 1)
+ {
+ result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
+ result.SetStatus(eReturnStatusFailed);
+ return false;
+ }
+
+ for (size_t i = 0; i < argc; i++)
+ {
+ const char* cateName = command.GetArgumentAtIndex(i);
+ TypeCategoryImplSP category_sp;
+ if (DataVisualization::Categories::GetCategory(ConstString(cateName), category_sp) && category_sp)
+ {
+ category_sp->AddLanguage(m_options.m_cate_language.GetCurrentValue());
+ if (m_options.m_define_enabled.GetCurrentValue())
+ DataVisualization::Categories::Enable(category_sp, TypeCategoryMap::Default);
+ }
+ }
+
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ return result.Succeeded();
+ }
+
+};
+
+OptionDefinition
+CommandObjectTypeCategoryDefine::CommandOptions::g_option_table[] =
+{
+ { LLDB_OPT_SET_ALL, false, "enabled", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "If specified, this category will be created enabled."},
+ { LLDB_OPT_SET_ALL, false, "language", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLanguage, "Specify the language that this category is supported for."},
+ { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
+};
+
+//-------------------------------------------------------------------------
// CommandObjectTypeCategoryEnable
//-------------------------------------------------------------------------
@@ -2865,9 +3002,7 @@ private:
const char* cate_name = cate->GetName();
if (regex == NULL || strcmp(cate_name, regex->GetText()) == 0 || regex->Execute(cate_name))
- result->GetOutputStream().Printf("Category %s is%s enabled\n",
- cate_name,
- (cate->IsEnabled() ? "" : " not"));
+ result->GetOutputStream().Printf("Category: %s\n", cate->GetDescription().c_str());
return true;
}
public:
@@ -3081,9 +3216,7 @@ private:
if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
return true;
- result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
- cate_name,
- (cate->IsEnabled() ? "enabled" : "disabled"));
+ result->GetOutputStream().Printf("-----------------------\nCategory: %s\n-----------------------\n", cate->GetDescription().c_str());
cate->GetTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
@@ -3296,9 +3429,7 @@ private:
if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
return true;
- result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
- cate_name,
- (cate->IsEnabled() ? "enabled" : "disabled"));
+ result->GetOutputStream().Printf("-----------------------\nCategory: %s\n-----------------------\n", cate->GetDescription().c_str());
cate->GetTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
@@ -4117,10 +4248,10 @@ CommandObjectTypeSynthAdd::CommandOption
{
{ LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
{ LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
- { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-tNULL, ype objects."},
+ { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
{ LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
{ LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children."},
- { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument,NULL, NULL, 0, eArgTypeNone, "Type Python code to generate a class that NULL, provides synthetic children."},
+ { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type Python code to generate a class that provides synthetic children."},
{ LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
};
@@ -4591,6 +4722,7 @@ public:
"A set of commands for operating on categories",
"type category [<sub-command-options>] ")
{
+ LoadSubCommand ("define", CommandObjectSP (new CommandObjectTypeCategoryDefine (interpreter)));
LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTypeCategoryEnable (interpreter)));
LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTypeCategoryDisable (interpreter)));
LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeCategoryDelete (interpreter)));
Modified: lldb/trunk/source/DataFormatters/DataVisualization.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/DataVisualization.cpp?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/DataVisualization.cpp (original)
+++ lldb/trunk/source/DataFormatters/DataVisualization.cpp Wed Sep 16 19:14:50 2015
@@ -164,7 +164,7 @@ DataVisualization::Categories::Enable (c
{
if (GetFormatManager().GetCategory(category)->IsEnabled())
GetFormatManager().DisableCategory(category);
- GetFormatManager().EnableCategory(category, pos);
+ GetFormatManager().EnableCategory(category, pos, std::initializer_list<lldb::LanguageType>());
}
void
Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Wed Sep 16 19:14:50 2015
@@ -1036,8 +1036,8 @@ FormatManager::FormatManager() :
LoadSystemFormatters();
LoadVectorFormatters();
- EnableCategory(m_vectortypes_category_name,TypeCategoryMap::Last);
- EnableCategory(m_system_category_name,TypeCategoryMap::Last);
+ EnableCategory(m_vectortypes_category_name,TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus);
+ EnableCategory(m_system_category_name,TypeCategoryMap::Last, lldb::eLanguageTypeObjC_plus_plus);
}
void
Modified: lldb/trunk/source/DataFormatters/FormattersHelpers.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormattersHelpers.cpp?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormattersHelpers.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormattersHelpers.cpp Wed Sep 16 19:14:50 2015
@@ -40,6 +40,17 @@ lldb_private::formatters::AddFormat (Typ
category_sp->GetTypeFormatsContainer()->Add(type_name, format_sp);
}
+void
+lldb_private::formatters::AddSummary(TypeCategoryImpl::SharedPointer category_sp,
+ TypeSummaryImplSP summary_sp,
+ ConstString type_name,
+ bool regex)
+{
+ if (regex)
+ category_sp->GetRegexTypeSummariesContainer()->Add(RegularExpressionSP(new RegularExpression(type_name.AsCString())),summary_sp);
+ else
+ category_sp->GetTypeSummariesContainer()->Add(type_name, summary_sp);
+}
void
lldb_private::formatters::AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
Modified: lldb/trunk/source/DataFormatters/TypeCategory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeCategory.cpp?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/TypeCategory.cpp (original)
+++ lldb/trunk/source/DataFormatters/TypeCategory.cpp Wed Sep 16 19:14:50 2015
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lldb/DataFormatters/TypeCategory.h"
+#include "lldb/Target/Language.h"
// C Includes
// C++ Includes
@@ -18,7 +19,8 @@ using namespace lldb;
using namespace lldb_private;
TypeCategoryImpl::TypeCategoryImpl(IFormatChangeListener* clist,
- ConstString name) :
+ ConstString name,
+ std::initializer_list<lldb::LanguageType> langs) :
m_format_cont("format","regex-format",clist),
m_summary_cont("summary","regex-summary",clist),
m_filter_cont("filter","regex-filter",clist),
@@ -29,8 +31,118 @@ m_validator_cont("validator","regex-vali
m_enabled(false),
m_change_listener(clist),
m_mutex(Mutex::eMutexTypeRecursive),
-m_name(name)
-{}
+m_name(name),
+m_languages()
+{
+ for (const lldb::LanguageType lang : langs)
+ AddLanguage(lang);
+}
+
+static bool
+IsApplicable(lldb::LanguageType category_lang,
+ lldb::LanguageType valobj_lang)
+{
+ switch (category_lang)
+ {
+ // these are not languages that LLDB would ordinarily deal with
+ // only allow an exact equality here, since we really don't know
+ // any better
+ case eLanguageTypeAda83:
+ case eLanguageTypeCobol74:
+ case eLanguageTypeCobol85:
+ case eLanguageTypeFortran77:
+ case eLanguageTypeFortran90:
+ case eLanguageTypePascal83:
+ case eLanguageTypeModula2:
+ case eLanguageTypeJava:
+ case eLanguageTypeAda95:
+ case eLanguageTypeFortran95:
+ case eLanguageTypePLI:
+ case eLanguageTypeUPC:
+ case eLanguageTypeD:
+ case eLanguageTypePython:
+ return category_lang == valobj_lang;
+
+ // the C family, we consider it as one
+ case eLanguageTypeC89:
+ case eLanguageTypeC:
+ case eLanguageTypeC99:
+ return valobj_lang == eLanguageTypeC89 ||
+ valobj_lang == eLanguageTypeC ||
+ valobj_lang == eLanguageTypeC99;
+
+ // ObjC knows about C and itself
+ case eLanguageTypeObjC:
+ return valobj_lang == eLanguageTypeC89 ||
+ valobj_lang == eLanguageTypeC ||
+ valobj_lang == eLanguageTypeC99 ||
+ valobj_lang == eLanguageTypeObjC;
+
+ // C++ knows about C and C++
+ case eLanguageTypeC_plus_plus:
+ return valobj_lang == eLanguageTypeC89 ||
+ valobj_lang == eLanguageTypeC ||
+ valobj_lang == eLanguageTypeC99 ||
+ valobj_lang == eLanguageTypeC_plus_plus;
+
+ // ObjC++ knows about C,C++,ObjC and ObjC++
+ case eLanguageTypeObjC_plus_plus:
+ return valobj_lang == eLanguageTypeC89 ||
+ valobj_lang == eLanguageTypeC ||
+ valobj_lang == eLanguageTypeC99 ||
+ valobj_lang == eLanguageTypeC_plus_plus ||
+ valobj_lang == eLanguageTypeObjC;
+
+ default:
+ case eLanguageTypeUnknown:
+ return true;
+ }
+}
+
+bool
+TypeCategoryImpl::IsApplicable (ValueObject& valobj)
+{
+ lldb::LanguageType valobj_lang = valobj.GetObjectRuntimeLanguage();
+ for (size_t idx = 0;
+ idx < GetNumLanguages();
+ idx++)
+ {
+ const lldb::LanguageType category_lang = GetLanguageAtIndex(idx);
+ if (::IsApplicable(category_lang,valobj_lang))
+ return true;
+ }
+ return false;
+}
+
+size_t
+TypeCategoryImpl::GetNumLanguages ()
+{
+ if (m_languages.empty())
+ return 1;
+ return m_languages.size();
+}
+
+lldb::LanguageType
+TypeCategoryImpl::GetLanguageAtIndex (size_t idx)
+{
+ if (m_languages.empty())
+ return lldb::eLanguageTypeUnknown;
+ return m_languages[idx];
+}
+
+void
+TypeCategoryImpl::AddLanguage (lldb::LanguageType lang)
+{
+ m_languages.push_back(lang);
+}
+
+bool
+TypeCategoryImpl::HasLanguage (lldb::LanguageType lang)
+{
+ const auto iter = std::find(m_languages.begin(), m_languages.end(), lang),
+ end = m_languages.end();
+ return (iter != end);
+}
bool
TypeCategoryImpl::Get (ValueObject& valobj,
@@ -38,7 +150,7 @@ TypeCategoryImpl::Get (ValueObject& valo
lldb::TypeFormatImplSP& entry,
uint32_t* reason)
{
- if (!IsEnabled())
+ if (!IsEnabled() || !IsApplicable(valobj))
return false;
if (GetTypeFormatsContainer()->Get(candidates, entry, reason))
return true;
@@ -54,7 +166,7 @@ TypeCategoryImpl::Get (ValueObject& valo
lldb::TypeSummaryImplSP& entry,
uint32_t* reason)
{
- if (!IsEnabled())
+ if (!IsEnabled() || !IsApplicable(valobj))
return false;
if (GetTypeSummariesContainer()->Get(candidates, entry, reason))
return true;
@@ -70,7 +182,7 @@ TypeCategoryImpl::Get (ValueObject& valo
lldb::SyntheticChildrenSP& entry,
uint32_t* reason)
{
- if (!IsEnabled())
+ if (!IsEnabled() || !IsApplicable(valobj))
return false;
TypeFilterImpl::SharedPointer filter_sp;
uint32_t reason_filter = 0;
@@ -567,3 +679,30 @@ TypeCategoryImpl::Enable (bool value, ui
if (m_change_listener)
m_change_listener->Changed();
}
+
+std::string
+TypeCategoryImpl::GetDescription ()
+{
+ StreamString stream;
+ stream.Printf("%s (%s",
+ GetName(),
+ (IsEnabled() ? "enabled" : "disabled"));
+ StreamString lang_stream;
+ lang_stream.Printf(", applicable for language(s): ");
+ bool print_lang = false;
+ for (size_t idx = 0;
+ idx < GetNumLanguages();
+ idx++)
+ {
+ const lldb::LanguageType lang = GetLanguageAtIndex(idx);
+ if (lang != lldb::eLanguageTypeUnknown)
+ print_lang = true;
+ lang_stream.Printf("%s%s",
+ Language::GetNameForLanguageType(lang),
+ idx+1<GetNumLanguages() ? ", " : "");
+ }
+ if (print_lang)
+ stream.Printf("%s",lang_stream.GetData());
+ stream.PutChar(')');
+ return stream.GetData();
+}
Modified: lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp (original)
+++ lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp Wed Sep 16 19:14:50 2015
@@ -247,7 +247,7 @@ TypeCategoryMap::GetFormat (ValueObject&
lldb::TypeCategoryImplSP category_sp = *begin;
lldb::TypeFormatImplSP current_format;
if (log)
- log->Printf("\n[TypeCategoryMap::GetFormat] Trying to use category %s", category_sp->GetName());
+ log->Printf("[TypeCategoryMap::GetFormat] Trying to use category %s", category_sp->GetName());
if (!category_sp->Get(valobj, matches, current_format, &reason_why))
continue;
return current_format;
@@ -287,7 +287,7 @@ TypeCategoryMap::GetSummaryFormat (Value
lldb::TypeCategoryImplSP category_sp = *begin;
lldb::TypeSummaryImplSP current_format;
if (log)
- log->Printf("\n[CategoryMap::GetSummaryFormat] Trying to use category %s", category_sp->GetName());
+ log->Printf("[CategoryMap::GetSummaryFormat] Trying to use category %s", category_sp->GetName());
if (!category_sp->Get(valobj, matches, current_format, &reason_why))
continue;
return current_format;
@@ -329,7 +329,7 @@ TypeCategoryMap::GetSyntheticChildren (V
lldb::TypeCategoryImplSP category_sp = *begin;
lldb::SyntheticChildrenSP current_format;
if (log)
- log->Printf("\n[CategoryMap::GetSyntheticChildren] Trying to use category %s", category_sp->GetName());
+ log->Printf("[CategoryMap::GetSyntheticChildren] Trying to use category %s", category_sp->GetName());
if (!category_sp->Get(valobj, matches, current_format, &reason_why))
continue;
return current_format;
@@ -356,7 +356,7 @@ TypeCategoryMap::GetValidator (ValueObje
{
for (auto match : matches)
{
- log->Printf("[CategoryMap::GetSummaryFormat] candidate match = %s %s %s %s reason = %" PRIu32,
+ log->Printf("[CategoryMap::GetValidator] candidate match = %s %s %s %s reason = %" PRIu32,
match.GetTypeName().GetCString(),
match.DidStripPointer() ? "strip-pointers" : "no-strip-pointers",
match.DidStripReference() ? "strip-reference" : "no-strip-reference",
@@ -370,7 +370,7 @@ TypeCategoryMap::GetValidator (ValueObje
lldb::TypeCategoryImplSP category_sp = *begin;
lldb::TypeValidatorImplSP current_format;
if (log)
- log->Printf("\n[CategoryMap::GetValidator] Trying to use category %s", category_sp->GetName());
+ log->Printf("[CategoryMap::GetValidator] Trying to use category %s", category_sp->GetName());
if (!category_sp->Get(valobj, matches, current_format, &reason_why))
continue;
return current_format;
Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py Wed Sep 16 19:14:50 2015
@@ -159,8 +159,6 @@ class CategoriesDataFormatterTestCase(Te
self.runCmd("type summary add Rectangle -w Category1 --summary-string \"Category1\"")
self.runCmd("type summary add Rectangle -w Category2 --summary-string \"Category2\"")
- self.runCmd("type category list")
-
self.runCmd("type category enable Category2")
self.runCmd("type category enable Category1")
@@ -302,7 +300,7 @@ class CategoriesDataFormatterTestCase(Te
# check that list commands work
self.expect("type category list",
- substrs = ['RectangleStarCategory is enabled'])
+ substrs = ['RectangleStarCategory (enabled)'])
self.expect("type summary list",
substrs = ['ARectangleStar'])
@@ -312,7 +310,7 @@ class CategoriesDataFormatterTestCase(Te
# check that list commands work
self.expect("type category list",
- substrs = ['CircleCategory is not enabled'])
+ substrs = ['CircleCategory (disabled'])
self.expect("frame variable c1 r_ptr",
substrs = ['AShape',
Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py?rev=247872&r1=247871&r2=247872&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-disabling/TestDataFormatterDisabling.py Wed Sep 16 19:14:50 2015
@@ -55,7 +55,7 @@ class DataFormatterDisablingTestCase(Tes
#self.runCmd('type category enable system VectorTypes libcxx gnu-libstdc++ CoreGraphics CoreServices AppKit CoreFoundation objc default', check=False)
- self.expect('type category list', substrs = ['system is enabled',])
+ self.expect('type category list', substrs = ['system','enabled',])
self.expect("frame variable numbers",
substrs = ['[0] = 1', '[3] = 1234'])
@@ -70,23 +70,23 @@ class DataFormatterDisablingTestCase(Tes
self.expect('frame variable string1', matching=False, substrs = ['hello world'])
- self.expect('type category list', substrs = ['system is not enabled',])
+ self.expect('type category list', substrs = ['system','disabled',])
# now enable and check that we are back to normal
self.runCmd("type category enable *")
- self.expect('type category list', substrs = ['system is enabled'])
+ self.expect('type category list', substrs = ['system','enabled'])
self.expect("frame variable numbers",
substrs = ['[0] = 1', '[3] = 1234'])
self.expect('frame variable string1', substrs = ['hello world'])
- self.expect('type category list', substrs = ['system is enabled'])
+ self.expect('type category list', substrs = ['system','enabled'])
# last check - our cleanup will re-enable everything
self.runCmd('type category disable *')
- self.expect('type category list', substrs = ['system is not enabled'])
+ self.expect('type category list', substrs = ['system','disabled'])
if __name__ == '__main__':
More information about the lldb-commits
mailing list