summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2015-11-14 05:44:23 +0000
committerEnrico Granata <egranata@apple.com>2015-11-14 05:44:23 +0000
commitb56d01033e524cbf3e6281282cf21950499c3d7f (patch)
tree7e0623d4f97252d07a8898ec094485fa96abf1c6 /lldb/source
parentbd9fc28444c256bd1ed1e29a59bd938160c60674 (diff)
downloadbcm5719-llvm-b56d01033e524cbf3e6281282cf21950499c3d7f.tar.gz
bcm5719-llvm-b56d01033e524cbf3e6281282cf21950499c3d7f.zip
The existing logic to loop over formatters is very pre-C++11, using void* batons, and function pointers, and raw memory allocations instead of safer more modern constructs
This is a first pass at a cleanup of that code, modernizing the "type X clear" commands, and providing the basic infrastructure I plan to use all over More cleanup will come over the next few days llvm-svn: 253125
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Commands/CommandObjectType.cpp74
-rw-r--r--lldb/source/DataFormatters/DataVisualization.cpp6
-rw-r--r--lldb/source/DataFormatters/FormatManager.cpp15
-rw-r--r--lldb/source/DataFormatters/TypeCategoryMap.cpp33
4 files changed, 80 insertions, 48 deletions
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 022b326120e..6dba43d456e 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -1156,14 +1156,6 @@ private:
return &m_options;
}
- static bool
- PerCategoryCallback(void* param,
- const lldb::TypeCategoryImplSP& cate)
- {
- cate->Clear(eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
- return true;
- }
-
public:
CommandObjectTypeFormatClear (CommandInterpreter &interpreter) :
CommandObjectParsed (interpreter,
@@ -1183,8 +1175,12 @@ protected:
DoExecute (Args& command, CommandReturnObject &result) override
{
if (m_options.m_delete_all)
- DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
-
+ {
+ DataVisualization::Categories::ForEach( [] (const TypeCategoryImplSP& category_sp) -> bool {
+ category_sp->Clear(eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
+ return true;
+ });
+ }
else
{
lldb::TypeCategoryImplSP category;
@@ -2188,16 +2184,6 @@ private:
return &m_options;
}
- static bool
- PerCategoryCallback(void* param,
- const lldb::TypeCategoryImplSP& cate)
- {
- cate->GetTypeSummariesContainer()->Clear();
- cate->GetRegexTypeSummariesContainer()->Clear();
- return true;
-
- }
-
public:
CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) :
CommandObjectParsed (interpreter,
@@ -2218,8 +2204,12 @@ protected:
{
if (m_options.m_delete_all)
- DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
-
+ {
+ DataVisualization::Categories::ForEach( [] (const TypeCategoryImplSP& category_sp) -> bool {
+ category_sp->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
+ return true;
+ });
+ }
else
{
lldb::TypeCategoryImplSP category;
@@ -3931,15 +3921,6 @@ private:
return &m_options;
}
- static bool
- PerCategoryCallback(void* param,
- const lldb::TypeCategoryImplSP& cate)
- {
- cate->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
- return true;
-
- }
-
public:
CommandObjectTypeFilterClear (CommandInterpreter &interpreter) :
CommandObjectParsed (interpreter,
@@ -3960,8 +3941,12 @@ protected:
{
if (m_options.m_delete_all)
- DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
-
+ {
+ DataVisualization::Categories::ForEach( [] (const TypeCategoryImplSP& category_sp) -> bool {
+ category_sp->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
+ return true;
+ });
+ }
else
{
lldb::TypeCategoryImplSP category;
@@ -3973,8 +3958,7 @@ protected:
}
else
DataVisualization::Categories::GetCategory(ConstString(NULL), category);
- category->GetTypeFiltersContainer()->Clear();
- category->GetRegexTypeFiltersContainer()->Clear();
+ category->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
}
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -4059,15 +4043,6 @@ private:
return &m_options;
}
- static bool
- PerCategoryCallback(void* param,
- const lldb::TypeCategoryImplSP& cate)
- {
- cate->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
- return true;
-
- }
-
public:
CommandObjectTypeSynthClear (CommandInterpreter &interpreter) :
CommandObjectParsed (interpreter,
@@ -4088,8 +4063,12 @@ protected:
{
if (m_options.m_delete_all)
- DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
-
+ {
+ DataVisualization::Categories::ForEach( [] (const TypeCategoryImplSP& category_sp) -> bool {
+ category_sp->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
+ return true;
+ });
+ }
else
{
lldb::TypeCategoryImplSP category;
@@ -4101,8 +4080,7 @@ protected:
}
else
DataVisualization::Categories::GetCategory(ConstString(NULL), category);
- category->GetTypeSyntheticsContainer()->Clear();
- category->GetRegexTypeSyntheticsContainer()->Clear();
+ category->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
}
result.SetStatus(eReturnStatusSuccessFinishResult);
diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp
index 440091d1ed6..581ef3f851a 100644
--- a/lldb/source/DataFormatters/DataVisualization.cpp
+++ b/lldb/source/DataFormatters/DataVisualization.cpp
@@ -231,6 +231,12 @@ DataVisualization::Categories::LoopThrough (FormatManager::CategoryCallback call
GetFormatManager().LoopThroughCategories(callback, callback_baton);
}
+void
+DataVisualization::Categories::ForEach (TypeCategoryMap::ForEachCallback callback)
+{
+ GetFormatManager().ForEachCategory(callback);
+}
+
uint32_t
DataVisualization::Categories::GetCount ()
{
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index 2362ba52526..3237f73f64e 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -500,6 +500,21 @@ FormatManager::LoopThroughCategories (CategoryCallback callback, void* param)
}
}
+void
+FormatManager::ForEachCategory(TypeCategoryMap::ForEachCallback callback)
+{
+ m_categories_map.ForEach(callback);
+ Mutex::Locker locker(m_language_categories_mutex);
+ for (const auto& entry : m_language_categories_map)
+ {
+ if (auto category_sp = entry.second->GetCategory())
+ {
+ if (!callback(category_sp))
+ break;
+ }
+ }
+}
+
lldb::TypeCategoryImplSP
FormatManager::GetCategory (const ConstString& category_name,
bool can_create)
diff --git a/lldb/source/DataFormatters/TypeCategoryMap.cpp b/lldb/source/DataFormatters/TypeCategoryMap.cpp
index aafcfa9536c..19164a3c003 100644
--- a/lldb/source/DataFormatters/TypeCategoryMap.cpp
+++ b/lldb/source/DataFormatters/TypeCategoryMap.cpp
@@ -405,6 +405,39 @@ TypeCategoryMap::LoopThrough(CallbackType callback, void* param)
}
}
+void
+TypeCategoryMap::ForEach(ForEachCallback callback)
+{
+ if (callback)
+ {
+ Mutex::Locker locker(m_map_mutex);
+
+ // loop through enabled categories in respective order
+ {
+ ActiveCategoriesIterator begin, end = m_active_categories.end();
+ for (begin = m_active_categories.begin(); begin != end; begin++)
+ {
+ lldb::TypeCategoryImplSP category = *begin;
+ if (!callback(category))
+ break;
+ }
+ }
+
+ // loop through disabled categories in just any order
+ {
+ MapIterator pos, end = m_map.end();
+ for (pos = m_map.begin(); pos != end; pos++)
+ {
+ if (pos->second->IsEnabled())
+ continue;
+ KeyType type = pos->first;
+ if (!callback(pos->second))
+ break;
+ }
+ }
+ }
+}
+
TypeCategoryImplSP
TypeCategoryMap::GetAtIndex (uint32_t index)
{
OpenPOWER on IntegriCloud