[Lldb-commits] [lldb] r242374 - Add a class ValueObjectConstResultCast.

Siva Chandra sivachandra at google.com
Wed Jul 15 18:47:13 PDT 2015


Author: sivachandra
Date: Wed Jul 15 20:47:12 2015
New Revision: 242374

URL: http://llvm.org/viewvc/llvm-project?rev=242374&view=rev
Log:
Add a class ValueObjectConstResultCast.

Summary:
Other changes around the main change include:

1. Add a method Cast to ValueObjectConstResult, ValueObjectConstResultImpl
and ValueObjectConstResultChild.

2. Add an argument |live_address| of type lldb::addr_t to the constructor
of ValueObjectConstResultChild. This is passed on to the backing
ValueObjectConstResultImpl object constructor so that the address of the
child value can be calculated properly.

Reviewers: granata.enrico, clayborg

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D11203

Added:
    lldb/trunk/include/lldb/Core/ValueObjectConstResultCast.h
    lldb/trunk/source/Core/ValueObjectConstResultCast.cpp
Modified:
    lldb/trunk/include/lldb/Core/ValueObjectCast.h
    lldb/trunk/include/lldb/Core/ValueObjectConstResult.h
    lldb/trunk/include/lldb/Core/ValueObjectConstResultChild.h
    lldb/trunk/include/lldb/Core/ValueObjectConstResultImpl.h
    lldb/trunk/source/Core/CMakeLists.txt
    lldb/trunk/source/Core/ValueObjectConstResult.cpp
    lldb/trunk/source/Core/ValueObjectConstResultChild.cpp
    lldb/trunk/source/Core/ValueObjectConstResultImpl.cpp
    lldb/trunk/test/python_api/value/TestValueAPI.py
    lldb/trunk/test/python_api/value/main.c

Modified: lldb/trunk/include/lldb/Core/ValueObjectCast.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectCast.h?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectCast.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectCast.h Wed Jul 15 20:47:12 2015
@@ -71,11 +71,11 @@ protected:
     
     ClangASTType m_cast_type;
     
-private:
     ValueObjectCast (ValueObject &parent, 
                      const ConstString &name, 
                      const ClangASTType &cast_type);
     
+private:
     //------------------------------------------------------------------
     // For ValueObject only
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Core/ValueObjectConstResult.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectConstResult.h?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectConstResult.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectConstResult.h Wed Jul 15 20:47:12 2015
@@ -131,6 +131,9 @@ public:
     virtual lldb::LanguageType
     GetPreferredDisplayLanguage ();
 
+    virtual lldb::ValueObjectSP
+    Cast (const ClangASTType &clang_ast_type);
+
 protected:
     virtual bool
     UpdateValue ();

Added: lldb/trunk/include/lldb/Core/ValueObjectConstResultCast.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectConstResultCast.h?rev=242374&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectConstResultCast.h (added)
+++ lldb/trunk/include/lldb/Core/ValueObjectConstResultCast.h Wed Jul 15 20:47:12 2015
@@ -0,0 +1,77 @@
+//===-- ValueObjectConstResultCast.h ----------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ValueObjectConstResultCast_h_
+#define liblldb_ValueObjectConstResultCast_h_
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Core/ValueObjectCast.h"
+#include "lldb/Core/ValueObjectConstResultImpl.h"
+
+namespace lldb_private {
+
+class ValueObjectConstResultCast : public ValueObjectCast
+{
+public:
+    ValueObjectConstResultCast (
+        ValueObject &parent,
+        const ConstString &name,
+        const ClangASTType &cast_type,
+        lldb::addr_t live_address = LLDB_INVALID_ADDRESS);
+
+    virtual
+    ~ValueObjectConstResultCast ();
+
+    virtual lldb::ValueObjectSP
+    Dereference (Error &error);
+
+    virtual ValueObject *
+    CreateChildAtIndex (size_t idx,
+                        bool synthetic_array_member,
+                        int32_t synthetic_index);
+
+    virtual ClangASTType
+    GetClangType ()
+    {
+        return ValueObjectCast::GetClangType();
+    }
+
+    virtual lldb::ValueObjectSP
+    GetSyntheticChildAtOffset(uint32_t offset,
+                              const ClangASTType& type,
+                              bool can_create);
+
+    virtual lldb::ValueObjectSP
+    AddressOf (Error &error);
+
+    virtual size_t
+    GetPointeeData (DataExtractor& data,
+                    uint32_t item_idx = 0,
+                    uint32_t item_count = 1);
+
+    virtual lldb::ValueObjectSP
+    Cast (const ClangASTType &clang_ast_type);
+
+protected:
+    ValueObjectConstResultImpl m_impl;
+
+private:
+    friend class ValueObject;
+    friend class ValueObjectConstResult;
+    friend class ValueObjectConstResultImpl;
+
+    DISALLOW_COPY_AND_ASSIGN (ValueObjectConstResultCast);
+};
+
+} // namespace lldb_private
+
+#endif // liblldb_ValueObjectConstResultCast_h_

Modified: lldb/trunk/include/lldb/Core/ValueObjectConstResultChild.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectConstResultChild.h?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectConstResultChild.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectConstResultChild.h Wed Jul 15 20:47:12 2015
@@ -34,7 +34,8 @@ public:
                                  uint32_t bitfield_bit_size,
                                  uint32_t bitfield_bit_offset,
                                  bool is_base_class,
-                                 bool is_deref_of_parent);
+                                 bool is_deref_of_parent,
+                                 lldb::addr_t live_address = LLDB_INVALID_ADDRESS);
     
     virtual ~ValueObjectConstResultChild();
     
@@ -60,6 +61,9 @@ public:
     GetPointeeData (DataExtractor& data,
                     uint32_t item_idx = 0,
 					uint32_t item_count = 1);
+
+    virtual lldb::ValueObjectSP
+    Cast (const ClangASTType &clang_ast_type);
     
 protected:
     ValueObjectConstResultImpl m_impl;

Modified: lldb/trunk/include/lldb/Core/ValueObjectConstResultImpl.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObjectConstResultImpl.h?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObjectConstResultImpl.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObjectConstResultImpl.h Wed Jul 15 20:47:12 2015
@@ -52,6 +52,9 @@ public:
     {
         return m_live_address;
     }
+
+    lldb::ValueObjectSP
+    Cast (const ClangASTType &clang_ast_type);
     
     void
     SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,

Modified: lldb/trunk/source/Core/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CMakeLists.txt?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/source/Core/CMakeLists.txt (original)
+++ lldb/trunk/source/Core/CMakeLists.txt Wed Jul 15 20:47:12 2015
@@ -65,6 +65,7 @@ add_lldb_library(lldbCore
   ValueObjectCast.cpp
   ValueObjectChild.cpp
   ValueObjectConstResult.cpp
+  ValueObjectConstResultCast.cpp
   ValueObjectConstResultChild.cpp
   ValueObjectConstResultImpl.cpp
   ValueObjectDynamicValue.cpp

Modified: lldb/trunk/source/Core/ValueObjectConstResult.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResult.cpp?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectConstResult.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectConstResult.cpp Wed Jul 15 20:47:12 2015
@@ -365,6 +365,12 @@ ValueObjectConstResult::GetDynamicValue
     return ValueObjectSP();
 }
 
+lldb::ValueObjectSP
+ValueObjectConstResult::Cast (const ClangASTType &clang_ast_type)
+{
+    return m_impl.Cast(clang_ast_type);
+}
+
 lldb::LanguageType
 ValueObjectConstResult::GetPreferredDisplayLanguage ()
 {

Added: lldb/trunk/source/Core/ValueObjectConstResultCast.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResultCast.cpp?rev=242374&view=auto
==============================================================================
--- lldb/trunk/source/Core/ValueObjectConstResultCast.cpp (added)
+++ lldb/trunk/source/Core/ValueObjectConstResultCast.cpp Wed Jul 15 20:47:12 2015
@@ -0,0 +1,75 @@
+//===-- ValueObjectConstResultCast.cpp --------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/ValueObjectConstResultCast.h"
+
+#include "lldb/Core/ValueObjectConstResult.h"
+#include "lldb/Core/ValueObjectList.h"
+
+#include "lldb/Symbol/ClangASTContext.h"
+
+using namespace lldb_private;
+
+ValueObjectConstResultCast::ValueObjectConstResultCast(
+    ValueObject &parent,
+    const ConstString &name,
+    const ClangASTType &cast_type,
+    lldb::addr_t live_address) :
+    ValueObjectCast (parent, name, cast_type),
+    m_impl(this, live_address)
+{
+    m_name = name;
+}
+
+ValueObjectConstResultCast::~ValueObjectConstResultCast()
+{
+}
+
+lldb::ValueObjectSP
+ValueObjectConstResultCast::Dereference (Error &error)
+{
+    return m_impl.Dereference(error);
+}
+
+lldb::ValueObjectSP
+ValueObjectConstResultCast::GetSyntheticChildAtOffset(uint32_t offset,
+                                                      const ClangASTType& type,
+                                                      bool can_create)
+{
+    return m_impl.GetSyntheticChildAtOffset(offset, type, can_create);
+}
+
+lldb::ValueObjectSP
+ValueObjectConstResultCast::AddressOf (Error &error)
+{
+    return m_impl.AddressOf(error);
+}
+
+ValueObject *
+ValueObjectConstResultCast::CreateChildAtIndex (size_t idx,
+                                                bool synthetic_array_member,
+                                                int32_t synthetic_index)
+{
+    return m_impl.CreateChildAtIndex(
+        idx, synthetic_array_member, synthetic_index);
+}
+
+size_t
+ValueObjectConstResultCast::GetPointeeData (DataExtractor& data,
+                                             uint32_t item_idx,
+                                             uint32_t item_count)
+{
+    return m_impl.GetPointeeData(data, item_idx, item_count);
+}
+
+lldb::ValueObjectSP
+ValueObjectConstResultCast::Cast (const ClangASTType &clang_ast_type)
+{
+    return m_impl.Cast(clang_ast_type);
+}

Modified: lldb/trunk/source/Core/ValueObjectConstResultChild.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResultChild.cpp?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectConstResultChild.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectConstResultChild.cpp Wed Jul 15 20:47:12 2015
@@ -26,7 +26,8 @@ ValueObjectConstResultChild::ValueObject
     uint32_t bitfield_bit_size,
     uint32_t bitfield_bit_offset,
     bool is_base_class,
-    bool is_deref_of_parent
+    bool is_deref_of_parent,
+    lldb::addr_t live_address
 ) :
     ValueObjectChild (parent,
                       clang_type,
@@ -38,7 +39,7 @@ ValueObjectConstResultChild::ValueObject
                       is_base_class,
                       is_deref_of_parent,
                       eAddressTypeLoad),
-    m_impl(this)
+    m_impl(this, live_address)
 {
     m_name = name;
 }
@@ -78,3 +79,9 @@ ValueObjectConstResultChild::GetPointeeD
 {
     return m_impl.GetPointeeData(data, item_idx, item_count);
 }
+
+lldb::ValueObjectSP
+ValueObjectConstResultChild::Cast (const ClangASTType &clang_ast_type)
+{
+    return m_impl.Cast(clang_ast_type);
+}

Modified: lldb/trunk/source/Core/ValueObjectConstResultImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectConstResultImpl.cpp?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectConstResultImpl.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectConstResultImpl.cpp Wed Jul 15 20:47:12 2015
@@ -11,6 +11,7 @@
 
 #include "lldb/Core/ValueObjectChild.h"
 #include "lldb/Core/ValueObjectConstResult.h"
+#include "lldb/Core/ValueObjectConstResultCast.h"
 #include "lldb/Core/ValueObjectConstResultChild.h"
 #include "lldb/Core/ValueObjectMemory.h"
 #include "lldb/Core/DataExtractor.h"
@@ -96,7 +97,7 @@ ValueObjectConstResultImpl::CreateChildA
         ConstString child_name;
         if (!child_name_str.empty())
             child_name.SetCString (child_name_str.c_str());
-        
+
         valobj = new ValueObjectConstResultChild (*m_impl_backend,
                                                   child_clang_type,
                                                   child_name,
@@ -155,6 +156,17 @@ ValueObjectConstResultImpl::AddressOf (E
         return m_impl_backend->ValueObject::AddressOf(error);
 }
 
+lldb::ValueObjectSP
+ValueObjectConstResultImpl::Cast (const ClangASTType &clang_ast_type)
+{
+    if (m_impl_backend == NULL)
+        return lldb::ValueObjectSP();
+
+    ValueObjectConstResultCast *result_cast = new ValueObjectConstResultCast(
+        *m_impl_backend, m_impl_backend->GetName(), clang_ast_type, m_live_address);
+    return result_cast->GetSP();
+}
+
 lldb::addr_t
 ValueObjectConstResultImpl::GetAddressOf (bool scalar_is_load_address,
                                           AddressType *address_type)

Modified: lldb/trunk/test/python_api/value/TestValueAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/value/TestValueAPI.py?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/test/python_api/value/TestValueAPI.py (original)
+++ lldb/trunk/test/python_api/value/TestValueAPI.py Wed Jul 15 20:47:12 2015
@@ -137,6 +137,12 @@ class ValueAPITestCase(TestBase):
         self.DebugSBValue(val2)
         self.assertTrue(child.GetValue() == val2.GetValue() and
                         child.GetSummary() == val2.GetSummary())
+
+        val_i = target.EvaluateExpression('i')
+        val_s = target.EvaluateExpression('s')
+        val_a = target.EvaluateExpression('a')
+        self.assertTrue(val_s.GetChildMemberWithName('a').AddressOf(), VALID_VARIABLE)
+        self.assertTrue(val_a.Cast(val_i.GetType()).AddressOf(), VALID_VARIABLE)
         
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/python_api/value/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/value/main.c?rev=242374&r1=242373&r2=242374&view=diff
==============================================================================
--- lldb/trunk/test/python_api/value/main.c (original)
+++ lldb/trunk/test/python_api/value/main.c Wed Jul 15 20:47:12 2015
@@ -28,9 +28,19 @@ const char *weekdays[5] = { "Monday",
 
 const char **g_table[2] = { days_of_week, weekdays };
 
+typedef int MyInt;
+
+struct MyStruct
+{
+  int a;
+  int b;
+};
+
 int main (int argc, char const *argv[])
 {
     int i;
+    MyInt a = 12345;
+    struct MyStruct s = { 11, 22 };
     int *my_int_ptr = &g_my_int;
     printf("my_int_ptr points to location %p\n", my_int_ptr);
     const char **str_ptr = days_of_week;





More information about the lldb-commits mailing list