[Lldb-commits] [lldb] r192239 - <rdar://problem/14028923>

Enrico Granata egranata at apple.com
Tue Oct 8 14:49:02 PDT 2013


Author: enrico
Date: Tue Oct  8 16:49:02 2013
New Revision: 192239

URL: http://llvm.org/viewvc/llvm-project?rev=192239&view=rev
Log:
<rdar://problem/14028923>

Implement SBTarget::CreateValueFromAddress() with a behavior equivalent to SBValue::CreateValueFromAddress()
(but without the need to grab an SBValue first just as a starting point to make up another SBValue out of whole cloth)


Modified:
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/include/lldb/Target/ExecutionContext.h
    lldb/trunk/scripts/Python/interface/SBTarget.i
    lldb/trunk/source/API/SBTarget.cpp
    lldb/trunk/source/API/SBValue.cpp
    lldb/trunk/source/Target/ExecutionContext.cpp

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=192239&r1=192238&r2=192239&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Tue Oct  8 16:49:02 2013
@@ -747,6 +747,9 @@ public:
     lldb::SBType
     GetBasicType(lldb::BasicType type);
     
+    lldb::SBValue
+    CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
+    
     SBSourceManager
     GetSourceManager();
     

Modified: lldb/trunk/include/lldb/Target/ExecutionContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ExecutionContext.h?rev=192239&r1=192238&r2=192239&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/ExecutionContext.h (original)
+++ lldb/trunk/include/lldb/Target/ExecutionContext.h Tue Oct  8 16:49:02 2013
@@ -461,6 +461,9 @@ public:
 
     uint32_t
     GetAddressByteSize() const;
+    
+    lldb::ByteOrder
+    GetByteOrder() const;
 
     //------------------------------------------------------------------
     /// Returns a pointer to the target object.

Modified: lldb/trunk/scripts/Python/interface/SBTarget.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBTarget.i?rev=192239&r1=192238&r2=192239&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBTarget.i (original)
+++ lldb/trunk/scripts/Python/interface/SBTarget.i Tue Oct  8 16:49:02 2013
@@ -723,6 +723,9 @@ public:
 
     lldb::SBBroadcaster
     GetBroadcaster () const;
+              
+    lldb::SBValue
+    CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
     
     lldb::SBInstructionList
     ReadInstructions (lldb::SBAddress base_addr, uint32_t count);    

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=192239&r1=192238&r2=192239&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Tue Oct  8 16:49:02 2013
@@ -41,6 +41,7 @@
 #include "lldb/Core/SearchFilter.h"
 #include "lldb/Core/Section.h"
 #include "lldb/Core/STLUtils.h"
+#include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Core/ValueObjectList.h"
 #include "lldb/Core/ValueObjectVariable.h"
 #include "lldb/Host/FileSpec.h"
@@ -1862,6 +1863,50 @@ SBTarget::DisableAllWatchpoints ()
     return false;
 }
 
+SBValue
+SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type)
+{
+    SBValue sb_value;
+    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().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));
+            }
+        }
+    }
+    sb_value.SetSP(new_value_sp);
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    {
+        if (new_value_sp)
+            log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", m_opaque_sp.get(), new_value_sp->GetName().AsCString());
+        else
+            log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", m_opaque_sp.get());
+    }
+    return sb_value;
+}
+
 bool
 SBTarget::DeleteAllWatchpoints ()
 {

Modified: lldb/trunk/source/API/SBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBValue.cpp?rev=192239&r1=192238&r2=192239&view=diff
==============================================================================
--- lldb/trunk/source/API/SBValue.cpp (original)
+++ lldb/trunk/source/API/SBValue.cpp Tue Oct  8 16:49:02 2013
@@ -761,17 +761,17 @@ SBValue::CreateValueFromAddress(const ch
     lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
     if (value_sp && type_impl_sp)
     {
-        ClangASTType pointee_ast_type(type_impl_sp->GetClangASTType().GetPointerType ());
-        if (pointee_ast_type)
+        ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType().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(),
-                                                                               pointee_ast_type,
+                                                                               pointer_ast_type,
                                                                                ConstString(name),
                                                                                buffer,
-                                                                               lldb::endian::InlHostByteOrder(),
+                                                                               exe_ctx.GetByteOrder(),
                                                                                exe_ctx.GetAddressByteSize()));
             
             if (ptr_result_valobj_sp)

Modified: lldb/trunk/source/Target/ExecutionContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ExecutionContext.cpp?rev=192239&r1=192238&r2=192239&view=diff
==============================================================================
--- lldb/trunk/source/Target/ExecutionContext.cpp (original)
+++ lldb/trunk/source/Target/ExecutionContext.cpp Tue Oct  8 16:49:02 2013
@@ -241,7 +241,15 @@ ExecutionContext::GetAddressByteSize() c
     return sizeof(void *);
 }
 
-
+lldb::ByteOrder
+ExecutionContext::GetByteOrder() const
+{
+    if (m_target_sp && m_target_sp->GetArchitecture().IsValid())
+        m_target_sp->GetArchitecture().GetByteOrder();
+    if (m_process_sp)
+        m_process_sp->GetByteOrder();
+    return lldb::endian::InlHostByteOrder();
+}
 
 RegisterContext *
 ExecutionContext::GetRegisterContext () const





More information about the lldb-commits mailing list