1 //===-- 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 
26 using namespace lldb;
27 using namespace lldb_private;
28 
29 ValueObjectConstResult::ValueObjectConstResult
30 (
31     ExecutionContextScope *exe_scope,
32     ByteOrder byte_order,
33     uint32_t addr_byte_size
34 ) :
35     ValueObject (exe_scope),
36     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 
47 ValueObjectConstResult::ValueObjectConstResult
48 (
49     ExecutionContextScope *exe_scope,
50     clang::ASTContext *clang_ast,
51     void *clang_type,
52     const ConstString &name,
53     const DataExtractor &data
54 ) :
55     ValueObject (exe_scope),
56     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 
70 ValueObjectConstResult::ValueObjectConstResult
71 (
72     ExecutionContextScope *exe_scope,
73     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 ) :
80     ValueObject (exe_scope),
81     m_clang_ast (clang_ast),
82     m_type_name (),
83     m_byte_size (0)
84 {
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);
90     m_value.SetContext(Value::eContextTypeClangType, clang_type);
91     m_name = name;
92     SetIsConstant ();
93     SetValueIsValid(true);
94     m_pointers_point_to_load_addrs = true;
95 }
96 
97 ValueObjectConstResult::ValueObjectConstResult
98 (
99     ExecutionContextScope *exe_scope,
100     clang::ASTContext *clang_ast,
101     void *clang_type,
102     const ConstString &name,
103     lldb::addr_t address,
104     AddressType address_type,
105     uint8_t addr_byte_size
106 ) :
107     ValueObject (exe_scope),
108     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;
129 }
130 
131 ValueObjectConstResult::ValueObjectConstResult (
132     ExecutionContextScope *exe_scope,
133     const Error& error) :
134     ValueObject (exe_scope),
135     m_clang_ast (NULL),
136     m_type_name (),
137     m_byte_size (0)
138 {
139     m_error = error;
140     SetIsConstant ();
141     m_pointers_point_to_load_addrs = true;
142 }
143 
144 ValueObjectConstResult::~ValueObjectConstResult()
145 {
146 }
147 
148 lldb::clang_type_t
149 ValueObjectConstResult::GetClangType()
150 {
151     return m_value.GetClangType();
152 }
153 
154 lldb::ValueType
155 ValueObjectConstResult::GetValueType() const
156 {
157     return eValueTypeConstResult;
158 }
159 
160 size_t
161 ValueObjectConstResult::GetByteSize()
162 {
163     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 
171 void
172 ValueObjectConstResult::SetByteSize (size_t size)
173 {
174     m_byte_size = size;
175 }
176 
177 uint32_t
178 ValueObjectConstResult::CalculateNumChildren()
179 {
180     return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
181 }
182 
183 clang::ASTContext *
184 ValueObjectConstResult::GetClangAST ()
185 {
186     return m_clang_ast;
187 }
188 
189 ConstString
190 ValueObjectConstResult::GetTypeName()
191 {
192     if (m_type_name.IsEmpty())
193         m_type_name = ClangASTType::GetClangTypeName (GetClangType());
194     return m_type_name;
195 }
196 
197 bool
198 ValueObjectConstResult::UpdateValue ()
199 {
200     // Const value is always valid
201     SetValueIsValid (true);
202     return true;
203 }
204 
205 
206 bool
207 ValueObjectConstResult::IsInScope ()
208 {
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 }
213