2010-06-09 00:52:24 +08:00
|
|
|
//===-- ValueObjectVariable.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/ValueObjectVariable.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/ValueObjectList.h"
|
|
|
|
#include "lldb/Core/Value.h"
|
|
|
|
|
|
|
|
#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/RegisterContext.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2010-09-02 10:59:18 +08:00
|
|
|
ValueObjectVariable::ValueObjectVariable (const lldb::VariableSP &var_sp) :
|
2010-10-15 06:52:14 +08:00
|
|
|
ValueObject(NULL),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_variable_sp(var_sp)
|
|
|
|
{
|
|
|
|
// Do not attempt to construct one of these objects with no variable!
|
|
|
|
assert (m_variable_sp.get() != NULL);
|
|
|
|
m_name = var_sp->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectVariable::~ValueObjectVariable()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
lldb::clang_type_t
|
2010-09-29 09:12:09 +08:00
|
|
|
ValueObjectVariable::GetClangType ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
Type *var_type = m_variable_sp->GetType();
|
|
|
|
if (var_type)
|
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 var_type->GetClangForwardType();
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
ValueObjectVariable::GetTypeName()
|
|
|
|
{
|
|
|
|
Type * var_type = m_variable_sp->GetType();
|
|
|
|
if (var_type)
|
|
|
|
return var_type->GetName();
|
|
|
|
ConstString empty_type_name;
|
|
|
|
return empty_type_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ValueObjectVariable::CalculateNumChildren()
|
|
|
|
{
|
|
|
|
Type *var_type = m_variable_sp->GetType();
|
|
|
|
if (var_type)
|
|
|
|
return var_type->GetNumChildren(true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
clang::ASTContext *
|
|
|
|
ValueObjectVariable::GetClangAST ()
|
|
|
|
{
|
|
|
|
return m_variable_sp->GetType()->GetClangAST();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
ValueObjectVariable::GetByteSize()
|
|
|
|
{
|
|
|
|
return m_variable_sp->GetType()->GetByteSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ValueType
|
|
|
|
ValueObjectVariable::GetValueType() const
|
|
|
|
{
|
|
|
|
if (m_variable_sp)
|
|
|
|
return m_variable_sp->GetScope();
|
|
|
|
return lldb::eValueTypeInvalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ValueObjectVariable::UpdateValue (ExecutionContextScope *exe_scope)
|
|
|
|
{
|
|
|
|
SetValueIsValid (false);
|
|
|
|
m_error.Clear();
|
|
|
|
|
|
|
|
Variable *variable = m_variable_sp.get();
|
|
|
|
DWARFExpression &expr = variable->LocationExpression();
|
2010-09-14 10:20:48 +08:00
|
|
|
lldb::addr_t loclist_base_load_addr = LLDB_INVALID_ADDRESS;
|
2010-06-09 00:52:24 +08:00
|
|
|
ExecutionContext exe_ctx (exe_scope);
|
2010-09-18 12:00:06 +08:00
|
|
|
|
2011-02-16 05:59:32 +08:00
|
|
|
if (exe_ctx.target)
|
2010-09-18 12:00:06 +08:00
|
|
|
{
|
2011-02-16 05:59:32 +08:00
|
|
|
m_data.SetByteOrder(exe_ctx.target->GetArchitecture().GetByteOrder());
|
|
|
|
m_data.SetAddressByteSize(exe_ctx.target->GetArchitecture().GetAddressByteSize());
|
2010-09-18 12:00:06 +08:00
|
|
|
}
|
|
|
|
|
2010-09-14 10:20:48 +08:00
|
|
|
if (expr.IsLocationList())
|
|
|
|
{
|
|
|
|
SymbolContext sc;
|
|
|
|
variable->CalculateSymbolContext (&sc);
|
|
|
|
if (sc.function)
|
2010-09-15 07:36:40 +08:00
|
|
|
loclist_base_load_addr = sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.target);
|
2010-09-14 10:20:48 +08:00
|
|
|
}
|
|
|
|
Value old_value(m_value);
|
2011-01-26 07:55:37 +08:00
|
|
|
if (expr.Evaluate (&exe_ctx, GetClangAST(), NULL, NULL, NULL, loclist_base_load_addr, NULL, m_value, &m_error))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-11-13 11:52:47 +08:00
|
|
|
m_value.SetContext(Value::eContextTypeVariable, variable);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
Value::ValueType value_type = m_value.GetValueType();
|
|
|
|
|
|
|
|
switch (value_type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
assert(!"Unhandled expression result value kind...");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeScalar:
|
|
|
|
// The variable value is in the Scalar value inside the m_value.
|
|
|
|
// We can point our m_data right to it.
|
|
|
|
m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST(), m_data, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
case Value::eValueTypeLoadAddress:
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
// The DWARF expression result was an address in the inferior
|
|
|
|
// process. If this variable is an aggregate type, we just need
|
|
|
|
// the address as the main value as all child variable objects
|
|
|
|
// will rely upon this location and add an offset and then read
|
|
|
|
// their own values as needed. If this variable is a simple
|
|
|
|
// type, we read all data for it into m_data.
|
|
|
|
// Make sure this type has a value before we try and read it
|
2010-09-13 10:37:44 +08:00
|
|
|
|
|
|
|
// If we have a file address, convert it to a load address if we can.
|
|
|
|
if (value_type == Value::eValueTypeFileAddress && exe_ctx.process)
|
|
|
|
{
|
|
|
|
lldb::addr_t file_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
if (file_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
SymbolContext var_sc;
|
|
|
|
variable->CalculateSymbolContext(&var_sc);
|
|
|
|
if (var_sc.module_sp)
|
|
|
|
{
|
|
|
|
ObjectFile *objfile = var_sc.module_sp->GetObjectFile();
|
|
|
|
if (objfile)
|
|
|
|
{
|
|
|
|
Address so_addr(file_addr, objfile->GetSectionList());
|
2010-09-15 07:36:40 +08:00
|
|
|
lldb::addr_t load_addr = so_addr.GetLoadAddress (exe_ctx.target);
|
2010-09-13 10:37:44 +08:00
|
|
|
if (load_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_value.SetValueType(Value::eValueTypeLoadAddress);
|
|
|
|
m_value.GetScalar() = load_addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-29 09:12:09 +08:00
|
|
|
if (ClangASTContext::IsAggregateType (GetClangType()))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// this value object represents an aggregate type whose
|
|
|
|
// children have values, but this object does not. So we
|
|
|
|
// say we are changed if our location has changed.
|
|
|
|
SetValueDidChange (value_type != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Copy the Value and set the context to use our Variable
|
|
|
|
// so it can extract read its value into m_data appropriately
|
|
|
|
Value value(m_value);
|
2010-11-13 11:52:47 +08:00
|
|
|
value.SetContext(Value::eContextTypeVariable, variable);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_error = value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetValueIsValid (m_error.Success());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObjectVariable::IsInScope (StackFrame *frame)
|
|
|
|
{
|
|
|
|
return m_variable_sp->IsInScope (frame);
|
|
|
|
}
|
|
|
|
|