[Lldb-commits] [lldb] r138315 - in /lldb/trunk: include/lldb/ include/lldb/Core/ scripts/Python/ source/Commands/ source/Core/ test/functionalities/data-formatter/data-formatter-categories/ test/functionalities/data-formatter/data-formatter-globals/ test/functionalities/data-formatter/data-formatter-script/ test/functionalities/data-formatter/data-formatter-synth/

Enrico Granata granata.enrico at gmail.com
Mon Aug 22 17:32:52 PDT 2011


Author: enrico
Date: Mon Aug 22 19:32:52 2011
New Revision: 138315

URL: http://llvm.org/viewvc/llvm-project?rev=138315&view=rev
Log:
Additional code cleanups ; Short option name for --python-script in type summary add moved from -s to -o (this is a preliminary step in moving the short option for --summary-string from -f to -s) ; Accordingly updated the test suite

Modified:
    lldb/trunk/include/lldb/Core/FormatClasses.h
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/include/lldb/lldb-private-enumerations.h
    lldb/trunk/scripts/Python/python-wrapper.swig
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Core/DataVisualization.cpp
    lldb/trunk/source/Core/Debugger.cpp
    lldb/trunk/source/Core/FormatClasses.cpp
    lldb/trunk/source/Core/FormatManager.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-categories/TestDataFormatterCategories.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py

Modified: lldb/trunk/include/lldb/Core/FormatClasses.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatClasses.h?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatClasses.h (original)
+++ lldb/trunk/include/lldb/Core/FormatClasses.h Mon Aug 22 19:32:52 2011
@@ -31,10 +31,8 @@
 #include "lldb/lldb-public.h"
 #include "lldb/lldb-enumerations.h"
 
-#include "lldb/API/SBValue.h"
 #include "lldb/Core/ValueObject.h"
 #include "lldb/Interpreter/ScriptInterpreterPython.h"
-#include "lldb/Symbol/SymbolContext.h"
 
 namespace lldb_private {
 
@@ -48,13 +46,7 @@
     ValueFormat (lldb::Format f = lldb::eFormatInvalid,
                  bool casc = false,
                  bool skipptr = false,
-                 bool skipref = false) : 
-    m_cascades(casc),
-    m_skip_pointers(skipptr),
-    m_skip_references(skipref),
-    m_format (f)
-    {
-    }
+                 bool skipref = false);
     
     typedef lldb::SharedPtr<ValueFormat>::Type SharedPointer;
     typedef bool(*ValueCallback)(void*, ConstString, const lldb::ValueFormatSP&);
@@ -335,25 +327,7 @@
         }
         
         virtual lldb::ValueObjectSP
-        GetChildAtIndex (uint32_t idx, bool can_create)
-        {
-            if (m_wrapper == NULL || m_interpreter == NULL)
-                return lldb::ValueObjectSP();
-            
-            PyObject* py_return = (PyObject*)m_interpreter->GetChildAtIndex(m_wrapper, idx);
-            if (py_return == NULL || py_return == Py_None)
-            {
-                Py_XDECREF(py_return);
-                return lldb::ValueObjectSP();
-            }
-            
-            lldb::SBValue *sb_ptr = m_interpreter->CastPyObjectToSBValue(py_return);
-            
-            if (py_return == NULL || sb_ptr == NULL)
-                return lldb::ValueObjectSP();
-            
-            return sb_ptr->m_opaque_sp;
-        }
+        GetChildAtIndex (uint32_t idx, bool can_create);
         
         virtual void
         Update()
@@ -383,122 +357,121 @@
     }
     
 };
-
-struct SyntheticArrayRange
-{
-private:
-    int m_low;
-    int m_high;
-    SyntheticArrayRange* m_next;
     
+class SyntheticArrayView : public SyntheticChildren
+{
 public:
     
-    SyntheticArrayRange () : 
+    struct SyntheticArrayRange
+    {
+    private:
+        int m_low;
+        int m_high;
+        SyntheticArrayRange* m_next;
+        
+    public:
+        
+        SyntheticArrayRange () : 
         m_low(-1),
         m_high(-2),
         m_next(NULL)
-    {}
-
-    SyntheticArrayRange (int L) : 
+        {}
+        
+        SyntheticArrayRange (int L) : 
         m_low(L),
         m_high(L),
         m_next(NULL)
-    {}
-    
-    SyntheticArrayRange (int L, int H) : 
+        {}
+        
+        SyntheticArrayRange (int L, int H) : 
         m_low(L),
         m_high(H),
         m_next(NULL)
-    {}
-    
-    SyntheticArrayRange (int L, int H, SyntheticArrayRange* N) : 
+        {}
+        
+        SyntheticArrayRange (int L, int H, SyntheticArrayRange* N) : 
         m_low(L),
         m_high(H),
         m_next(N)
-    {}
-    
-    inline int
-    GetLow ()
-    {
-        return m_low;
-    }
-    
-    inline int
-    GetHigh ()
-    {
-        return m_high;
-    }
-    
-    inline void
-    SetLow (int L)
-    {
-        m_low = L;
-    }
-    
-    inline void
-    SetHigh (int H)
-    {
-        m_high = H;
-    }
-    
-    inline  int
-    GetSelfCount()
-    {
-        return GetHigh() - GetLow() + 1;
-    }
-    
-    int
-    GetCount()
-    {
-        int count = GetSelfCount();
-        if (m_next)
-            count += m_next->GetCount();
-        return count;
-    }
-    
-    inline SyntheticArrayRange*
-    GetNext()
-    {
-        return m_next;
-    }
-    
-    void
-    SetNext(SyntheticArrayRange* N)
-    {
-        if (m_next)
-            delete m_next;
-        m_next = N;
-    }
-    
-    void
-    SetNext(int L, int H)
-    {
-        if (m_next)
-            delete m_next;
-        m_next = new SyntheticArrayRange(L, H);
-    }
-    
-    void
-    SetNext(int L)
-    {
-        if (m_next)
+        {}
+        
+        inline int
+        GetLow ()
+        {
+            return m_low;
+        }
+        
+        inline int
+        GetHigh ()
+        {
+            return m_high;
+        }
+        
+        inline void
+        SetLow (int L)
+        {
+            m_low = L;
+        }
+        
+        inline void
+        SetHigh (int H)
+        {
+            m_high = H;
+        }
+        
+        inline  int
+        GetSelfCount()
+        {
+            return GetHigh() - GetLow() + 1;
+        }
+        
+        int
+        GetCount()
+        {
+            int count = GetSelfCount();
+            if (m_next)
+                count += m_next->GetCount();
+            return count;
+        }
+        
+        inline SyntheticArrayRange*
+        GetNext()
+        {
+            return m_next;
+        }
+        
+        void
+        SetNext(SyntheticArrayRange* N)
+        {
+            if (m_next)
+                delete m_next;
+            m_next = N;
+        }
+        
+        void
+        SetNext(int L, int H)
+        {
+            if (m_next)
+                delete m_next;
+            m_next = new SyntheticArrayRange(L, H);
+        }
+        
+        void
+        SetNext(int L)
+        {
+            if (m_next)
+                delete m_next;
+            m_next = new SyntheticArrayRange(L);
+        }
+        
+        ~SyntheticArrayRange()
+        {
             delete m_next;
-        m_next = new SyntheticArrayRange(L);
-    }
-    
-    ~SyntheticArrayRange()
-    {
-        delete m_next;
-        m_next = NULL;
-    }
-    
-};
+            m_next = NULL;
+        }
+        
+    };
     
-class SyntheticArrayView : public SyntheticChildren
-{
-    SyntheticArrayRange m_head;
-    SyntheticArrayRange *m_tail;
-public:
     SyntheticArrayView(bool casc = false,
                        bool skipptr = false,
                        bool skipref = false) :
@@ -524,29 +497,7 @@
     }
     
     const int
-    GetRealIndexForIndex(int i)
-    {
-        if (i >= GetCount())
-            return -1;
-        
-        SyntheticArrayRange* ptr = &m_head;
-        
-        int residual = i;
-        
-        while(ptr && ptr != m_tail)
-        {
-            if (residual >= ptr->GetSelfCount())
-            {
-                residual -= ptr->GetSelfCount();
-                ptr = ptr->GetNext();
-            }
-            
-            return ptr->GetLow() + residual;
-        }
-        
-        return -1;
-        
-    }
+    GetRealIndexForIndex(int i);
     
     bool
     IsScripted()
@@ -592,20 +543,7 @@
         Update() {}
         
         virtual uint32_t
-        GetIndexOfChildWithName (const ConstString &name_cs)
-        {
-            const char* name_cstr = name_cs.GetCString();
-            if (*name_cstr != '[')
-                return UINT32_MAX;
-            std::string name(name_cstr+1);
-            if (name[name.size()-1] != ']')
-                return UINT32_MAX;
-            name = name.erase(name.size()-1,1);
-            int index = Args::StringToSInt32 (name.c_str(), -1);
-            if (index < 0)
-                return UINT32_MAX;
-            return index;
-        }
+        GetIndexOfChildWithName (const ConstString &name_cs);
         
         typedef lldb::SharedPtr<SyntheticChildrenFrontEnd>::Type SharedPointer;
         
@@ -616,6 +554,9 @@
     {
         return SyntheticChildrenFrontEnd::SharedPointer(new FrontEnd(this, backend));
     }
+private:
+    SyntheticArrayRange m_head;
+    SyntheticArrayRange *m_tail;
     
 };
 
@@ -635,15 +576,7 @@
                   bool skipref = false,
                   bool nochildren = true,
                   bool novalue = true,
-                  bool oneliner = false) :
-    m_cascades(casc),
-    m_skip_pointers(skipptr),
-    m_skip_references(skipref),
-    m_dont_show_children(nochildren),
-    m_dont_show_value(novalue),
-    m_show_members_oneliner(oneliner)
-    {
-    }
+                  bool oneliner = false);
     
     bool
     Cascades() const
@@ -707,11 +640,7 @@
                         bool nochildren = true,
                         bool novalue = true,
                         bool oneliner = false,
-                        std::string f = "") :
-    SummaryFormat(casc,skipptr,skipref,nochildren,novalue,oneliner),
-    m_format(f)
-    {
-    }
+                        std::string f = "");
     
     std::string
     GetFormat() const
@@ -745,12 +674,7 @@
                         bool novalue = true,
                         bool oneliner = false,
                         std::string fname = "",
-                        std::string pscri = "") :
-    SummaryFormat(casc,skipptr,skipref,nochildren,novalue,oneliner),
-    m_function_name(fname),
-    m_python_script(pscri)
-    {
-    }
+                        std::string pscri = "");
     
     std::string
     GetFunctionName() const

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Mon Aug 22 19:32:52 2011
@@ -115,39 +115,14 @@
     Get (ValueObject& valobj,
          lldb::SummaryFormatSP& entry,
          lldb::DynamicValueType use_dynamic,
-         uint32_t* reason = NULL)
-    {
-        if (!IsEnabled())
-            return false;
-        if (GetSummaryNavigator()->Get(valobj, entry, use_dynamic, reason))
-            return true;
-        bool regex = GetRegexSummaryNavigator()->Get(valobj, entry, use_dynamic, reason);
-        if (regex && reason)
-            *reason |= lldb::eFormatterChoiceCriterionRegularExpressionSummary;
-        return regex;
-    }
+         uint32_t* reason = NULL);
     
     bool
     Get (ValueObject& valobj,
          lldb::SyntheticChildrenSP& entry,
          lldb::DynamicValueType use_dynamic,
          uint32_t* reason = NULL);
-    
-    // just a shortcut for GetSummaryNavigator()->Clear; GetRegexSummaryNavigator()->Clear()
-    void
-    ClearSummaries ()
-    {
-        Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
-    }
-    
-    // just a shortcut for (GetSummaryNavigator()->Delete(name) || GetRegexSummaryNavigator()->Delete(name))
-    bool
-    DeleteSummaries (ConstString name)
-    {
-        return Delete(name, (eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary));
-    }
-    
-    
+        
     void
     Clear (FormatCategoryItems items = ALL_ITEM_TYPES);
     
@@ -275,19 +250,6 @@
         m_active_categories.push_front(category);
     }
     
-    class delete_matching_categories
-    {
-        lldb::FormatCategorySP ptr;
-    public:
-        delete_matching_categories(lldb::FormatCategorySP p) : ptr(p)
-        {}
-        
-        bool operator()(const lldb::FormatCategorySP& other)
-        {
-            return ptr.get() == other.get();
-        }
-    };
-    
     void
     Disable (KeyType category_name)
     {
@@ -329,22 +291,7 @@
                 FormatCategory::FormatCategoryItems items = FormatCategory::ALL_ITEM_TYPES,
                 bool only_enabled = true,
                 const char** matching_category = NULL,
-                FormatCategory::FormatCategoryItems* matching_type = NULL)
-    {
-        Mutex::Locker(m_map_mutex);
-        
-        MapIterator pos, end = m_map.end();
-        for (pos = m_map.begin(); pos != end; pos++)
-        {
-            if (pos->second->AnyMatches(type_name,
-                                        items,
-                                        only_enabled,
-                                        matching_category,
-                                        matching_type))
-                return true;
-        }
-        return false;
-    }
+                FormatCategory::FormatCategoryItems* matching_type = NULL);
     
     uint32_t
     GetCount ()
@@ -355,49 +302,28 @@
     bool
     Get (ValueObject& valobj,
          lldb::SummaryFormatSP& entry,
-         lldb::DynamicValueType use_dynamic)
-    {
-        Mutex::Locker(m_map_mutex);
-        
-        uint32_t reason_why;        
-        ActiveCategoriesIterator begin, end = m_active_categories.end();
-        
-        for (begin = m_active_categories.begin(); begin != end; begin++)
-        {
-            lldb::FormatCategorySP category = *begin;
-            lldb::SummaryFormatSP current_format;
-            if (!category->Get(valobj, current_format, use_dynamic, &reason_why))
-                continue;
-            entry = current_format;
-            return true;
-        }
-        return false;
-    }
+         lldb::DynamicValueType use_dynamic);
     
     bool
     Get (ValueObject& valobj,
          lldb::SyntheticChildrenSP& entry,
-         lldb::DynamicValueType use_dynamic)
+         lldb::DynamicValueType use_dynamic);
+    
+private:
+    
+    class delete_matching_categories
     {
-        Mutex::Locker(m_map_mutex);
-        
-        uint32_t reason_why;
-        
-        ActiveCategoriesIterator begin, end = m_active_categories.end();
+        lldb::FormatCategorySP ptr;
+    public:
+        delete_matching_categories(lldb::FormatCategorySP p) : ptr(p)
+        {}
         
-        for (begin = m_active_categories.begin(); begin != end; begin++)
+        bool operator()(const lldb::FormatCategorySP& other)
         {
-            lldb::FormatCategorySP category = *begin;
-            lldb::SyntheticChildrenSP current_format;
-            if (!category->Get(valobj, current_format, use_dynamic, &reason_why))
-                continue;
-            entry = current_format;
-            return true;
+            return ptr.get() == other.get();
         }
-        return false;
-    }
+    };
     
-private:
     Mutex m_map_mutex;
     IFormatChangeListener* listener;
     
@@ -425,14 +351,10 @@
 
 class FormatManager : public IFormatChangeListener
 {
-private:
-    
     typedef FormatNavigator<ConstString, ValueFormat> ValueNavigator;
-
     typedef ValueNavigator::MapType ValueMap;
     typedef FormatMap<ConstString, SummaryFormat> NamedSummariesMap;
     typedef CategoryMap::MapType::iterator CategoryMapIterator;
-
 public:
     
     typedef CategoryMap::CallbackType CategoryCallback;
@@ -498,20 +420,7 @@
     
     lldb::FormatCategorySP
     Category (const ConstString& category_name,
-              bool can_create = true)
-    {
-        if (!category_name)
-            return Category(m_default_category_name);
-        lldb::FormatCategorySP category;
-        if (m_categories_map.Get(category_name, category))
-            return category;
-        
-        if (!can_create)
-            return lldb::FormatCategorySP();
-        
-        m_categories_map.Add(category_name,lldb::FormatCategorySP(new FormatCategory(this, category_name.AsCString())));
-        return Category(category_name);
-    }
+              bool can_create = true);
     
     bool
     Get (ValueObject& valobj,
@@ -520,6 +429,7 @@
     {
         return m_categories_map.Get(valobj, entry, use_dynamic);
     }
+    
     bool
     Get (ValueObject& valobj,
          lldb::SyntheticChildrenSP& entry,

Modified: lldb/trunk/include/lldb/lldb-private-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-enumerations.h?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-private-enumerations.h Mon Aug 22 19:32:52 2011
@@ -207,11 +207,11 @@
 typedef enum FormatCategoryItem
 {
     eFormatCategoryItemSummary =         0x0001,
-    eFormatCategoryItemRegexSummary =    0x1001,
-    eFormatCategoryItemFilter =          0x0002,
-    eFormatCategoryItemRegexFilter =     0x1002,
-    eFormatCategoryItemSynth =           0x0004,
-    eFormatCategoryItemRegexSynth =      0x1004,
+    eFormatCategoryItemRegexSummary =    0x0002,
+    eFormatCategoryItemFilter =          0x0004,
+    eFormatCategoryItemRegexFilter =     0x0008,
+    eFormatCategoryItemSynth =           0x0010,
+    eFormatCategoryItemRegexSynth =      0x0020,
 } FormatCategoryItem;
 
 } // namespace lldb

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Mon Aug 22 19:32:52 2011
@@ -679,6 +679,4 @@
 return retval;
 }
 
-#undef RETURN_RETVAL
-
 %}

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Mon Aug 22 19:32:52 2011
@@ -627,7 +627,7 @@
         case 'n':
             m_name = new ConstString(option_arg);
             break;
-        case 's':
+        case 'o':
             m_python_script = std::string(option_arg);
             m_is_add_script = true;
             break;
@@ -1082,7 +1082,7 @@
     { LLDB_OPT_SET_ALL, false,  "regex", 'x', no_argument, NULL, 0, eArgTypeNone,    "Type names are actually regular expressions."},
     { LLDB_OPT_SET_1  , true, "inline-children", 'c', no_argument, NULL, 0, eArgTypeNone,    "If true, inline all child values into summary string."},
     { LLDB_OPT_SET_2  , true, "summary-string", 'f', required_argument, NULL, 0, eArgTypeSummaryString,    "Summary string used to display text and object contents."},
-    { LLDB_OPT_SET_3, false, "python-script", 's', required_argument, NULL, 0, eArgTypeName, "Give a one-liner Python script as part of the command."},
+    { LLDB_OPT_SET_3, false, "python-script", 'o', required_argument, NULL, 0, eArgTypeName, "Give a one-liner Python script as part of the command."},
     { LLDB_OPT_SET_3, false, "python-function", 'F', required_argument, NULL, 0, eArgTypeName, "Give the name of a Python function to use for this type."},
     { LLDB_OPT_SET_3, false, "input-python", 'P', no_argument, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."},
     { LLDB_OPT_SET_2 | LLDB_OPT_SET_3,   false, "expand", 'e', no_argument, NULL, 0, eArgTypeNone,    "Expand aggregate data types to show children on separate lines."},
@@ -1228,7 +1228,8 @@
         lldb::FormatCategorySP category;
         DataVisualization::Categories::Get(ConstString(m_options.m_category.c_str()), category);
         
-        bool delete_category = category->DeleteSummaries(typeCS);
+        bool delete_category = category->Delete(typeCS,
+                                                eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
         bool delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS);
         
         if (delete_category || delete_named)
@@ -1360,7 +1361,7 @@
             }
             else
                 DataVisualization::Categories::Get(ConstString(NULL), category);
-            category->ClearSummaries();
+            category->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
         }
         
         DataVisualization::NamedSummaryFormats::Clear();
@@ -3436,6 +3437,32 @@
         
         m_arguments.push_back (type_arg);
         
+        SetHelpLong(
+                    "Some examples of using this command.\n"
+                    "We use as reference the following snippet of code:\n"
+                    "\n"
+                    "class Foo {;\n"
+                    "    int a;\n"
+                    "    int b;\n"
+                    "    int c;\n"
+                    "    int d;\n"
+                    "    int e;\n"
+                    "    int f;\n"
+                    "    int g;\n"
+                    "    int h;\n"
+                    "    int i;\n"
+                    "} \n"
+                    "Typing:\n"
+                    "type filter add --child a -- child g Foo\n"
+                    "frame variable a_foo\n"
+                    "will produce an output where only a and b are displayed\n"
+                    "Other children of a_foo (b,c,d,e,f,h and i) are available by asking for them, as in:\n"
+                    "frame variable a_foo.b a_foo.c ... a_foo.i\n"
+                    "\n"
+                    "Use option --raw to frame variable prevails on the filter\n"
+                    "frame variable a_foo --raw\n"
+                    "shows all the children of a_foo (a thru i) as if no filter was defined\n"
+                    );        
     }
     
     ~CommandObjectTypeFilterAdd ()

Modified: lldb/trunk/source/Core/DataVisualization.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataVisualization.cpp?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataVisualization.cpp (original)
+++ lldb/trunk/source/Core/DataVisualization.cpp Mon Aug 22 19:32:52 2011
@@ -132,7 +132,7 @@
 void
 DataVisualization::Categories::Clear (ConstString &category)
 {
-    GetFormatManager().Category(category)->ClearSummaries();
+    GetFormatManager().Category(category)->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
 }
 
 void

Modified: lldb/trunk/source/Core/Debugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Debugger.cpp?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/source/Core/Debugger.cpp (original)
+++ lldb/trunk/source/Core/Debugger.cpp Mon Aug 22 19:32:52 2011
@@ -694,20 +694,13 @@
     }
 }
 
-#define IFERROR_PRINT_IT if (error.Fail()) \
-{ \
-    if (log) \
-        log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
-    break; \
-}
-
 static bool
-ScanFormatDescriptor(const char* var_name_begin,
-                     const char* var_name_end,
-                     const char** var_name_final,
-                     const char** percent_position,
-                     lldb::Format* custom_format,
-                     ValueObject::ValueObjectRepresentationStyle* val_obj_display)
+ScanFormatDescriptor (const char* var_name_begin,
+                      const char* var_name_end,
+                      const char** var_name_final,
+                      const char** percent_position,
+                      lldb::Format* custom_format,
+                      ValueObject::ValueObjectRepresentationStyle* val_obj_display)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
     *percent_position = ::strchr(var_name_begin,'%');
@@ -766,15 +759,15 @@
 }
 
 static bool
-ScanBracketedRange(const char* var_name_begin,
-                   const char* var_name_end,
-                   const char* var_name_final,
-                   const char** open_bracket_position,
-                   const char** separator_position,
-                   const char** close_bracket_position,
-                   const char** var_name_final_if_array_range,
-                   int64_t* index_lower,
-                   int64_t* index_higher)
+ScanBracketedRange (const char* var_name_begin,
+                    const char* var_name_end,
+                    const char* var_name_final,
+                    const char** open_bracket_position,
+                    const char** separator_position,
+                    const char** close_bracket_position,
+                    const char** var_name_final_if_array_range,
+                    int64_t* index_lower,
+                    int64_t* index_higher)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
     *open_bracket_position = ::strchr(var_name_begin,'[');
@@ -829,12 +822,12 @@
 
 
 static ValueObjectSP
-ExpandExpressionPath(ValueObject* valobj,
-                     StackFrame* frame,
-                     bool* do_deref_pointer,
-                     const char* var_name_begin,
-                     const char* var_name_final,
-                     Error& error)
+ExpandExpressionPath (ValueObject* valobj,
+                      StackFrame* frame,
+                      bool* do_deref_pointer,
+                      const char* var_name_begin,
+                      const char* var_name_final,
+                      Error& error)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
     StreamString sstring;
@@ -870,10 +863,10 @@
 }
 
 static ValueObjectSP
-ExpandIndexedExpression(ValueObject* valobj,
-                        uint32_t index,
-                        StackFrame* frame,
-                        bool deref_pointer)
+ExpandIndexedExpression (ValueObject* valobj,
+                         uint32_t index,
+                         StackFrame* frame,
+                         bool deref_pointer)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
     const char* ptr_deref_format = "[%d]";
@@ -1153,7 +1146,12 @@
                                     // to get to the target ValueObject
                                     Error error;
                                     target = target->Dereference(error).get();
-                                    IFERROR_PRINT_IT
+                                    if (error.Fail())
+                                    {
+                                        if (log)
+                                            log->Printf("ERROR: %s\n", error.AsCString("unknown")); \
+                                        break;
+                                    }
                                     do_deref_pointer = false;
                                 }
                                 

Modified: lldb/trunk/source/Core/FormatClasses.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatClasses.cpp?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatClasses.cpp (original)
+++ lldb/trunk/source/Core/FormatClasses.cpp Mon Aug 22 19:32:52 2011
@@ -30,6 +30,17 @@
 using namespace lldb;
 using namespace lldb_private;
 
+ValueFormat::ValueFormat (lldb::Format f,
+                          bool casc,
+                          bool skipptr,
+                          bool skipref) : 
+    m_cascades(casc),
+    m_skip_pointers(skipptr),
+    m_skip_references(skipref),
+    m_format (f)
+{
+}
+
 std::string
 ValueFormat::FormatObject(lldb::ValueObjectSP object)
 {
@@ -54,6 +65,39 @@
     }
 }
 
+SummaryFormat::SummaryFormat(bool casc,
+                             bool skipptr,
+                             bool skipref,
+                             bool nochildren,
+                             bool novalue,
+                             bool oneliner) :
+    m_cascades(casc),
+    m_skip_pointers(skipptr),
+    m_skip_references(skipref),
+    m_dont_show_children(nochildren),
+    m_dont_show_value(novalue),
+    m_show_members_oneliner(oneliner)
+{
+}
+
+StringSummaryFormat::StringSummaryFormat(bool casc,
+                                         bool skipptr,
+                                         bool skipref,
+                                         bool nochildren,
+                                         bool novalue,
+                                         bool oneliner,
+                                         std::string f) :
+    SummaryFormat(casc,
+                  skipptr,
+                  skipref,
+                  nochildren,
+                  novalue,
+                  oneliner),
+    m_format(f)
+{
+}
+
+
 std::string
 StringSummaryFormat::FormatObject(lldb::ValueObjectSP object)
 {
@@ -119,6 +163,26 @@
     return sstr.GetString();
 }
 
+ScriptSummaryFormat::ScriptSummaryFormat(bool casc,
+                                         bool skipptr,
+                                         bool skipref,
+                                         bool nochildren,
+                                         bool novalue,
+                                         bool oneliner,
+                                         std::string fname,
+                                         std::string pscri) :
+    SummaryFormat(casc,
+                  skipptr,
+                  skipref,
+                  nochildren,
+                  novalue,
+                  oneliner),
+    m_function_name(fname),
+    m_python_script(pscri)
+{
+}
+
+
 std::string
 ScriptSummaryFormat::FormatObject(lldb::ValueObjectSP object)
 {
@@ -245,6 +309,27 @@
         m_wrapper = (PyObject*)m_interpreter->CreateSyntheticScriptedProvider(m_python_class, m_backend);
 }
 
+lldb::ValueObjectSP
+SyntheticScriptProvider::FrontEnd::GetChildAtIndex (uint32_t idx, bool can_create)
+{
+    if (m_wrapper == NULL || m_interpreter == NULL)
+        return lldb::ValueObjectSP();
+    
+    PyObject* py_return = (PyObject*)m_interpreter->GetChildAtIndex(m_wrapper, idx);
+    if (py_return == NULL || py_return == Py_None)
+    {
+        Py_XDECREF(py_return);
+        return lldb::ValueObjectSP();
+    }
+    
+    lldb::SBValue *sb_ptr = m_interpreter->CastPyObjectToSBValue(py_return);
+    
+    if (py_return == NULL || sb_ptr == NULL)
+        return lldb::ValueObjectSP();
+    
+    return sb_ptr->m_opaque_sp;
+}
+
 std::string
 SyntheticScriptProvider::GetDescription()
 {
@@ -257,3 +342,43 @@
     
     return sstr.GetString();
 }
+
+const int
+SyntheticArrayView::GetRealIndexForIndex(int i)
+{
+    if (i >= GetCount())
+        return -1;
+    
+    SyntheticArrayRange* ptr = &m_head;
+    
+    int residual = i;
+    
+    while(ptr && ptr != m_tail)
+    {
+        if (residual >= ptr->GetSelfCount())
+        {
+            residual -= ptr->GetSelfCount();
+            ptr = ptr->GetNext();
+        }
+        
+        return ptr->GetLow() + residual;
+    }
+    
+    return -1;
+}
+
+uint32_t
+SyntheticArrayView::FrontEnd::GetIndexOfChildWithName (const ConstString &name_cs)
+{
+    const char* name_cstr = name_cs.GetCString();
+    if (*name_cstr != '[')
+        return UINT32_MAX;
+    std::string name(name_cstr+1);
+    if (name[name.size()-1] != ']')
+        return UINT32_MAX;
+    name = name.erase(name.size()-1,1);
+    int index = Args::StringToSInt32 (name.c_str(), -1);
+    if (index < 0)
+        return UINT32_MAX;
+    return index;
+}
\ No newline at end of file

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Mon Aug 22 19:32:52 2011
@@ -169,6 +169,22 @@
 {}
 
 bool
+FormatCategory::Get (ValueObject& valobj,
+                     lldb::SummaryFormatSP& entry,
+                     lldb::DynamicValueType use_dynamic,
+                     uint32_t* reason)
+{
+    if (!IsEnabled())
+        return false;
+    if (GetSummaryNavigator()->Get(valobj, entry, use_dynamic, reason))
+        return true;
+    bool regex = GetRegexSummaryNavigator()->Get(valobj, entry, use_dynamic, reason);
+    if (regex && reason)
+        *reason |= lldb::eFormatterChoiceCriterionRegularExpressionSummary;
+    return regex;
+}
+
+bool
 FormatCategory::Get(ValueObject& valobj,
                     lldb::SyntheticChildrenSP& entry,
                     lldb::DynamicValueType use_dynamic,
@@ -364,6 +380,73 @@
     return false;
 }
 
+bool
+CategoryMap::AnyMatches (ConstString type_name,
+                                    FormatCategory::FormatCategoryItems items,
+                                    bool only_enabled,
+                                    const char** matching_category,
+                                    FormatCategory::FormatCategoryItems* matching_type)
+{
+    Mutex::Locker(m_map_mutex);
+    
+    MapIterator pos, end = m_map.end();
+    for (pos = m_map.begin(); pos != end; pos++)
+    {
+        if (pos->second->AnyMatches(type_name,
+                                    items,
+                                    only_enabled,
+                                    matching_category,
+                                    matching_type))
+            return true;
+    }
+    return false;
+}
+
+bool
+CategoryMap::Get (ValueObject& valobj,
+                  lldb::SummaryFormatSP& entry,
+                  lldb::DynamicValueType use_dynamic)
+{
+    Mutex::Locker(m_map_mutex);
+    
+    uint32_t reason_why;        
+    ActiveCategoriesIterator begin, end = m_active_categories.end();
+    
+    for (begin = m_active_categories.begin(); begin != end; begin++)
+    {
+        lldb::FormatCategorySP category = *begin;
+        lldb::SummaryFormatSP current_format;
+        if (!category->Get(valobj, current_format, use_dynamic, &reason_why))
+            continue;
+        entry = current_format;
+        return true;
+    }
+    return false;
+}
+
+bool
+CategoryMap::Get (ValueObject& valobj,
+                  lldb::SyntheticChildrenSP& entry,
+                  lldb::DynamicValueType use_dynamic)
+{
+    Mutex::Locker(m_map_mutex);
+    
+    uint32_t reason_why;
+    
+    ActiveCategoriesIterator begin, end = m_active_categories.end();
+    
+    for (begin = m_active_categories.begin(); begin != end; begin++)
+    {
+        lldb::FormatCategorySP category = *begin;
+        lldb::SyntheticChildrenSP current_format;
+        if (!category->Get(valobj, current_format, use_dynamic, &reason_why))
+            continue;
+        entry = current_format;
+        return true;
+    }
+    return false;
+}
+
 void
 CategoryMap::LoopThrough(CallbackType callback, void* param)
 {
@@ -398,6 +481,23 @@
     }
 }
 
+lldb::FormatCategorySP
+FormatManager::Category (const ConstString& category_name,
+                         bool can_create)
+{
+    if (!category_name)
+        return Category(m_default_category_name);
+    lldb::FormatCategorySP category;
+    if (m_categories_map.Get(category_name, category))
+        return category;
+    
+    if (!can_create)
+        return lldb::FormatCategorySP();
+    
+    m_categories_map.Add(category_name,lldb::FormatCategorySP(new FormatCategory(this, category_name.AsCString())));
+    return Category(category_name);
+}
+
 lldb::Format
 FormatManager::GetSingleItemFormat(lldb::Format vector_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=138315&r1=138314&r2=138315&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 Mon Aug 22 19:32:52 2011
@@ -102,7 +102,7 @@
 
         # Add summaries to two different categories and check that we can switch
         self.runCmd("type summary add -f \"Width = ${var.w}, Height = ${var.h}\" Rectangle -w Category1")
-        self.runCmd("type summary add -s \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2")
+        self.runCmd("type summary add --python-script \"return 'Area = ' + str( int(valobj.GetChildMemberWithName('w').GetValue()) * int(valobj.GetChildMemberWithName('h').GetValue()) );\" Rectangle -w Category2")
 
         # check that enable A B is the same as enable B enable A
         self.runCmd("type category enable Category1 Category2")

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-globals/TestDataFormatterGlobals.py Mon Aug 22 19:32:52 2011
@@ -67,7 +67,7 @@
                     substrs = ['(Point *) g_point_pointer ='])
 
         # Test Python code on resulting SBValue
-        self.runCmd("type summary add -s \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point")
+        self.runCmd("type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point")
 
         self.expect("target variable g_point",
                     substrs = ['x='])

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-script/TestDataFormatterScript.py Mon Aug 22 19:32:52 2011
@@ -56,7 +56,7 @@
         # Set the script here to ease the formatting
         script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'Hello from Python, \' + a_val + \' time\'; return str + (\'!\' if a_val == \'1\' else \'s!\');'
 
-        self.runCmd("type summary add i_am_cool -s \"%s\"" % script)
+        self.runCmd("type summary add i_am_cool --python-script \"%s\"" % script)
 
         self.expect("frame variable one",
             substrs = ['Hello from Python',
@@ -81,7 +81,7 @@
         script = 'a = valobj.GetChildMemberWithName(\'integer\'); a_val = a.GetValue(); str = \'int says \' + a_val; return str;'
 
         # Check that changes in the script are immediately reflected
-        self.runCmd("type summary add i_am_cool -s \"%s\"" % script)
+        self.runCmd("type summary add i_am_cool --python-script \"%s\"" % script)
 
         self.expect("frame variable two",
                     substrs = ['int says 1'])
@@ -101,14 +101,14 @@
                                'and float says 2.71'])
 
         # Force a failure for pointers
-        self.runCmd("type summary add i_am_cool -p -s \"%s\"" % script)
+        self.runCmd("type summary add i_am_cool -p --python-script \"%s\"" % script)
 
         self.expect("frame variable twoptr", matching=False,
                     substrs = ['and float says 2.71'])
 
         script = 'return \'Python summary\'';
 
-        self.runCmd("type summary add --name test_summary -s \"%s\"" % script)
+        self.runCmd("type summary add --name test_summary --python-script \"%s\"" % script)
 
         # attach the Python named summary to someone
         self.runCmd("frame variable one --summary test_summary")
@@ -140,7 +140,7 @@
 
         # disable type summary for pointers, and make a Python regex summary
         self.runCmd("type summary add i_am_cool -p -f \"Text summary\"")
-        self.runCmd("type summary add -x cool -s \"%s\"" % script)
+        self.runCmd("type summary add -x cool --python-script \"%s\"" % script)
 
         # variables should stick to the type summary
         self.expect("frame variable one",

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py?rev=138315&r1=138314&r2=138315&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py Mon Aug 22 19:32:52 2011
@@ -90,7 +90,7 @@
                                'z = 8'])
         
         # Same output, but using Python
-        self.runCmd("type summary add BagOfInts -s \"return 'y='+valobj.GetChildMemberWithName('y').GetValue()\" -e")
+        self.runCmd("type summary add BagOfInts --python-script \"return 'y='+valobj.GetChildMemberWithName('y').GetValue()\" -e")
         self.expect('frame variable int_bag',
                     substrs = ['y=7',
                                'x = 6',





More information about the lldb-commits mailing list