2010-06-09 00:52:24 +08:00
|
|
|
//===-- ValueObject.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/ValueObject.h"
|
|
|
|
|
|
|
|
// C Includes
|
2010-09-15 07:36:40 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/DataBufferHeap.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
|
|
|
#include "lldb/Core/ValueObjectChild.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/ClangASTContext.h"
|
|
|
|
#include "lldb/Symbol/Type.h"
|
|
|
|
|
2010-09-11 07:12:17 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-09-28 09:25:32 +08:00
|
|
|
#include "lldb/Target/LanguageRuntime.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-09-15 07:36:40 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
static lldb::user_id_t g_value_obj_uid = 0;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// ValueObject constructor
|
|
|
|
//----------------------------------------------------------------------
|
2010-10-15 06:52:14 +08:00
|
|
|
ValueObject::ValueObject (ValueObject *parent) :
|
2010-06-09 00:52:24 +08:00
|
|
|
UserID (++g_value_obj_uid), // Unique identifier for every value object
|
2010-10-15 06:52:14 +08:00
|
|
|
m_parent (parent),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_update_id (0), // Value object lists always start at 1, value objects start at zero
|
|
|
|
m_name (),
|
|
|
|
m_data (),
|
|
|
|
m_value (),
|
|
|
|
m_error (),
|
2010-09-02 10:59:18 +08:00
|
|
|
m_value_str (),
|
|
|
|
m_old_value_str (),
|
|
|
|
m_location_str (),
|
|
|
|
m_summary_str (),
|
2010-09-11 07:12:17 +08:00
|
|
|
m_object_desc_str (),
|
2010-09-02 10:59:18 +08:00
|
|
|
m_children (),
|
|
|
|
m_synthetic_children (),
|
2010-10-06 11:09:11 +08:00
|
|
|
m_dynamic_value_sp (),
|
|
|
|
m_format (eFormatDefault),
|
2010-09-02 10:59:18 +08:00
|
|
|
m_value_is_valid (false),
|
|
|
|
m_value_did_change (false),
|
|
|
|
m_children_count_valid (false),
|
|
|
|
m_old_value_valid (false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ValueObject::~ValueObject ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
user_id_t
|
|
|
|
ValueObject::GetUpdateID() const
|
|
|
|
{
|
|
|
|
return m_update_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObject::UpdateValueIfNeeded (ExecutionContextScope *exe_scope)
|
|
|
|
{
|
2010-10-05 11:13:51 +08:00
|
|
|
// If this is a constant value, then our success is predicated on whether
|
|
|
|
// we have an error or not
|
|
|
|
if (GetIsConstant())
|
|
|
|
return m_error.Success();
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (exe_scope)
|
|
|
|
{
|
|
|
|
Process *process = exe_scope->CalculateProcess();
|
|
|
|
if (process)
|
|
|
|
{
|
|
|
|
const user_id_t stop_id = process->GetStopID();
|
|
|
|
if (m_update_id != stop_id)
|
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
bool first_update = m_update_id == 0;
|
2010-08-28 08:08:07 +08:00
|
|
|
// Save the old value using swap to avoid a string copy which
|
|
|
|
// also will clear our m_value_str
|
2010-09-02 10:59:18 +08:00
|
|
|
if (m_value_str.empty())
|
|
|
|
{
|
|
|
|
m_old_value_valid = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_old_value_valid = true;
|
|
|
|
m_old_value_str.swap (m_value_str);
|
|
|
|
m_value_str.clear();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
m_location_str.clear();
|
|
|
|
m_summary_str.clear();
|
2010-09-11 07:12:17 +08:00
|
|
|
m_object_desc_str.clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-08-28 08:08:07 +08:00
|
|
|
const bool value_was_valid = GetValueIsValid();
|
|
|
|
SetValueDidChange (false);
|
|
|
|
|
|
|
|
m_error.Clear();
|
|
|
|
|
|
|
|
// Call the pure virtual function to update the value
|
2010-06-09 00:52:24 +08:00
|
|
|
UpdateValue (exe_scope);
|
2010-08-28 08:08:07 +08:00
|
|
|
|
|
|
|
// Update the fact that we tried to update the value for this
|
2010-09-18 11:37:20 +08:00
|
|
|
// value object whether or not we succeed
|
2010-08-28 08:08:07 +08:00
|
|
|
m_update_id = stop_id;
|
|
|
|
bool success = m_error.Success();
|
|
|
|
SetValueIsValid (success);
|
2010-09-02 10:59:18 +08:00
|
|
|
|
|
|
|
if (first_update)
|
|
|
|
SetValueDidChange (false);
|
|
|
|
else if (!m_value_did_change && success == false)
|
2010-08-28 08:08:07 +08:00
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
// The value wasn't gotten successfully, so we mark this
|
|
|
|
// as changed if the value used to be valid and now isn't
|
|
|
|
SetValueDidChange (value_was_valid);
|
2010-08-28 08:08:07 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_error.Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
const DataExtractor &
|
|
|
|
ValueObject::GetDataExtractor () const
|
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataExtractor &
|
|
|
|
ValueObject::GetDataExtractor ()
|
|
|
|
{
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Error &
|
|
|
|
ValueObject::GetError() const
|
|
|
|
{
|
|
|
|
return m_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConstString &
|
|
|
|
ValueObject::GetName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ValueObject::GetLocationAsCString (ExecutionContextScope *exe_scope)
|
|
|
|
{
|
|
|
|
if (UpdateValueIfNeeded(exe_scope))
|
|
|
|
{
|
|
|
|
if (m_location_str.empty())
|
|
|
|
{
|
|
|
|
StreamString sstr;
|
|
|
|
|
|
|
|
switch (m_value.GetValueType())
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeScalar:
|
|
|
|
if (m_value.GetContextType() == Value::eContextTypeDCRegisterInfo)
|
|
|
|
{
|
|
|
|
RegisterInfo *reg_info = m_value.GetRegisterInfo();
|
|
|
|
if (reg_info)
|
|
|
|
{
|
|
|
|
if (reg_info->name)
|
|
|
|
m_location_str = reg_info->name;
|
|
|
|
else if (reg_info->alt_name)
|
|
|
|
m_location_str = reg_info->alt_name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_location_str = "scalar";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeLoadAddress:
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
{
|
|
|
|
uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2;
|
|
|
|
sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
|
|
|
|
m_location_str.swap(sstr.GetString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_location_str.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
Value &
|
|
|
|
ValueObject::GetValue()
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Value &
|
|
|
|
ValueObject::GetValue() const
|
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-09-02 10:59:18 +08:00
|
|
|
ValueObject::GetValueIsValid () const
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
return m_value_is_valid;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ValueObject::SetValueIsValid (bool b)
|
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
m_value_is_valid = b;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-09-02 10:59:18 +08:00
|
|
|
ValueObject::GetValueDidChange (ExecutionContextScope *exe_scope)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
GetValueAsCString (exe_scope);
|
|
|
|
return m_value_did_change;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ValueObject::SetValueDidChange (bool value_changed)
|
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
m_value_did_change = value_changed;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectSP
|
|
|
|
ValueObject::GetChildAtIndex (uint32_t idx, bool can_create)
|
|
|
|
{
|
|
|
|
ValueObjectSP child_sp;
|
|
|
|
if (idx < GetNumChildren())
|
|
|
|
{
|
|
|
|
// Check if we have already made the child value object?
|
|
|
|
if (can_create && m_children[idx].get() == NULL)
|
|
|
|
{
|
|
|
|
// No we haven't created the child at this index, so lets have our
|
|
|
|
// subclass do it and cache the result for quick future access.
|
|
|
|
m_children[idx] = CreateChildAtIndex (idx, false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
child_sp = m_children[idx];
|
|
|
|
}
|
|
|
|
return child_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ValueObject::GetIndexOfChildWithName (const ConstString &name)
|
|
|
|
{
|
|
|
|
bool omit_empty_base_classes = true;
|
|
|
|
return ClangASTContext::GetIndexOfChildWithName (GetClangAST(),
|
2010-09-29 09:12:09 +08:00
|
|
|
GetClangType(),
|
2010-06-09 00:52:24 +08:00
|
|
|
name.AsCString(),
|
|
|
|
omit_empty_base_classes);
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectSP
|
|
|
|
ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
|
|
|
|
{
|
|
|
|
// when getting a child by name, it could be burried inside some base
|
|
|
|
// classes (which really aren't part of the expression path), so we
|
|
|
|
// need a vector of indexes that can get us down to the correct child
|
|
|
|
std::vector<uint32_t> child_indexes;
|
|
|
|
clang::ASTContext *clang_ast = GetClangAST();
|
2010-09-29 09:12:09 +08:00
|
|
|
void *clang_type = GetClangType();
|
2010-06-09 00:52:24 +08:00
|
|
|
bool omit_empty_base_classes = true;
|
|
|
|
const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast,
|
|
|
|
clang_type,
|
|
|
|
name.AsCString(),
|
|
|
|
omit_empty_base_classes,
|
|
|
|
child_indexes);
|
|
|
|
ValueObjectSP child_sp;
|
|
|
|
if (num_child_indexes > 0)
|
|
|
|
{
|
|
|
|
std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
|
|
|
|
std::vector<uint32_t>::const_iterator end = child_indexes.end ();
|
|
|
|
|
|
|
|
child_sp = GetChildAtIndex(*pos, can_create);
|
|
|
|
for (++pos; pos != end; ++pos)
|
|
|
|
{
|
|
|
|
if (child_sp)
|
|
|
|
{
|
|
|
|
ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
|
|
|
|
child_sp = new_child_sp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return child_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ValueObject::GetNumChildren ()
|
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
if (!m_children_count_valid)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
SetNumChildren (CalculateNumChildren());
|
|
|
|
}
|
|
|
|
return m_children.size();
|
|
|
|
}
|
|
|
|
void
|
|
|
|
ValueObject::SetNumChildren (uint32_t num_children)
|
|
|
|
{
|
2010-09-02 10:59:18 +08:00
|
|
|
m_children_count_valid = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
m_children.resize(num_children);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ValueObject::SetName (const char *name)
|
|
|
|
{
|
|
|
|
m_name.SetCString(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ValueObject::SetName (const ConstString &name)
|
|
|
|
{
|
|
|
|
m_name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectSP
|
|
|
|
ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index)
|
|
|
|
{
|
|
|
|
ValueObjectSP valobj_sp;
|
|
|
|
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;
|
2010-10-15 06:52:14 +08:00
|
|
|
bool child_is_base_class = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
const bool transparent_pointers = synthetic_array_member == false;
|
|
|
|
clang::ASTContext *clang_ast = GetClangAST();
|
2010-10-27 11:32:59 +08:00
|
|
|
clang_type_t clang_type = GetClangType();
|
|
|
|
clang_type_t child_clang_type;
|
2010-06-09 00:52:24 +08:00
|
|
|
child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (clang_ast,
|
|
|
|
GetName().AsCString(),
|
|
|
|
clang_type,
|
|
|
|
idx,
|
|
|
|
transparent_pointers,
|
|
|
|
omit_empty_base_classes,
|
|
|
|
child_name_str,
|
|
|
|
child_byte_size,
|
|
|
|
child_byte_offset,
|
|
|
|
child_bitfield_bit_size,
|
2010-10-15 06:52:14 +08:00
|
|
|
child_bitfield_bit_offset,
|
|
|
|
child_is_base_class);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (child_clang_type)
|
|
|
|
{
|
|
|
|
if (synthetic_index)
|
|
|
|
child_byte_offset += child_byte_size * synthetic_index;
|
|
|
|
|
|
|
|
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,
|
2010-10-15 06:52:14 +08:00
|
|
|
child_bitfield_bit_offset,
|
|
|
|
child_is_base_class));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return valobj_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ValueObject::GetSummaryAsCString (ExecutionContextScope *exe_scope)
|
|
|
|
{
|
|
|
|
if (UpdateValueIfNeeded (exe_scope))
|
|
|
|
{
|
|
|
|
if (m_summary_str.empty())
|
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
clang_type_t clang_type = GetClangType();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// See if this is a pointer to a C string?
|
2010-09-13 11:32:57 +08:00
|
|
|
if (clang_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-13 11:32:57 +08:00
|
|
|
StreamString sstr;
|
2010-10-27 11:32:59 +08:00
|
|
|
clang_type_t elem_or_pointee_clang_type;
|
|
|
|
const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type,
|
|
|
|
GetClangAST(),
|
|
|
|
&elem_or_pointee_clang_type));
|
2010-09-13 11:32:57 +08:00
|
|
|
|
2010-10-27 11:32:59 +08:00
|
|
|
if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) &&
|
|
|
|
ClangASTContext::IsCharType (elem_or_pointee_clang_type))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-13 11:32:57 +08:00
|
|
|
Process *process = exe_scope->CalculateProcess();
|
|
|
|
if (process != NULL)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS;
|
2010-09-13 11:32:57 +08:00
|
|
|
lldb::AddressType cstr_address_type = eAddressTypeInvalid;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-27 11:32:59 +08:00
|
|
|
size_t cstr_len = 0;
|
|
|
|
if (type_flags.Test (ClangASTContext::eTypeIsArray))
|
|
|
|
{
|
|
|
|
// We have an array
|
|
|
|
cstr_len = ClangASTContext::GetArraySize (clang_type);
|
|
|
|
cstr_address = GetAddressOf (cstr_address_type, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We have a pointer
|
|
|
|
cstr_address = GetPointerValue (cstr_address_type, true);
|
|
|
|
}
|
2010-09-13 11:32:57 +08:00
|
|
|
if (cstr_address != LLDB_INVALID_ADDRESS)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-13 11:32:57 +08:00
|
|
|
DataExtractor data;
|
|
|
|
size_t bytes_read = 0;
|
|
|
|
std::vector<char> data_buffer;
|
|
|
|
std::vector<char> cstr_buffer;
|
|
|
|
size_t cstr_length;
|
|
|
|
Error error;
|
2010-10-27 11:32:59 +08:00
|
|
|
if (cstr_len > 0)
|
2010-09-13 11:32:57 +08:00
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
data_buffer.resize(cstr_len);
|
2010-09-13 11:32:57 +08:00
|
|
|
// Resize the formatted buffer in case every character
|
|
|
|
// uses the "\xXX" format and one extra byte for a NULL
|
|
|
|
cstr_buffer.resize(data_buffer.size() * 4 + 1);
|
|
|
|
data.SetData (&data_buffer.front(), data_buffer.size(), eByteOrderHost);
|
2010-10-27 11:32:59 +08:00
|
|
|
bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), cstr_len, error);
|
2010-09-13 11:32:57 +08:00
|
|
|
if (bytes_read > 0)
|
|
|
|
{
|
|
|
|
sstr << '"';
|
|
|
|
cstr_length = data.Dump (&sstr,
|
|
|
|
0, // Start offset in "data"
|
|
|
|
eFormatChar, // Print as characters
|
|
|
|
1, // Size of item (1 byte for a char!)
|
|
|
|
bytes_read, // How many bytes to print?
|
|
|
|
UINT32_MAX, // num per line
|
|
|
|
LLDB_INVALID_ADDRESS,// base address
|
|
|
|
0, // bitfield bit size
|
|
|
|
0); // bitfield bit offset
|
|
|
|
sstr << '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const size_t k_max_buf_size = 256;
|
|
|
|
data_buffer.resize (k_max_buf_size + 1);
|
|
|
|
// NULL terminate in case we don't get the entire C string
|
|
|
|
data_buffer.back() = '\0';
|
|
|
|
// Make a formatted buffer that can contain take 4
|
|
|
|
// bytes per character in case each byte uses the
|
|
|
|
// "\xXX" format and one extra byte for a NULL
|
|
|
|
cstr_buffer.resize (k_max_buf_size * 4 + 1);
|
|
|
|
|
|
|
|
data.SetData (&data_buffer.front(), data_buffer.size(), eByteOrderHost);
|
|
|
|
size_t total_cstr_len = 0;
|
|
|
|
while ((bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), k_max_buf_size, error)) > 0)
|
|
|
|
{
|
|
|
|
size_t len = strlen(&data_buffer.front());
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
if (len > bytes_read)
|
|
|
|
len = bytes_read;
|
|
|
|
if (sstr.GetSize() == 0)
|
|
|
|
sstr << '"';
|
|
|
|
|
|
|
|
cstr_length = data.Dump (&sstr,
|
|
|
|
0, // Start offset in "data"
|
|
|
|
eFormatChar, // Print as characters
|
|
|
|
1, // Size of item (1 byte for a char!)
|
|
|
|
len, // How many bytes to print?
|
|
|
|
UINT32_MAX, // num per line
|
|
|
|
LLDB_INVALID_ADDRESS,// base address
|
|
|
|
0, // bitfield bit size
|
|
|
|
0); // bitfield bit offset
|
|
|
|
|
|
|
|
if (len < k_max_buf_size)
|
|
|
|
break;
|
|
|
|
cstr_address += total_cstr_len;
|
|
|
|
}
|
|
|
|
if (sstr.GetSize() > 0)
|
|
|
|
sstr << '"';
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-13 11:32:57 +08:00
|
|
|
|
|
|
|
if (sstr.GetSize() > 0)
|
|
|
|
m_summary_str.assign (sstr.GetData(), sstr.GetSize());
|
|
|
|
}
|
|
|
|
else if (ClangASTContext::IsFunctionPointerType (clang_type))
|
|
|
|
{
|
|
|
|
lldb::AddressType func_ptr_address_type = eAddressTypeInvalid;
|
|
|
|
lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-13 11:32:57 +08:00
|
|
|
if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-13 11:32:57 +08:00
|
|
|
switch (func_ptr_address_type)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-13 11:32:57 +08:00
|
|
|
case eAddressTypeInvalid:
|
|
|
|
case eAddressTypeFile:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eAddressTypeLoad:
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-09-13 11:32:57 +08:00
|
|
|
Address so_addr;
|
2010-09-15 07:36:40 +08:00
|
|
|
Target *target = exe_scope->CalculateTarget();
|
|
|
|
if (target && target->GetSectionLoadList().IsEmpty() == false)
|
2010-09-13 11:32:57 +08:00
|
|
|
{
|
2010-09-15 07:36:40 +08:00
|
|
|
if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
|
2010-09-13 11:32:57 +08:00
|
|
|
{
|
|
|
|
so_addr.Dump (&sstr,
|
|
|
|
exe_scope,
|
|
|
|
Address::DumpStyleResolvedDescription,
|
|
|
|
Address::DumpStyleSectionNameOffset);
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-09-13 11:32:57 +08:00
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-13 11:32:57 +08:00
|
|
|
case eAddressTypeHost:
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2010-09-13 11:32:57 +08:00
|
|
|
}
|
|
|
|
if (sstr.GetSize() > 0)
|
|
|
|
{
|
|
|
|
m_summary_str.assign (1, '(');
|
|
|
|
m_summary_str.append (sstr.GetData(), sstr.GetSize());
|
|
|
|
m_summary_str.append (1, ')');
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_summary_str.empty())
|
|
|
|
return NULL;
|
|
|
|
return m_summary_str.c_str();
|
|
|
|
}
|
|
|
|
|
2010-09-11 07:12:17 +08:00
|
|
|
const char *
|
|
|
|
ValueObject::GetObjectDescription (ExecutionContextScope *exe_scope)
|
|
|
|
{
|
|
|
|
if (!m_object_desc_str.empty())
|
|
|
|
return m_object_desc_str.c_str();
|
|
|
|
|
|
|
|
if (!GetValueIsValid())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
Process *process = exe_scope->CalculateProcess();
|
2010-09-28 09:25:32 +08:00
|
|
|
if (process == NULL)
|
2010-09-11 07:12:17 +08:00
|
|
|
return NULL;
|
2010-09-28 09:25:32 +08:00
|
|
|
|
|
|
|
StreamString s;
|
2010-09-11 07:12:17 +08:00
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
lldb::LanguageType language = GetObjectRuntimeLanguage();
|
|
|
|
LanguageRuntime *runtime = process->GetLanguageRuntime(language);
|
2010-09-11 07:12:17 +08:00
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
if (runtime && runtime->GetObjectDescription(s, *this, exe_scope))
|
2010-09-11 07:12:17 +08:00
|
|
|
{
|
|
|
|
m_object_desc_str.append (s.GetData());
|
|
|
|
}
|
2010-10-23 08:18:49 +08:00
|
|
|
|
|
|
|
if (m_object_desc_str.empty())
|
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return m_object_desc_str.c_str();
|
2010-09-11 07:12:17 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
const char *
|
|
|
|
ValueObject::GetValueAsCString (ExecutionContextScope *exe_scope)
|
|
|
|
{
|
|
|
|
// If our byte size is zero this is an aggregate type that has children
|
2010-09-29 09:12:09 +08:00
|
|
|
if (ClangASTContext::IsAggregateType (GetClangType()) == false)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (UpdateValueIfNeeded(exe_scope))
|
|
|
|
{
|
|
|
|
if (m_value_str.empty())
|
|
|
|
{
|
|
|
|
const Value::ContextType context_type = m_value.GetContextType();
|
|
|
|
|
|
|
|
switch (context_type)
|
|
|
|
{
|
|
|
|
case Value::eContextTypeOpaqueClangQualType:
|
|
|
|
case Value::eContextTypeDCType:
|
|
|
|
case Value::eContextTypeDCVariable:
|
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
clang_type_t clang_type = GetClangType ();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (clang_type)
|
|
|
|
{
|
|
|
|
StreamString sstr;
|
2010-10-06 11:09:11 +08:00
|
|
|
if (m_format == eFormatDefault)
|
|
|
|
m_format = ClangASTType::GetFormat(clang_type);
|
|
|
|
|
|
|
|
if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST
|
|
|
|
clang_type, // The clang type to display
|
|
|
|
&sstr,
|
|
|
|
m_format, // Format to display this type with
|
|
|
|
m_data, // Data to extract from
|
|
|
|
0, // Byte offset into "m_data"
|
|
|
|
GetByteSize(), // Byte size of item in "m_data"
|
|
|
|
GetBitfieldBitSize(), // Bitfield bit size
|
|
|
|
GetBitfieldBitOffset())) // Bitfield bit offset
|
2010-06-09 00:52:24 +08:00
|
|
|
m_value_str.swap(sstr.GetString());
|
|
|
|
else
|
|
|
|
m_value_str.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eContextTypeDCRegisterInfo:
|
|
|
|
{
|
|
|
|
const RegisterInfo *reg_info = m_value.GetRegisterInfo();
|
|
|
|
if (reg_info)
|
|
|
|
{
|
|
|
|
StreamString reg_sstr;
|
|
|
|
m_data.Dump(®_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0);
|
|
|
|
m_value_str.swap(reg_sstr.GetString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-07-10 04:39:50 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-02 10:59:18 +08:00
|
|
|
|
|
|
|
if (!m_value_did_change && m_old_value_valid)
|
|
|
|
{
|
|
|
|
// The value was gotten successfully, so we consider the
|
|
|
|
// value as changed if the value string differs
|
|
|
|
SetValueDidChange (m_old_value_str != m_value_str);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_value_str.empty())
|
|
|
|
return NULL;
|
|
|
|
return m_value_str.c_str();
|
|
|
|
}
|
|
|
|
|
2010-10-27 11:32:59 +08:00
|
|
|
addr_t
|
|
|
|
ValueObject::GetAddressOf (lldb::AddressType &address_type, bool scalar_is_load_address)
|
|
|
|
{
|
|
|
|
switch (m_value.GetValueType())
|
|
|
|
{
|
|
|
|
case Value::eValueTypeScalar:
|
|
|
|
if (scalar_is_load_address)
|
|
|
|
{
|
|
|
|
address_type = eAddressTypeLoad;
|
|
|
|
return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeLoadAddress:
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
{
|
|
|
|
address_type = m_value.GetValueAddressType ();
|
|
|
|
return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
address_type = eAddressTypeInvalid;
|
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
|
2010-09-13 11:32:57 +08:00
|
|
|
addr_t
|
|
|
|
ValueObject::GetPointerValue (lldb::AddressType &address_type, bool scalar_is_load_address)
|
|
|
|
{
|
|
|
|
lldb::addr_t address = LLDB_INVALID_ADDRESS;
|
|
|
|
address_type = eAddressTypeInvalid;
|
2010-10-27 11:32:59 +08:00
|
|
|
switch (m_value.GetValueType())
|
2010-09-13 11:32:57 +08:00
|
|
|
{
|
|
|
|
case Value::eValueTypeScalar:
|
|
|
|
if (scalar_is_load_address)
|
|
|
|
{
|
|
|
|
address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
|
|
|
|
address_type = eAddressTypeLoad;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Value::eValueTypeLoadAddress:
|
|
|
|
case Value::eValueTypeFileAddress:
|
|
|
|
case Value::eValueTypeHostAddress:
|
|
|
|
{
|
|
|
|
uint32_t data_offset = 0;
|
|
|
|
address = m_data.GetPointer(&data_offset);
|
|
|
|
address_type = m_value.GetValueAddressType();
|
|
|
|
if (address_type == eAddressTypeInvalid)
|
|
|
|
address_type = eAddressTypeLoad;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
ValueObject::SetValueFromCString (ExecutionContextScope *exe_scope, const char *value_str)
|
|
|
|
{
|
|
|
|
// Make sure our value is up to date first so that our location and location
|
|
|
|
// type is valid.
|
|
|
|
if (!UpdateValueIfNeeded(exe_scope))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uint32_t count = 0;
|
2010-09-29 09:12:09 +08:00
|
|
|
lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
char *end = NULL;
|
2010-07-14 08:18:15 +08:00
|
|
|
const size_t byte_size = GetByteSize();
|
2010-06-09 00:52:24 +08:00
|
|
|
switch (encoding)
|
|
|
|
{
|
|
|
|
case eEncodingInvalid:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case eEncodingUint:
|
|
|
|
if (byte_size > sizeof(unsigned long long))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned long long ull_val = strtoull(value_str, &end, 0);
|
|
|
|
if (end && *end != '\0')
|
|
|
|
return false;
|
|
|
|
m_value = ull_val;
|
|
|
|
// Limit the bytes in our m_data appropriately.
|
|
|
|
m_value.GetScalar().GetData (m_data, byte_size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eEncodingSint:
|
|
|
|
if (byte_size > sizeof(long long))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long long sll_val = strtoll(value_str, &end, 0);
|
|
|
|
if (end && *end != '\0')
|
|
|
|
return false;
|
|
|
|
m_value = sll_val;
|
|
|
|
// Limit the bytes in our m_data appropriately.
|
|
|
|
m_value.GetScalar().GetData (m_data, byte_size);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eEncodingIEEE754:
|
|
|
|
{
|
|
|
|
const off_t byte_offset = GetByteOffset();
|
2010-07-10 04:39:50 +08:00
|
|
|
uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (dst != NULL)
|
|
|
|
{
|
|
|
|
// We are decoding a float into host byte order below, so make
|
|
|
|
// sure m_data knows what it contains.
|
|
|
|
m_data.SetByteOrder(eByteOrderHost);
|
|
|
|
const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue (
|
|
|
|
GetClangAST(),
|
2010-09-29 09:12:09 +08:00
|
|
|
GetClangType(),
|
2010-06-09 00:52:24 +08:00
|
|
|
value_str,
|
|
|
|
dst,
|
|
|
|
byte_size);
|
|
|
|
|
|
|
|
if (converted_byte_size == byte_size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eEncodingVector:
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have made it here the value is in m_data and we should write it
|
|
|
|
// out to the target
|
|
|
|
return Write ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObject::Write ()
|
|
|
|
{
|
|
|
|
// Clear the update ID so the next time we try and read the value
|
|
|
|
// we try and read it again.
|
|
|
|
m_update_id = 0;
|
|
|
|
|
|
|
|
// TODO: when Value has a method to write a value back, call it from here.
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-28 09:25:32 +08:00
|
|
|
lldb::LanguageType
|
|
|
|
ValueObject::GetObjectRuntimeLanguage ()
|
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
clang_type_t opaque_qual_type = GetClangType();
|
2010-09-28 09:25:32 +08:00
|
|
|
if (opaque_qual_type == NULL)
|
|
|
|
return lldb::eLanguageTypeC;
|
|
|
|
|
|
|
|
// If the type is a reference, then resolve it to what it refers to first:
|
|
|
|
clang::QualType qual_type (clang::QualType::getFromOpaquePtr(opaque_qual_type).getNonReferenceType());
|
|
|
|
if (qual_type->isAnyPointerType())
|
|
|
|
{
|
|
|
|
if (qual_type->isObjCObjectPointerType())
|
|
|
|
return lldb::eLanguageTypeObjC;
|
|
|
|
|
|
|
|
clang::QualType pointee_type (qual_type->getPointeeType());
|
|
|
|
if (pointee_type->getCXXRecordDeclForPointerType() != NULL)
|
|
|
|
return lldb::eLanguageTypeC_plus_plus;
|
|
|
|
if (pointee_type->isObjCObjectOrInterfaceType())
|
|
|
|
return lldb::eLanguageTypeObjC;
|
|
|
|
if (pointee_type->isObjCClassType())
|
|
|
|
return lldb::eLanguageTypeObjC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ClangASTContext::IsObjCClassType (opaque_qual_type))
|
|
|
|
return lldb::eLanguageTypeObjC;
|
2010-09-29 00:10:54 +08:00
|
|
|
if (ClangASTContext::IsCXXClassType (opaque_qual_type))
|
2010-09-28 09:25:32 +08:00
|
|
|
return lldb::eLanguageTypeC_plus_plus;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lldb::eLanguageTypeC;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
ValueObject::AddSyntheticChild (const ConstString &key, ValueObjectSP& valobj_sp)
|
|
|
|
{
|
|
|
|
m_synthetic_children[key] = valobj_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectSP
|
|
|
|
ValueObject::GetSyntheticChild (const ConstString &key) const
|
|
|
|
{
|
|
|
|
ValueObjectSP synthetic_child_sp;
|
|
|
|
std::map<ConstString, ValueObjectSP>::const_iterator pos = m_synthetic_children.find (key);
|
|
|
|
if (pos != m_synthetic_children.end())
|
|
|
|
synthetic_child_sp = pos->second;
|
|
|
|
return synthetic_child_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObject::IsPointerType ()
|
|
|
|
{
|
2010-09-29 09:12:09 +08:00
|
|
|
return ClangASTContext::IsPointerType (GetClangType());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-10-27 11:32:59 +08:00
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
ValueObject::IsPointerOrReferenceType ()
|
|
|
|
{
|
2010-09-29 09:12:09 +08:00
|
|
|
return ClangASTContext::IsPointerOrReferenceType(GetClangType());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectSP
|
|
|
|
ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create)
|
|
|
|
{
|
|
|
|
ValueObjectSP synthetic_child_sp;
|
|
|
|
if (IsPointerType ())
|
|
|
|
{
|
|
|
|
char index_str[64];
|
|
|
|
snprintf(index_str, sizeof(index_str), "[%i]", index);
|
|
|
|
ConstString index_const_str(index_str);
|
|
|
|
// Check if we have already created a synthetic array member in this
|
|
|
|
// valid object. If we have we will re-use it.
|
|
|
|
synthetic_child_sp = GetSyntheticChild (index_const_str);
|
|
|
|
if (!synthetic_child_sp)
|
|
|
|
{
|
|
|
|
// We haven't made a synthetic array member for INDEX yet, so
|
|
|
|
// lets make one and cache it for any future reference.
|
|
|
|
synthetic_child_sp = CreateChildAtIndex(0, true, index);
|
|
|
|
|
|
|
|
// Cache the value if we got one back...
|
|
|
|
if (synthetic_child_sp)
|
|
|
|
AddSyntheticChild(index_const_str, synthetic_child_sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return synthetic_child_sp;
|
|
|
|
}
|
2010-09-23 10:01:19 +08:00
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObject::SetDynamicValue ()
|
|
|
|
{
|
|
|
|
if (!IsPointerOrReferenceType())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that the runtime class is correct for determining the most specific class.
|
|
|
|
// If it is a C++ class, see if it is dynamic:
|
2010-09-28 09:25:32 +08:00
|
|
|
|
2010-09-23 10:01:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-10-05 08:00:42 +08:00
|
|
|
|
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
void
|
|
|
|
ValueObject::GetExpressionPath (Stream &s)
|
|
|
|
{
|
|
|
|
if (m_parent)
|
|
|
|
{
|
|
|
|
m_parent->GetExpressionPath (s);
|
|
|
|
clang_type_t parent_clang_type = m_parent->GetClangType();
|
|
|
|
if (parent_clang_type)
|
|
|
|
{
|
|
|
|
if (ClangASTContext::IsPointerType(parent_clang_type))
|
|
|
|
{
|
|
|
|
s.PutCString("->");
|
|
|
|
}
|
|
|
|
else if (ClangASTContext::IsAggregateType (parent_clang_type))
|
|
|
|
{
|
|
|
|
if (ClangASTContext::IsArrayType (parent_clang_type) == false &&
|
|
|
|
m_parent->IsBaseClass() == false)
|
|
|
|
s.PutChar('.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsBaseClass())
|
|
|
|
{
|
|
|
|
clang_type_t clang_type = GetClangType();
|
|
|
|
std::string cxx_class_name;
|
|
|
|
if (ClangASTContext::GetCXXClassName (clang_type, cxx_class_name))
|
|
|
|
{
|
|
|
|
s << cxx_class_name.c_str() << "::";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *name = GetName().AsCString();
|
|
|
|
if (name)
|
|
|
|
s.PutCString(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-05 08:00:42 +08:00
|
|
|
void
|
|
|
|
ValueObject::DumpValueObject
|
|
|
|
(
|
|
|
|
Stream &s,
|
|
|
|
ExecutionContextScope *exe_scope,
|
|
|
|
ValueObject *valobj,
|
|
|
|
const char *root_valobj_name,
|
|
|
|
uint32_t ptr_depth,
|
|
|
|
uint32_t curr_depth,
|
|
|
|
uint32_t max_depth,
|
|
|
|
bool show_types,
|
|
|
|
bool show_location,
|
|
|
|
bool use_objc,
|
2010-10-15 06:52:14 +08:00
|
|
|
bool scope_already_checked,
|
|
|
|
bool flat_output
|
2010-10-05 08:00:42 +08:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (valobj)
|
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
clang_type_t clang_type = valobj->GetClangType();
|
|
|
|
|
2010-10-27 11:32:59 +08:00
|
|
|
const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL));
|
2010-10-15 06:52:14 +08:00
|
|
|
const char *err_cstr = NULL;
|
2010-10-27 11:32:59 +08:00
|
|
|
const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren);
|
|
|
|
const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue);
|
2010-10-15 06:52:14 +08:00
|
|
|
|
|
|
|
const bool print_valobj = flat_output == false || has_value;
|
|
|
|
|
|
|
|
if (print_valobj)
|
2010-10-05 08:00:42 +08:00
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
if (show_location)
|
|
|
|
{
|
|
|
|
s.Printf("%s: ", valobj->GetLocationAsCString(exe_scope));
|
|
|
|
}
|
2010-10-05 08:00:42 +08:00
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
s.Indent();
|
2010-10-05 08:00:42 +08:00
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
if (show_types)
|
|
|
|
s.Printf("(%s) ", valobj->GetTypeName().AsCString());
|
2010-10-05 08:00:42 +08:00
|
|
|
|
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
if (flat_output)
|
|
|
|
{
|
|
|
|
valobj->GetExpressionPath(s);
|
|
|
|
s.PutCString(" =");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
|
|
|
|
s.Printf ("%s =", name_cstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scope_already_checked && !valobj->IsInScope(exe_scope->CalculateStackFrame()))
|
|
|
|
{
|
|
|
|
err_cstr = "error: out of scope";
|
|
|
|
}
|
2010-10-05 08:00:42 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
const char *val_cstr = NULL;
|
|
|
|
|
|
|
|
if (err_cstr == NULL)
|
|
|
|
{
|
|
|
|
val_cstr = valobj->GetValueAsCString(exe_scope);
|
|
|
|
err_cstr = valobj->GetError().AsCString();
|
|
|
|
}
|
2010-10-05 08:00:42 +08:00
|
|
|
|
|
|
|
if (err_cstr)
|
|
|
|
{
|
2010-10-22 10:39:02 +08:00
|
|
|
s.Printf (" %s\n", err_cstr);
|
2010-10-05 08:00:42 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference);
|
2010-10-15 06:52:14 +08:00
|
|
|
if (print_valobj)
|
|
|
|
{
|
|
|
|
const char *sum_cstr = valobj->GetSummaryAsCString(exe_scope);
|
2010-10-05 08:00:42 +08:00
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
if (val_cstr)
|
|
|
|
s.Printf(" %s", val_cstr);
|
2010-10-05 08:00:42 +08:00
|
|
|
|
2010-10-15 06:52:14 +08:00
|
|
|
if (sum_cstr)
|
|
|
|
s.Printf(" %s", sum_cstr);
|
|
|
|
|
|
|
|
if (use_objc)
|
|
|
|
{
|
|
|
|
const char *object_desc = valobj->GetObjectDescription(exe_scope);
|
|
|
|
if (object_desc)
|
|
|
|
s.Printf(" %s\n", object_desc);
|
|
|
|
else
|
2010-10-23 08:18:49 +08:00
|
|
|
s.Printf (" [no Objective-C description available]\n");
|
2010-10-15 06:52:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-10-05 08:00:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curr_depth < max_depth)
|
|
|
|
{
|
2010-10-27 11:32:59 +08:00
|
|
|
// We will show children for all concrete types. We won't show
|
|
|
|
// pointer contents unless a pointer depth has been specified.
|
|
|
|
// We won't reference contents unless the reference is the
|
|
|
|
// root object (depth of zero).
|
|
|
|
bool print_children = true;
|
|
|
|
|
|
|
|
// Use a new temporary pointer depth in case we override the
|
|
|
|
// current pointer depth below...
|
|
|
|
uint32_t curr_ptr_depth = ptr_depth;
|
|
|
|
|
|
|
|
const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer);
|
|
|
|
if (is_ptr || is_ref)
|
|
|
|
{
|
|
|
|
// We have a pointer or reference whose value is an address.
|
|
|
|
// Make sure that address is not NULL
|
|
|
|
lldb::AddressType ptr_address_type;
|
|
|
|
if (valobj->GetPointerValue (ptr_address_type, true) == 0)
|
|
|
|
print_children = false;
|
|
|
|
|
|
|
|
else if (is_ref && curr_depth == 0)
|
|
|
|
{
|
|
|
|
// If this is the root object (depth is zero) that we are showing
|
|
|
|
// and it is a reference, and no pointer depth has been supplied
|
|
|
|
// print out what it references. Don't do this at deeper depths
|
|
|
|
// otherwise we can end up with infinite recursion...
|
|
|
|
curr_ptr_depth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curr_ptr_depth == 0)
|
|
|
|
print_children = false;
|
|
|
|
}
|
2010-10-05 08:00:42 +08:00
|
|
|
|
2010-10-27 11:32:59 +08:00
|
|
|
if (print_children)
|
2010-10-05 08:00:42 +08:00
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
const uint32_t num_children = valobj->GetNumChildren();
|
|
|
|
if (num_children)
|
2010-10-05 08:00:42 +08:00
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
if (flat_output)
|
2010-10-05 08:00:42 +08:00
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
if (print_valobj)
|
|
|
|
s.EOL();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (print_valobj)
|
|
|
|
s.PutCString(" {\n");
|
|
|
|
s.IndentMore();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t idx=0; idx<num_children; ++idx)
|
|
|
|
{
|
|
|
|
ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true));
|
|
|
|
if (child_sp.get())
|
|
|
|
{
|
|
|
|
DumpValueObject (s,
|
|
|
|
exe_scope,
|
|
|
|
child_sp.get(),
|
|
|
|
NULL,
|
2010-10-27 11:32:59 +08:00
|
|
|
(is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
|
2010-10-15 06:52:14 +08:00
|
|
|
curr_depth + 1,
|
|
|
|
max_depth,
|
|
|
|
show_types,
|
|
|
|
show_location,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
flat_output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!flat_output)
|
|
|
|
{
|
|
|
|
s.IndentLess();
|
|
|
|
s.Indent("}\n");
|
2010-10-05 08:00:42 +08:00
|
|
|
}
|
|
|
|
}
|
2010-10-15 06:52:14 +08:00
|
|
|
else if (has_children)
|
|
|
|
{
|
|
|
|
// Aggregate, no children...
|
|
|
|
if (print_valobj)
|
2010-10-27 11:32:59 +08:00
|
|
|
s.PutCString(" {}\n");
|
2010-10-15 06:52:14 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (print_valobj)
|
|
|
|
s.EOL();
|
|
|
|
}
|
|
|
|
|
2010-10-05 08:00:42 +08:00
|
|
|
}
|
2010-10-15 06:52:14 +08:00
|
|
|
else
|
|
|
|
{
|
2010-10-05 08:00:42 +08:00
|
|
|
s.EOL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
if (has_children && print_valobj)
|
2010-10-05 08:00:42 +08:00
|
|
|
{
|
2010-10-15 06:52:14 +08:00
|
|
|
s.PutCString("{...}\n");
|
2010-10-05 08:00:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|