[Lldb-commits] [lldb] r224460 - Provide CreateValueFromData,Expression at the SBTarget level as well as the SBValue level; and also make all the implenentations agree on using the matching ValueObject::Create instead of doing code copypastas

Enrico Granata egranata at apple.com
Wed Dec 17 13:18:44 PST 2014


Author: enrico
Date: Wed Dec 17 15:18:43 2014
New Revision: 224460

URL: http://llvm.org/viewvc/llvm-project?rev=224460&view=rev
Log:
Provide CreateValueFromData,Expression at the SBTarget level as well as the SBValue level; and also make all the implenentations agree on using the matching ValueObject::Create instead of doing code copypastas

Modified:
    lldb/trunk/include/lldb/API/SBData.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Core/ValueObject.h
    lldb/trunk/scripts/Python/interface/SBTarget.i
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/Core/ValueObject.cpp

Modified: lldb/trunk/include/lldb/API/SBData.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBData.h?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBData.h (original)
+++ lldb/trunk/include/lldb/API/SBData.h Wed Dec 17 15:18:43 2014
@@ -169,6 +169,7 @@ private:
     friend class SBInstruction;
     friend class SBProcess;
     friend class SBSection;
+    friend class SBTarget;
     friend class SBValue;
 
     lldb::DataExtractorSP  m_opaque_sp;

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Wed Dec 17 15:18:43 2014
@@ -998,6 +998,12 @@ public:
     
     lldb::SBValue
     CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
+
+    lldb::SBValue
+    CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type);
+
+    lldb::SBValue
+    CreateValueFromExpression (const char *name, const char* expr);
     
     SBSourceManager
     GetSourceManager();

Modified: lldb/trunk/include/lldb/Core/ValueObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ValueObject.h?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ValueObject.h (original)
+++ lldb/trunk/include/lldb/Core/ValueObject.h Wed Dec 17 15:18:43 2014
@@ -796,11 +796,17 @@ public:
                                      const ExecutionContext& exe_ctx);
     
     static lldb::ValueObjectSP
+    CreateValueObjectFromExpression (const char* name,
+                                     const char* expression,
+                                     const ExecutionContext& exe_ctx,
+                                     const EvaluateExpressionOptions& options);
+    
+    static lldb::ValueObjectSP
     CreateValueObjectFromAddress (const char* name,
                                   uint64_t address,
                                   const ExecutionContext& exe_ctx,
                                   ClangASTType type);
-    
+
     static lldb::ValueObjectSP
     CreateValueObjectFromData (const char* name,
                                const DataExtractor& data,

Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Wed Dec 17 15:18:43 2014
@@ -869,6 +869,12 @@ public:
     lldb::SBValue
     CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
 
+    lldb::SBValue
+    CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type);
+  
+    lldb::SBValue
+    CreateValueFromExpression (const char *name, const char* expr);
+              
     %feature("docstring", "
     Disassemble a specified number of instructions starting at an address.
     Parameters:

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Wed Dec 17 15:18:43 2014
@@ -1945,30 +1945,10 @@ SBTarget::CreateValueFromAddress (const
     lldb::ValueObjectSP new_value_sp;
     if (IsValid() && name && *name && addr.IsValid() && type.IsValid())
     {
-        lldb::addr_t address(addr.GetLoadAddress(*this));
-        lldb::TypeImplSP type_impl_sp (type.GetSP());
-        ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ());
-        if (pointer_ast_type)
-        {
-            lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
-
-            ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
-            ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
-                                                                               pointer_ast_type,
-                                                                               ConstString(name),
-                                                                               buffer,
-                                                                               exe_ctx.GetByteOrder(),
-                                                                               exe_ctx.GetAddressByteSize()));
-
-            if (ptr_result_valobj_sp)
-            {
-                ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
-                Error err;
-                new_value_sp = ptr_result_valobj_sp->Dereference(err);
-                if (new_value_sp)
-                    new_value_sp->SetName(ConstString(name));
-            }
-        }
+        lldb::addr_t load_addr(addr.GetLoadAddress(*this));
+        ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
+        ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
+        new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type);
     }
     sb_value.SetSP(new_value_sp);
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
@@ -1983,6 +1963,58 @@ SBTarget::CreateValueFromAddress (const
                          static_cast<void*>(m_opaque_sp.get()));
     }
     return sb_value;
+}
+
+lldb::SBValue
+SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type)
+{
+    SBValue sb_value;
+    lldb::ValueObjectSP new_value_sp;
+    if (IsValid() && name && *name && data.IsValid() && type.IsValid())
+    {
+        DataExtractorSP extractor(*data);
+        ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
+        ClangASTType ast_type(type.GetSP()->GetClangASTType(true));
+        new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type);
+    }
+    sb_value.SetSP(new_value_sp);
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    {
+        if (new_value_sp)
+            log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"",
+                         static_cast<void*>(m_opaque_sp.get()),
+                         new_value_sp->GetName().AsCString());
+        else
+            log->Printf ("SBTarget(%p)::CreateValueFromData => NULL",
+                         static_cast<void*>(m_opaque_sp.get()));
+    }
+    return sb_value;
+}
+
+lldb::SBValue
+SBTarget::CreateValueFromExpression (const char *name, const char* expr)
+{
+    SBValue sb_value;
+    lldb::ValueObjectSP new_value_sp;
+    if (IsValid() && name && *name && expr && *expr)
+    {
+        ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false)));
+        new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx);
+    }
+    sb_value.SetSP(new_value_sp);
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    {
+        if (new_value_sp)
+            log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"",
+                         static_cast<void*>(m_opaque_sp.get()),
+                         new_value_sp->GetName().AsCString());
+        else
+            log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL",
+                         static_cast<void*>(m_opaque_sp.get()));
+    }
+    return sb_value;
 }
 
 bool

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Wed Dec 17 15:18:43 2014
@@ -864,21 +864,11 @@ SBValue::CreateValueFromExpression (cons
     if (value_sp)
     {
         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
-        Target* target = exe_ctx.GetTargetPtr();
-        if (target)
-        {
-            options.ref().SetKeepInMemory(true);
-            target->EvaluateExpression (expression,
-                                        exe_ctx.GetFramePtr(),
-                                        new_value_sp,
-                                        options.ref());
-            if (new_value_sp)
-            {
-                new_value_sp->SetName(ConstString(name));
-                sb_value.SetSP(new_value_sp);
-            }
-        }
+        new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
+        if (new_value_sp)
+            new_value_sp->SetName(ConstString(name));
     }
+    sb_value.SetSP(new_value_sp);
     if (log)
     {
         if (new_value_sp)
@@ -902,30 +892,11 @@ SBValue::CreateValueFromAddress(const ch
     lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
     if (value_sp && type_impl_sp)
     {
-        ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(false).GetPointerType ());
-        if (pointer_ast_type)
-        {
-            lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
-
-            ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
-            ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
-                                                                               pointer_ast_type,
-                                                                               ConstString(name),
-                                                                               buffer,
-                                                                               exe_ctx.GetByteOrder(),
-                                                                               exe_ctx.GetAddressByteSize()));
-
-            if (ptr_result_valobj_sp)
-            {
-                ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
-                Error err;
-                new_value_sp = ptr_result_valobj_sp->Dereference(err);
-                if (new_value_sp)
-                    new_value_sp->SetName(ConstString(name));
-            }
-            sb_value.SetSP(new_value_sp);
-        }
+        ClangASTType ast_type(type_impl_sp->GetClangASTType(true));
+        ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
+        new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
     }
+    sb_value.SetSP(new_value_sp);
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {
@@ -950,15 +921,10 @@ SBValue::CreateValueFromData (const char
     if (value_sp)
     {
         ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
-
-        new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
-                                                       type.m_opaque_sp->GetClangASTType(false),
-                                                       ConstString(name),
-                                                       *data.m_opaque_sp,
-                                                       LLDB_INVALID_ADDRESS);
+        new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true));
         new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
-        sb_value.SetSP(new_value_sp);
     }
+    sb_value.SetSP(new_value_sp);
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
     if (log)
     {

Modified: lldb/trunk/source/Core/ValueObject.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObject.cpp?rev=224460&r1=224459&r2=224460&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObject.cpp (original)
+++ lldb/trunk/source/Core/ValueObject.cpp Wed Dec 17 15:18:43 2014
@@ -4041,6 +4041,16 @@ ValueObject::CreateValueObjectFromExpres
                                               const char* expression,
                                               const ExecutionContext& exe_ctx)
 {
+    return CreateValueObjectFromExpression(name, expression, exe_ctx, EvaluateExpressionOptions());
+}
+
+
+lldb::ValueObjectSP
+ValueObject::CreateValueObjectFromExpression (const char* name,
+                                              const char* expression,
+                                              const ExecutionContext& exe_ctx,
+                                              const EvaluateExpressionOptions& options)
+{
     lldb::ValueObjectSP retval_sp;
     lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
     if (!target_sp)
@@ -4049,7 +4059,8 @@ ValueObject::CreateValueObjectFromExpres
         return retval_sp;
     target_sp->EvaluateExpression (expression,
                                    exe_ctx.GetFrameSP().get(),
-                                   retval_sp);
+                                   retval_sp,
+                                   options);
     if (retval_sp && name && *name)
         retval_sp->SetName(ConstString(name));
     return retval_sp;
@@ -4071,7 +4082,7 @@ ValueObject::CreateValueObjectFromAddres
                                                                                      pointer_type,
                                                                                      ConstString(name),
                                                                                      buffer,
-                                                                                     lldb::endian::InlHostByteOrder(),
+                                                                                     exe_ctx.GetByteOrder(),
                                                                                      exe_ctx.GetAddressByteSize()));
             if (ptr_result_valobj_sp)
             {





More information about the lldb-commits mailing list