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 ValueObjectSP 134 ValueObjectConstResult::Create (ExecutionContextScope *exe_scope, 135 clang::ASTContext *clang_ast, 136 Value &value, 137 const ConstString &name) 138 { 139 return (new ValueObjectConstResult (exe_scope, clang_ast, value, name))->GetSP(); 140 } 141 142 ValueObjectConstResult::ValueObjectConstResult 143 ( 144 ExecutionContextScope *exe_scope, 145 clang::ASTContext *clang_ast, 146 void *clang_type, 147 const ConstString &name, 148 const lldb::DataBufferSP &data_sp, 149 lldb::ByteOrder data_byte_order, 150 uint8_t data_addr_size, 151 lldb::addr_t address 152 ) : 153 ValueObject (exe_scope), 154 m_clang_ast (clang_ast), 155 m_type_name (), 156 m_byte_size (0), 157 m_impl(this, address) 158 { 159 m_data.SetByteOrder(data_byte_order); 160 m_data.SetAddressByteSize(data_addr_size); 161 m_data.SetData(data_sp); 162 m_value.GetScalar() = (uintptr_t)data_sp->GetBytes(); 163 m_value.SetValueType(Value::eValueTypeHostAddress); 164 m_value.SetContext(Value::eContextTypeClangType, clang_type); 165 m_name = name; 166 SetIsConstant (); 167 SetValueIsValid(true); 168 SetAddressTypeOfChildren(eAddressTypeLoad); 169 } 170 171 ValueObjectSP 172 ValueObjectConstResult::Create 173 ( 174 ExecutionContextScope *exe_scope, 175 clang::ASTContext *clang_ast, 176 void *clang_type, 177 const ConstString &name, 178 lldb::addr_t address, 179 AddressType address_type, 180 uint8_t addr_byte_size 181 ) 182 { 183 return (new ValueObjectConstResult (exe_scope, 184 clang_ast, 185 clang_type, 186 name, 187 address, 188 address_type, 189 addr_byte_size))->GetSP(); 190 } 191 192 ValueObjectConstResult::ValueObjectConstResult 193 ( 194 ExecutionContextScope *exe_scope, 195 clang::ASTContext *clang_ast, 196 void *clang_type, 197 const ConstString &name, 198 lldb::addr_t address, 199 AddressType address_type, 200 uint8_t addr_byte_size 201 ) : 202 ValueObject (exe_scope), 203 m_clang_ast (clang_ast), 204 m_type_name (), 205 m_byte_size (0), 206 m_impl(this, address) 207 { 208 m_value.GetScalar() = address; 209 m_data.SetAddressByteSize(addr_byte_size); 210 m_value.GetScalar().GetData (m_data, addr_byte_size); 211 //m_value.SetValueType(Value::eValueTypeHostAddress); 212 switch (address_type) 213 { 214 default: 215 case eAddressTypeInvalid: m_value.SetValueType(Value::eValueTypeScalar); break; 216 case eAddressTypeFile: m_value.SetValueType(Value::eValueTypeFileAddress); break; 217 case eAddressTypeLoad: m_value.SetValueType(Value::eValueTypeLoadAddress); break; 218 case eAddressTypeHost: m_value.SetValueType(Value::eValueTypeHostAddress); break; 219 } 220 m_value.SetContext(Value::eContextTypeClangType, clang_type); 221 m_name = name; 222 SetIsConstant (); 223 SetValueIsValid(true); 224 SetAddressTypeOfChildren(eAddressTypeLoad); 225 } 226 227 ValueObjectSP 228 ValueObjectConstResult::Create 229 ( 230 ExecutionContextScope *exe_scope, 231 const Error& error 232 ) 233 { 234 return (new ValueObjectConstResult (exe_scope, 235 error))->GetSP(); 236 } 237 238 ValueObjectConstResult::ValueObjectConstResult ( 239 ExecutionContextScope *exe_scope, 240 const Error& error) : 241 ValueObject (exe_scope), 242 m_clang_ast (NULL), 243 m_type_name (), 244 m_byte_size (0), 245 m_impl(this) 246 { 247 m_error = error; 248 SetIsConstant (); 249 } 250 251 ValueObjectConstResult::ValueObjectConstResult ( 252 ExecutionContextScope *exe_scope, 253 clang::ASTContext *clang_ast, 254 const Value &value, 255 const ConstString &name) : 256 ValueObject (exe_scope), 257 m_type_name (), 258 m_byte_size (0), 259 m_clang_ast (clang_ast), 260 m_impl(this) 261 { 262 m_value = value; 263 m_value.GetData(m_data); 264 } 265 266 ValueObjectConstResult::~ValueObjectConstResult() 267 { 268 } 269 270 lldb::clang_type_t 271 ValueObjectConstResult::GetClangType() 272 { 273 return m_value.GetClangType(); 274 } 275 276 lldb::ValueType 277 ValueObjectConstResult::GetValueType() const 278 { 279 return eValueTypeConstResult; 280 } 281 282 size_t 283 ValueObjectConstResult::GetByteSize() 284 { 285 if (m_byte_size == 0) 286 m_byte_size = ClangASTType::GetTypeByteSize(GetClangAST(), GetClangType()); 287 return m_byte_size; 288 } 289 290 void 291 ValueObjectConstResult::SetByteSize (size_t size) 292 { 293 m_byte_size = size; 294 } 295 296 uint32_t 297 ValueObjectConstResult::CalculateNumChildren() 298 { 299 return ClangASTContext::GetNumChildren (GetClangAST (), GetClangType(), true); 300 } 301 302 clang::ASTContext * 303 ValueObjectConstResult::GetClangAST () 304 { 305 return m_clang_ast; 306 } 307 308 ConstString 309 ValueObjectConstResult::GetTypeName() 310 { 311 if (m_type_name.IsEmpty()) 312 m_type_name = ClangASTType::GetConstTypeName (GetClangType()); 313 return m_type_name; 314 } 315 316 bool 317 ValueObjectConstResult::UpdateValue () 318 { 319 // Const value is always valid 320 SetValueIsValid (true); 321 return true; 322 } 323 324 325 bool 326 ValueObjectConstResult::IsInScope () 327 { 328 // A const result value is always in scope since it serializes all 329 // information needed to contain the constant value. 330 return true; 331 } 332 333 lldb::ValueObjectSP 334 ValueObjectConstResult::Dereference (Error &error) 335 { 336 return m_impl.Dereference(error); 337 } 338 339 lldb::ValueObjectSP 340 ValueObjectConstResult::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) 341 { 342 return m_impl.GetSyntheticChildAtOffset(offset, type, can_create); 343 } 344 345 lldb::ValueObjectSP 346 ValueObjectConstResult::AddressOf (Error &error) 347 { 348 return m_impl.AddressOf(error); 349 } 350 351 lldb::addr_t 352 ValueObjectConstResult::GetAddressOf (bool scalar_is_load_address, 353 AddressType *address_type) 354 { 355 return m_impl.GetAddressOf(scalar_is_load_address, address_type); 356 } 357 358 ValueObject * 359 ValueObjectConstResult::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) 360 { 361 return m_impl.CreateChildAtIndex(idx, synthetic_array_member, synthetic_index); 362 } 363 364 size_t 365 ValueObjectConstResult::GetPointeeData (DataExtractor& data, 366 uint32_t item_idx, 367 uint32_t item_count) 368 { 369 return m_impl.GetPointeeData(data, item_idx, item_count); 370 } 371