blob: ff5d265a4f8c60a925d7b6a486b107fbce7884e5 [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
29ValueObjectConstResult::ValueObjectConstResult
30(
Jim Ingham6035b672011-03-31 00:19:25 +000031 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000032 ByteOrder byte_order,
33 uint32_t addr_byte_size
34) :
Jim Ingham6035b672011-03-31 00:19:25 +000035 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000036 m_clang_ast (NULL),
37 m_type_name (),
38 m_byte_size (0)
39{
40 SetIsConstant ();
41 SetValueIsValid(true);
42 m_data.SetByteOrder(byte_order);
43 m_data.SetAddressByteSize(addr_byte_size);
44 m_pointers_point_to_load_addrs = true;
45}
46
47ValueObjectConstResult::ValueObjectConstResult
48(
Jim Ingham6035b672011-03-31 00:19:25 +000049 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000050 clang::ASTContext *clang_ast,
51 void *clang_type,
52 const ConstString &name,
53 const DataExtractor &data
54) :
Jim Ingham6035b672011-03-31 00:19:25 +000055 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000056 m_clang_ast (clang_ast),
57 m_type_name (),
58 m_byte_size (0)
59{
60 m_data = data;
61 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
62 m_value.SetValueType(Value::eValueTypeHostAddress);
63 m_value.SetContext(Value::eContextTypeClangType, clang_type);
64 m_name = name;
65 SetIsConstant ();
66 SetValueIsValid(true);
67 m_pointers_point_to_load_addrs = true;
68}
69
70ValueObjectConstResult::ValueObjectConstResult
71(
Jim Ingham6035b672011-03-31 00:19:25 +000072 ExecutionContextScope *exe_scope,
Greg Clayton1d3afba2010-10-05 00:00:42 +000073 clang::ASTContext *clang_ast,
74 void *clang_type,
75 const ConstString &name,
76 const lldb::DataBufferSP &data_sp,
77 lldb::ByteOrder data_byte_order,
78 uint8_t data_addr_size
79) :
Jim Ingham6035b672011-03-31 00:19:25 +000080 ValueObject (exe_scope),
Greg Clayton1d3afba2010-10-05 00:00:42 +000081 m_clang_ast (clang_ast),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000082 m_type_name (),
83 m_byte_size (0)
Greg Clayton1d3afba2010-10-05 00:00:42 +000084{
85 m_data.SetByteOrder(data_byte_order);
86 m_data.SetAddressByteSize(data_addr_size);
87 m_data.SetData(data_sp);
88 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
89 m_value.SetValueType(Value::eValueTypeHostAddress);
Greg Clayton526e5af2010-11-13 03:52:47 +000090 m_value.SetContext(Value::eContextTypeClangType, clang_type);
Greg Clayton1d3afba2010-10-05 00:00:42 +000091 m_name = name;
Greg Claytonb71f3842010-10-05 03:13:51 +000092 SetIsConstant ();
Jim Inghame2f88412010-10-15 22:47:36 +000093 SetValueIsValid(true);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000094 m_pointers_point_to_load_addrs = true;
95}
96
97ValueObjectConstResult::ValueObjectConstResult
98(
Jim Ingham6035b672011-03-31 00:19:25 +000099 ExecutionContextScope *exe_scope,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000100 clang::ASTContext *clang_ast,
101 void *clang_type,
102 const ConstString &name,
103 lldb::addr_t address,
Greg Claytone0d378b2011-03-24 21:19:54 +0000104 AddressType address_type,
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000105 uint8_t addr_byte_size
106) :
Jim Ingham6035b672011-03-31 00:19:25 +0000107 ValueObject (exe_scope),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000108 m_clang_ast (clang_ast),
109 m_type_name (),
110 m_byte_size (0)
111{
112 m_value.GetScalar() = address;
113 m_data.SetAddressByteSize(addr_byte_size);
114 m_value.GetScalar().GetData (m_data, addr_byte_size);
115 //m_value.SetValueType(Value::eValueTypeHostAddress);
116 switch (address_type)
117 {
118 default:
119 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break;
120 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break;
121 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break;
122 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break;
123 }
124 m_value.SetContext(Value::eContextTypeClangType, clang_type);
125 m_name = name;
126 SetIsConstant ();
127 SetValueIsValid(true);
128 m_pointers_point_to_load_addrs = true;
Greg Claytonb71f3842010-10-05 03:13:51 +0000129}
130
Jim Ingham6035b672011-03-31 00:19:25 +0000131ValueObjectConstResult::ValueObjectConstResult (
132 ExecutionContextScope *exe_scope,
133 const Error& error) :
134 ValueObject (exe_scope),
Greg Claytonb71f3842010-10-05 03:13:51 +0000135 m_clang_ast (NULL),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000136 m_type_name (),
137 m_byte_size (0)
Greg Claytonb71f3842010-10-05 03:13:51 +0000138{
139 m_error = error;
140 SetIsConstant ();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000141 m_pointers_point_to_load_addrs = true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000142}
143
144ValueObjectConstResult::~ValueObjectConstResult()
145{
146}
147
Greg Clayton6beaaa62011-01-17 03:46:26 +0000148lldb::clang_type_t
Greg Clayton1d3afba2010-10-05 00:00:42 +0000149ValueObjectConstResult::GetClangType()
150{
151 return m_value.GetClangType();
152}
153
154lldb::ValueType
155ValueObjectConstResult::GetValueType() const
156{
157 return eValueTypeConstResult;
158}
159
160size_t
161ValueObjectConstResult::GetByteSize()
162{
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000163 if (m_byte_size == 0)
164 {
165 uint64_t bit_width = ClangASTType::GetClangTypeBitWidth (GetClangAST(), GetClangType());
166 m_byte_size = (bit_width + 7 ) / 8;
167 }
168 return m_byte_size;
169}
170
171void
172ValueObjectConstResult::SetByteSize (size_t size)
173{
174 m_byte_size = size;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000175}
176
177uint32_t
178ValueObjectConstResult::CalculateNumChildren()
179{
Greg Clayton6beaaa62011-01-17 03:46:26 +0000180 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
Greg Clayton1d3afba2010-10-05 00:00:42 +0000181}
182
183clang::ASTContext *
184ValueObjectConstResult::GetClangAST ()
185{
186 return m_clang_ast;
187}
188
189ConstString
190ValueObjectConstResult::GetTypeName()
191{
192 if (m_type_name.IsEmpty())
193 m_type_name = ClangASTType::GetClangTypeName (GetClangType());
194 return m_type_name;
195}
196
Jim Ingham6035b672011-03-31 00:19:25 +0000197bool
198ValueObjectConstResult::UpdateValue ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000199{
Greg Clayton1d3afba2010-10-05 00:00:42 +0000200 // Const value is always valid
201 SetValueIsValid (true);
Jim Ingham6035b672011-03-31 00:19:25 +0000202 return true;
Greg Clayton1d3afba2010-10-05 00:00:42 +0000203}
204
205
206bool
Jim Ingham6035b672011-03-31 00:19:25 +0000207ValueObjectConstResult::IsInScope ()
Greg Clayton1d3afba2010-10-05 00:00:42 +0000208{
209 // A const result value is always in scope since it serializes all
210 // information needed to contain the constant value.
211 return true;
212}