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     ByteOrder byte_order,
32     uint32_t addr_byte_size
33 ) :
34     ValueObject (NULL),
35     m_clang_ast (NULL),
36     m_type_name (),
37     m_byte_size (0)
38 {
39     SetIsConstant ();
40     SetValueIsValid(true);
41     m_data.SetByteOrder(byte_order);
42     m_data.SetAddressByteSize(addr_byte_size);
43     m_pointers_point_to_load_addrs = true;
44 }
45 
46 ValueObjectConstResult::ValueObjectConstResult
47 (
48     clang::ASTContext *clang_ast,
49     void *clang_type,
50     const ConstString &name,
51     const DataExtractor &data
52 ) :
53     ValueObject (NULL),
54     m_clang_ast (clang_ast),
55     m_type_name (),
56     m_byte_size (0)
57 {
58     m_data = data;
59     m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
60     m_value.SetValueType(Value::eValueTypeHostAddress);
61     m_value.SetContext(Value::eContextTypeClangType, clang_type);
62     m_name = name;
63     SetIsConstant ();
64     SetValueIsValid(true);
65     m_pointers_point_to_load_addrs = true;
66 }
67 
68 ValueObjectConstResult::ValueObjectConstResult
69 (
70     clang::ASTContext *clang_ast,
71     void *clang_type,
72     const ConstString &name,
73     const lldb::DataBufferSP &data_sp,
74     lldb::ByteOrder data_byte_order,
75     uint8_t data_addr_size
76 ) :
77     ValueObject (NULL),
78     m_clang_ast (clang_ast),
79     m_type_name (),
80     m_byte_size (0)
81 {
82     m_data.SetByteOrder(data_byte_order);
83     m_data.SetAddressByteSize(data_addr_size);
84     m_data.SetData(data_sp);
85     m_value.GetScalar() = (uintptr_t)data_sp->GetBytes();
86     m_value.SetValueType(Value::eValueTypeHostAddress);
87     m_value.SetContext(Value::eContextTypeClangType, clang_type);
88     m_name = name;
89     SetIsConstant ();
90     SetValueIsValid(true);
91     m_pointers_point_to_load_addrs = true;
92 }
93 
94 ValueObjectConstResult::ValueObjectConstResult
95 (
96     clang::ASTContext *clang_ast,
97     void *clang_type,
98     const ConstString &name,
99     lldb::addr_t address,
100     lldb::AddressType address_type,
101     uint8_t addr_byte_size
102 ) :
103     ValueObject (NULL),
104     m_clang_ast (clang_ast),
105     m_type_name (),
106     m_byte_size (0)
107 {
108     m_value.GetScalar() = address;
109     m_data.SetAddressByteSize(addr_byte_size);
110     m_value.GetScalar().GetData (m_data, addr_byte_size);
111     //m_value.SetValueType(Value::eValueTypeHostAddress);
112     switch (address_type)
113     {
114     default:
115     case eAddressTypeInvalid:   m_value.SetValueType(Value::eValueTypeScalar);      break;
116     case eAddressTypeFile:      m_value.SetValueType(Value::eValueTypeFileAddress); break;
117     case eAddressTypeLoad:      m_value.SetValueType(Value::eValueTypeLoadAddress); break;
118     case eAddressTypeHost:      m_value.SetValueType(Value::eValueTypeHostAddress); break;
119     }
120     m_value.SetContext(Value::eContextTypeClangType, clang_type);
121     m_name = name;
122     SetIsConstant ();
123     SetValueIsValid(true);
124     m_pointers_point_to_load_addrs = true;
125 }
126 
127 ValueObjectConstResult::ValueObjectConstResult (const Error& error) :
128     ValueObject (NULL),
129     m_clang_ast (NULL),
130     m_type_name (),
131     m_byte_size (0)
132 {
133     m_error = error;
134     SetIsConstant ();
135     m_pointers_point_to_load_addrs = true;
136 }
137 
138 ValueObjectConstResult::~ValueObjectConstResult()
139 {
140 }
141 
142 lldb::clang_type_t
143 ValueObjectConstResult::GetClangType()
144 {
145     return m_value.GetClangType();
146 }
147 
148 lldb::ValueType
149 ValueObjectConstResult::GetValueType() const
150 {
151     return eValueTypeConstResult;
152 }
153 
154 size_t
155 ValueObjectConstResult::GetByteSize()
156 {
157     if (m_byte_size == 0)
158     {
159         uint64_t bit_width = ClangASTType::GetClangTypeBitWidth (GetClangAST(), GetClangType());
160         m_byte_size = (bit_width + 7 ) / 8;
161     }
162     return m_byte_size;
163 }
164 
165 void
166 ValueObjectConstResult::SetByteSize (size_t size)
167 {
168     m_byte_size = size;
169 }
170 
171 uint32_t
172 ValueObjectConstResult::CalculateNumChildren()
173 {
174     return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true);
175 }
176 
177 clang::ASTContext *
178 ValueObjectConstResult::GetClangAST ()
179 {
180     return m_clang_ast;
181 }
182 
183 ConstString
184 ValueObjectConstResult::GetTypeName()
185 {
186     if (m_type_name.IsEmpty())
187         m_type_name = ClangASTType::GetClangTypeName (GetClangType());
188     return m_type_name;
189 }
190 
191 void
192 ValueObjectConstResult::UpdateValue (ExecutionContextScope *exe_scope)
193 {
194     // Const value is always valid
195     SetValueIsValid (true);
196 }
197 
198 
199 bool
200 ValueObjectConstResult::IsInScope (StackFrame *frame)
201 {
202     // A const result value is always in scope since it serializes all
203     // information needed to contain the constant value.
204     return true;
205 }
206