2011-04-16 08:01:13 +08:00
|
|
|
//===-- ValueObjectMemory.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/ValueObjectMemory.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/Core/ValueObject.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"
|
|
|
|
|
2011-04-23 07:53:53 +08:00
|
|
|
using namespace lldb;
|
2011-04-16 08:01:13 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
2011-04-23 07:53:53 +08:00
|
|
|
ValueObjectSP
|
|
|
|
ValueObjectMemory::Create (ExecutionContextScope *exe_scope,
|
|
|
|
const char *name,
|
|
|
|
const Address &address,
|
|
|
|
lldb::TypeSP &type_sp)
|
|
|
|
{
|
|
|
|
return (new ValueObjectMemory (exe_scope, name, address, type_sp))->GetSP();
|
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
ValueObjectSP
|
|
|
|
ValueObjectMemory::Create (ExecutionContextScope *exe_scope,
|
|
|
|
const char *name,
|
|
|
|
const Address &address,
|
2015-08-12 06:53:00 +08:00
|
|
|
const CompilerType &ast_type)
|
2011-04-28 06:04:39 +08:00
|
|
|
{
|
|
|
|
return (new ValueObjectMemory (exe_scope, name, address, ast_type))->GetSP();
|
|
|
|
}
|
|
|
|
|
2011-04-16 08:01:13 +08:00
|
|
|
ValueObjectMemory::ValueObjectMemory (ExecutionContextScope *exe_scope,
|
|
|
|
const char *name,
|
|
|
|
const Address &address,
|
|
|
|
lldb::TypeSP &type_sp) :
|
|
|
|
ValueObject(exe_scope),
|
|
|
|
m_address (address),
|
2011-04-28 06:04:39 +08:00
|
|
|
m_type_sp(type_sp),
|
2015-09-24 11:54:50 +08:00
|
|
|
m_compiler_type()
|
2011-04-16 08:01:13 +08:00
|
|
|
{
|
|
|
|
// Do not attempt to construct one of these objects with no variable!
|
|
|
|
assert (m_type_sp.get() != NULL);
|
2011-07-30 03:53:35 +08:00
|
|
|
SetName (ConstString(name));
|
2011-04-16 08:01:13 +08:00
|
|
|
m_value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get());
|
2012-02-17 15:49:44 +08:00
|
|
|
TargetSP target_sp (GetTargetSP());
|
|
|
|
lldb::addr_t load_address = m_address.GetLoadAddress(target_sp.get());
|
2011-04-16 08:01:13 +08:00
|
|
|
if (load_address != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_value.SetValueType(Value::eValueTypeLoadAddress);
|
|
|
|
m_value.GetScalar() = load_address;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lldb::addr_t file_address = m_address.GetFileAddress();
|
|
|
|
if (file_address != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_value.SetValueType(Value::eValueTypeFileAddress);
|
|
|
|
m_value.GetScalar() = file_address;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_value.GetScalar() = m_address.GetOffset();
|
|
|
|
m_value.SetValueType (Value::eValueTypeScalar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 06:04:39 +08:00
|
|
|
ValueObjectMemory::ValueObjectMemory (ExecutionContextScope *exe_scope,
|
|
|
|
const char *name,
|
|
|
|
const Address &address,
|
2015-08-12 06:53:00 +08:00
|
|
|
const CompilerType &ast_type) :
|
2011-04-28 06:04:39 +08:00
|
|
|
ValueObject(exe_scope),
|
|
|
|
m_address (address),
|
|
|
|
m_type_sp(),
|
2015-09-24 11:54:50 +08:00
|
|
|
m_compiler_type(ast_type)
|
2011-04-28 06:04:39 +08:00
|
|
|
{
|
|
|
|
// Do not attempt to construct one of these objects with no variable!
|
2015-09-24 11:54:50 +08:00
|
|
|
assert (m_compiler_type.GetTypeSystem());
|
|
|
|
assert (m_compiler_type.GetOpaqueQualType());
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2012-02-17 15:49:44 +08:00
|
|
|
TargetSP target_sp (GetTargetSP());
|
|
|
|
|
2011-07-30 03:53:35 +08:00
|
|
|
SetName (ConstString(name));
|
2015-09-24 11:54:50 +08:00
|
|
|
// m_value.SetContext(Value::eContextTypeClangType, m_compiler_type.GetOpaqueQualType());
|
|
|
|
m_value.SetCompilerType(m_compiler_type);
|
2012-02-17 15:49:44 +08:00
|
|
|
lldb::addr_t load_address = m_address.GetLoadAddress (target_sp.get());
|
2011-04-28 06:04:39 +08:00
|
|
|
if (load_address != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_value.SetValueType(Value::eValueTypeLoadAddress);
|
|
|
|
m_value.GetScalar() = load_address;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lldb::addr_t file_address = m_address.GetFileAddress();
|
|
|
|
if (file_address != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_value.SetValueType(Value::eValueTypeFileAddress);
|
|
|
|
m_value.GetScalar() = file_address;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_value.GetScalar() = m_address.GetOffset();
|
|
|
|
m_value.SetValueType (Value::eValueTypeScalar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-16 08:01:13 +08:00
|
|
|
ValueObjectMemory::~ValueObjectMemory()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-12 06:53:00 +08:00
|
|
|
CompilerType
|
2015-08-25 07:46:31 +08:00
|
|
|
ValueObjectMemory::GetCompilerTypeImpl ()
|
2011-04-16 08:01:13 +08:00
|
|
|
{
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_type_sp)
|
2015-08-25 07:46:31 +08:00
|
|
|
return m_type_sp->GetForwardCompilerType ();
|
2015-09-24 11:54:50 +08:00
|
|
|
return m_compiler_type;
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ConstString
|
|
|
|
ValueObjectMemory::GetTypeName()
|
|
|
|
{
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_type_sp)
|
|
|
|
return m_type_sp->GetName();
|
2015-09-24 11:54:50 +08:00
|
|
|
return m_compiler_type.GetConstTypeName();
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
|
Introduce the concept of a "display name" for types
Rationale:
Pretty simply, the idea is that sometimes type names are way too long and contain way too many details for the average developer to care about. For instance, a plain ol' vector of int might be shown as
std::__1::vector<int, std::__1::allocator<....
rather than the much simpler std::vector<int> form, which is what most developers would actually type in their code
Proposed solution:
Introduce a notion of "display name" and a corresponding API GetDisplayTypeName() to return such a crafted for visual representation type name
Obviously, the display name and the fully qualified (or "true") name are not necessarily the same - that's the whole point
LLDB could choose to pick the "display name" as its one true notion of a type name, and if somebody really needs the fully qualified version of it, let them deal with the problem
Or, LLDB could rename what it currently calls the "type name" to be the "display name", and add new APIs for the fully qualified name, making the display name the default choice
The choice that I am making here is that the type name will keep meaning the same, and people who want a type name suited for display will explicitly ask for one
It is the less risky/disruptive choice - and it should eventually make it fairly obvious when someone is asking for the wrong type
Caveats:
- for now, GetDisplayTypeName() == GetTypeName(), there is no logic to produce customized display type names yet.
- while the fully-qualified type name is still the main key to the kingdom of data formatters, if we start showing custom names to people, those should match formatters
llvm-svn: 209072
2014-05-18 03:14:17 +08:00
|
|
|
ConstString
|
|
|
|
ValueObjectMemory::GetDisplayTypeName()
|
|
|
|
{
|
|
|
|
if (m_type_sp)
|
2015-08-25 07:46:31 +08:00
|
|
|
return m_type_sp->GetForwardCompilerType ().GetDisplayTypeName();
|
2015-09-24 11:54:50 +08:00
|
|
|
return m_compiler_type.GetDisplayTypeName();
|
Introduce the concept of a "display name" for types
Rationale:
Pretty simply, the idea is that sometimes type names are way too long and contain way too many details for the average developer to care about. For instance, a plain ol' vector of int might be shown as
std::__1::vector<int, std::__1::allocator<....
rather than the much simpler std::vector<int> form, which is what most developers would actually type in their code
Proposed solution:
Introduce a notion of "display name" and a corresponding API GetDisplayTypeName() to return such a crafted for visual representation type name
Obviously, the display name and the fully qualified (or "true") name are not necessarily the same - that's the whole point
LLDB could choose to pick the "display name" as its one true notion of a type name, and if somebody really needs the fully qualified version of it, let them deal with the problem
Or, LLDB could rename what it currently calls the "type name" to be the "display name", and add new APIs for the fully qualified name, making the display name the default choice
The choice that I am making here is that the type name will keep meaning the same, and people who want a type name suited for display will explicitly ask for one
It is the less risky/disruptive choice - and it should eventually make it fairly obvious when someone is asking for the wrong type
Caveats:
- for now, GetDisplayTypeName() == GetTypeName(), there is no logic to produce customized display type names yet.
- while the fully-qualified type name is still the main key to the kingdom of data formatters, if we start showing custom names to people, those should match formatters
llvm-svn: 209072
2014-05-18 03:14:17 +08:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:06:21 +08:00
|
|
|
size_t
|
2011-04-16 08:01:13 +08:00
|
|
|
ValueObjectMemory::CalculateNumChildren()
|
|
|
|
{
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_type_sp)
|
|
|
|
return m_type_sp->GetNumChildren(true);
|
|
|
|
const bool omit_empty_base_classes = true;
|
2015-09-24 11:54:50 +08:00
|
|
|
return m_compiler_type.GetNumChildren (omit_empty_base_classes);
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 02:31:44 +08:00
|
|
|
uint64_t
|
2011-04-16 08:01:13 +08:00
|
|
|
ValueObjectMemory::GetByteSize()
|
|
|
|
{
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_type_sp)
|
|
|
|
return m_type_sp->GetByteSize();
|
2015-09-24 11:54:50 +08:00
|
|
|
return m_compiler_type.GetByteSize (nullptr);
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ValueType
|
|
|
|
ValueObjectMemory::GetValueType() const
|
|
|
|
{
|
|
|
|
// RETHINK: Should this be inherited from somewhere?
|
|
|
|
return lldb::eValueTypeVariableGlobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObjectMemory::UpdateValue ()
|
|
|
|
{
|
|
|
|
SetValueIsValid (false);
|
|
|
|
m_error.Clear();
|
|
|
|
|
2012-02-17 15:49:44 +08:00
|
|
|
ExecutionContext exe_ctx (GetExecutionContextRef());
|
2011-04-16 08:01:13 +08:00
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
if (target)
|
2011-04-16 08:01:13 +08:00
|
|
|
{
|
2011-09-22 12:58:26 +08:00
|
|
|
m_data.SetByteOrder(target->GetArchitecture().GetByteOrder());
|
|
|
|
m_data.SetAddressByteSize(target->GetArchitecture().GetAddressByteSize());
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Value old_value(m_value);
|
|
|
|
if (m_address.IsValid())
|
|
|
|
{
|
|
|
|
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.
|
2013-07-12 06:46:58 +08:00
|
|
|
m_error = m_value.GetValueAsData (&exe_ctx, m_data, 0, GetModule().get());
|
2011-04-16 08:01:13 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
// If we have a file address, convert it to a load address if we can.
|
2011-09-22 12:58:26 +08:00
|
|
|
if (value_type == Value::eValueTypeFileAddress && exe_ctx.GetProcessPtr())
|
2011-04-16 08:01:13 +08:00
|
|
|
{
|
2011-09-22 12:58:26 +08:00
|
|
|
lldb::addr_t load_addr = m_address.GetLoadAddress(target);
|
2011-04-16 08:01:13 +08:00
|
|
|
if (load_addr != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
m_value.SetValueType(Value::eValueTypeLoadAddress);
|
|
|
|
m_value.GetScalar() = load_addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Extend synthetic children to produce synthetic values (as in, those that GetValueAsUnsigned(), GetValueAsCString() would return)
The way to do this is to write a synthetic child provider for your type, and have it vend the (optional) get_value function.
If get_value is defined, and it returns a valid SBValue, that SBValue's value (as in lldb_private::Value) will be used as the synthetic ValueObject's Value
The rationale for doing things this way is twofold:
- there are many possible ways to define a "value" (SBData, a Python number, ...) but SBValue seems general enough as a thing that stores a "value", so we just trade values that way and that keeps our currency trivial
- we could introduce a new level of layering (ValueObjectSyntheticValue), a new kind of formatter (synthetic value producer), but that would complicate the model (can I have a dynamic with no synthetic children but synthetic value? synthetic value with synthetic children but no dynamic?), and I really couldn't see much benefit to be reaped from this added complexity in the matrix
On the other hand, just defining a synthetic child provider with a get_value but returning no actual children is easy enough that it's not a significant road-block to adoption of this feature
Comes with a test case
llvm-svn: 219330
2014-10-09 02:27:36 +08:00
|
|
|
if (!CanProvideValue())
|
2011-04-16 08:01:13 +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);
|
2011-04-28 06:04:39 +08:00
|
|
|
if (m_type_sp)
|
|
|
|
value.SetContext(Value::eContextTypeLLDBType, m_type_sp.get());
|
|
|
|
else
|
2013-07-12 06:46:58 +08:00
|
|
|
{
|
2015-09-24 11:54:50 +08:00
|
|
|
//value.SetContext(Value::eContextTypeClangType, m_compiler_type.GetOpaqueQualType());
|
|
|
|
value.SetCompilerType(m_compiler_type);
|
2013-07-12 06:46:58 +08:00
|
|
|
}
|
2011-04-28 06:04:39 +08:00
|
|
|
|
2013-07-12 06:46:58 +08:00
|
|
|
m_error = value.GetValueAsData(&exe_ctx, m_data, 0, GetModule().get());
|
2011-04-16 08:01:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetValueIsValid (m_error.Success());
|
|
|
|
}
|
|
|
|
return m_error.Success();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
ValueObjectMemory::IsInScope ()
|
|
|
|
{
|
|
|
|
// FIXME: Maybe try to read the memory address, and if that works, then
|
|
|
|
// we are in scope?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-07 09:59:51 +08:00
|
|
|
|
2012-02-24 09:59:29 +08:00
|
|
|
lldb::ModuleSP
|
2011-07-07 09:59:51 +08:00
|
|
|
ValueObjectMemory::GetModule()
|
|
|
|
{
|
2012-02-24 09:59:29 +08:00
|
|
|
return m_address.GetModule();
|
2011-07-07 09:59:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|