blob: fbb35eb42aa8abeb7ed9d112864d2de19c525676 [file] [log] [blame]
Greg Clayton1d3afba2010-10-05 00:00:42 +00001//===-- ValueObjectConstResult.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/ValueObjectConstResult.h"
11
12#include "lldb/Core/DataExtractor.h"
13#include "lldb/Core/Module.h"
14#include "lldb/Core/ValueObjectList.h"
15
16#include "lldb/Symbol/ClangASTType.h"
17#include "lldb/Symbol/ObjectFile.h"
18#include "lldb/Symbol/SymbolContext.h"
19#include "lldb/Symbol/Type.h"
20#include "lldb/Symbol/Variable.h"
21
22#include "lldb/Target/ExecutionContext.h"
23#include "lldb/Target/Process.h"
24#include "lldb/Target/Target.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
Jim Ingham58b59f92011-04-22 23:53:53 +000029ValueObjectSP
30ValueObjectConstResult::Create
31(
32 ExecutionContextScope *exe_scope,
33 ByteOrder byte_order,
34 uint32_t addr_byte_size
35)
36{
37 return (new ValueObjectConstResult (exe_scope,
38 byte_order,
39 addr_byte_size))->GetSP();
40}
41
Greg Clayton1d3afba2010-10-05 00:00:42 +000042ValueObjectConstResult::ValueObjectConstResult
43(
Jim Ingham6035b672011-03-31 00:19:25 +000044 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000045 ByteOrder byte_order,
46 uint32_t addr_byte_size
47) :
Jim Ingham6035b672011-03-31 00:19:25 +000048 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000049 m_clang_ast (NULL),
50 m_type_name (),
51 m_byte_size (0)
52{
53 SetIsConstant ();
54 SetValueIsValid(true);
55 m_data.SetByteOrder(byte_order);
56 m_data.SetAddressByteSize(addr_byte_size);
57 m_pointers_point_to_load_addrs = true;
58}
59
Jim Ingham58b59f92011-04-22 23:53:53 +000060ValueObjectSP
61ValueObjectConstResult::Create
62(
63 ExecutionContextScope *exe_scope,
64 clang::ASTContext *clang_ast,
65 void *clang_type,
66 const ConstString &name,
67 const DataExtractor &data
68)
69{
70 return (new ValueObjectConstResult (exe_scope,
71 clang_ast,
72 clang_type,
73 name,
74 data))->GetSP();
75}
76
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000077ValueObjectConstResult::ValueObjectConstResult
78(
Jim Ingham6035b672011-03-31 00:19:25 +000079 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000080 clang::ASTContext *clang_ast,
81 void *clang_type,
82 const ConstString &name,
83 const DataExtractor &data
84) :
Jim Ingham6035b672011-03-31 00:19:25 +000085 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000086 m_clang_ast (clang_ast),
87 m_type_name (),
88 m_byte_size (0)
89{
90 m_data = data;
91 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
92 m_value.SetValueType(Value::eValueTypeHostAddress);
93 m_value.SetContext(Value::eContextTypeClangType, clang_type);
94 m_name = name;
95 SetIsConstant ();
96 SetValueIsValid(true);
97 m_pointers_point_to_load_addrs = true;
98}
99
Jim Ingham58b59f92011-04-22 23:53:53 +0000100ValueObjectSP
101ValueObjectConstResult::Create
102(
103 ExecutionContextScope *exe_scope,
104 clang::ASTContext *clang_ast,
105 void *clang_type,
106 const ConstString &name,
107 const lldb::DataBufferSP &data_sp,
108 lldb::ByteOrder data_byte_order,
109 uint8_t data_addr_size
110)
111{
112 return (new ValueObjectConstResult (exe_scope,
113 clang_ast,
114 clang_type,
115 name,
116 data_sp,
117 data_byte_order,
118 data_addr_size))->GetSP();
119}
120
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000121ValueObjectConstResult::ValueObjectConstResult
122(
Jim Ingham6035b672011-03-31 00:19:25 +0000123 ExecutionContextScope *exe_scope,
Greg Clayton1d3afba2010-10-05 00:00:42 +0000124 clang::ASTContext *clang_ast,
125 void *clang_type,
126 const ConstString &name,
127 const lldb::DataBufferSP &data_sp,
128 lldb::ByteOrder data_byte_order,
129 uint8_t data_addr_size
130) :
Jim Ingham6035b672011-03-31 00:19:25 +0000131 ValueObject (exe_scope),
Greg Clayton1d3afba2010-10-05 00:00:42 +0000132 m_clang_ast (clang_ast),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000133 m_type_name (),
134 m_byte_size (0)
Greg Clayton1d3afba2010-10-05 00:00:42 +0000135{
136 m_data.SetByteOrder(data_byte_order);
137 m_data.SetAddressByteSize(data_addr_size);
138 m_data.SetData(data_sp);
139 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
140 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton526e5af2010-11-13 03:52:47 +0000141 m_value.SetContext(Value::eContextTypeClangType, clang_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000142 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +0000143 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +0000144 SetValueIsValid(true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000145 m_pointers_point_to_load_addrs = true;
146}
147
Jim Ingham58b59f92011-04-22 23:53:53 +0000148ValueObjectSP
149ValueObjectConstResult::Create
150(
151 ExecutionContextScope *exe_scope,
152 clang::ASTContext *clang_ast,
153 void *clang_type,
154 const ConstString &name,
155 lldb::addr_t address,
156 AddressType address_type,
157 uint8_t addr_byte_size
158)
159{
160 return (new ValueObjectConstResult (exe_scope,
161 clang_ast,
162 clang_type,
163 name,
164 address,
165 address_type,
166 addr_byte_size))->GetSP();
167}
168
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000169ValueObjectConstResult::ValueObjectConstResult
170(
Jim Ingham6035b672011-03-31 00:19:25 +0000171 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000172 clang::ASTContext *clang_ast,
173 void *clang_type,
174 const ConstString &name,
175 lldb::addr_t address,
Greg Claytone0d378b2011-03-24 21:19:54 +0000176 AddressType address_type,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000177 uint8_t addr_byte_size
178) :
Jim Ingham6035b672011-03-31 00:19:25 +0000179 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000180 m_clang_ast (clang_ast),
181 m_type_name (),
182 m_byte_size (0)
183{
184 m_value.GetScalar() = address;
185 m_data.SetAddressByteSize(addr_byte_size);
186 m_value.GetScalar().GetData (m_data, addr_byte_size);
187 //m_value.SetValueType(Value::eValueTypeHostAddress);
188 switch (address_type)
189 {
190 default:
191 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
192 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
193 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
194 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
195 }
196 m_value.SetContext(Value::eContextTypeClangType, clang_type);
197 m_name = name;
198 SetIsConstant ();
199 SetValueIsValid(true);
200 m_pointers_point_to_load_addrs = true;
Greg Claytonb71f3842010-10-05 03:13:51 +0000201}
202
Jim Ingham58b59f92011-04-22 23:53:53 +0000203ValueObjectSP
204ValueObjectConstResult::Create
205(
206 ExecutionContextScope *exe_scope,
207 const Error& error
208)
209{
210 return (new ValueObjectConstResult (exe_scope,
211 error))->GetSP();
212}
213
Jim Ingham6035b672011-03-31 00:19:25 +0000214ValueObjectConstResult::ValueObjectConstResult (
215 ExecutionContextScope *exe_scope,
216 const Error& error) :
217 ValueObject (exe_scope),
Greg Claytonb71f3842010-10-05 03:13:51 +0000218 m_clang_ast (NULL),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000219 m_type_name (),
220 m_byte_size (0)
Greg Claytonb71f3842010-10-05 03:13:51 +0000221{
222 m_error = error;
223 SetIsConstant ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000224 m_pointers_point_to_load_addrs = true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000225}
226
227ValueObjectConstResult::~ValueObjectConstResult()
228{
229}
230
Greg Clayton6beaaa62011-01-17 03:46:26 +0000231lldb::clang_type_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000232ValueObjectConstResult::GetClangType()
233{
234 return m_value.GetClangType();
235}
236
237lldb::ValueType
238ValueObjectConstResult::GetValueType() const
239{
240 return eValueTypeConstResult;
241}
242
243size_t
244ValueObjectConstResult::GetByteSize()
245{
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000246 if (m_byte_size == 0)
247 {
248 uint64_t bit_width = ClangASTType::GetClangTypeBitWidth (GetClangAST(), GetClangType());
249 m_byte_size = (bit_width + 7 ) / 8;
250 }
251 return m_byte_size;
252}
253
254void
255ValueObjectConstResult::SetByteSize (size_t size)
256{
257 m_byte_size = size;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000258}
259
260uint32_t
261ValueObjectConstResult::CalculateNumChildren()
262{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000263 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000264}
265
266clang::ASTContext *
267ValueObjectConstResult::GetClangAST ()
268{
269 return m_clang_ast;
270}
271
272ConstString
273ValueObjectConstResult::GetTypeName()
274{
275 if (m_type_name.IsEmpty())
276 m_type_name = ClangASTType::GetClangTypeName (GetClangType());
277 return m_type_name;
278}
279
Jim Ingham6035b672011-03-31 00:19:25 +0000280bool
281ValueObjectConstResult::UpdateValue ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000282{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000283 // Const value is always valid
284 SetValueIsValid (true);
Jim Ingham6035b672011-03-31 00:19:25 +0000285 return true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000286}
287
288
289bool
Jim Ingham6035b672011-03-31 00:19:25 +0000290ValueObjectConstResult::IsInScope ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000291{
292 // A const result value is always in scope since it serializes all
293 // information needed to contain the constant value.
294 return true;
295}