[Lldb-commits] [lldb] r139201 - in /lldb/trunk: include/lldb/Core/DataVisualization.h include/lldb/Core/FormatManager.h include/lldb/Core/ValueObject.h source/Commands/CommandObjectType.cpp source/Core/DataVisualization.cpp source/Core/FormatManager.cpp source/Core/ValueObject.cpp

Enrico Granata granata.enrico at gmail.com
Tue Sep 6 15:59:55 PDT 2011


Author: enrico
Date: Tue Sep  6 17:59:55 2011
New Revision: 139201

URL: http://llvm.org/viewvc/llvm-project?rev=139201&view=rev
Log:
Refactoring of Get() methods in FormatManager/FormatCategory to have explicative names and return shared-pointers instead of bools
Reduced the amount of memory required to avoid loops in DumpPrintableRepresentation() from 32 bits down to 1 bit
 - Additionally, disallowed creating summary strings of the form ${var%S} which did nothing but cause endless loops by definition

Modified:
    lldb/trunk/include/lldb/Core/DataVisualization.h
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/Core/DataVisualization.cpp
    lldb/trunk/source/Core/FormatManager.cpp
    lldb/trunk/source/Core/ValueObject.cpp

Modified: lldb/trunk/include/lldb/Core/DataVisualization.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DataVisualization.h?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/DataVisualization.h (original)
+++ lldb/trunk/include/lldb/Core/DataVisualization.h Tue Sep  6 17:59:55 2011
@@ -48,8 +48,8 @@
     class ValueFormats
     {
     public:
-        static bool
-        Get (ValueObject& valobj, lldb::DynamicValueType use_dynamic, lldb::ValueFormatSP &entry);
+        static lldb::ValueFormatSP
+        Get (ValueObject& valobj, lldb::DynamicValueType use_dynamic);
         
         static void
         Add (const ConstString &type, const lldb::ValueFormatSP &entry);
@@ -67,14 +67,13 @@
         GetCount ();
     };
     
-    static bool
+    static lldb::SummaryFormatSP
     GetSummaryFormat(ValueObject& valobj,
-                     lldb::DynamicValueType use_dynamic,
-                     lldb::SummaryFormatSP& entry);
-    static bool
+                     lldb::DynamicValueType use_dynamic);
+    
+    static lldb::SyntheticChildrenSP
     GetSyntheticChildren(ValueObject& valobj,
-                         lldb::DynamicValueType use_dynamic,
-                         lldb::SyntheticChildrenSP& entry);
+                         lldb::DynamicValueType use_dynamic);
     
     static bool
     AnyMatches(ConstString type_name,

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Tue Sep  6 17:59:55 2011
@@ -299,15 +299,13 @@
         return m_map.size();
     }
     
-    bool
-    Get (ValueObject& valobj,
-         lldb::SummaryFormatSP& entry,
+    lldb::SummaryFormatSP
+    GetSummaryFormat (ValueObject& valobj,
          lldb::DynamicValueType use_dynamic);
     
-    bool
-    Get (ValueObject& valobj,
-         lldb::SyntheticChildrenSP& entry,
-         lldb::DynamicValueType use_dynamic);
+    lldb::SyntheticChildrenSP
+    GetSyntheticChildren (ValueObject& valobj,
+                          lldb::DynamicValueType use_dynamic);
     
 private:
     
@@ -422,20 +420,18 @@
     GetCategory (const ConstString& category_name,
                  bool can_create = true);
     
-    bool
-    Get (ValueObject& valobj,
-         lldb::SummaryFormatSP& entry,
-         lldb::DynamicValueType use_dynamic)
+    lldb::SummaryFormatSP
+    GetSummaryFormat (ValueObject& valobj,
+                      lldb::DynamicValueType use_dynamic)
     {
-        return m_categories_map.Get(valobj, entry, use_dynamic);
+        return m_categories_map.GetSummaryFormat(valobj, use_dynamic);
     }
     
-    bool
-    Get (ValueObject& valobj,
-         lldb::SyntheticChildrenSP& entry,
-         lldb::DynamicValueType use_dynamic)
+    lldb::SyntheticChildrenSP
+    GetSyntheticChildren (ValueObject& valobj,
+                          lldb::DynamicValueType use_dynamic)
     {
-        return m_categories_map.Get(valobj, entry, use_dynamic);
+        return m_categories_map.GetSyntheticChildren(valobj, use_dynamic);
     }
     
     bool

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Tue Sep  6 17:59:55 2011
@@ -920,6 +920,7 @@
         m_forced_summary_format = format;
         m_user_id_of_forced_summary = m_update_point.GetModID();
         m_summary_str.clear();
+        m_trying_summary_already = false;
     }
     
     lldb::SummaryFormatSP
@@ -949,6 +950,42 @@
             return m_forced_summary_format;
         return m_last_summary_format;
     }
+    
+    void
+    SetSummaryFormat(lldb::SummaryFormatSP format)
+    {
+        m_last_summary_format = format;
+        m_summary_str.clear();
+        m_trying_summary_already = false;
+    }
+    
+    void
+    SetValueFormat(lldb::ValueFormatSP format)
+    {
+        m_last_value_format = format;
+        m_value_str.clear();
+    }
+    
+    lldb::ValueFormatSP
+    GetValueFormat()
+    {
+        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
+        return m_last_value_format;
+    }
+    
+    void
+    SetSyntheticChildren(lldb::SyntheticChildrenSP synth)
+    {
+        m_last_synthetic_filter = synth;
+        m_synthetic_value = NULL;
+    }
+    
+    lldb::SyntheticChildrenSP
+    GetSyntheticChildren()
+    {
+        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
+        return m_last_synthetic_filter;
+    }
 
     // Use GetParent for display purposes, but if you want to tell the parent to update itself
     // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
@@ -1012,13 +1049,15 @@
                                         // as a shared pointer to any of them has been handed out.  Shared pointers to
                                         // value objects must always be made with the GetSP method.
 
-    std::vector<ValueObject *> m_children;
+    std::vector<ValueObject *>           m_children;
     std::map<ConstString, ValueObject *> m_synthetic_children;
-    ValueObject *m_dynamic_value;
-    ValueObject *m_synthetic_value;
+    
+    ValueObject*                         m_dynamic_value;
+    ValueObject*                         m_synthetic_value;
+    ValueObject*                         m_deref_valobj;
+    
     lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
                                              // as an independent ValueObjectConstResult, which isn't managed by us.
-    ValueObject *m_deref_valobj;
 
     lldb::Format                m_format;
     uint32_t                    m_last_format_mgr_revision;
@@ -1028,6 +1067,7 @@
     lldb::ValueFormatSP         m_last_value_format;
     lldb::SyntheticChildrenSP   m_last_synthetic_filter;
     ProcessModID                m_user_id_of_forced_summary;
+    AddressType                 m_address_type_of_ptr_or_ref_children;
     
     bool                m_value_is_valid:1,
                         m_value_did_change:1,
@@ -1037,12 +1077,8 @@
                         m_is_array_item_for_pointer:1,
                         m_is_bitfield_for_scalar:1,
                         m_is_expression_path_child:1,
-                        m_is_child_at_offset:1;
-    
-    // used to prevent endless looping into GetPrintableRepresentation()
-    uint32_t            m_dump_printable_counter;
-    
-    AddressType         m_address_type_of_ptr_or_ref_children;
+                        m_is_child_at_offset:1,
+                        m_trying_summary_already:1; // used to prevent endless recursion in printing summaries
     
     friend class ClangExpressionDeclMap;  // For GetValue
     friend class ClangExpressionVariable; // For SetName

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Sep  6 17:59:55 2011
@@ -873,6 +873,14 @@
     
     const char* format_cstr = (m_options.m_one_liner ? "" : m_options.m_format_string.c_str());
     
+    // ${var%S} is an endless recursion, prevent it
+    if (strcmp(format_cstr, "${var%S}") == 0)
+    {
+        result.AppendError("recursive summary not allowed");
+        result.SetStatus(eReturnStatusFailed);
+        return false;
+    }
+    
     Error error;
     
     lldb::SummaryFormatSP entry(new StringSummaryFormat(m_options.m_cascade,

Modified: lldb/trunk/source/Core/DataVisualization.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataVisualization.cpp?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataVisualization.cpp (original)
+++ lldb/trunk/source/Core/DataVisualization.cpp Tue Sep  6 17:59:55 2011
@@ -38,10 +38,12 @@
     return GetFormatManager().GetCurrentRevision();
 }
 
-bool
-DataVisualization::ValueFormats::Get (ValueObject& valobj, lldb::DynamicValueType use_dynamic, lldb::ValueFormatSP &entry)
+lldb::ValueFormatSP
+DataVisualization::ValueFormats::Get (ValueObject& valobj, lldb::DynamicValueType use_dynamic)
 {
-    return GetFormatManager().GetValueNavigator().Get(valobj,entry, use_dynamic);
+    lldb::ValueFormatSP entry;
+    GetFormatManager().GetValueNavigator().Get(valobj, entry, use_dynamic);
+    return entry;
 }
 
 void
@@ -74,19 +76,18 @@
     return GetFormatManager().GetValueNavigator().GetCount();
 }
 
-bool
+lldb::SummaryFormatSP
 DataVisualization::GetSummaryFormat (ValueObject& valobj,
-                                     lldb::DynamicValueType use_dynamic,
-                                     lldb::SummaryFormatSP& entry)
+                                     lldb::DynamicValueType use_dynamic)
 {
-    return GetFormatManager().Get(valobj, entry, use_dynamic);
+    return GetFormatManager().GetSummaryFormat(valobj, use_dynamic);
 }
-bool
+
+lldb::SyntheticChildrenSP
 DataVisualization::GetSyntheticChildren (ValueObject& valobj,
-                                         lldb::DynamicValueType use_dynamic,
-                                         lldb::SyntheticChildrenSP& entry)
+                                         lldb::DynamicValueType use_dynamic)
 {
-    return GetFormatManager().Get(valobj, entry, use_dynamic);
+    return GetFormatManager().GetSyntheticChildren(valobj, use_dynamic);
 }
 
 bool

Modified: lldb/trunk/source/Core/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatManager.cpp?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatManager.cpp (original)
+++ lldb/trunk/source/Core/FormatManager.cpp Tue Sep  6 17:59:55 2011
@@ -402,10 +402,9 @@
     return false;
 }
 
-bool
-CategoryMap::Get (ValueObject& valobj,
-                  lldb::SummaryFormatSP& entry,
-                  lldb::DynamicValueType use_dynamic)
+lldb::SummaryFormatSP
+CategoryMap::GetSummaryFormat (ValueObject& valobj,
+                               lldb::DynamicValueType use_dynamic)
 {
     Mutex::Locker(m_map_mutex);
     
@@ -418,16 +417,14 @@
         lldb::SummaryFormatSP current_format;
         if (!category->Get(valobj, current_format, use_dynamic, &reason_why))
             continue;
-        entry = current_format;
-        return true;
+        return current_format;
     }
-    return false;
+    return lldb::SummaryFormatSP();
 }
 
-bool
-CategoryMap::Get (ValueObject& valobj,
-                  lldb::SyntheticChildrenSP& entry,
-                  lldb::DynamicValueType use_dynamic)
+lldb::SyntheticChildrenSP
+CategoryMap::GetSyntheticChildren (ValueObject& valobj,
+                                   lldb::DynamicValueType use_dynamic)
 {
     Mutex::Locker(m_map_mutex);
     
@@ -441,10 +438,9 @@
         lldb::SyntheticChildrenSP current_format;
         if (!category->Get(valobj, current_format, use_dynamic, &reason_why))
             continue;
-        entry = current_format;
-        return true;
+        return current_format;
     }
-    return false;
+    return lldb::SyntheticChildrenSP();
 }
 
 void

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=139201&r1=139200&r2=139201&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Tue Sep  6 17:59:55 2011
@@ -94,8 +94,8 @@
     m_is_bitfield_for_scalar(false),
     m_is_expression_path_child(false),
     m_is_child_at_offset(false),
-    m_dump_printable_counter(0),
-    m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid)
+    m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
+    m_trying_summary_already(false)
 {
     m_manager->ManageObject(this);
 }
@@ -140,8 +140,8 @@
     m_is_bitfield_for_scalar(false),
     m_is_expression_path_child(false),
     m_is_child_at_offset(false),
-    m_dump_printable_counter(0),
-    m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type)
+    m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
+    m_trying_summary_already(false)
 {
     m_manager = new ValueObjectManager();
     m_manager->ManageObject (this);
@@ -241,30 +241,21 @@
     if (HasCustomSummaryFormat() && m_update_point.GetModID() != m_user_id_of_forced_summary)
     {
         ClearCustomSummaryFormat();
-        m_summary_str.clear();
+        
         any_change = true;
     }
+    
     if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()) ||
           m_last_format_mgr_dynamic != use_dynamic)
     {
-        if (m_last_summary_format.get())
-            m_last_summary_format.reset((StringSummaryFormat*)NULL);
-        if (m_last_value_format.get())
-            m_last_value_format.reset(/*(ValueFormat*)NULL*/);
-        if (m_last_synthetic_filter.get())
-            m_last_synthetic_filter.reset(/*(SyntheticFilter*)NULL*/);
-
-        m_synthetic_value = NULL;
-        
-        any_change = true;
-        DataVisualization::ValueFormats::Get(*this, eNoDynamicValues, m_last_value_format);
-        DataVisualization::GetSummaryFormat(*this, use_dynamic, m_last_summary_format);
-        DataVisualization::GetSyntheticChildren(*this, use_dynamic, m_last_synthetic_filter);
+        SetValueFormat(DataVisualization::ValueFormats::Get(*this, eNoDynamicValues));
+        SetSummaryFormat(DataVisualization::GetSummaryFormat(*this, use_dynamic));
+        SetSyntheticChildren(DataVisualization::GetSyntheticChildren(*this, use_dynamic));
 
         m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
         m_last_format_mgr_dynamic = use_dynamic;
-
-        ClearUserVisibleData();
+        
+        any_change = true;
     }
     
     return any_change;
@@ -1122,8 +1113,6 @@
                                         Format custom_format)
 {
 
-    RefCounter ref(&m_dump_printable_counter);
-    
     if (custom_format != eFormatInvalid)
         SetFormat(custom_format);
     
@@ -1136,8 +1125,15 @@
             return_value = GetValueAsCString();
             break;
         case eDisplaySummary:
-            return_value = GetSummaryAsCString();
-            break;
+            if (m_trying_summary_already)
+                return_value = NULL;
+            else
+            {
+                m_trying_summary_already = true;
+                return_value = GetSummaryAsCString();
+                m_trying_summary_already = false;
+                break;
+            }
         case eDisplayLanguageSpecific:
             return_value = GetObjectDescription();
             break;
@@ -1159,20 +1155,17 @@
             break;
     }
     
-    // this code snippet might lead to endless recursion, thus we use a RefCounter here to
-    // check that we are not looping endlessly
-    if (!return_value && (m_dump_printable_counter < 3))
+    if (!return_value)
     {
-        // try to pick the other choice
         if (val_obj_display == eDisplayValue)
-            return_value = GetSummaryAsCString();
+            return_value = GetSummaryAsCString();        
         else if (val_obj_display == eDisplaySummary)
         {
             if (ClangASTContext::IsAggregateType (GetClangType()) == true)
             {
                 // this thing has no value, and it seems to have no summary
                 // some combination of unitialized data and other factors can also
-                // raise this condition, so let's print a nice generic error message
+                // raise this condition, so let's print a nice generic description
                 {
                     alloc_mem.resize(684);
                     return_value = &alloc_mem[0];
@@ -3704,6 +3697,7 @@
     m_value_str.clear();
     m_summary_str.clear();
     m_object_desc_str.clear();
+    m_trying_summary_already = false;
 }
 
 SymbolContextScope *





More information about the lldb-commits mailing list