diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 15aeed4b600c..7bcf91c16d77 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -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(); diff --git a/lldb/include/lldb/Target/ExecutionContext.h b/lldb/include/lldb/Target/ExecutionContext.h index de5fe14934a7..4038e70b0c56 100644 --- a/lldb/include/lldb/Target/ExecutionContext.h +++ b/lldb/include/lldb/Target/ExecutionContext.h @@ -461,6 +461,9 @@ public: 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 a171d6f087a4..d259d924854e 100644 --- a/lldb/scripts/Python/interface/SBTarget.i +++ b/lldb/scripts/Python/interface/SBTarget.i @@ -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); diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index d3cd85c3dd72..b9947d985a98 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 @@ 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 () { diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index c860876fd12d..408d51cc54b5 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -761,17 +761,17 @@ SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType s 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 8b5731e80280..7a8b60189bc8 100644 --- a/lldb/source/Target/ExecutionContext.cpp +++ b/lldb/source/Target/ExecutionContext.cpp @@ -241,7 +241,15 @@ ExecutionContext::GetAddressByteSize() const 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