blob: fc5f6c850f5a274d9e90fac44ef0d6f4b99f332b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObjectChild.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/ValueObjectChild.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/Module.h"
13#include "lldb/Core/ValueObjectList.h"
14
Greg Claytone1a916a2010-07-21 22:12:05 +000015#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Symbol/ObjectFile.h"
17#include "lldb/Symbol/SymbolContext.h"
18#include "lldb/Symbol/Type.h"
19#include "lldb/Symbol/Variable.h"
20
21#include "lldb/Target/ExecutionContext.h"
22#include "lldb/Target/Process.h"
23#include "lldb/Target/Target.h"
24
25using namespace lldb_private;
26
27ValueObjectChild::ValueObjectChild
28(
Jim Ingham6035b672011-03-31 00:19:25 +000029 ValueObject &parent,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030 clang::ASTContext *clang_ast,
31 void *clang_type,
32 const ConstString &name,
33 uint32_t byte_size,
34 int32_t byte_offset,
35 uint32_t bitfield_bit_size,
Greg Clayton8f92f0a2010-10-14 22:52:14 +000036 uint32_t bitfield_bit_offset,
Greg Claytone221f822011-01-21 01:59:00 +000037 bool is_base_class,
38 bool is_deref_of_parent
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039) :
Greg Clayton8f92f0a2010-10-14 22:52:14 +000040 ValueObject (parent),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041 m_clang_ast (clang_ast),
42 m_clang_type (clang_type),
43 m_byte_size (byte_size),
44 m_byte_offset (byte_offset),
45 m_bitfield_bit_size (bitfield_bit_size),
Greg Clayton8f92f0a2010-10-14 22:52:14 +000046 m_bitfield_bit_offset (bitfield_bit_offset),
Greg Claytone221f822011-01-21 01:59:00 +000047 m_is_base_class (is_base_class),
48 m_is_deref_of_parent (is_deref_of_parent)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049{
50 m_name = name;
51}
52
53ValueObjectChild::~ValueObjectChild()
54{
55}
56
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057lldb::ValueType
58ValueObjectChild::GetValueType() const
59{
60 return m_parent->GetValueType();
61}
62
63uint32_t
64ValueObjectChild::CalculateNumChildren()
65{
Greg Clayton6beaaa62011-01-17 03:46:26 +000066 return ClangASTContext::GetNumChildren (GetClangAST (), m_clang_type, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067}
68
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069ConstString
70ValueObjectChild::GetTypeName()
71{
72 if (m_type_name.IsEmpty())
73 {
Greg Clayton1be10fc2010-09-29 01:12:09 +000074 m_type_name = ClangASTType::GetClangTypeName (GetClangType());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075 if (m_type_name)
76 {
77 if (m_bitfield_bit_size > 0)
78 {
79 const char *clang_type_name = m_type_name.AsCString();
80 if (clang_type_name)
81 {
Greg Claytonc982c762010-07-09 20:39:50 +000082 std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0);
Greg Clayton471b31c2010-07-20 22:52:08 +000083 ::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, m_bitfield_bit_size);
84 m_type_name.SetCString(&bitfield_type_name.front());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085 }
86 }
87 }
88 }
89 return m_type_name;
90}
91
Jim Ingham6035b672011-03-31 00:19:25 +000092bool
93ValueObjectChild::UpdateValue ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094{
95 m_error.Clear();
96 SetValueIsValid (false);
97 ValueObject* parent = m_parent;
98 if (parent)
99 {
Jim Ingham6035b672011-03-31 00:19:25 +0000100 if (parent->UpdateValue())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101 {
Greg Clayton526e5af2010-11-13 03:52:47 +0000102 m_value.SetContext(Value::eContextTypeClangType, m_clang_type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103
104 // Copy the parent scalar value and the scalar value type
105 m_value.GetScalar() = parent->GetValue().GetScalar();
106 Value::ValueType value_type = parent->GetValue().GetValueType();
107 m_value.SetValueType (value_type);
108
Greg Clayton1be10fc2010-09-29 01:12:09 +0000109 if (ClangASTContext::IsPointerOrReferenceType (parent->GetClangType()))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 {
111 uint32_t offset = 0;
112 m_value.GetScalar() = parent->GetDataExtractor().GetPointer(&offset);
Greg Clayton7c8a9662010-11-02 01:50:16 +0000113
114 lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
115
116 if (addr == LLDB_INVALID_ADDRESS)
117 {
118 m_error.SetErrorString ("parent address is invalid.");
119 }
120 else if (addr == 0)
121 {
122 m_error.SetErrorString ("parent is NULL");
123 }
124 else
125 {
Greg Claytondf797c12010-11-02 21:21:20 +0000126 m_value.GetScalar() += m_byte_offset;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000127 if (m_pointers_point_to_load_addrs ||
128 value_type == Value::eValueTypeScalar ||
Greg Clayton7c8a9662010-11-02 01:50:16 +0000129 value_type == Value::eValueTypeFileAddress)
130 m_value.SetValueType (Value::eValueTypeLoadAddress);
131 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132 }
133 else
134 {
135 switch (value_type)
136 {
137 case Value::eValueTypeLoadAddress:
138 case Value::eValueTypeFileAddress:
139 case Value::eValueTypeHostAddress:
140 {
141 lldb::addr_t addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton7c8a9662010-11-02 01:50:16 +0000142 if (addr == LLDB_INVALID_ADDRESS)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143 {
Greg Clayton7c8a9662010-11-02 01:50:16 +0000144 m_error.SetErrorString ("parent address is invalid.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 }
Greg Clayton7c8a9662010-11-02 01:50:16 +0000146 else if (addr == 0)
147 {
148 m_error.SetErrorString ("parent is NULL");
149 }
150 else
151 {
152 // Set this object's scalar value to the address of its
153 // value be adding its byte offset to the parent address
154 m_value.GetScalar() += GetByteOffset();
155 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156 }
157 break;
158
159 case Value::eValueTypeScalar:
160 // TODO: What if this is a register value? Do we try and
161 // extract the child value from within the parent data?
162 // Probably...
163 default:
164 m_error.SetErrorString ("Parent has invalid value.");
165 break;
166 }
167 }
168
169 if (m_error.Success())
170 {
Jim Ingham6035b672011-03-31 00:19:25 +0000171 ExecutionContext exe_ctx (GetExecutionContextScope());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000172 m_error = m_value.GetValueAsData (&exe_ctx, GetClangAST (), m_data, 0);
173 }
174 }
175 else
176 {
177 m_error.SetErrorStringWithFormat("Parent failed to evaluate: %s.\n", parent->GetError().AsCString());
178 }
179 }
180 else
181 {
182 m_error.SetErrorString("ValueObjectChild has a NULL parent ValueObject.");
183 }
Jim Ingham6035b672011-03-31 00:19:25 +0000184
185 return m_error.Success();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186}
187
188
189bool
Jim Ingham6035b672011-03-31 00:19:25 +0000190ValueObjectChild::IsInScope ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191{
Jim Ingham6035b672011-03-31 00:19:25 +0000192 return m_parent->IsInScope ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000193}