Fixed casting in the lldb::SBValue::Cast(SBType) function.

llvm-svn: 149673
This commit is contained in:
Greg Clayton 2012-02-03 05:34:10 +00:00
parent ccb673659a
commit 9a142cf84d
6 changed files with 205 additions and 3 deletions

View File

@ -773,6 +773,9 @@ public:
{
}
virtual lldb::ValueObjectSP
Cast (const ClangASTType &clang_ast_type);
virtual lldb::ValueObjectSP
CastPointerType (const char *name,
ClangASTType &ast_type);

View File

@ -15,9 +15,85 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/ValueObject.h"
#include "lldb/Symbol/ClangASTType.h"
namespace lldb_private {
class ValueObjectCast : public ValueObject
{
public:
virtual
~ValueObjectCast();
virtual size_t
GetByteSize();
virtual clang::ASTContext *
GetClangAST ();
virtual lldb::clang_type_t
GetClangType ();
virtual ConstString
GetTypeName();
virtual uint32_t
CalculateNumChildren();
virtual lldb::ValueType
GetValueType() const;
virtual bool
IsInScope ();
virtual bool
IsDynamic ()
{
return true;
}
virtual ValueObject *
GetParent()
{
if (m_parent)
return m_parent->GetParent();
else
return NULL;
}
virtual const ValueObject *
GetParent() const
{
if (m_parent)
return m_parent->GetParent();
else
return NULL;
}
virtual lldb::ValueObjectSP
GetStaticValue ()
{
return m_parent->GetSP();
}
protected:
virtual bool
UpdateValue ();
ClangASTType m_cast_type;
private:
friend class ValueObject;
ValueObjectCast (ValueObject &parent,
const ConstString &name,
const ClangASTType &cast_type);
//------------------------------------------------------------------
// For ValueObject only
//------------------------------------------------------------------
DISALLOW_COPY_AND_ASSIGN (ValueObjectCast);
};
//----------------------------------------------------------------------
// A ValueObject that represents memory at a given address, viewed as some
// set lldb type.

View File

@ -201,6 +201,15 @@ public:
GetTemplateArgumentKind (uint32_t idx);
%pythoncode %{
def template_arg_array(self):
num_args = self.num_template_args
if num_args:
template_args = []
for i in range(num_args):
template_args.append(self.GetTemplateArgumentType(i))
return template_args
return None
__swig_getmethods__["name"] = GetName
if _newclass: x = property(GetName, None)
@ -222,9 +231,16 @@ public:
__swig_getmethods__["num_vbases"] = GetNumberOfVirtualBaseClasses
if _newclass: x = property(GetNumberOfVirtualBaseClasses, None)
__swig_getmethods__["num_template_args"] = GetNumberOfTemplateArguments
if _newclass: x = property(GetNumberOfTemplateArguments, None)
__swig_getmethods__["template_args"] = template_arg_array
if _newclass: x = property(template_arg_array, None)
__swig_getmethods__["class"] = GetTypeClass
if _newclass: x = property(GetTypeClass, None)
%}
%}
};

View File

@ -378,8 +378,8 @@ lldb::SBValue
SBValue::Cast (SBType type)
{
lldb::SBValue sb_value;
if (m_opaque_sp)
sb_value = CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
if (m_opaque_sp && type.IsValid())
*sb_value = m_opaque_sp->Cast(type.ref().GetClangASTType());
return sb_value;
}

View File

@ -3429,6 +3429,12 @@ ValueObject::AddressOf (Error &error)
return m_addr_of_valobj_sp;
}
ValueObjectSP
ValueObject::Cast (const ClangASTType &clang_ast_type)
{
ValueObjectSP valobj_sp(new ValueObjectCast (*this, GetName(), clang_ast_type));
return valobj_sp;
}
ValueObjectSP
ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)

View File

@ -34,6 +34,107 @@
using namespace lldb_private;
ValueObjectCast::ValueObjectCast
(
ValueObject &parent,
const ConstString &name,
const ClangASTType &cast_type
) :
ValueObject(parent),
m_cast_type (cast_type)
{
SetName (name);
m_value.SetContext (Value::eContextTypeClangType, cast_type.GetOpaqueQualType());
}
ValueObjectCast::~ValueObjectCast()
{
}
lldb::clang_type_t
ValueObjectCast::GetClangType ()
{
return m_cast_type.GetOpaqueQualType();
}
ConstString
ValueObjectCast::GetTypeName()
{
return ClangASTType::GetConstTypeName (GetClangType());
}
uint32_t
ValueObjectCast::CalculateNumChildren()
{
return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
}
clang::ASTContext *
ValueObjectCast::GetClangAST ()
{
return m_cast_type.GetASTContext();
}
size_t
ValueObjectCast::GetByteSize()
{
return m_value.GetValueByteSize(GetClangAST(), NULL);
}
lldb::ValueType
ValueObjectCast::GetValueType() const
{
// Let our parent answer global, local, argument, etc...
return m_parent->GetValueType();
}
bool
ValueObjectCast::UpdateValue ()
{
SetValueIsValid (false);
m_error.Clear();
if (m_parent->UpdateValueIfNeeded(false))
{
Value old_value(m_value);
m_update_point.SetUpdated();
m_value = m_parent->GetValue();
m_value.SetContext (Value::eContextTypeClangType, GetClangType());
SetAddressTypeOfChildren(m_parent->GetAddressTypeOfChildren());
if (ClangASTContext::IsAggregateType (GetClangType()))
{
// 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 (m_value.GetValueType() != old_value.GetValueType() || m_value.GetScalar() != old_value.GetScalar());
}
ExecutionContext exe_ctx (GetExecutionContextScope());
m_error = m_value.GetValueAsData(&exe_ctx, GetClangAST(), m_data, 0, GetModule());
SetValueDidChange (m_parent->GetValueDidChange());
return true;
}
// The dynamic value failed to get an error, pass the error along
if (m_error.Success() && m_parent->GetError().Fail())
m_error = m_parent->GetError();
SetValueIsValid (false);
return false;
}
bool
ValueObjectCast::IsInScope ()
{
return m_parent->IsInScope();
}
//----------------------------------------------------------------------
ValueObjectDynamicValue::ValueObjectDynamicValue (ValueObject &parent, lldb::DynamicValueType use_dynamic) :
ValueObject(parent),
m_address (),