[Lldb-commits] [lldb] r123957 - in /lldb/trunk: include/lldb/API/SBType.h include/lldb/Core/ValueObject.h include/lldb/Core/ValueObjectChild.h include/lldb/Symbol/ClangASTContext.h include/lldb/Symbol/Type.h source/API/SBType.cpp source/Core/ValueObject.cpp source/Core/ValueObjectChild.cpp source/Symbol/ClangASTContext.cpp source/Symbol/Type.cpp

Greg Clayton gclayton at apple.com
Thu Jan 20 17:59:01 PST 2011


Author: gclayton
Date: Thu Jan 20 19:59:00 2011
New Revision: 123957

URL: http://llvm.org/viewvc/llvm-project?rev=123957&view=rev
Log:
Fixed up the SBValue::GetExpressionPath() to be more correct under more
circumstances.


Modified:
    lldb/trunk/include/lldb/API/SBType.h
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/include/lldb/Core/ValueObjectChild.h
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/include/lldb/Symbol/Type.h
    lldb/trunk/source/API/SBType.cpp
    lldb/trunk/source/Core/ValueObject.cpp
    lldb/trunk/source/Core/ValueObjectChild.cpp
    lldb/trunk/source/Symbol/ClangASTContext.cpp
    lldb/trunk/source/Symbol/Type.cpp

Modified: lldb/trunk/include/lldb/API/SBType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBType.h?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBType.h (original)
+++ lldb/trunk/include/lldb/API/SBType.h Thu Jan 20 19:59:00 2011
@@ -128,6 +128,7 @@
     uint32_t m_bit_size;
     uint32_t m_bit_offset;
     bool m_is_base_class;
+    bool m_is_deref_of_paremt;
 };
 
 

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Thu Jan 20 19:59:00 2011
@@ -86,6 +86,15 @@
     {
         return false;
     }
+    
+    virtual bool
+    IsDereferenceOfParent ()
+    {
+        return false;
+    }
+    
+    virtual bool
+    GetBaseClassPath (Stream &s);
 
     virtual void
     GetExpressionPath (Stream &s, bool qualify_cxx_base_classes);
@@ -276,7 +285,10 @@
     {
         return m_parent;
     }
-    
+
+    ValueObject *
+    GetNonBaseClassParent();
+
     void
     SetPointersPointToLoadAddrs (bool b)
     {
@@ -312,7 +324,8 @@
                         m_value_did_change:1,
                         m_children_count_valid:1,
                         m_old_value_valid:1,
-                        m_pointers_point_to_load_addrs:1;
+                        m_pointers_point_to_load_addrs:1,
+                        m_is_deref_of_parent:1;
     
     friend class CommandObjectExpression;
     friend class ClangExpressionVariable;

Modified: lldb/trunk/include/lldb/Core/ValueObjectChild.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectChild.h?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectChild.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectChild.h Thu Jan 20 19:59:00 2011
@@ -32,7 +32,8 @@
                       int32_t byte_offset,
                       uint32_t bitfield_bit_size,
                       uint32_t bitfield_bit_offset,
-                      bool is_base_class);
+                      bool is_base_class,
+                      bool is_deref_of_parent);
 
 
     virtual ~ValueObjectChild();
@@ -94,6 +95,12 @@
         return m_is_base_class;
     }
 
+    virtual bool
+    IsDereferenceOfParent ()
+    {
+        return m_is_deref_of_parent;
+    }
+
 protected:
     clang::ASTContext *m_clang_ast; // The clang AST that the clang type comes from
     void *m_clang_type; // The type of the child in question within the parent (m_parent_sp)
@@ -103,6 +110,7 @@
     uint8_t m_bitfield_bit_size;
     uint8_t m_bitfield_bit_offset;
     bool m_is_base_class;
+    bool m_is_deref_of_parent;
 
 //
 //  void

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Thu Jan 20 19:59:00 2011
@@ -393,8 +393,9 @@
                               int32_t &child_byte_offset,
                               uint32_t &child_bitfield_bit_size,
                               uint32_t &child_bitfield_bit_offset,
-                              bool &child_is_base_class);
-    
+                              bool &child_is_base_class,
+                              bool &child_is_deref_of_parent);
+ 
     static lldb::clang_type_t
     GetChildClangTypeAtIndex (clang::ASTContext *ast,
                               const char *parent_name,
@@ -407,7 +408,8 @@
                               int32_t &child_byte_offset,
                               uint32_t &child_bitfield_bit_size,
                               uint32_t &child_bitfield_bit_offset,
-                              bool &child_is_base_class);
+                              bool &child_is_base_class,
+                              bool &child_is_deref_of_parent);
     
     // Lookup a child given a name. This function will match base class names
     // and member member names in "clang_type" only, not descendants.

Modified: lldb/trunk/include/lldb/Symbol/Type.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Type.h?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/Type.h (original)
+++ lldb/trunk/include/lldb/Symbol/Type.h Thu Jan 20 19:59:00 2011
@@ -202,18 +202,6 @@
     ClangASTContext &
     GetClangASTContext ();
 
-    lldb::clang_type_t 
-    GetChildClangTypeAtIndex (const char *parent_name,
-                              uint32_t idx,
-                              bool transparent_pointers,
-                              bool omit_empty_base_classes,
-                              ConstString& name,
-                              uint32_t &child_byte_size,
-                              int32_t &child_byte_offset,
-                              uint32_t &child_bitfield_bit_size,
-                              uint32_t &child_bitfield_bit_offset,
-                              bool &child_is_base_class);
-
     static int
     Compare(const Type &a, const Type &b);
 

Modified: lldb/trunk/source/API/SBType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBType.cpp?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/source/API/SBType.cpp (original)
+++ lldb/trunk/source/API/SBType.cpp Thu Jan 20 19:59:00 2011
@@ -113,6 +113,7 @@
     uint32_t child_bitfield_bit_size = 0;
     uint32_t child_bitfield_bit_offset = 0;
     bool child_is_base_class = false;
+    bool child_is_deref_of_parent = false;
 
     if (IsValid ())
     {
@@ -128,7 +129,8 @@
                                                                       child_byte_offset,
                                                                       child_bitfield_bit_size,
                                                                       child_bitfield_bit_offset,
-                                                                      child_is_base_class);
+                                                                      child_is_base_class,
+                                                                      child_is_deref_of_parent);
         
     }
     
@@ -142,6 +144,7 @@
         member.m_bit_size = child_bitfield_bit_size;
         member.m_bit_offset = child_bitfield_bit_offset;
         member.m_is_base_class = child_is_base_class;
+        member.m_is_deref_of_paremt = child_is_deref_of_parent;
     }
     else
     {

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Thu Jan 20 19:59:00 2011
@@ -64,7 +64,8 @@
     m_value_did_change (false),
     m_children_count_valid (false),
     m_old_value_valid (false),
-    m_pointers_point_to_load_addrs (false)
+    m_pointers_point_to_load_addrs (false),
+    m_is_deref_of_parent (false)
 {
 }
 
@@ -367,6 +368,8 @@
     uint32_t child_bitfield_bit_size = 0;
     uint32_t child_bitfield_bit_offset = 0;
     bool child_is_base_class = false;
+    bool child_is_deref_of_parent = false;
+
     const bool transparent_pointers = synthetic_array_member == false;
     clang::ASTContext *clang_ast = GetClangAST();
     clang_type_t clang_type = GetClangType();
@@ -382,7 +385,8 @@
                                                                   child_byte_offset,
                                                                   child_bitfield_bit_size,
                                                                   child_bitfield_bit_offset,
-                                                                  child_is_base_class);
+                                                                  child_is_base_class,
+                                                                  child_is_deref_of_parent);
     if (child_clang_type && child_byte_size)
     {
         if (synthetic_index)
@@ -400,7 +404,8 @@
                                                child_byte_offset,
                                                child_bitfield_bit_size,
                                                child_bitfield_bit_offset,
-                                               child_is_base_class));
+                                               child_is_base_class,
+                                               child_is_deref_of_parent));
         if (m_pointers_point_to_load_addrs)
             valobj_sp->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs);
     }
@@ -931,47 +936,90 @@
     return true;
 }
 
+bool
+ValueObject::GetBaseClassPath (Stream &s)
+{
+    if (IsBaseClass())
+    {
+        bool parent_had_base_class = m_parent && m_parent->GetBaseClassPath (s);
+        clang_type_t clang_type = GetClangType();
+        std::string cxx_class_name;
+        bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
+        if (this_had_base_class)
+        {
+            if (parent_had_base_class)
+                s.PutCString("::");
+            s.PutCString(cxx_class_name.c_str());
+        }
+        return parent_had_base_class || this_had_base_class;
+    }
+    return false;
+}
+
+
+ValueObject *
+ValueObject::GetNonBaseClassParent()
+{
+    if (m_parent)
+    {
+        if (m_parent->IsBaseClass())
+            return m_parent->GetNonBaseClassParent();
+        else
+            return m_parent;
+    }
+    return NULL;
+}
 
 void
 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes)
 {
+    const bool is_deref_of_parent = IsDereferenceOfParent ();
+    
+    if (is_deref_of_parent)
+        s.PutCString("*(");
+
     if (m_parent)
-    {
         m_parent->GetExpressionPath (s, qualify_cxx_base_classes);
-        clang_type_t parent_clang_type = m_parent->GetClangType();
-        if (parent_clang_type)
+    
+    if (!IsBaseClass())
+    {
+        if (!is_deref_of_parent)
         {
-            if (ClangASTContext::IsPointerType(parent_clang_type))
+            ValueObject *non_base_class_parent = GetNonBaseClassParent();
+            if (non_base_class_parent)
             {
-                s.PutCString("->");
+                clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
+                if (non_base_class_parent_clang_type)
+                {
+                    const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
+                    
+                    if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
+                    {
+                        s.PutCString("->");
+                    }
+                    else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
+                        !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
+                    {
+                        s.PutChar('.');
+                    }
+                }
             }
-            else if (ClangASTContext::IsAggregateType (parent_clang_type))
+
+            const char *name = GetName().GetCString();
+            if (name)
             {
-                if (ClangASTContext::IsArrayType (parent_clang_type) == false &&
-                    m_parent->IsBaseClass() == false)
-                    s.PutChar('.');
+                if (qualify_cxx_base_classes)
+                {
+                    if (GetBaseClassPath (s))
+                        s.PutCString("::");
+                }
+                s.PutCString(name);
             }
         }
     }
     
-    if (IsBaseClass())
-    {
-        if (qualify_cxx_base_classes)
-        {
-            clang_type_t clang_type = GetClangType();
-            std::string cxx_class_name;
-            if (ClangASTContext::GetCXXClassName (clang_type, cxx_class_name))
-            {
-                s << cxx_class_name.c_str() << "::";
-            }
-        }
-    }
-    else
-    {
-        const char *name = GetName().GetCString();
-        if (name)
-            s.PutCString(name);    
-    }
+    if (is_deref_of_parent)
+        s.PutChar(')');
 }
 
 void
@@ -1012,7 +1060,7 @@
             s.Indent();
 
             // Always show the type for the top level items.
-            if (show_types || curr_depth == 0)
+            if (show_types || (curr_depth == 0 && !flat_output))
                 s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>"));
 
 
@@ -1223,6 +1271,7 @@
         uint32_t child_bitfield_bit_size = 0;
         uint32_t child_bitfield_bit_offset = 0;
         bool child_is_base_class = false;
+        bool child_is_deref_of_parent = false;
         const bool transparent_pointers = false;
         clang::ASTContext *clang_ast = GetClangAST();
         clang_type_t clang_type = GetClangType();
@@ -1238,7 +1287,8 @@
                                                                       child_byte_offset,
                                                                       child_bitfield_bit_size,
                                                                       child_bitfield_bit_offset,
-                                                                      child_is_base_class);
+                                                                      child_is_base_class,
+                                                                      child_is_deref_of_parent);
         if (child_clang_type && child_byte_size)
         {
             ConstString child_name;
@@ -1253,7 +1303,8 @@
                                                    child_byte_offset,
                                                    child_bitfield_bit_size,
                                                    child_bitfield_bit_offset,
-                                                   child_is_base_class));
+                                                   child_is_base_class,
+                                                   child_is_deref_of_parent));
         }
     }
 

Modified: lldb/trunk/source/Core/ValueObjectChild.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectChild.cpp?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectChild.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectChild.cpp Thu Jan 20 19:59:00 2011
@@ -34,7 +34,8 @@
     int32_t byte_offset,
     uint32_t bitfield_bit_size,
     uint32_t bitfield_bit_offset,
-    bool is_base_class
+    bool is_base_class,
+    bool is_deref_of_parent
 ) :
     ValueObject (parent),
     m_clang_ast (clang_ast),
@@ -43,7 +44,8 @@
     m_byte_offset (byte_offset),
     m_bitfield_bit_size (bitfield_bit_size),
     m_bitfield_bit_offset (bitfield_bit_offset),
-    m_is_base_class (is_base_class)
+    m_is_base_class (is_base_class),
+    m_is_deref_of_parent (is_deref_of_parent)
 {
     m_name = name;
 }

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Thu Jan 20 19:59:00 2011
@@ -2373,7 +2373,8 @@
     int32_t &child_byte_offset,
     uint32_t &child_bitfield_bit_size,
     uint32_t &child_bitfield_bit_offset,
-    bool &child_is_base_class
+    bool &child_is_base_class,
+    bool &child_is_deref_of_parent
 )
 {
     if (parent_clang_type)
@@ -2389,7 +2390,8 @@
                                          child_byte_offset,
                                          child_bitfield_bit_size,
                                          child_bitfield_bit_offset,
-                                         child_is_base_class);
+                                         child_is_base_class, 
+                                         child_is_deref_of_parent);
     return NULL;
 }
 
@@ -2407,7 +2409,8 @@
     int32_t &child_byte_offset,
     uint32_t &child_bitfield_bit_size,
     uint32_t &child_bitfield_bit_offset,
-    bool &child_is_base_class
+    bool &child_is_base_class,
+    bool &child_is_deref_of_parent
 )
 {
     if (parent_clang_type == NULL)
@@ -2612,6 +2615,8 @@
 
                 if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
                 {
+                    child_is_deref_of_parent = false;
+                    bool tmp_child_is_deref_of_parent = false;
                     return GetChildClangTypeAtIndex (ast,
                                                      parent_name,
                                                      pointer_type->getPointeeType().getAsOpaquePtr(),
@@ -2623,10 +2628,12 @@
                                                      child_byte_offset,
                                                      child_bitfield_bit_size,
                                                      child_bitfield_bit_offset,
-                                                     child_is_base_class);
+                                                     child_is_base_class,
+                                                     tmp_child_is_deref_of_parent);
                 }
                 else
                 {
+                    child_is_deref_of_parent = true;
                     if (parent_name)
                     {
                         child_name.assign(1, '*');
@@ -2681,6 +2688,8 @@
 
                 if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
                 {
+                    child_is_deref_of_parent = false;
+                    bool tmp_child_is_deref_of_parent = false;
                     return GetChildClangTypeAtIndex (ast,
                                                      parent_name,
                                                      pointer_type->getPointeeType().getAsOpaquePtr(),
@@ -2692,10 +2701,13 @@
                                                      child_byte_offset,
                                                      child_bitfield_bit_size,
                                                      child_bitfield_bit_offset,
-                                                     child_is_base_class);
+                                                     child_is_base_class,
+                                                     tmp_child_is_deref_of_parent);
                 }
                 else
                 {
+                    child_is_deref_of_parent = true;
+
                     if (parent_name)
                     {
                         child_name.assign(1, '*');
@@ -2723,6 +2735,8 @@
                 clang_type_t pointee_clang_type = pointee_type.getAsOpaquePtr();
                 if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_clang_type))
                 {
+                    child_is_deref_of_parent = false;
+                    bool tmp_child_is_deref_of_parent = false;
                     return GetChildClangTypeAtIndex (ast,
                                                      parent_name,
                                                      pointee_clang_type,
@@ -2734,7 +2748,8 @@
                                                      child_byte_offset,
                                                      child_bitfield_bit_size,
                                                      child_bitfield_bit_offset,
-                                                     child_is_base_class);
+                                                     child_is_base_class,
+                                                     tmp_child_is_deref_of_parent);
                 }
                 else
                 {
@@ -2769,7 +2784,8 @@
                                              child_byte_offset,
                                              child_bitfield_bit_size,
                                              child_bitfield_bit_offset,
-                                             child_is_base_class);
+                                             child_is_base_class,
+                                             child_is_deref_of_parent);
             break;
 
         default:

Modified: lldb/trunk/source/Symbol/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=123957&r1=123956&r2=123957&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Type.cpp (original)
+++ lldb/trunk/source/Symbol/Type.cpp Thu Jan 20 19:59:00 2011
@@ -559,50 +559,6 @@
     }
     return m_clang_type != NULL;
 }
-
-clang_type_t 
-lldb_private::Type::GetChildClangTypeAtIndex
-(
-    const char *parent_name,
-    uint32_t idx,
-    bool transparent_pointers,
-    bool omit_empty_base_classes,
-    ConstString& name,
-    uint32_t &child_byte_size,
-    int32_t &child_byte_offset,
-    uint32_t &child_bitfield_bit_size,
-    uint32_t &child_bitfield_bit_offset,
-    bool &child_is_base_class
-)
-{
-    clang_type_t child_qual_type = NULL;
-    
-    if (GetClangType())
-    {
-        std::string name_str;
-        child_qual_type = GetClangASTContext().GetChildClangTypeAtIndex (parent_name,
-                                                                         m_clang_type,
-                                                                         idx,
-                                                                         transparent_pointers,
-                                                                         omit_empty_base_classes,
-                                                                         name_str,
-                                                                         child_byte_size,
-                                                                         child_byte_offset,
-                                                                         child_bitfield_bit_size,
-                                                                         child_bitfield_bit_offset,
-                                                                         child_is_base_class);
-        
-        if (child_qual_type)
-        {
-            if (!name_str.empty())
-                name.SetCString(name_str.c_str());
-            else
-                name.Clear();
-        }
-    }
-    return child_qual_type;
-}
-
 uint32_t
 lldb_private::Type::GetEncodingMask ()
 {





More information about the lldb-commits mailing list