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/ValueObjectChild.h" 13 #include "lldb/Core/ValueObjectConstResultChild.h" 14 #include "lldb/Core/DataExtractor.h" 15 #include "lldb/Core/Module.h" 16 #include "lldb/Core/ValueObjectList.h" 17 18 #include "lldb/Symbol/ClangASTType.h" 19 #include "lldb/Symbol/ObjectFile.h" 20 #include "lldb/Symbol/SymbolContext.h" 21 #include "lldb/Symbol/Type.h" 22 #include "lldb/Symbol/Variable.h" 23 24 #include "lldb/Target/ExecutionContext.h" 25 #include "lldb/Target/Process.h" 26 #include "lldb/Target/Target.h" 27 28 using namespace lldb; 29 using namespace lldb_private; 30 31 ValueObjectSP 32 ValueObjectConstResult::Create 33 ( 34 ExecutionContextScope *exe_scope, 35 ByteOrder byte_order, 36 uint32_t addr_byte_size, 37 lldb::addr_t address 38 ) 39 { 40 return (new ValueObjectConstResult (exe_scope, 41 byte_order, 42 addr_byte_size, 43 address))->GetSP(); 44 } 45 46 ValueObjectConstResult::ValueObjectConstResult 47 ( 48 ExecutionContextScope *exe_scope, 49 ByteOrder byte_order, 50 uint32_t addr_byte_size, 51 lldb::addr_t address 52 ) : 53 ValueObject (exe_scope), 54 m_clang_ast (NULL), 55 m_type_name (), 56 m_byte_size (0), 57 m_impl(this, address) 58 { 59 SetIsConstant (); 60 SetValueIsValid(true); 61 m_data.SetByteOrder(byte_order); 62 m_data.SetAddressByteSize(addr_byte_size); 63 SetAddressTypeOfChildren(eAddressTypeLoad); 64 } 65 66 ValueObjectSP 67 ValueObjectConstResult::Create 68 ( 69 ExecutionContextScope *exe_scope, 70 clang::ASTContext *clang_ast, 71 void *clang_type, 72 const ConstString &name, 73 const DataExtractor &data, 74 lldb::addr_t address 75 ) 76 { 77 return (new ValueObjectConstResult (exe_scope, 78 clang_ast, 79 clang_type, 80 name, 81 data, 82 address))->GetSP(); 83 } 84 85 ValueObjectConstResult::ValueObjectConstResult 86 ( 87 ExecutionContextScope *exe_scope, 88 clang::ASTContext *clang_ast, 89 void *clang_type, 90 const ConstString &name, 91 const DataExtractor &data, 92 lldb::addr_t address 93 ) : 94 ValueObject (exe_scope), 95 m_clang_ast (clang_ast), 96 m_type_name (), 97 m_byte_size (0), 98 m_impl(this, address) 99 { 100 m_data = data; 101 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 102 m_value.SetValueType(Value::eValueTypeHostAddress); 103 m_value.SetContext(Value::eContextTypeClangType, clang_type); 104 m_name = name; 105 SetIsConstant (); 106 SetValueIsValid(true); 107 SetAddressTypeOfChildren(eAddressTypeLoad); 108 } 109 110 ValueObjectSP 111 ValueObjectConstResult::Create 112 ( 113 ExecutionContextScope *exe_scope, 114 clang::ASTContext *clang_ast, 115 void *clang_type, 116 const ConstString &name, 117 const lldb::DataBufferSP &data_sp, 118 lldb::ByteOrder data_byte_order, 119 uint8_t data_addr_size, 120 lldb::addr_t address 121 ) 122 { 123 return (new ValueObjectConstResult (exe_scope, 124 clang_ast, 125 clang_type, 126 name, 127 data_sp, 128 data_byte_order, 129 data_addr_size, 130 address))->GetSP(); 131 } 132 133 ValueObjectConstResult::ValueObjectConstResult 134 ( 135 ExecutionContextScope *exe_scope, 136 clang::ASTContext *clang_ast, 137 void *clang_type, 138 const ConstString &name, 139 const lldb::DataBufferSP &data_sp, 140 lldb::ByteOrder data_byte_order, 141 uint8_t data_addr_size, 142 lldb::addr_t address 143 ) : 144 ValueObject (exe_scope), 145 m_clang_ast (clang_ast), 146 m_type_name (), 147 m_byte_size (0), 148 m_impl(this, address) 149 { 150 m_data.SetByteOrder(data_byte_order); 151 m_data.SetAddressByteSize(data_addr_size); 152 m_data.SetData(data_sp); 153 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes(); 154 m_value.SetValueType(Value::eValueTypeHostAddress); 155 m_value.SetContext(Value::eContextTypeClangType, clang_type); 156 m_name = name; 157 SetIsConstant (); 158 SetValueIsValid(true); 159 SetAddressTypeOfChildren(eAddressTypeLoad); 160 } 161 162 ValueObjectSP 163 ValueObjectConstResult::Create 164 ( 165 ExecutionContextScope *exe_scope, 166 clang::ASTContext *clang_ast, 167 void *clang_type, 168 const ConstString &name, 169 lldb::addr_t address, 170 AddressType address_type, 171 uint8_t addr_byte_size 172 ) 173 { 174 return (new ValueObjectConstResult (exe_scope, 175 clang_ast, 176 clang_type, 177 name, 178 address, 179 address_type, 180 addr_byte_size))->GetSP(); 181 } 182 183 ValueObjectConstResult::ValueObjectConstResult 184 ( 185 ExecutionContextScope *exe_scope, 186 clang::ASTContext *clang_ast, 187 void *clang_type, 188 const ConstString &name, 189 lldb::addr_t address, 190 AddressType address_type, 191 uint8_t addr_byte_size 192 ) : 193 ValueObject (exe_scope), 194 m_clang_ast (clang_ast), 195 m_type_name (), 196 m_byte_size (0), 197 m_impl(this, address) 198 { 199 m_value.GetScalar() = address; 200 m_data.SetAddressByteSize(addr_byte_size); 201 m_value.GetScalar().GetData (m_data, addr_byte_size); 202 //m_value.SetValueType(Value::eValueTypeHostAddress); 203 switch (address_type) 204 { 205 default: 206 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break; 207 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break; 208 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break; 209 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break; 210 } 211 m_value.SetContext(Value::eContextTypeClangType, clang_type); 212 m_name = name; 213 SetIsConstant (); 214 SetValueIsValid(true); 215 SetAddressTypeOfChildren(eAddressTypeLoad); 216 } 217 218 ValueObjectSP 219 ValueObjectConstResult::Create 220 ( 221 ExecutionContextScope *exe_scope, 222 const Error& error 223 ) 224 { 225 return (new ValueObjectConstResult (exe_scope, 226 error))->GetSP(); 227 } 228 229 ValueObjectConstResult::ValueObjectConstResult ( 230 ExecutionContextScope *exe_scope, 231 const Error& error) : 232 ValueObject (exe_scope), 233 m_clang_ast (NULL), 234 m_type_name (), 235 m_byte_size (0), 236 m_impl(this) 237 { 238 m_error = error; 239 SetIsConstant (); 240 } 241 242 ValueObjectConstResult::~ValueObjectConstResult() 243 { 244 } 245 246 lldb::clang_type_t 247 ValueObjectConstResult::GetClangType() 248 { 249 return m_value.GetClangType(); 250 } 251 252 lldb::ValueType 253 ValueObjectConstResult::GetValueType() const 254 { 255 return eValueTypeConstResult; 256 } 257 258 size_t 259 ValueObjectConstResult::GetByteSize() 260 { 261 if (m_byte_size == 0) 262 m_byte_size = ClangASTType::GetTypeByteSize(GetClangAST(), GetClangType()); 263 return m_byte_size; 264 } 265 266 void 267 ValueObjectConstResult::SetByteSize (size_t size) 268 { 269 m_byte_size = size; 270 } 271 272 uint32_t 273 ValueObjectConstResult::CalculateNumChildren() 274 { 275 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true); 276 } 277 278 clang::ASTContext * 279 ValueObjectConstResult::GetClangAST () 280 { 281 return m_clang_ast; 282 } 283 284 ConstString 285 ValueObjectConstResult::GetTypeName() 286 { 287 if (m_type_name.IsEmpty()) 288 m_type_name = ClangASTType::GetConstTypeName (GetClangType()); 289 return m_type_name; 290 } 291 292 bool 293 ValueObjectConstResult::UpdateValue () 294 { 295 // Const value is always valid 296 SetValueIsValid (true); 297 return true; 298 } 299 300 301 bool 302 ValueObjectConstResult::IsInScope () 303 { 304 // A const result value is always in scope since it serializes all 305 // information needed to contain the constant value. 306 return true; 307 } 308 309 lldb::ValueObjectSP 310 ValueObjectConstResult::Dereference (Error &error) 311 { 312 return m_impl.Dereference(error); 313 } 314 315 lldb::ValueObjectSP 316 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) 317 { 318 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create); 319 } 320 321 lldb::ValueObjectSP 322 ValueObjectConstResult::AddressOf (Error &error) 323 { 324 return m_impl.AddressOf(error); 325 } 326 327 ValueObject * 328 ValueObjectConstResult::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) 329 { 330 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index); 331 } 332 333 size_t 334 ValueObjectConstResult::GetPointeeData (DataExtractor& data, 335 uint32_t item_idx, 336 uint32_t item_count) 337 { 338 return m_impl.GetPointeeData(data, item_idx, item_count); 339 } 340