diff options
author | Greg Clayton <gclayton@apple.com> | 2010-12-14 02:59:59 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-12-14 02:59:59 +0000 |
commit | 8b2fe6dcbdf27b0df84ef4bdf514f9bc577c5804 (patch) | |
tree | 9816fbd1612d4cb872b44f996c47f67f9fc6470f /lldb/source/Core/ValueObject.cpp | |
parent | 12960558416a6797ea7504e7d9934bb11a5b1f42 (diff) | |
download | bcm5719-llvm-8b2fe6dcbdf27b0df84ef4bdf514f9bc577c5804.tar.gz bcm5719-llvm-8b2fe6dcbdf27b0df84ef4bdf514f9bc577c5804.zip |
Modified LLDB expressions to not have to JIT and run code just to see variable
values or persistent expression variables. Now if an expression consists of
a value that is a child of a variable, or of a persistent variable only, we
will create a value object for it and make a ValueObjectConstResult from it to
freeze the value (for program variables only, not persistent variables) and
avoid running JITed code. For everything else we still parse up and JIT code
and run it in the inferior.
There was also a lot of clean up in the expression code. I made the
ClangExpressionVariables be stored in collections of shared pointers instead
of in collections of objects. This will help stop a lot of copy constructors on
these large objects and also cleans up the code considerably. The persistent
clang expression variables were moved over to the Target to ensure they persist
across process executions.
Added the ability for lldb_private::Target objects to evaluate expressions.
We want to evaluate expressions at the target level in case we aren't running
yet, or we have just completed running. We still want to be able to access the
persistent expression variables between runs, and also evaluate constant
expressions.
Added extra logging to the dynamic loader plug-in for MacOSX. ModuleList objects
can now dump their contents with the UUID, arch and full paths being logged with
appropriate prefix values.
Thread hardened the Communication class a bit by making the connection auto_ptr
member into a shared pointer member and then making a local copy of the shared
pointer in each method that uses it to make sure another thread can't nuke the
connection object while it is being used by another thread.
Added a new file to the lldb/test/load_unload test that causes the test a.out file
to link to the libd.dylib file all the time. This will allow us to test using
the DYLD_LIBRARY_PATH environment variable after moving libd.dylib somewhere else.
llvm-svn: 121745
Diffstat (limited to 'lldb/source/Core/ValueObject.cpp')
-rw-r--r-- | lldb/source/Core/ValueObject.cpp | 218 |
1 files changed, 210 insertions, 8 deletions
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 64c646ba567..60b1009ad7a 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -21,6 +21,7 @@ #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/StreamString.h" #include "lldb/Core/ValueObjectChild.h" +#include "lldb/Core/ValueObjectConstResult.h" #include "lldb/Core/ValueObjectList.h" #include "lldb/Symbol/ClangASTType.h" @@ -62,7 +63,8 @@ ValueObject::ValueObject (ValueObject *parent) : m_value_is_valid (false), m_value_did_change (false), m_children_count_valid (false), - m_old_value_valid (false) + m_old_value_valid (false), + m_pointers_point_to_load_addrs (false) { } @@ -281,7 +283,7 @@ ValueObject::GetIndexOfChildWithName (const ConstString &name) bool omit_empty_base_classes = true; return ClangASTContext::GetIndexOfChildWithName (GetClangAST(), GetClangType(), - name.AsCString(), + name.GetCString(), omit_empty_base_classes); } @@ -297,7 +299,7 @@ ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) bool omit_empty_base_classes = true; const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast, clang_type, - name.AsCString(), + name.GetCString(), omit_empty_base_classes, child_indexes); ValueObjectSP child_sp; @@ -370,7 +372,7 @@ ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int3 clang_type_t clang_type = GetClangType(); clang_type_t child_clang_type; child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (clang_ast, - GetName().AsCString(), + GetName().GetCString(), clang_type, idx, transparent_pointers, @@ -399,6 +401,8 @@ ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int3 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class)); + if (m_pointers_point_to_load_addrs) + valobj_sp->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs); } return valobj_sp; } @@ -418,8 +422,8 @@ ValueObject::GetSummaryAsCString (ExecutionContextScope *exe_scope) StreamString sstr; clang_type_t elem_or_pointee_clang_type; const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, - GetClangAST(), - &elem_or_pointee_clang_type)); + GetClangAST(), + &elem_or_pointee_clang_type)); if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && ClangASTContext::IsCharType (elem_or_pointee_clang_type)) @@ -721,6 +725,10 @@ ValueObject::GetPointerValue (lldb::AddressType &address_type, bool scalar_is_lo } break; } + + if (m_pointers_point_to_load_addrs) + address_type = eAddressTypeLoad; + return address; } @@ -956,7 +964,7 @@ ValueObject::GetExpressionPath (Stream &s) } else { - const char *name = GetName().AsCString(); + const char *name = GetName().GetCString(); if (name) s.PutCString(name); } @@ -1001,7 +1009,7 @@ ValueObject::DumpValueObject // Always show the type for the top level items. if (show_types || curr_depth == 0) - s.Printf("(%s) ", valobj->GetTypeName().AsCString()); + s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>")); if (flat_output) @@ -1163,3 +1171,197 @@ ValueObject::DumpValueObject } } + +ValueObjectSP +ValueObject::CreateConstantValue (ExecutionContextScope *exe_scope, const ConstString &name) +{ + ValueObjectSP valobj_sp; + + if (UpdateValueIfNeeded(exe_scope) && m_error.Success()) + { + ExecutionContext exe_ctx; + exe_scope->CalculateExecutionContext(exe_ctx); + + clang::ASTContext *ast = GetClangAST (); + + DataExtractor data; + data.SetByteOrder (m_data.GetByteOrder()); + data.SetAddressByteSize(m_data.GetAddressByteSize()); + + m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0); + + valobj_sp.reset (new ValueObjectConstResult (ast, + GetClangType(), + name, + data)); + } + else + { + valobj_sp.reset (new ValueObjectConstResult (m_error)); + } + return valobj_sp; +} + +lldb::ValueObjectSP +ValueObject::Dereference (ExecutionContextScope *exe_scope, Error *error_ptr) +{ + lldb::ValueObjectSP valobj_sp; + if (IsPointerType()) + { + bool omit_empty_base_classes = true; + + std::string child_name_str; + uint32_t child_byte_size = 0; + int32_t child_byte_offset = 0; + uint32_t child_bitfield_bit_size = 0; + uint32_t child_bitfield_bit_offset = 0; + bool child_is_base_class = false; + const bool transparent_pointers = false; + clang::ASTContext *clang_ast = GetClangAST(); + clang_type_t clang_type = GetClangType(); + clang_type_t child_clang_type; + child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (clang_ast, + GetName().GetCString(), + clang_type, + 0, + transparent_pointers, + omit_empty_base_classes, + child_name_str, + child_byte_size, + child_byte_offset, + child_bitfield_bit_size, + child_bitfield_bit_offset, + child_is_base_class); + if (child_clang_type) + { + ConstString child_name; + if (!child_name_str.empty()) + child_name.SetCString (child_name_str.c_str()); + + valobj_sp.reset (new ValueObjectChild (this, + clang_ast, + child_clang_type, + child_name, + child_byte_size, + child_byte_offset, + child_bitfield_bit_size, + child_bitfield_bit_offset, + child_is_base_class)); + } + } + else + { + if (error_ptr) + error_ptr->SetErrorString("can't dereference a non-pointer value"); + } + + return valobj_sp; +} + + + +//lldb::ValueObjectSP +//ValueObject::Dereference (ExecutionContextScope *exe_scope, Error *error_ptr) +//{ +// lldb::ValueObjectSP valobj_sp; +// if (IsPointerType()) +// { +// UpdateValueIfNeeded(exe_scope); +// if (m_error.Success()) +// { +// lldb::AddressType address_type = eAddressTypeInvalid; +// const bool scalar_is_load_address = true; +// lldb::addr_t addr = GetPointerValue (address_type, scalar_is_load_address); +// if (addr != LLDB_INVALID_ADDRESS) +// { +// switch (address_type) +// { +// case eAddressTypeInvalid: +// if (error_ptr) +// error_ptr->SetErrorString("value is not in memory"); +// break; +// case eAddressTypeFile: +// case eAddressTypeLoad: +// case eAddressTypeHost: +// { +// clang::ASTContext *ast = GetClangAST(); +// clang_type_t clang_type = ClangASTType::GetPointeeType (GetClangType()); +// if (ast && clang_type) +// { +// std::string name (1, '*'); +// name.append (m_name.AsCString("")); +// valobj_sp.reset (new ValueObjectConstResult (ast, +// ClangASTContext::CreatePointerType (ast, clang_type), +// ConstString (name.c_str()), +// addr, +// address_type, +// m_data.GetAddressByteSize())); +// } +// else +// { +// if (error_ptr) +// error_ptr->SetErrorString("invalid clang type info"); +// } +// } +// break; +// } +// } +// else +// { +// if (error_ptr) +// error_ptr->SetErrorString("failed to extract pointer value"); +// } +// } +// else +// { +// if (error_ptr) +// *error_ptr = m_error; +// } +// } +// else +// { +// if (error_ptr) +// error_ptr->SetErrorString("can't dereference a non-pointer value"); +// } +// +// return valobj_sp; +//} + +lldb::ValueObjectSP +ValueObject::AddressOf () +{ + lldb::ValueObjectSP valobj_sp; + + lldb::AddressType address_type = eAddressTypeInvalid; + const bool scalar_is_load_address = false; + lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); + if (addr != LLDB_INVALID_ADDRESS) + { + switch (address_type) + { + case eAddressTypeInvalid: + break; + case eAddressTypeFile: + case eAddressTypeLoad: + case eAddressTypeHost: + { + clang::ASTContext *ast = GetClangAST(); + clang_type_t clang_type = GetClangType(); + if (ast && clang_type) + { + std::string name (1, '&'); + name.append (m_name.AsCString("")); + valobj_sp.reset (new ValueObjectConstResult (ast, + ClangASTContext::CreatePointerType (ast, clang_type), + ConstString (name.c_str()), + addr, + address_type, + m_data.GetAddressByteSize())); + } + } + break; + } + } + return valobj_sp; +} + |