2010-06-09 00:52:24 +08:00
|
|
|
//===-- ValueObjectChild.cpp ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Core/ValueObjectChild.h"
|
|
|
|
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/ValueObjectList.h"
|
|
|
|
|
2010-07-22 06:12:05 +08:00
|
|
|
#include "lldb/Symbol/ClangASTType.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
|
|
#include "lldb/Symbol/SymbolContext.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
#include "lldb/Symbol/Variable.h"
|
|
|
|
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
ValueObjectChild::ValueObjectChild
|
|
|
|
(
|
2011-03-31 08:19:25 +08:00
|
|
|
ValueObject &parent,
|
2010-06-09 00:52:24 +08:00
|
|
|
clang::ASTContext *clang_ast,
|
|
|
|
void *clang_type,
|
|
|
|
const ConstString &name,
|
|
|
|
uint32_t byte_size,
|
|
|
|
int32_t byte_offset,
|
|
|
|
uint32_t bitfield_bit_size,
|
2010-10-15 06:52:14 +08:00
|
|
|
uint32_t bitfield_bit_offset,
|
2011-01-21 09:59:00 +08:00
|
|
|
bool is_base_class,
|
|
|
|
bool is_deref_of_parent
|
2010-06-09 00:52:24 +08:00
|
|
|
) :
|
2010-10-15 06:52:14 +08:00
|
|
|
ValueObject (parent),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_clang_ast (clang_ast),
|
|
|
|
m_clang_type (clang_type),
|
|
|
|
m_byte_size (byte_size),
|
|
|
|
m_byte_offset (byte_offset),
|
|
|
|
m_bitfield_bit_size (bitfield_bit_size),
|
2010-10-15 06:52:14 +08:00
|
|
|
m_bitfield_bit_offset (bitfield_bit_offset),
|
2011-01-21 09:59:00 +08:00
|
|
|
m_is_base_class (is_base_class),
|
|
|
|
m_is_deref_of_parent (is_deref_of_parent)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectChild::~ValueObjectChild()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ValueType
|
|
|
|
ValueObjectChild::GetValueType() const
|
|
|
|
{
|
|
|
|
return m_parent->GetValueType();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ValueObjectChild::CalculateNumChildren()
|
|
|
|
{
|
A few of the issue I have been trying to track down and fix have been due to
the way LLDB lazily gets complete definitions for types within the debug info.
When we run across a class/struct/union definition in the DWARF, we will only
parse the full definition if we need to. This works fine for top level types
that are assigned directly to variables and arguments, but when we have a
variable with a class, lets say "A" for this example, that has a member:
"B *m_b". Initially we don't need to hunt down a definition for this class
unless we are ever asked to do something with it ("expr m_b->getDecl()" for
example). With my previous approach to lazy type completion, we would be able
to take a "A *a" and get a complete type for it, but we wouldn't be able to
then do an "a->m_b->getDecl()" unless we always expanded all types within a
class prior to handing out the type. Expanding everything is very costly and
it would be great if there were a better way.
A few months ago I worked with the llvm/clang folks to have the
ExternalASTSource class be able to complete classes if there weren't completed
yet:
class ExternalASTSource {
....
virtual void
CompleteType (clang::TagDecl *Tag);
virtual void
CompleteType (clang::ObjCInterfaceDecl *Class);
};
This was great, because we can now have the class that is producing the AST
(SymbolFileDWARF and SymbolFileDWARFDebugMap) sign up as external AST sources
and the object that creates the forward declaration types can now also
complete them anywhere within the clang type system.
This patch makes a few major changes:
- lldb_private::Module classes now own the AST context. Previously the TypeList
objects did.
- The DWARF parsers now sign up as an external AST sources so they can complete
types.
- All of the pure clang type system wrapper code we have in LLDB (ClangASTContext,
ClangASTType, and more) can now be iterating through children of any type,
and if a class/union/struct type (clang::RecordType or ObjC interface)
is found that is incomplete, we can ask the AST to get the definition.
- The SymbolFileDWARFDebugMap class now will create and use a single AST that
all child SymbolFileDWARF classes will share (much like what happens when
we have a complete linked DWARF for an executable).
We will need to modify some of the ClangUserExpression code to take more
advantage of this completion ability in the near future. Meanwhile we should
be better off now that we can be accessing any children of variables through
pointers and always be able to resolve the clang type if needed.
llvm-svn: 123613
2011-01-17 11:46:26 +08:00
|
|
|
return ClangASTContext::GetNumChildren (GetClangAST (), m_clang_type, true);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
ValueObjectChild::GetTypeName()
|
|
|
|
{
|
|
|
|
if (m_type_name.IsEmpty())
|
|
|
|
{
|
2011-06-30 10:28:26 +08:00
|
|
|
m_type_name = ClangASTType::GetConstTypeName (GetClangType());
|
2010-06-09 00:52:24 +08:00
|
|
|
if (m_type_name)
|
|
|
|
{
|
|
|
|
if (m_bitfield_bit_size > 0)
|
|
|
|
{
|
|
|
|
const char *clang_type_name = m_type_name.AsCString();
|
|
|
|
if (clang_type_name)
|
|
|
|
{
|
2010-07-10 04:39:50 +08:00
|
|
|
std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0);
|
2010-07-21 06:52:08 +08:00
|
|
|
::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, m_bitfield_bit_size);
|
|
|
|
m_type_name.SetCString(&bitfield_type_name.front());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_type_name;
|
|
|
|
}
|
|
|
|
|
2011-03-31 08:19:25 +08:00
|
|
|
bool
|
|
|
|
ValueObjectChild::UpdateValue ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_error.Clear();
|
|
|
|
SetValueIsValid (false);
|
|
|
|
ValueObject* parent = m_parent;
|
|
|
|
if (parent)
|
|
|
|
{
|
2011-04-16 08:01:13 +08:00
|
|
|
if (parent->UpdateValueIfNeeded())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-13 11:52:47 +08:00
|
|
|
m_value.SetContext(Value::eContextTypeClangType, m_clang_type);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Copy the parent scalar value and the scalar value type
|
|
|
|
m_value.GetScalar() = parent->GetValue().GetScalar();
|
|
|
|
Value::ValueType value_type = parent->GetValue().GetValueType();
|
|
|
|
m_value.SetValueType (value_type);
|
|
|
|
|
2010-09-29 09:12:09 +08:00
|
|
|
if (ClangASTContext::IsPointerOrReferenceType (parent->GetClangType()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
uint32_t offset = 0;
|
|
|
|
m_value.GetScalar() = parent->GetDataExtractor().GetPointer(&offset);
|
2010-11-02 09:50:16 +08:00
|
|
|
|
|
|
|
lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
|
|
|
|
if (addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_error.SetErrorString ("parent address is invalid.");
|
|
|
|
}
|
|
|
|
else if (addr == 0)
|
|
|
|
{
|
|
|
|
m_error.SetErrorString ("parent is NULL");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-03 05:21:20 +08:00
|
|
|
m_value.GetScalar() += m_byte_offset;
|
2010-12-14 10:59:59 +08:00
|
|
|
if (m_pointers_point_to_load_addrs ||
|
|
|
|
value_type == Value::eValueTypeScalar ||
|
2010-11-02 09:50:16 +08:00
|
|
|
value_type == Value::eValueTypeFileAddress)
|
|
|
|
m_value.SetValueType (Value::eValueTypeLoadAddress);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (value_type)
|
|
|
|
{
|
|
|
|
case Value::eValueTypeLoadAddress:
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
{
|
|
|
|
lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
2010-11-02 09:50:16 +08:00
|
|
|
if (addr == LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_error.SetErrorString ("parent address is invalid.");
|
|
|
|
}
|
|
|
|
else if (addr == 0)
|
|
|
|
{
|
|
|
|
m_error.SetErrorString ("parent is NULL");
|
|
|
|
}
|
|
|
|
else
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-02 09:50:16 +08:00
|
|
|
// Set this object's scalar value to the address of its
|
|
|
|
// value be adding its byte offset to the parent address
|
|
|
|
m_value.GetScalar() += GetByteOffset();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeScalar:
|
|
|
|
// TODO: What if this is a register value? Do we try and
|
|
|
|
// extract the child value from within the parent data?
|
|
|
|
// Probably...
|
|
|
|
default:
|
|
|
|
m_error.SetErrorString ("Parent has invalid value.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_error.Success())
|
|
|
|
{
|
2011-03-31 08:19:25 +08:00
|
|
|
ExecutionContext exe_ctx (GetExecutionContextScope());
|
2010-06-09 00:52:24 +08:00
|
|
|
m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST (), m_data, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_error.SetErrorStringWithFormat("Parent failed to evaluate: %s.\n", parent->GetError().AsCString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_error.SetErrorString("ValueObjectChild has a NULL parent ValueObject.");
|
|
|
|
}
|
2011-03-31 08:19:25 +08:00
|
|
|
|
|
|
|
return m_error.Success();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2011-03-31 08:19:25 +08:00
|
|
|
ValueObjectChild::IsInScope ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-03-31 08:19:25 +08:00
|
|
|
return m_parent->IsInScope ();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|