[Lldb-commits] [lldb] r253423 - Cleanup the type X list commands to use the new ForEach goodness

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 18 11:45:52 PST 2015


Sending        include/lldb/DataFormatters/DataVisualization.h
Sending        include/lldb/DataFormatters/FormatManager.h
Sending        include/lldb/DataFormatters/FormattersContainer.h
Sending        include/lldb/DataFormatters/TypeCategory.h
Sending        include/lldb/DataFormatters/TypeCategoryMap.h
Sending        include/lldb/DataFormatters/TypeFormat.h
Sending        include/lldb/DataFormatters/TypeSummary.h
Sending        include/lldb/DataFormatters/TypeSynthetic.h
Sending        include/lldb/DataFormatters/TypeValidator.h
Sending        source/API/SBTypeCategory.cpp
Sending        source/Commands/CommandObjectType.cpp
Sending        source/DataFormatters/DataVisualization.cpp
Sending        source/DataFormatters/FormatManager.cpp
Sending        source/DataFormatters/TypeCategoryMap.cpp
Transmitting file data ..............
Committed revision 253493.

Compiles just fine for me on clang with your change!

Thanks for helping out!

> On Nov 18, 2015, at 11:35 AM, Zachary Turner <zturner at google.com> wrote:
> 
> +list in case anyone else is curious
> 
> On Wed, Nov 18, 2015 at 11:34 AM Zachary Turner <zturner at google.com <mailto:zturner at google.com>> wrote:
> Can you roll your head back to r253448, apply this patch on top and see if it works?  If so feel free to resubmit your patch and then these changes on top.
> 
> Sadly this is in fact a bug in the compiler's support for Expression SFINAE.  The most reasonable workaround we could come up with is to not use the name Set() for both the Regex and the Exact match case.  So I've renamed them to SetExact() and SetWithRegex().  This allows the enable-if's to work correctly.
> 
> 
> 
> 
> On Wed, Nov 18, 2015 at 11:07 AM Enrico Granata <egranata at apple.com <mailto:egranata at apple.com>> wrote:
> Much appreciated, thanks :-)
> 
>> On Nov 18, 2015, at 10:40 AM, Zachary Turner <zturner at google.com <mailto:zturner at google.com>> wrote:
>> 
>> I'll take a look
>> 
>> On Wed, Nov 18, 2015 at 10:21 AM Enrico Granata <egranata at apple.com <mailto:egranata at apple.com>> wrote:
>> This smells like compiler bug:
>> trying to match the argument list '(bool (__cdecl *)(lldb_private::ConstString,const lldb_private::TypeFormatImpl::SharedPointer &))'
>> it fails saying this could be a candidate:
>>         c:\lldbSlave\lldb-win7-android\llvm\tools\lldb\include\lldb/DataFormatters/TypeCategory.h(122): or       'lldb_private::TypeCategoryImpl::ForEachCallbacks<FormatterType> &lldb_private::TypeCategoryImpl::ForEachCallbacks<FormatterType>::Set<lldb_private::TypeFormatImpl>(std::function<bool (KeyType,const std::shared_ptr<lldb_private::TypeFormatImpl> &)>)'
>>         with
>>         [
>>             FormatterType=lldb_private::TypeFormatImpl
>> ,            KeyType=lldb_private::ConstString
>>         ]
>> (hint: it is)
>> 
>> or else this one is also a candidate:
>>         c:\lldbSlave\lldb-win7-android\llvm\tools\lldb\include\lldb/DataFormatters/TypeCategory.h(129): could be 'lldb_private::TypeCategoryImpl::ForEachCallbacks<FormatterType> &lldb_private::TypeCategoryImpl::ForEachCallbacks<FormatterType>::Set<lldb_private::TypeFormatImpl>(std::function<bool (KeyType,const std::shared_ptr<lldb_private::TypeFormatImpl> &)>)'
>>         with
>>         [
>>             FormatterType=lldb_private::TypeFormatImpl
>> ,            KeyType=lldb::RegularExpressionSP
>>         ]
>> which seems highly unlikely given that there is nothing in common between ConstString and RegularExpressionSP
>> 
>> With that said, since I do want to get this code in, is it possible to get someone on the Windows side to help me clean up in such a way that it works on MSVC?
>> I would do the dance myself, but I don’t have a Windows install handy
>> 
>>> On Nov 18, 2015, at 4:14 AM, Tamas Berghammer <tberghammer at google.com <mailto:tberghammer at google.com>> wrote:
>>> 
>>> Hi Enrico,
>>> 
>>> I reverted this CL and the follow-up one (r253424) as they are breaking the Windows build. For the error message please see http://lab.llvm.org:8011/builders/lldb-windows7-android/builds/2781 <http://lab.llvm.org:8011/builders/lldb-windows7-android/builds/2781>
>>> 
>>> Tamas
>>> 
>>> On Wed, Nov 18, 2015 at 1:40 AM Enrico Granata via lldb-commits <lldb-commits at lists.llvm.org <mailto:lldb-commits at lists.llvm.org>> wrote:
>>> Author: enrico
>>> Date: Tue Nov 17 19:37:49 2015
>>> New Revision: 253423
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=253423&view=rev <http://llvm.org/viewvc/llvm-project?rev=253423&view=rev>
>>> Log:
>>> Cleanup the type X list commands to use the new ForEach goodness
>>> 
>>> 
>>> Modified:
>>>     lldb/trunk/include/lldb/DataFormatters/DataVisualization.h
>>>     lldb/trunk/include/lldb/DataFormatters/FormatManager.h
>>>     lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h
>>>     lldb/trunk/include/lldb/DataFormatters/TypeCategory.h
>>>     lldb/trunk/include/lldb/DataFormatters/TypeCategoryMap.h
>>>     lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h
>>>     lldb/trunk/source/API/SBTypeCategory.cpp
>>>     lldb/trunk/source/Commands/CommandObjectType.cpp
>>>     lldb/trunk/source/DataFormatters/DataVisualization.cpp
>>>     lldb/trunk/source/DataFormatters/FormatManager.cpp
>>>     lldb/trunk/source/DataFormatters/TypeCategoryMap.cpp
>>> 
>>> Modified: lldb/trunk/include/lldb/DataFormatters/DataVisualization.h
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/DataVisualization.h?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/DataVisualization.h?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/include/lldb/DataFormatters/DataVisualization.h (original)
>>> +++ lldb/trunk/include/lldb/DataFormatters/DataVisualization.h Tue Nov 17 19:37:49 2015
>>> @@ -101,7 +101,7 @@ public:
>>>          Clear ();
>>> 
>>>          static void
>>> -        LoopThrough (TypeSummaryImpl::SummaryCallback callback, void* callback_baton);
>>> +        ForEach (std::function<bool(ConstString, const lldb::TypeSummaryImplSP&)> callback);
>>> 
>>>          static uint32_t
>>>          GetCount ();
>>> @@ -158,9 +158,6 @@ public:
>>>          DisableStar ();
>>> 
>>>          static void
>>> -        LoopThrough (FormatManager::CategoryCallback callback, void* callback_baton);
>>> -
>>> -        static void
>>>          ForEach (TypeCategoryMap::ForEachCallback callback);
>>> 
>>>          static uint32_t
>>> 
>>> Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/include/lldb/DataFormatters/FormatManager.h (original)
>>> +++ lldb/trunk/include/lldb/DataFormatters/FormatManager.h Tue Nov 17 19:37:49 2015
>>> @@ -140,9 +140,6 @@ public:
>>>      }
>>> 
>>>      void
>>> -    LoopThroughCategories (CategoryCallback callback, void* param);
>>> -
>>> -    void
>>>      ForEachCategory (TypeCategoryMap::ForEachCallback callback);
>>> 
>>>      lldb::TypeCategoryImplSP
>>> 
>>> Modified: lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h (original)
>>> +++ lldb/trunk/include/lldb/DataFormatters/FormattersContainer.h Tue Nov 17 19:37:49 2015
>>> @@ -141,22 +141,6 @@ public:
>>>      }
>>> 
>>>      void
>>> -    LoopThrough (CallbackType callback, void* param)
>>> -    {
>>> -        if (callback)
>>> -        {
>>> -            Mutex::Locker locker(m_map_mutex);
>>> -            MapIterator pos, end = m_map.end();
>>> -            for (pos = m_map.begin(); pos != end; pos++)
>>> -            {
>>> -                KeyType type = pos->first;
>>> -                if (!callback(param, type, pos->second))
>>> -                    break;
>>> -            }
>>> -        }
>>> -    }
>>> -
>>> -    void
>>>      ForEach (ForEachCallback callback)
>>>      {
>>>          if (callback)
>>> @@ -316,12 +300,6 @@ public:
>>>      }
>>> 
>>>      void
>>> -    LoopThrough (CallbackType callback, void* param)
>>> -    {
>>> -        m_format_map.LoopThrough(callback,param);
>>> -    }
>>> -
>>> -    void
>>>      ForEach (ForEachCallback callback)
>>>      {
>>>          m_format_map.ForEach(callback);
>>> 
>>> Modified: lldb/trunk/include/lldb/DataFormatters/TypeCategory.h
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeCategory.h?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeCategory.h?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/include/lldb/DataFormatters/TypeCategory.h (original)
>>> +++ lldb/trunk/include/lldb/DataFormatters/TypeCategory.h Tue Nov 17 19:37:49 2015
>>> @@ -67,14 +67,6 @@ namespace lldb_private {
>>>              return m_regex_sp;
>>>          }
>>> 
>>> -        void
>>> -        LoopThrough (typename ExactMatchContainer::CallbackType exact_callback,
>>> -                     typename RegexMatchContainer::CallbackType regex_callback)
>>> -        {
>>> -            GetExactMatch()->LoopThrough(exact_callback);
>>> -            GetRegexMatch()->LoopThrough(regex_callback);
>>> -        }
>>> -
>>>          uint32_t
>>>          GetCount ()
>>>          {
>>> @@ -95,7 +87,7 @@ namespace lldb_private {
>>>          typedef FormatterContainerPair<TypeValidatorImpl> ValidatorContainer;
>>> 
>>>  #ifndef LLDB_DISABLE_PYTHON
>>> -        typedef FormatterContainerPair<ScriptedSyntheticChildren> SynthContainer;
>>> +        typedef FormatterContainerPair<SyntheticChildren> SynthContainer;
>>>  #endif // LLDB_DISABLE_PYTHON
>>> 
>>>      public:
>>> @@ -118,74 +110,84 @@ namespace lldb_private {
>>>          typedef ValidatorContainer::ExactMatchContainerSP ValidatorContainerSP;
>>>          typedef ValidatorContainer::RegexMatchContainerSP RegexValidatorContainerSP;
>>> 
>>> -        class ForEach
>>> +        template <typename T>
>>> +        class ForEachCallbacks
>>>          {
>>>          public:
>>> -            ForEach () = default;
>>> -            ~ForEach () = default;
>>> +            ForEachCallbacks () = default;
>>> +            ~ForEachCallbacks () = default;
>>> 
>>> -            ForEach&
>>> -            SetFormatExactCallback (FormatContainer::ExactMatchForEachCallback callback)
>>> +            template<typename U = TypeFormatImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (FormatContainer::ExactMatchForEachCallback callback)
>>>              {
>>>                  m_format_exact = callback;
>>>                  return *this;
>>>              }
>>> -            ForEach&
>>> -            SetFormatRegexCallback (FormatContainer::RegexMatchForEachCallback callback)
>>> +            template<typename U = TypeFormatImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (FormatContainer::RegexMatchForEachCallback callback)
>>>              {
>>>                  m_format_regex = callback;
>>>                  return *this;
>>>              }
>>> 
>>> -            ForEach&
>>> -            SetSummaryExactCallback (SummaryContainer::ExactMatchForEachCallback callback)
>>> +            template<typename U = TypeSummaryImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (SummaryContainer::ExactMatchForEachCallback callback)
>>>              {
>>>                  m_summary_exact = callback;
>>>                  return *this;
>>>              }
>>> -            ForEach&
>>> -            SetSummaryRegexCallback (SummaryContainer::RegexMatchForEachCallback callback)
>>> +            template<typename U = TypeSummaryImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (SummaryContainer::RegexMatchForEachCallback callback)
>>>              {
>>>                  m_summary_regex = callback;
>>>                  return *this;
>>>              }
>>> 
>>> -            ForEach&
>>> -            SetFilterExactCallback (FilterContainer::ExactMatchForEachCallback callback)
>>> +            template<typename U = TypeFilterImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (FilterContainer::ExactMatchForEachCallback callback)
>>>              {
>>>                  m_filter_exact = callback;
>>>                  return *this;
>>>              }
>>> -            ForEach&
>>> -            SetFilterRegexCallback (FilterContainer::RegexMatchForEachCallback callback)
>>> +            template<typename U = TypeFilterImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (FilterContainer::RegexMatchForEachCallback callback)
>>>              {
>>>                  m_filter_regex = callback;
>>>                  return *this;
>>>              }
>>> 
>>>  #ifndef LLDB_DISABLE_PYTHON
>>> -            ForEach&
>>> -            SetSynthExactCallback (SynthContainer::ExactMatchForEachCallback callback)
>>> +            template<typename U = SyntheticChildren>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (SynthContainer::ExactMatchForEachCallback callback)
>>>              {
>>>                  m_synth_exact = callback;
>>>                  return *this;
>>>              }
>>> -            ForEach&
>>> -            SetSynthRegexCallback (SynthContainer::RegexMatchForEachCallback callback)
>>> +            template<typename U = SyntheticChildren>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (SynthContainer::RegexMatchForEachCallback callback)
>>>              {
>>>                  m_synth_regex = callback;
>>>                  return *this;
>>>              }
>>>  #endif // LLDB_DISABLE_PYTHON
>>> -
>>> -            ForEach&
>>> -            SetValidatorExactCallback (ValidatorContainer::ExactMatchForEachCallback callback)
>>> +            template<typename U = TypeValidatorImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (ValidatorContainer::ExactMatchForEachCallback callback)
>>>              {
>>>                  m_validator_exact = callback;
>>>                  return *this;
>>>              }
>>> -            ForEach&
>>> -            SetValidatorRegexCallback (ValidatorContainer::RegexMatchForEachCallback callback)
>>> +            template<typename U = TypeValidatorImpl>
>>> +            typename std::enable_if<std::is_same<U,T>::value, ForEachCallbacks&>::type
>>> +            Set (ValidatorContainer::RegexMatchForEachCallback callback)
>>>              {
>>>                  m_validator_regex = callback;
>>>                  return *this;
>>> @@ -271,8 +273,9 @@ namespace lldb_private {
>>>                            ConstString name,
>>>                            std::initializer_list<lldb::LanguageType> langs = {});
>>> 
>>> +        template <typename T>
>>>          void
>>> -        ForEach (const ForEach &foreach)
>>> +        ForEach (const ForEachCallbacks<T> &foreach)
>>>          {
>>>              GetTypeFormatsContainer()->ForEach(foreach.GetFormatExactCallback());
>>>              GetRegexTypeFormatsContainer()->ForEach(foreach.GetFormatRegexCallback());
>>> 
>>> Modified: lldb/trunk/include/lldb/DataFormatters/TypeCategoryMap.h
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeCategoryMap.h?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeCategoryMap.h?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/include/lldb/DataFormatters/TypeCategoryMap.h (original)
>>> +++ lldb/trunk/include/lldb/DataFormatters/TypeCategoryMap.h Tue Nov 17 19:37:49 2015
>>> @@ -88,9 +88,6 @@ namespace lldb_private {
>>>               ValueSP& entry);
>>> 
>>>          void
>>> -        LoopThrough (CallbackType callback, void* param);
>>> -
>>> -        void
>>>          ForEach (ForEachCallback callback);
>>> 
>>>          lldb::TypeCategoryImplSP
>>> 
>>> Modified: lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h (original)
>>> +++ lldb/trunk/include/lldb/DataFormatters/TypeSynthetic.h Tue Nov 17 19:37:49 2015
>>> @@ -479,6 +479,8 @@ namespace lldb_private {
>>>              return SyntheticChildrenFrontEnd::AutoPointer(new FrontEnd(this, backend));
>>>          }
>>> 
>>> +        typedef std::shared_ptr<TypeFilterImpl> SharedPointer;
>>> +
>>>      private:
>>>          DISALLOW_COPY_AND_ASSIGN(TypeFilterImpl);
>>>      };
>>> 
>>> Modified: lldb/trunk/source/API/SBTypeCategory.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTypeCategory.cpp?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTypeCategory.cpp?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/source/API/SBTypeCategory.cpp (original)
>>> +++ lldb/trunk/source/API/SBTypeCategory.cpp Tue Nov 17 19:37:49 2015
>>> @@ -180,7 +180,7 @@ SBTypeCategory::GetFilterForType (SBType
>>>      if (!spec.IsValid())
>>>          return SBTypeFilter();
>>> 
>>> -    lldb::SyntheticChildrenSP children_sp;
>>> +    lldb::TypeFilterImplSP children_sp;
>>> 
>>>      if (spec.IsRegex())
>>>          m_opaque_sp->GetRegexTypeFiltersContainer()->GetExact(ConstString(spec.GetName()), children_sp);
>>> 
>>> Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=253423&r1=253422&r2=253423&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=253423&r1=253422&r2=253423&view=diff>
>>> ==============================================================================
>>> --- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
>>> +++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Nov 17 19:37:49 2015
>>> @@ -1089,13 +1089,6 @@ CommandObjectTypeFormatterDelete::Comman
>>>      { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
>>>  };
>>> 
>>> -
>>> -
>>> -
>>> -
>>> -
>>> -
>>> -
>>>  class CommandObjectTypeFormatterClear : public CommandObjectParsed
>>>  {
>>>  private:
>>> @@ -1224,10 +1217,6 @@ CommandObjectTypeFormatterClear::Command
>>>      { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
>>>  };
>>> 
>>> -
>>> -
>>> -
>>> -
>>>  //-------------------------------------------------------------------------
>>>  // CommandObjectTypeFormatDelete
>>>  //-------------------------------------------------------------------------
>>> @@ -1264,25 +1253,8 @@ public:
>>>      }
>>>  };
>>> 
>>> -//-------------------------------------------------------------------------
>>> -// CommandObjectTypeFormatList
>>> -//-------------------------------------------------------------------------
>>> -
>>> -bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
>>> -bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
>>> -
>>> -class CommandObjectTypeFormatList;
>>> -
>>> -struct CommandObjectTypeFormatList_LoopCallbackParam {
>>> -    CommandObjectTypeFormatList* self;
>>> -    CommandReturnObject* result;
>>> -    RegularExpression* regex;
>>> -    RegularExpression* cate_regex;
>>> -    CommandObjectTypeFormatList_LoopCallbackParam(CommandObjectTypeFormatList* S, CommandReturnObject* R,
>>> -                                            RegularExpression* X = NULL, RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
>>> -};
>>> -
>>> -class CommandObjectTypeFormatList : public CommandObjectParsed
>>> +template <typename FormatterType>
>>> +class CommandObjectTypeFormatterList : public CommandObjectParsed
>>>  {
>>>      class CommandOptions : public Options
>>>      {
>>> @@ -1323,6 +1295,12 @@ class CommandObjectTypeFormatList : publ
>>>          const OptionDefinition*
>>>          GetDefinitions () override
>>>          {
>>> +            static OptionDefinition g_option_table[] =
>>> +            {
>>> +                { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName,  "Only show categories matching this filter."},
>>> +                { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
>>> +            };
>>> +
>>>              return g_option_table;
>>>          }
>>> 
>>> @@ -1345,10 +1323,12 @@ class CommandObjectTypeFormatList : publ
>>>      }
>>> 
>>>  public:
>>> -    CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
>>> +    CommandObjectTypeFormatterList (CommandInterpreter &interpreter,
>>> +                                    const char* name,
>>> +                                    const char* help) :
>>>          CommandObjectParsed (interpreter,
>>> -                             "type format list",
>>> -                             "Show a list of current formatting styles.",
>>> +                             name,
>>> +                             help,
>>>                               NULL),
>>>      m_options(interpreter)
>>>      {
>>> @@ -1363,115 +1343,137 @@ public:
>>>          m_arguments.push_back (type_arg);
>>>      }
>>> 
>>> -    ~CommandObjectTypeFormatList () override
>>> +    ~CommandObjectTypeFormatterList () override
>>>      {
>>>      }
>>> 
>>>  protected:
>>> +    virtual void
>>> +    FormatterSpecificList (CommandReturnObject &result)
>>> +    {
>>> +    }
>>> +
>>>      bool
>>>      DoExecute (Args& command, CommandReturnObject &result) override
>>>      {
>>>          const size_t argc = command.GetArgumentCount();
>>> 
>>> -        CommandObjectTypeFormatList_LoopCallbackParam *param;
>>> -        RegularExpression* cate_regex =
>>> -        m_options.m_category_regex.empty() ? NULL :
>>> -        new RegularExpression(m_options.m_category_regex.c_str());
>>> +        std::unique_ptr<RegularExpression> category_regex;
>>> +        std::unique_ptr<RegularExpression> formatter_regex;
>>> +
>>> +        if (m_options.m_category_regex.size() > 0)
>>> +        {
>>> +            category_regex.reset(new RegularExpression());
>>> +            if (!category_regex->Compile(m_options.m_category_regex.c_str()))
>>> +            {
>>> +                result.AppendErrorWithFormat("syntax error in category regular expression '%s'", m_options.m_category_regex.c_str());
>>> +                result.SetStatus(eReturnStatusFailed);
>>> +                return false;
>>> +            }
>>> +        }
>>> 
>>>          if (argc == 1)
>>>          {
>>> -            RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
>>> -            regex->Compile(command.GetArgumentAtIndex(0));
>>> -            param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,regex,cate_regex);
>>> +            const char* arg = command.GetArgumentAtIndex(1);
>>> +            formatter_regex.reset(new RegularExpression());
>>> +            if (!formatter_regex->Compile(arg))
>>> +            {
>>> +                result.AppendErrorWithFormat("syntax error in regular expression '%s'", arg);
>>> +                result.SetStatus(eReturnStatusFailed);
>>> +                return false;
>>> +            }
>>>          }
>>> -        else
>>> -            param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,NULL,cate_regex);
>>> 
>>> -        DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
>>> -        delete param;
>>> +        DataVisualization::Categories::ForEach( [this, &command, &result, &category_regex, &formatter_regex] (const lldb::TypeCategoryImplSP& category) -> bool {
>>> +            if (category_regex)
>>> +            {
>>> +                bool escape = true;
>>> +                if (0 == strcmp(category->GetName(), category_regex->GetText()))
>>> +                {
>>> +                    escape = false;
>>> +                }
>>> +                else if (category_regex->Execute(category->GetName()))
>>> +                {
>>> +                    escape = false;
>>> +                }
>>> +
>>> +                if (escape)
>>> +                    return true;
>>> +            }
>>> +
>>> +            result.GetOutputStream().Printf("-----------------------\nCategory: %s\n-----------------------\n", category->GetName());
>>> +
>>> +            TypeCategoryImpl::ForEachCallbacks<FormatterType> foreach;
>>> +            foreach.Set( [&result, &formatter_regex] (ConstString name, const typename FormatterType::SharedPointer& format_sp) -> bool {
>>> +                if (formatter_regex)
>>> +                {
>>> +                    bool escape = true;
>>> +                    if (0 == strcmp(name.AsCString(), formatter_regex->GetText()))
>>> +                    {
>>> +                        escape = false;
>>> +                    }
>>> +                    else if (formatter_regex->Execute(name.AsCString()))
>>> +                    {
>>> +                        escape = false;
>>> +                    }
>>> +
>>> +                    if (escape)
>>> +                        return true;
>>> +                }
>>> +
>>> +                result.GetOutputStream().Printf ("%s: %s\n", name.AsCString(), format_sp->GetDescription().c_str());
>>> +
>>> +                return true;
>>> +            });
>>> +
>>> +            foreach.Set( [&result, &formatter_regex] (RegularExpressionSP regex_sp, const typename FormatterType::SharedPointer& format_sp) -> bool {
>>> +                if (formatter_regex)
>>> +                {
>>> +                    bool escape = true;
>>> +                    if (0 == strcmp(regex_sp->GetText(), formatter_regex->GetText()))
>>> +                    {
>>> +                        escape = false;
>>> +                    }
>>> +                    else if (formatter_regex->Execute(regex_sp->GetText()))
>>> +                    {
>>> +                        escape = false;
>>> +                    }
>>> +
>>> +                    if (escape)
>>> +                        return true;
>>> +                }
>>> +
>>> +                result.GetOutputStream().Printf ("%s: %s\n", regex_sp->GetText(), format_sp->GetDescription().c_str());
>>> +
>>> +                return true;
>>> +            });
>>> 
>>> -        if (cate_regex)
>>> -            delete cate_regex;
>>> +            category->ForEach(foreach);
>>> +
>>> +            return true;
>>> +        });
>>> 
>>> +        FormatterSpecificList(result);
>>> +
>>>          result.SetStatus(eReturnStatusSuccessFinishResult);
>>>          return result.Succeeded();
>>>      }
>>> -
>>> -private:
>>> -
>>> -    static bool
>>> -    PerCategoryCallback(void* param_vp,
>>> -                        const lldb::TypeCategoryImplSP& cate)
>>> -    {
>>> -
>>> -        CommandObjectTypeFormatList_LoopCallbackParam* param =
>>> -        (CommandObjectTypeFormatList_LoopCallbackParam*)param_vp;
>>> -        CommandReturnObject* result = param->result;
>>> -
>>> -        const char* cate_name = cate->GetName();
>>> -
>>> -        // if the category is disabled or empty and there is no regex, just skip it
>>> -        if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemValue | eFormatCategoryItemRegexValue) == 0) && param->cate_regex == NULL)
>>> -            return true;
>>> -
>>> -        // if we have a regex and this category does not match it, just skip it
>>> -        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\n-----------------------\n", cate->GetDescription().c_str());
>>> -
>>> -        cate->GetTypeFormatsContainer()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
>>> -
>>> -        if (cate->GetRegexTypeFormatsContainer()->GetCount() > 0)
>>> -        {
>>> -            result->GetOutputStream().Printf("Regex-based formats (slower):\n");
>>> -            cate->GetRegexTypeFormatsContainer()->LoopThrough(CommandObjectTypeRXFormatList_LoopCallback, param_vp);
>>> -        }
>>> -        return true;
>>> -    }
>>> -
>>> -
>>> -    bool
>>> -    LoopCallback (const char* type,
>>> -                  const lldb::TypeFormatImplSP& entry,
>>> -                  RegularExpression* regex,
>>> -                  CommandReturnObject *result)
>>> -    {
>>> -        if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
>>> -            result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
>>> -        return true;
>>> -    }
>>> -
>>> -    friend bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
>>> -    friend bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
>>> -
>>>  };
>>> 
>>> -bool
>>> -CommandObjectTypeFormatList_LoopCallback (
>>> -                                    void* pt2self,
>>> -                                    ConstString type,
>>> -                                    const lldb::TypeFormatImplSP& entry)
>>> -{
>>> -    CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
>>> -    return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
>>> -}
>>> -
>>> -bool
>>> -CommandObjectTypeRXFormatList_LoopCallback (
>>> -                                             void* pt2self,
>>> -                                             lldb::RegularExpressionSP regex,
>>> -                                             const lldb::TypeFormatImplSP& entry)
>>> -{
>>> -    CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
>>> -    return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
>>> -}
>>> +//-------------------------------------------------------------------------
>>> +// CommandObjectTypeFormatList
>>> +//-------------------------------------------------------------------------
>>> 
>>> -OptionDefinition
>>> -CommandObjectTypeFormatList::CommandOptions::g_option_table[] =
>>> +class CommandObjectTypeFormatList : public CommandObjectTypeFormatterList<TypeFormatImpl>
>>>  {
>>> -    { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName,  "Only show categories matching this filter."},
>>> -    { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
>>> +public:
>>> +
>>> +    CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
>>> +        CommandObjectTypeFormatterList(interpreter,
>>> +                                       "type format list",
>>> +                                       "Show a list of current formats.")
>>> +    {
>>> +    }
>>>  };
>>> 
>>>  #ifndef LLDB_DISABLE_PYTHON
>>> @@ -2046,226 +2048,30 @@ protected:
>>>  // CommandObjectTypeSummaryList
>>>  //-------------------------------------------------------------------------
>>> 
>>> -bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const StringSummaryFormat::SharedPointer& entry);
>>> -bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const StringSummaryFormat::SharedPointer& entry);
>>> -
>>> -class CommandObjectTypeSummaryList;
>>> -
>>> -struct CommandObjectTypeSummaryList_LoopCallbackParam {
>>> -    CommandObjectTypeSummaryList* self;
>>> -    CommandReturnObject* result;
>>> -    RegularExpression* regex;
>>> -    RegularExpression* cate_regex;
>>> -    CommandObjectTypeSummaryList_LoopCallbackParam(CommandObjectTypeSummaryList* S, CommandReturnObject* R,
>>> -                                                  RegularExpression* X = NULL,
>>> -                                                  RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
>>> -};
>>> -
>>> -class CommandObjectTypeSummaryList : public CommandObjectParsed
>>> +class CommandObjectTypeSummaryList : public CommandObjectTypeFormatterList<TypeSummaryImpl>
>>>  {
>>> -
>>> -    class CommandOptions : public Options
>>> -    {
>>> -    public:
>>> -
>>> -        CommandOptions (CommandInterpreter &interpreter) :
>>> -        Options (interpreter)
>>> -        {
>>> -        }
>>> -
>>> -        ~CommandOptions () override {}
>>> -
>>> -        Error
>>> -        SetOptionValue (uint32_t option_idx, const char *option_arg) override
>>> -        {
>>> -            Error error;
>>> -            const int short_option = m_getopt_table[option_idx].val;
>>> -
>>> -            switch (short_option)
>>> -            {
>>> -                case 'w':
>>> -                    m_category_regex = std::string(option_arg);
>>> -                    break;
>>> -                default:
>>> -                    error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
>>> -                    break;
>>> -            }
>>> -
>>> -            return error;
>>> -        }
>>> -
>>> -        void
>>> -        OptionParsingStarting () override
>>> -        {
>>> -            m_category_regex = "";
>>> -        }
>>> -
>>> -        const OptionDefinition*
>>> -        GetDefinitions () override
>>> -        {
>>> -            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.
>>> -
>>> -        std::string m_category_regex;
>>> -
>>> -    };
>>> -
>>> -    CommandOptions m_options;
>>> -
>>> -    Options *
>>> -    GetOptions () override
>>> -    {
>>> -        return &m_options;
>>> -    }
>>> -
>>>  public:
>>> -    CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
>>> -        CommandObjectParsed (interpreter,
>>> -                             "type summary list",
>>> -                             "Show a list of current summary styles.",
>>> -                             NULL),
>>> -        m_options(interpreter)
>>> -    {
>>> -        CommandArgumentEntry type_arg;
>>> -        CommandArgumentData type_style_arg;
>>> -
>>> -        type_style_arg.arg_type = eArgTypeName;
>>> -        type_style_arg.arg_repetition = eArgRepeatOptional;
>>> -
>>> -        type_arg.push_back (type_style_arg);
>>> -
>>> -        m_arguments.push_back (type_arg);
>>> -    }
>>> 
>>> -    ~CommandObjectTypeSummaryList () override
>>> +    CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
>>> +    CommandObjectTypeFormatterList(interpreter,
>>> +                                   "type summary list",
>>> +                                   "Show a list of current summaries.")
>>>      {
>>>      }
>>> 
>>>  protected:
>>> -    bool
>>> -    DoExecute (Args& command, CommandReturnObject &result) override
>>> +    void
>>> +    FormatterSpecificList (CommandReturnObject &result) override
>>>      {
>>> -        const size_t argc = command.GetArgumentCount();
>>> -
>>> -        CommandObjectTypeSummaryList_LoopCallbackParam *param;
>>> -        RegularExpression* cate_regex =
>>> -        m_options.m_category_regex.empty() ? NULL :
>>> -        new RegularExpression(m_options.m_category_regex.c_str());
>>> -
>>> -        if (argc == 1)
>>> -        {
>>> -            RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
>>> -            regex->Compile(command.GetArgumentAtIndex(0));
>>> -            param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex,cate_regex);
>>> -        }
>>> -        else
>>> -            param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
>>> -
>>> -        DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
>>> -        delete param;
>>> -
>>>          if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
>>>          {
>>>              result.GetOutputStream().Printf("Named summaries:\n");
>>> -            if (argc == 1)
>>> -            {
>>> -                RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
>>> -                regex->Compile(command.GetArgumentAtIndex(0));
>>> -                param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex);
>>> -            }
>>> -            else
>>> -                param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result);
>>> -            DataVisualization::NamedSummaryFormats::LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param);
>>> -            delete param;
>>> -        }
>>> -
>>> -        if (cate_regex)
>>> -            delete cate_regex;
>>> -
>>> -        result.SetStatus(eReturnStatusSuccessFinishResult);
>>> -        return result.Succeeded();
>>> -    }
>>> -
>>> -private:
>>> -
>>> -    static bool
>>> -    PerCategoryCallback(void* param_vp,
>>> -                        const lldb::TypeCategoryImplSP& cate)
>>> -    {
>>> -
>>> -        CommandObjectTypeSummaryList_LoopCallbackParam* param =
>>> -            (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
>>> -        CommandReturnObject* result = param->result;
>>> -
>>> -        const char* cate_name = cate->GetName();
>>> -
>>> -        // if the category is disabled or empty and there is no regex, just skip it
>>> -        if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary) == 0) && param->cate_regex == NULL)
>>> -            return true;
>>> -
>>> -        // if we have a regex and this category does not match it, just skip it
>>> -        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\n-----------------------\n", cate->GetDescription().c_str());
>>> -
>>> -        cate->GetTypeSummariesContainer()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
>>> -
>>> -        if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
>>> -        {
>>> -            result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
>>> -            cate->GetRegexTypeSummariesContainer()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
>>> +            DataVisualization::NamedSummaryFormats::ForEach( [&result] (ConstString name, const TypeSummaryImplSP& summary_sp) -> bool {
>>> +                result.GetOutputStream().Printf ("%s: %s\n", name.AsCString(), summary_sp->GetDescription().c_str());
>>> +                return true;
>>> +            });
>>>          }
>>> -        return true;
>>> -    }
>>> -
>>> -
>>> -    bool
>>> -    LoopCallback (const char* type,
>>> -                  const lldb::TypeSummaryImplSP& entry,
>>> -                  RegularExpression* regex,
>>> -                  CommandReturnObject *result)
>>> -    {
>>> -        if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
>>> -                result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
>>> -        return true;
>>>      }
>>> -
>>> -    friend bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeSummaryImplSP& entry);
>>> -    friend bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeSummaryImplSP& entry);
>>> -};
>>> -
>>> -bool
>>> -CommandObjectTypeSummaryList_LoopCallback (
>>> -                                          void* pt2self,
>>> -                                          ConstString type,
>>> -                                          const lldb::TypeSummaryImplSP& entry)
>>> -{
>>> -    CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
>>> -    return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
>>> -}
>>> -
>>> -bool
>>> -CommandObjectTypeRXSummaryList_LoopCallback (
>>> -                                           void* pt2self,
>>> -                                           lldb::RegularExpressionSP regex,
>>> -                                           const lldb::TypeSummaryImplSP& entry)
>>> -{
>>> -    CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
>>> -    return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
>>> -}
>>> -
>>> -OptionDefinition
>>> -CommandObjectTypeSummaryList::CommandOptions::g_option_table[] =
>>> -{
>>> -    { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName,  "Only show categories matching this filter."},
>>> -    { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
>>>  };
>>> 
>>>  //-------------------------------------------------------------------------
>>> @@ -2786,37 +2592,6 @@ CommandObjectTypeCategoryDisable::Comman
>>> 
>>>  class CommandObjectTypeCategoryList : public CommandObjectParsed
>>>  {
>>> -private:
>>> -
>>> -    struct CommandObjectTypeCategoryList_CallbackParam
>>> -    {
>>> -        CommandReturnObject* result;
>>> -        RegularExpression* regex;
>>> -
>>> -        CommandObjectTypeCategoryList_CallbackParam(CommandReturnObject* res,
>>> -                                                    RegularExpression* rex = NULL) :
>>> -        result(res),
>>> -        regex(rex)
>>> -        {
>>> -        }
>>> -
>>> -    };
>>> -
>>> -    static bool
>>> -    PerCategoryCallback(void* param_vp,
>>> -                        const lldb::TypeCategoryImplSP& cate)
>>> -    {
>>> -        CommandObjectTypeCategoryList_CallbackParam* param =
>>> -            (CommandObjectTypeCategoryList_CallbackParam*)param_vp;
>>> -        CommandReturnObject* result = param->result;
>>> -        RegularExpression* regex = param->regex;
>>> -
>>> -        const char* cate_name = cate->GetName();
>>> -
>>> -        if (regex == NULL || strcmp(cate_name, regex->GetText()) == 0 || regex->Execute(cate_name))
>>> -            result->GetOutputStream().Printf("Category: %s\n", cate->GetDescription().c_str());
>>> -        return true;
>>> -    }
>>>  public:
>>>      CommandObjectTypeCategoryList (CommandInterpreter &interpreter) :
>>>          CommandObjectParsed (interpreter,
>>> @@ -2844,26 +2619,48 @@ protected:
>>>      DoExecute (Args& command, CommandReturnObject &result) override
>>>      {
>>>          const size_t argc = command.GetArgumentCount();
>>> -        RegularExpression* regex = NULL;
>>> +
>>> +        std::unique_ptr<RegularExpression> regex;
>>> 
>>> -        if (argc == 0)
>>> -            ;
>>> -        else if (argc == 1)
>>> -            regex = new RegularExpression(command.GetArgumentAtIndex(0));
>>> -        else
>>> +        if (argc == 1)
>>> +        {
>>> +            regex.reset(new RegularExpression());
>>> +            const char* arg = command.GetArgumentAtIndex(0);
>>> +            if (!regex->Compile(arg))
>>> +            {
>>> +                result.AppendErrorWithFormat("syntax error in category regular expression '%s'", arg);
>>> +                result.SetStatus(eReturnStatusFailed);
>>> +                return false;
>>> +            }
>>> +        }
>>> +        else if (argc != 0)
>>>          {
>>>              result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
>>>              result.SetStatus(eReturnStatusFailed);
>>>              return false;
>>>          }
>>> 
>>> -        CommandObjectTypeCategoryList_CallbackParam param(&result,
>>> -                                                          regex);
>>> -
>>> -        DataVisualization::Categories::LoopThrough(PerCategoryCallback, &param);
>>> -
>>> -        if (regex)
>>> -            delete regex;
>>> +        DataVisualization::Categories::ForEach( [&regex, &result] (const lldb::TypeCategoryImplSP& category_sp) -> bool {
>>> +            if (regex)
>>> +            {
>>> +                bool escape = true;
>>> +                if (0 == strcmp(category_sp->GetName(), regex->GetText()))
>>> +                {
>>> +                    escape = false;
>>> +                }
>>> +                else if (regex->Execute(category_sp->GetName()))
>>> +                {
>>> +                    escape = false;
>>> +                }
>>> +
>>> +                if (escape)
>>> +                    return true;
>>> +            }
>>> +
>>> +            result.GetOutputStream().Printf("Category: %s\n", category_sp->GetDescription().c_str());
>>> +
>>> +            return true;
>>> +        });
>>> 
>>>          result.SetStatus(eReturnStatusSuccessFinishResult);
>>>          return result.Succeeded();
>>> @@ -2875,210 +2672,16 @@ protected:
>>>  // CommandObjectTypeFilterList
>>>  //-------------------------------------------------------------------------
>>> 
>>> -bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
>>> -bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
>>> -
>>> -class CommandObjectTypeFilterList;
>>> -
>>> -struct CommandObjectTypeFilterList_LoopCallbackParam {
>>> -    CommandObjectTypeFilterList* self;
>>> -    CommandReturnObject* result;
>>> -    RegularExpression* regex;
>>> -    RegularExpression* cate_regex;
>>> -    CommandObjectTypeFilterList_LoopCallbackParam(CommandObjectTypeFilterList* S, CommandReturnObject* R,
>>> -                                                  RegularExpression* X = NULL,
>>> -                                                  RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
>>> -};
>>> -
>>> -class CommandObjectTypeFilterList : public CommandObjectParsed
>>> +class CommandObjectTypeFilterList : public CommandObjectTypeFormatterList<TypeFilterImpl>
>>>  {
>>> -
>>> -    class CommandOptions : public Options
>>> -    {
>>> -    public:
>>> -
>>> -        CommandOptions (CommandInterpreter &interpreter) :
>>> -        Options (interpreter)
>>> -        {
>>> -        }
>>> -
>>> -        ~CommandOptions () override {}
>>> -
>>> -        Error
>>> -        SetOptionValue (uint32_t option_idx, const char *option_arg) override
>>> -        {
>>> -            Error error;
>>> -            const int short_option = m_getopt_table[option_idx].val;
>>> -
>>> -            switch (short_option)
>>> -            {
>>> -                case 'w':
>>> -                    m_category_regex = std::string(option_arg);
>>> -                    break;
>>> -                default:
>>> -                    error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
>>> -                    break;
>>> -            }
>>> -
>>> -            return error;
>>> -        }
>>> -
>>> -        void
>>> -        OptionParsingStarting () override
>>> -        {
>>> -            m_category_regex = "";
>>> -        }
>>> -
>>> -        const OptionDefinition*
>>> -        GetDefinitions () override
>>> -        {
>>> -            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.
>>> -
>>> -        std::string m_category_regex;
>>> -
>>> -    };
>>> -
>>> -    CommandOptions m_options;
>>> -
>>> -    Options *
>>> -    GetOptions () override
>>> -    {
>>> -        return &m_options;
>>> -    }
>>> -
>>>  public:
>>> -    CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
>>> -        CommandObjectParsed (interpreter,
>>> -                             "type filter list",
>>> -                             "Show a list of current filters.",
>>> -                             NULL),
>>> -        m_options(interpreter)
>>> -    {
>>> -        CommandArgumentEntry type_arg;
>>> -        CommandArgumentData type_style_arg;
>>> -
>>> -        type_style_arg.arg_type = eArgTypeName;
>>> -        type_style_arg.arg_repetition = eArgRepeatOptional;
>>> -
>>> -        type_arg.push_back (type_style_arg);
>>> -
>>> -        m_arguments.push_back (type_arg);
>>> -    }
>>> -
>>> -    ~CommandObjectTypeFilterList () override
>>> -    {
>>> -    }
>>> -
>>> -protected:
>>> -    bool
>>> -    DoExecute (Args& command, CommandReturnObject &result) override
>>> -    {
>>> -        const size_t argc = command.GetArgumentCount();
>>> -
>>> -        CommandObjectTypeFilterList_LoopCallbackParam *param;
>>> -        RegularExpression* cate_regex =
>>> -        m_options.m_category_regex.empty() ? NULL :
>>> -        new RegularExpression(m_options.m_category_regex.c_str());
>>> -
>>> -        if (argc == 1)
>>> -        {
>>> -            RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
>>> -            regex->Compile(command.GetArgumentAtIndex(0));
>>> -            param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,regex,cate_regex);
>>> -        }
>>> -        else
>>> -            param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,NULL,cate_regex);
>>> -
>>> -        DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
>>> -        delete param;
>>> -
>>> -        if (cate_regex)
>>> -            delete cate_regex;
>>> -
>>> -        result.SetStatus(eReturnStatusSuccessFinishResult);
>>> -        return result.Succeeded();
>>> -    }
>>> 
>>> -private:
>>> -
>>> -    static bool
>>> -    PerCategoryCallback(void* param_vp,
>>> -                        const lldb::TypeCategoryImplSP& cate)
>>> -    {
>>> -
>>> -        const char* cate_name = cate->GetName();
>>> -
>>> -        CommandObjectTypeFilterList_LoopCallbackParam* param =
>>> -        (CommandObjectTypeFilterList_LoopCallbackParam*)param_vp;
>>> -        CommandReturnObject* result = param->result;
>>> -
>>> -        // if the category is disabled or empty and there is no regex, just skip it
>>> -        if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter) == 0) && param->cate_regex == NULL)
>>> -            return true;
>>> -
>>> -        // if we have a regex and this category does not match it, just skip it
>>> -        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\n-----------------------\n", cate->GetDescription().c_str());
>>> -
>>> -        cate->GetTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
>>> -
>>> -        if (cate->GetRegexTypeFiltersContainer()->GetCount() > 0)
>>> -        {
>>> -            result->GetOutputStream().Printf("Regex-based filters (slower):\n");
>>> -            cate->GetRegexTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
>>> -        }
>>> -
>>> -        return true;
>>> -    }
>>> -
>>> -    bool
>>> -    LoopCallback (const char* type,
>>> -                  const SyntheticChildren::SharedPointer& entry,
>>> -                  RegularExpression* regex,
>>> -                  CommandReturnObject *result)
>>> +    CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
>>> +    CommandObjectTypeFormatterList(interpreter,
>>> +                                   "type filter list",
>>> +                                   "Show a list of current filters.")
>>>      {
>>> -        if (regex == NULL || regex->Execute(type))
>>> -            result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
>>> -        return true;
>>>      }
>>> -
>>> -    friend bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
>>> -    friend bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
>>> -};
>>> -
>>> -bool
>>> -CommandObjectTypeFilterList_LoopCallback (void* pt2self,
>>> -                                         ConstString type,
>>> -                                         const SyntheticChildren::SharedPointer& entry)
>>> -{
>>> -    CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
>>> -    return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
>>> -}
>>> -
>>> -bool
>>> -CommandObjectTypeFilterRXList_LoopCallback (void* pt2self,
>>> -                                           lldb::RegularExpressionSP regex,
>>> -                                           const SyntheticChildren::SharedPointer& entry)
>>> -{
>>> -    CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
>>> -    return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
>>> -}
>>> -
>>> -
>>> -OptionDefinition
>>> -CommandObjectTypeFilterList::CommandOptions::g_option_table[] =
>>> -{
>>> -    { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName,  "Only show categories matching this filter."},
>>> -    { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
>>>  };
>>> 
>>>  #ifndef LLDB_DISABLE_PYTHON
>>> @@ -3087,210 +2690,16 @@ CommandObjectTypeFilterList::CommandOpti
>>>  // CommandObjectTypeSynthList
>>>  //-------------------------------------------------------------------------
>>> 
>>> -bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
>>> -bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
>>> -
>>> -class CommandObjectTypeSynthList;
>>> -
>>> -struct CommandObjectTypeSynthList_LoopCallbackParam {
>>> -    CommandObjectTypeSynthList* self;
>>> -    CommandReturnObject* result;
>>> -    RegularExpression* regex;
>>> -    RegularExpression* cate_regex;
>>> -    CommandObjectTypeSynthList_LoopCallbackParam(CommandObjectTypeSynthList* S, CommandReturnObject* R,
>>> -                                                 RegularExpression* X = NULL,
>>> -                                                 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
>>> -};
>>> -
>>> -class CommandObjectTypeSynthList : public CommandObjectParsed
>>> +class CommandObjectTypeSynthList : public CommandObjectTypeFormatterList<SyntheticChildren>
>>>  {
>>> -
>>> -    class CommandOptions : public Options
>>> -    {
>>> -    public:
>>> -
>>> -        CommandOptions (CommandInterpreter &interpreter) :
>>> -        Options (interpreter)
>>> -        {
>>> -        }
>>> -
>>> -        ~CommandOptions () override {}
>>> -
>>> -        Error
>>> -        SetOptionValue (uint32_t option_idx, const char *option_arg) override
>>> -        {
>>> -            Error error;
>>> -            const int short_option = m_getopt_table[option_idx].val;
>>> -
>>> -            switch (short_option)
>>> -            {
>>> -                case 'w':
>>> -                    m_category_regex = std::string(option_arg);
>>> -                    break;
>>> -                default:
>>> -                    error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
>>> -                    break;
>>> -            }
>>> -
>>> -            return error;
>>> -        }
>>> -
>>> -        void
>>> -        OptionParsingStarting () override
>>> -        {
>>> -            m_category_regex = "";
>>> -        }
>>> -
>>> -        const OptionDefinition*
>>> -        GetDefinitions () override
>>> -        {
>>> -            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.
>>> -
>>> -        std::string m_category_regex;
>>> -
>>> -    };
>>> -
>>> -    CommandOptions m_options;
>>> -
>>> -    Options *
>>> -    GetOptions () override
>>> -    {
>>> -        return &m_options;
>>> -    }
>>> -
>>>  public:
>>> -    CommandObjectTypeSynthList (CommandInterpreter &interpreter) :
>>> -        CommandObjectParsed (interpreter,
>>> -                             "type synthetic list",
>>> -                             "Show a list of current synthetic providers.",
>>> -                             NULL),
>>> -        m_options(interpreter)
>>> -    {
>>> -        CommandArgumentEntry type_arg;
>>> -        CommandArgumentData type_style_arg;
>>> -
>>> -        type_style_arg.arg_type = eArgTypeName;
>>> -        type_style_arg.arg_repetition = eArgRepeatOptional;
>>> -
>>> -        type_arg.push_back (type_style_arg);
>>> -
>>> -        m_arguments.push_back (type_arg);
>>> -    }
>>> -
>>> -    ~CommandObjectTypeSynthList () override
>>> -    {
>>> -    }
>>> -
>>> -protected:
>>> -    bool
>>> -    DoExecute (Args& command, CommandReturnObject &result) override
>>> -    {
>>> -        const size_t argc = command.GetArgumentCount();
>>> -
>>> -        CommandObjectTypeSynthList_LoopCallbackParam *param;
>>> -        RegularExpression* cate_regex =
>>> -        m_options.m_category_regex.empty() ? NULL :
>>> -        new RegularExpression(m_options.m_category_regex.c_str());
>>> -
>>> -        if (argc == 1)
>>> -        {
>>> -            RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
>>> -            regex->Compile(command.GetArgumentAtIndex(0));
>>> -            param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,regex,cate_regex);
>>> -        }
>>> -        else
>>> -            param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,NULL,cate_regex);
>>> -
>>> -        DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
>>> -        delete param;
>>> -
>>> -        if (cate_regex)
>>> -            delete cate_regex;
>>> -
>>> -        result.SetStatus(eReturnStatusSuccessFinishResult);
>>> -        return result.Succeeded();
>>> -    }
>>> -
>>> -private:
>>> 
>>> -    static bool
>>> -    PerCategoryCallback(void* param_vp,
>>> -                        const lldb::TypeCategoryImplSP& cate)
>>> -    {
>>> -
>>> -        CommandObjectTypeSynthList_LoopCallbackParam* param =
>>> -        (CommandObjectTypeSynthList_LoopCallbackParam*)param_vp;
>>> -        CommandReturnObject* result = param->result;
>>> -
>>> -        const char* cate_name = cate->GetName();
>>> -
>>> -        // if the category is disabled or empty and there is no regex, just skip it
>>> -        if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth) == 0) && param->cate_regex == NULL)
>>> -            return true;
>>> -
>>> -        // if we have a regex and this category does not match it, just skip it
>>> -        if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
>>> -            return true;
>>> -
>>> -        result->GetOutputStream().P


Thanks,
- Enrico
📩 egranata@.com ☎️ 27683

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20151118/0300f0ef/attachment-0001.html>


More information about the lldb-commits mailing list