[Lldb-commits] [lldb] r248315 - Move the logic to post-process dynamic types for ValueObject purposes from the ValueObjects to the LanguageRuntime plugins

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 22 12:45:52 PDT 2015


Author: enrico
Date: Tue Sep 22 14:45:52 2015
New Revision: 248315

URL: http://llvm.org/viewvc/llvm-project?rev=248315&view=rev
Log:
Move the logic to post-process dynamic types for ValueObject purposes from the ValueObjects to the LanguageRuntime plugins

This is meant to cover cases such as the obvious

Base *base = new Derived();

where GetDynamicTypeAndAddress(base) would return the type "Derived", not "Derived *"


Modified:
    lldb/trunk/include/lldb/Target/LanguageRuntime.h
    lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
    lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h

Modified: lldb/trunk/include/lldb/Target/LanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/LanguageRuntime.h?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/LanguageRuntime.h (original)
+++ lldb/trunk/include/lldb/Target/LanguageRuntime.h Tue Sep 22 14:45:52 2015
@@ -59,6 +59,14 @@ public:
     // have a dynamic type.
     virtual bool
     CouldHaveDynamicValue (ValueObject &in_value) = 0;
+    
+    // The contract for GetDynamicTypeAndAddress() is to return a "bare-bones" dynamic type
+    // For instance, given a Base* pointer, GetDynamicTypeAndAddress() will return the type of
+    // Derived, not Derived*. The job of this API is to correct this misalignment between the
+    // static type and the discovered dynamic type
+    virtual TypeAndOrName
+    FixUpDynamicType(const TypeAndOrName& type_and_or_name,
+                     const CompilerType& static_type) = 0;
 
     virtual void
     SetExceptionBreakpoints ()

Modified: lldb/trunk/source/Core/ValueObjectDynamicValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectDynamicValue.cpp?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectDynamicValue.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectDynamicValue.cpp Tue Sep 22 14:45:52 2015
@@ -138,40 +138,6 @@ ValueObjectDynamicValue::GetValueType()
     return m_parent->GetValueType();
 }
 
-
-static TypeAndOrName
-FixupTypeAndOrName (const TypeAndOrName& type_andor_name,
-                    ValueObject& parent)
-{
-    TypeAndOrName ret(type_andor_name);
-    if (type_andor_name.HasType())
-    {
-        // The type will always be the type of the dynamic object.  If our parent's type was a pointer,
-        // then our type should be a pointer to the type of the dynamic object.  If a reference, then the original type
-        // should be okay...
-        CompilerType orig_type = type_andor_name.GetCompilerType();
-        CompilerType corrected_type = orig_type;
-        if (parent.IsPointerType())
-            corrected_type = orig_type.GetPointerType ();
-        else if (parent.IsPointerOrReferenceType())
-            corrected_type = orig_type.GetLValueReferenceType();
-        ret.SetCompilerType(corrected_type);
-    }
-    else /*if (m_dynamic_type_info.HasName())*/
-    {
-        // If we are here we need to adjust our dynamic type name to include the correct & or * symbol
-        std::string corrected_name (type_andor_name.GetName().GetCString());
-        if (parent.IsPointerType())
-            corrected_name.append(" *");
-        else if (parent.IsPointerOrReferenceType())
-            corrected_name.append(" &");
-        // the parent type should be a correctly pointer'ed or referenc'ed type
-        ret.SetCompilerType(parent.GetCompilerType());
-        ret.SetName(corrected_name.c_str());
-    }
-    return ret;
-}
-
 bool
 ValueObjectDynamicValue::UpdateValue ()
 {
@@ -211,25 +177,27 @@ ValueObjectDynamicValue::UpdateValue ()
     Address dynamic_address;
     bool found_dynamic_type = false;
     Value::ValueType value_type;
+    
+    LanguageRuntime *runtime = nullptr;
 
     lldb::LanguageType known_type = m_parent->GetObjectRuntimeLanguage();
     if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC)
     {
-        LanguageRuntime *runtime = process->GetLanguageRuntime (known_type);
+        runtime = process->GetLanguageRuntime (known_type);
         if (runtime)
             found_dynamic_type = runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type);
     }
     else
     {
-        LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
-        if (cpp_runtime)
-            found_dynamic_type = cpp_runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type);
+        runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus);
+        if (runtime)
+            found_dynamic_type = runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type);
 
         if (!found_dynamic_type)
         {
-            LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
-            if (objc_runtime)
-                found_dynamic_type = objc_runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type);
+            runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC);
+            if (runtime)
+                found_dynamic_type = runtime->GetDynamicTypeAndAddress (*m_parent, m_use_dynamic, class_type_or_name, dynamic_address, value_type);
         }
     }
 
@@ -238,11 +206,12 @@ ValueObjectDynamicValue::UpdateValue ()
 
     m_update_point.SetUpdated();
 
-    if (found_dynamic_type)
+    if (runtime && found_dynamic_type)
     {
         if (class_type_or_name.HasType())
         {
-            m_type_impl = TypeImpl(m_parent->GetCompilerType(),FixupTypeAndOrName(class_type_or_name, *m_parent).GetCompilerType());
+            m_type_impl = TypeImpl(m_parent->GetCompilerType(),
+                                   runtime->FixUpDynamicType(class_type_or_name, m_parent->GetCompilerType()).GetCompilerType());
         }
         else
         {
@@ -301,7 +270,8 @@ ValueObjectDynamicValue::UpdateValue ()
         m_value.GetScalar() = load_address;
     }
 
-    m_dynamic_type_info = FixupTypeAndOrName(m_dynamic_type_info, *m_parent);
+    if (runtime)
+        m_dynamic_type_info = runtime->FixUpDynamicType(m_dynamic_type_info, m_parent->GetCompilerType());
 
     //m_value.SetContext (Value::eContextTypeClangType, corrected_type);
     m_value.SetCompilerType (m_dynamic_type_info.GetCompilerType());

Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.cpp Tue Sep 22 14:45:52 2015
@@ -270,6 +270,40 @@ ItaniumABILanguageRuntime::GetDynamicTyp
     return class_type_or_name.IsEmpty() == false;
 }
 
+TypeAndOrName
+ItaniumABILanguageRuntime::FixUpDynamicType(const TypeAndOrName& type_and_or_name, const CompilerType& static_type)
+{
+    Flags static_type_flags(static_type.GetTypeInfo());
+    
+    TypeAndOrName ret(type_and_or_name);
+    if (type_and_or_name.HasType())
+    {
+        // The type will always be the type of the dynamic object.  If our parent's type was a pointer,
+        // then our type should be a pointer to the type of the dynamic object.  If a reference, then the original type
+        // should be okay...
+        CompilerType orig_type = type_and_or_name.GetCompilerType();
+        CompilerType corrected_type = orig_type;
+        if (static_type_flags.AllSet(eTypeIsPointer))
+            corrected_type = orig_type.GetPointerType ();
+        else if (static_type_flags.AllSet(eTypeIsReference))
+            corrected_type = orig_type.GetLValueReferenceType();
+        ret.SetCompilerType(corrected_type);
+    }
+    else
+    {
+        // If we are here we need to adjust our dynamic type name to include the correct & or * symbol
+        std::string corrected_name (type_and_or_name.GetName().GetCString());
+        if (static_type_flags.AllSet(eTypeIsPointer))
+            corrected_name.append(" *");
+        else if (static_type_flags.AllSet(eTypeIsReference))
+            corrected_name.append(" &");
+        // the parent type should be a correctly pointer'ed or referenc'ed type
+        ret.SetCompilerType(static_type);
+        ret.SetName(corrected_name.c_str());
+    }
+    return ret;
+}
+
 bool
 ItaniumABILanguageRuntime::IsVTableName (const char *name)
 {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h Tue Sep 22 14:45:52 2015
@@ -41,6 +41,10 @@ namespace lldb_private {
                                   Address &address,
                                   Value::ValueType &value_type);
         
+        virtual TypeAndOrName
+        FixUpDynamicType(const TypeAndOrName& type_and_or_name,
+                         const CompilerType& static_type);
+        
         virtual bool
         CouldHaveDynamicValue (ValueObject &in_value);
         

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.cpp Tue Sep 22 14:45:52 2015
@@ -269,6 +269,36 @@ AppleObjCRuntime::GetDynamicTypeAndAddre
     return false;
 }
 
+TypeAndOrName
+AppleObjCRuntime::FixUpDynamicType(const TypeAndOrName& type_and_or_name, const CompilerType& static_type)
+{
+    Flags static_type_flags(static_type.GetTypeInfo());
+    
+    TypeAndOrName ret(type_and_or_name);
+    if (type_and_or_name.HasType())
+    {
+        // The type will always be the type of the dynamic object.  If our parent's type was a pointer,
+        // then our type should be a pointer to the type of the dynamic object.  If a reference, then the original type
+        // should be okay...
+        CompilerType orig_type = type_and_or_name.GetCompilerType();
+        CompilerType corrected_type = orig_type;
+        if (static_type_flags.AllSet(eTypeIsPointer))
+            corrected_type = orig_type.GetPointerType ();
+        ret.SetCompilerType(corrected_type);
+    }
+    else
+    {
+        // If we are here we need to adjust our dynamic type name to include the correct & or * symbol
+        std::string corrected_name (type_and_or_name.GetName().GetCString());
+        if (static_type_flags.AllSet(eTypeIsPointer))
+            corrected_name.append(" *");
+        // the parent type should be a correctly pointer'ed or referenc'ed type
+        ret.SetCompilerType(static_type);
+        ret.SetName(corrected_name.c_str());
+    }
+    return ret;
+}
+
 bool
 AppleObjCRuntime::AppleIsModuleObjCLibrary (const ModuleSP &module_sp)
 {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntime.h Tue Sep 22 14:45:52 2015
@@ -49,6 +49,10 @@ public:
                               Address &address,
                               Value::ValueType &value_type) override;
 
+    TypeAndOrName
+    FixUpDynamicType(const TypeAndOrName& type_and_or_name,
+                     const CompilerType& static_type) override;
+    
     // These are the ObjC specific functions.
     
     bool

Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp Tue Sep 22 14:45:52 2015
@@ -313,6 +313,13 @@ RenderScriptRuntime::GetDynamicTypeAndAd
     return false;
 }
 
+TypeAndOrName
+RenderScriptRuntime::FixUpDynamicType(const TypeAndOrName& type_and_or_name,
+                                      const CompilerType& static_type)
+{
+    return type_and_or_name;
+}
+
 bool
 RenderScriptRuntime::CouldHaveDynamicValue(ValueObject &in_value)
 {

Modified: lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h?rev=248315&r1=248314&r2=248315&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h Tue Sep 22 14:45:52 2015
@@ -183,6 +183,10 @@ class RenderScriptRuntime : public lldb_
     virtual bool GetDynamicTypeAndAddress(ValueObject &in_value, lldb::DynamicValueType use_dynamic,
                                           TypeAndOrName &class_type_or_name, Address &address,
                                           Value::ValueType &value_type);
+    
+    virtual TypeAndOrName
+    FixUpDynamicType(const TypeAndOrName& type_and_or_name,
+                     const CompilerType& static_type);
 
     virtual bool CouldHaveDynamicValue(ValueObject &in_value);
 




More information about the lldb-commits mailing list