<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)
llvm-svn: 192239
diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h
index 15aeed4..7bcf91c 100644
--- a/lldb/include/lldb/API/SBTarget.h
+++ b/lldb/include/lldb/API/SBTarget.h
@@ -747,6 +747,9 @@
lldb::SBType
GetBasicType(lldb::BasicType type);
+ lldb::SBValue
+ CreateValueFromAddress (const char *name, lldb::SBAddress addr, lldb::SBType type);
+
SBSourceManager
GetSourceManager();
diff --git a/lldb/include/lldb/Target/ExecutionContext.h b/lldb/include/lldb/Target/ExecutionContext.h
index de5fe14..4038e70 100644
--- a/lldb/include/lldb/Target/ExecutionContext.h
+++ b/lldb/include/lldb/Target/ExecutionContext.h
@@ -461,6 +461,9 @@
uint32_t
GetAddressByteSize() const;
+
+ lldb::ByteOrder
+ GetByteOrder() const;
//------------------------------------------------------------------
/// Returns a pointer to the target object.
diff --git a/lldb/scripts/Python/interface/SBTarget.i b/lldb/scripts/Python/interface/SBTarget.i
index a171d6f..d259d92 100644
--- a/lldb/scripts/Python/interface/SBTarget.i
+++ b/lldb/scripts/Python/interface/SBTarget.i
@@ -723,6 +723,9 @@
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);
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index d3cd85c..b9947d9 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -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 @@
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 ()
{
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index c860876..408d51c 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -761,17 +761,17 @@
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)
diff --git a/lldb/source/Target/ExecutionContext.cpp b/lldb/source/Target/ExecutionContext.cpp
index 8b5731e..7a8b601 100644
--- a/lldb/source/Target/ExecutionContext.cpp
+++ b/lldb/source/Target/ExecutionContext.cpp
@@ -241,7 +241,15 @@
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