[Lldb-commits] [lldb] r138020 - in /lldb/trunk: include/lldb/Core/FormatManager.h include/lldb/Core/ValueObject.h include/lldb/Interpreter/ScriptInterpreter.h source/Commands/CommandObjectType.cpp source/Commands/CommandObjectType.h source/Core/FormatManager.cpp source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py

Enrico Granata granata.enrico at gmail.com
Thu Aug 18 18:14:49 PDT 2011


Author: enrico
Date: Thu Aug 18 20:14:49 2011
New Revision: 138020

URL: http://llvm.org/viewvc/llvm-project?rev=138020&view=rev
Log:
Third round of code cleanups:
 - reorganizing the PTS (Partial Template Specializations) in FormatManager.h
 - applied a patch by Filipe Cabecinhas to make LLDB compile with GCC
Functional changes:
 - fixed an issue where command type summary add for type "struct Foo" would not match any types.
   currently, "struct" will be stripped off and type "Foo" will be matched.
   similar behavior occurs for class, enum and union specifiers.

Modified:
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Commands/CommandObjectType.h
    lldb/trunk/source/Core/FormatManager.cpp
    lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Thu Aug 18 20:14:49 2011
@@ -79,6 +79,35 @@
     
 };
     
+// if the user tries to add formatters for, say, "struct Foo"
+// those will not match any type because of the way we strip qualifiers from typenames
+// this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
+// and strips the unnecessary qualifier
+static ConstString
+GetValidTypeName_Impl(const ConstString& type)
+{
+    int strip_len = 0;
+    
+    if (type == false)
+        return type;
+    
+    const char* type_cstr = type.AsCString();
+    
+    if ( ::strstr(type_cstr, "class ") == type_cstr)
+        strip_len = 6;
+    if ( ::strstr(type_cstr, "enum ") == type_cstr)
+        strip_len = 5;
+    if ( ::strstr(type_cstr, "struct ") == type_cstr)
+        strip_len = 7;
+    if ( ::strstr(type_cstr, "union ") == type_cstr)
+        strip_len = 6;
+    
+    if (strip_len == 0)
+        return type;
+    
+    return ConstString(type_cstr + strip_len);
+}
+    
 template<typename KeyType, typename ValueType>
 class FormatNavigator;
 
@@ -170,7 +199,7 @@
         return m_map.size();
     }
     
-private:
+protected:
     MapType m_map;    
     Mutex m_map_mutex;
     IFormatChangeListener* listener;
@@ -195,20 +224,19 @@
 template<typename KeyType, typename ValueType>
 class FormatNavigator
 {
-private:
+protected:
     typedef FormatMap<KeyType,ValueType> BackEndType;
     
-    BackEndType m_format_map;
-    
-    std::string m_name;
-        
+    template<typename, typename>
+    struct Types { };
+
 public:
     typedef typename BackEndType::MapType MapType;
     typedef typename MapType::iterator MapIterator;
     typedef typename MapType::key_type MapKeyType;
     typedef typename MapType::mapped_type MapValueType;
     typedef typename BackEndType::CallbackType CallbackType;
-    
+        
     typedef typename lldb::SharedPtr<FormatNavigator<KeyType, ValueType> >::Type SharedPointer;
     
     friend class FormatCategory;
@@ -224,15 +252,13 @@
     void
     Add (const MapKeyType &type, const MapValueType& entry)
     {
-        m_format_map.Add(type,entry);
+        Add_Impl(type, entry, Types<KeyType,ValueType>());
     }
     
-    // using ConstString instead of MapKeyType is necessary here
-    // to make the partial template specializations below work
     bool
     Delete (ConstString type)
     {
-        return m_format_map.Delete(type);
+        return Delete_Impl(type, Types<KeyType, ValueType>());
     }
         
     bool
@@ -270,19 +296,88 @@
     {
         return m_format_map.GetCount();
     }
+    
+protected:
         
-private:
+    BackEndType m_format_map;
+    
+    std::string m_name;
     
     DISALLOW_COPY_AND_ASSIGN(FormatNavigator);
     
     ConstString m_id_cs;
-    
-    // using ConstString instead of MapKeyType is necessary here
-    // to make the partial template specializations below work
+                           
+    template<typename K, typename V>
+    void
+    Add_Impl (const MapKeyType &type, const MapValueType& entry, Types<K,V>)
+    {
+       m_format_map.Add(type,entry);
+    }
+
+    template<typename V>
+    void Add_Impl (const ConstString &type, const MapValueType& entry, Types<ConstString,V>)
+    {
+       m_format_map.Add(GetValidTypeName_Impl(type), entry);
+    }
+
+    template<typename K, typename V>
+    bool
+    Delete_Impl (ConstString type, Types<K,V>)
+    {
+       return m_format_map.Delete(type);
+    }
+
+    template<typename V>
+    bool
+    Delete_Impl (ConstString type, Types<lldb::RegularExpressionSP,V>)
+    {
+       Mutex& x_mutex = m_format_map.mutex();
+        lldb_private::Mutex::Locker locker(x_mutex);
+       MapIterator pos, end = m_format_map.map().end();
+       for (pos = m_format_map.map().begin(); pos != end; pos++)
+       {
+           lldb::RegularExpressionSP regex = pos->first;
+           if ( ::strcmp(type.AsCString(),regex->GetText()) == 0)
+           {
+               m_format_map.map().erase(pos);
+               if (m_format_map.listener)
+                   m_format_map.listener->Changed();
+               return true;
+           }
+       }
+       return false;
+    }    
+
+    template<typename K, typename V>
+    bool
+    Get_Impl (ConstString type, MapValueType& entry, Types<K,V>)
+    {
+       return m_format_map.Get(type, entry);
+    }
+
+    template<typename V>
+    bool
+    Get_Impl (ConstString key, MapValueType& value, Types<lldb::RegularExpressionSP,V>)
+    {
+        Mutex& x_mutex = m_format_map.mutex();
+        lldb_private::Mutex::Locker locker(x_mutex);
+       MapIterator pos, end = m_format_map.map().end();
+       for (pos = m_format_map.map().begin(); pos != end; pos++)
+       {
+           lldb::RegularExpressionSP regex = pos->first;
+           if (regex->Execute(key.AsCString()))
+           {
+               value = pos->second;
+               return true;
+           }
+       }
+       return false;
+    }
+
     bool
     Get (ConstString type, MapValueType& entry)
     {
-        return m_format_map.Get(type, entry);
+        return Get_Impl(type, entry, Types<KeyType,ValueType>());
     }
     
     bool Get_ObjC(ValueObject& valobj,
@@ -577,30 +672,6 @@
         return false;
     }
 };
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Get(ConstString key, lldb::SummaryFormatSP& value);
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Delete(ConstString type);
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Get(ConstString key, SyntheticFilter::SharedPointer& value);
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Delete(ConstString type);
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Get(ConstString key, SyntheticFilter::SharedPointer& value);
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Delete(ConstString type);
     
 class CategoryMap;
     
@@ -633,7 +704,7 @@
         eFilter =          0x0002,
         eRegexFilter =     0x1002,
         eSynth =           0x0004,
-        eRegexSynth =      0x1004,
+        eRegexSynth =      0x1004
     };
     
     typedef uint16_t FormatCategoryItems;
@@ -1166,6 +1237,13 @@
     static const char *
     GetFormatAsCString (lldb::Format format);
     
+    // if the user tries to add formatters for, say, "struct Foo"
+    // those will not match any type because of the way we strip qualifiers from typenames
+    // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
+    // and strips the unnecessary qualifier
+    static ConstString
+    GetValidTypeName (const ConstString& type);
+    
     // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item
     // this method returns it, or eFormatInvalid if vector_format is not a vectorOf
     static lldb::Format

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Thu Aug 18 20:14:49 2011
@@ -79,7 +79,7 @@
         eDisplaySummary,
         eDisplayLanguageSpecific,
         eDisplayLocation,
-        eDisplayChildrenCount,
+        eDisplayChildrenCount
     };
     
     enum ExpressionPathScanEndReason

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Thu Aug 18 20:14:49 2011
@@ -66,7 +66,7 @@
         eFloat,
         eDouble,
         eChar,
-        eCharStrOrNone,
+        eCharStrOrNone
     } ReturnType;
 
 

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Thu Aug 18 20:14:49 2011
@@ -3366,7 +3366,7 @@
     enum FilterFormatType
     {
         eRegularFilter,
-        eRegexFilter,
+        eRegexFilter
     };
     
     bool

Modified: lldb/trunk/source/Commands/CommandObjectType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.h?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.h (original)
+++ lldb/trunk/source/Commands/CommandObjectType.h Thu Aug 18 20:14:49 2011
@@ -187,7 +187,7 @@
     {
         eRegularSummary,
         eRegexSummary,
-        eNamedSummary,
+        eNamedSummary
     };
 
     CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter);
@@ -330,7 +330,7 @@
     enum SynthFormatType
     {
         eRegularSynth,
-        eRegexSynth,
+        eRegexSynth
     };
     
     CommandObjectTypeSynthAdd (CommandInterpreter &interpreter);

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Thu Aug 18 20:14:49 2011
@@ -154,120 +154,6 @@
     return NULL;
 }
 
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Get(ConstString key, lldb::SummaryFormatSP& value)
-{
-    Mutex::Locker(m_format_map.mutex());
-    MapIterator pos, end = m_format_map.map().end();
-    for (pos = m_format_map.map().begin(); pos != end; pos++)
-    {
-        lldb::RegularExpressionSP regex = pos->first;
-        if (regex->Execute(key.AsCString()))
-        {
-            value = pos->second;
-            return true;
-        }
-    }
-    return false;
-}
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SummaryFormat>::Delete(ConstString type)
-{
-    Mutex::Locker(m_format_map.mutex());
-    MapIterator pos, end = m_format_map.map().end();
-    for (pos = m_format_map.map().begin(); pos != end; pos++)
-    {
-        lldb::RegularExpressionSP regex = pos->first;
-        if ( ::strcmp(type.AsCString(),regex->GetText()) == 0)
-        {
-            m_format_map.map().erase(pos);
-            if (m_format_map.listener)
-                m_format_map.listener->Changed();
-            return true;
-        }
-    }
-    return false;
-}
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Get(ConstString key, SyntheticFilter::SharedPointer& value)
-{
-    Mutex::Locker(m_format_map.mutex());
-    MapIterator pos, end = m_format_map.map().end();
-    for (pos = m_format_map.map().begin(); pos != end; pos++)
-    {
-        lldb::RegularExpressionSP regex = pos->first;
-        if (regex->Execute(key.AsCString()))
-        {
-            value = pos->second;
-            return true;
-        }
-    }
-    return false;
-}
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticFilter>::Delete(ConstString type)
-{
-    Mutex::Locker(m_format_map.mutex());
-    MapIterator pos, end = m_format_map.map().end();
-    for (pos = m_format_map.map().begin(); pos != end; pos++)
-    {
-        lldb::RegularExpressionSP regex = pos->first;
-        if ( ::strcmp(type.AsCString(),regex->GetText()) == 0)
-        {
-            m_format_map.map().erase(pos);
-            if (m_format_map.listener)
-                m_format_map.listener->Changed();
-            return true;
-        }
-    }
-    return false;
-}
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Get(ConstString key, SyntheticFilter::SharedPointer& value)
-{
-    Mutex::Locker(m_format_map.mutex());
-    MapIterator pos, end = m_format_map.map().end();
-    for (pos = m_format_map.map().begin(); pos != end; pos++)
-    {
-        lldb::RegularExpressionSP regex = pos->first;
-        if (regex->Execute(key.AsCString()))
-        {
-            value = pos->second;
-            return true;
-        }
-    }
-    return false;
-}
-
-template<>
-bool
-FormatNavigator<lldb::RegularExpressionSP, SyntheticScriptProvider>::Delete(ConstString type)
-{
-    Mutex::Locker(m_format_map.mutex());
-    MapIterator pos, end = m_format_map.map().end();
-    for (pos = m_format_map.map().begin(); pos != end; pos++)
-    {
-        lldb::RegularExpressionSP regex = pos->first;
-        if ( ::strcmp(type.AsCString(),regex->GetText()) == 0)
-        {
-            m_format_map.map().erase(pos);
-            if (m_format_map.listener)
-                m_format_map.listener->Changed();
-            return true;
-        }
-    }
-    return false;
-}
-
 FormatCategory::FormatCategory(IFormatChangeListener* clist,
                                std::string name) :
     m_summary_nav(new SummaryNavigator("summary",clist)),
@@ -486,6 +372,12 @@
     }
 }
 
+ConstString
+FormatManager::GetValidTypeName (const ConstString& type)
+{
+    return ::GetValidTypeName_Impl(type);
+}
+
 FormatManager::FormatManager() : 
     m_value_nav("format",this),
     m_named_summaries_map(this),
@@ -574,7 +466,6 @@
     
 }
 
-
 static FormatManager&
 GetFormatManager()
 {
@@ -603,7 +494,7 @@
 void
 DataVisualization::ValueFormats::Add(const ConstString &type, const lldb::ValueFormatSP &entry)
 {
-    GetFormatManager().Value().Add(type,entry);
+    GetFormatManager().Value().Add(FormatManager::GetValidTypeName(type),entry);
 }
 
 bool
@@ -731,7 +622,7 @@
 void
 DataVisualization::NamedSummaryFormats::Add(const ConstString &type, const lldb::SummaryFormatSP &entry)
 {
-    GetFormatManager().NamedSummary().Add(type,entry);
+    GetFormatManager().NamedSummary().Add(FormatManager::GetValidTypeName(type),entry);
 }
 
 bool

Modified: lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h (original)
+++ lldb/trunk/source/Plugins/Process/MacOSX-Kernel/CommunicationKDP.h Thu Aug 18 20:14:49 2011
@@ -62,12 +62,12 @@
         KDP_WRITEMEM64,
         KDP_BREAKPOINT_SET64,
         KDP_BREAKPOINT_REMOVE64,
-        KDP_KERNELVERSION,
+        KDP_KERNELVERSION
     } CommandType;
 
     enum 
     {
-        KDP_FEATURE_BP = (1u << 0),
+        KDP_FEATURE_BP = (1u << 0)
     };
 
     typedef enum

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp Thu Aug 18 20:14:49 2011
@@ -98,7 +98,7 @@
     fpu_fiseg = fpu_cs,
     fpu_fioff = fpu_ip,
     fpu_foseg = fpu_ds,
-    fpu_fooff = fpu_dp,
+    fpu_fooff = fpu_dp
 };
 
 enum gcc_dwarf_regnums
@@ -143,7 +143,7 @@
     gcc_dwarf_fpu_stmm4,
     gcc_dwarf_fpu_stmm5,
     gcc_dwarf_fpu_stmm6,
-    gcc_dwarf_fpu_stmm7,
+    gcc_dwarf_fpu_stmm7
 
 };
 
@@ -205,7 +205,7 @@
     gdb_fpu_xmm13   =  53,
     gdb_fpu_xmm14   =  54,
     gdb_fpu_xmm15   =  55,
-    gdb_fpu_mxcsr   =  56,
+    gdb_fpu_mxcsr   =  56
 };
 
 RegisterContextDarwin_x86_64::RegisterContextDarwin_x86_64 (Thread &thread, uint32_t concrete_frame_idx) :

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py?rev=138020&r1=138019&r2=138020&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-cpp/TestDataFormatterCpp.py Thu Aug 18 20:14:49 2011
@@ -202,6 +202,34 @@
         self.expect("frame variable the_coolest_guy",
             substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
 
+        # check that unwanted type specifiers are removed
+        self.runCmd("type summary delete i_am_cool")
+        self.runCmd("type summary add -f \"goofy\" \"class i_am_cool\"")
+        self.expect("frame variable the_coolest_guy",
+                substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
+
+        self.runCmd("type summary delete i_am_cool")
+        self.runCmd("type summary add -f \"goofy\" \"enum i_am_cool\"")
+        self.expect("frame variable the_coolest_guy",
+                    substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
+
+        self.runCmd("type summary delete i_am_cool")
+        self.runCmd("type summary add -f \"goofy\" \"struct i_am_cool\"")
+        self.expect("frame variable the_coolest_guy",
+                    substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
+
+        self.runCmd("type summary delete i_am_cool")
+        self.runCmd("type summary add -f \"goofy\" \"union i_am_cool\"")
+        self.expect("frame variable the_coolest_guy",
+                    substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
+
+        # but that not *every* specifier is removed
+        self.runCmd("type summary delete i_am_cool")
+        self.runCmd("type summary add -f \"goofy\" \"wrong i_am_cool\"")
+        self.expect("frame variable the_coolest_guy", matching=False,
+                    substrs = ['(i_am_cooler) the_coolest_guy = goofy'])
+
+
 if __name__ == '__main__':
     import atexit
     lldb.SBDebugger.Initialize()





More information about the lldb-commits mailing list