1 //===-- ValueObject.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/ValueObject.h" 11 12 // C Includes 13 #include <stdlib.h> 14 15 // C++ Includes 16 // Other libraries and framework includes 17 #include "llvm/Support/raw_ostream.h" 18 19 // Project includes 20 #include "lldb/Core/DataBufferHeap.h" 21 #include "lldb/Core/Debugger.h" 22 #include "lldb/Core/Log.h" 23 #include "lldb/Core/Module.h" 24 #include "lldb/Core/StreamString.h" 25 #include "lldb/Core/ValueObjectCast.h" 26 #include "lldb/Core/ValueObjectChild.h" 27 #include "lldb/Core/ValueObjectConstResult.h" 28 #include "lldb/Core/ValueObjectDynamicValue.h" 29 #include "lldb/Core/ValueObjectList.h" 30 #include "lldb/Core/ValueObjectMemory.h" 31 #include "lldb/Core/ValueObjectSyntheticFilter.h" 32 33 #include "lldb/DataFormatters/DataVisualization.h" 34 #include "lldb/DataFormatters/StringPrinter.h" 35 #include "lldb/DataFormatters/ValueObjectPrinter.h" 36 37 #include "Plugins/ExpressionParser/Clang/ClangExpressionVariable.h" 38 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h" 39 40 #include "lldb/Host/Endian.h" 41 42 #include "lldb/Interpreter/CommandInterpreter.h" 43 44 #include "lldb/Symbol/ClangASTContext.h" 45 #include "lldb/Symbol/CompileUnit.h" 46 #include "lldb/Symbol/CompilerType.h" 47 #include "lldb/Symbol/Type.h" 48 49 #include "lldb/Target/ExecutionContext.h" 50 #include "lldb/Target/Language.h" 51 #include "lldb/Target/LanguageRuntime.h" 52 #include "lldb/Target/ObjCLanguageRuntime.h" 53 #include "lldb/Target/Process.h" 54 #include "lldb/Target/RegisterContext.h" 55 #include "lldb/Target/SectionLoadList.h" 56 #include "lldb/Target/Target.h" 57 #include "lldb/Target/Thread.h" 58 59 using namespace lldb; 60 using namespace lldb_private; 61 using namespace lldb_utility; 62 63 static user_id_t g_value_obj_uid = 0; 64 65 //---------------------------------------------------------------------- 66 // ValueObject constructor 67 //---------------------------------------------------------------------- 68 ValueObject::ValueObject(ValueObject &parent) 69 : UserID(++g_value_obj_uid), // Unique identifier for every value object 70 m_parent(&parent), m_root(NULL), m_update_point(parent.GetUpdatePoint()), 71 m_name(), m_data(), m_value(), m_error(), m_value_str(), 72 m_old_value_str(), m_location_str(), m_summary_str(), m_object_desc_str(), 73 m_validation_result(), m_manager(parent.GetManager()), m_children(), 74 m_synthetic_children(), m_dynamic_value(NULL), m_synthetic_value(NULL), 75 m_deref_valobj(NULL), m_format(eFormatDefault), 76 m_last_format(eFormatDefault), m_last_format_mgr_revision(0), 77 m_type_summary_sp(), m_type_format_sp(), m_synthetic_children_sp(), 78 m_type_validator_sp(), m_user_id_of_forced_summary(), 79 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid), 80 m_value_checksum(), 81 m_preferred_display_language(lldb::eLanguageTypeUnknown), 82 m_language_flags(0), m_value_is_valid(false), m_value_did_change(false), 83 m_children_count_valid(false), m_old_value_valid(false), 84 m_is_deref_of_parent(false), m_is_array_item_for_pointer(false), 85 m_is_bitfield_for_scalar(false), m_is_child_at_offset(false), 86 m_is_getting_summary(false), 87 m_did_calculate_complete_objc_class_type(false), 88 m_is_synthetic_children_generated( 89 parent.m_is_synthetic_children_generated) { 90 m_manager->ManageObject(this); 91 } 92 93 //---------------------------------------------------------------------- 94 // ValueObject constructor 95 //---------------------------------------------------------------------- 96 ValueObject::ValueObject(ExecutionContextScope *exe_scope, 97 AddressType child_ptr_or_ref_addr_type) 98 : UserID(++g_value_obj_uid), // Unique identifier for every value object 99 m_parent(NULL), m_root(NULL), m_update_point(exe_scope), m_name(), 100 m_data(), m_value(), m_error(), m_value_str(), m_old_value_str(), 101 m_location_str(), m_summary_str(), m_object_desc_str(), 102 m_validation_result(), m_manager(), m_children(), m_synthetic_children(), 103 m_dynamic_value(NULL), m_synthetic_value(NULL), m_deref_valobj(NULL), 104 m_format(eFormatDefault), m_last_format(eFormatDefault), 105 m_last_format_mgr_revision(0), m_type_summary_sp(), m_type_format_sp(), 106 m_synthetic_children_sp(), m_type_validator_sp(), 107 m_user_id_of_forced_summary(), 108 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type), 109 m_value_checksum(), 110 m_preferred_display_language(lldb::eLanguageTypeUnknown), 111 m_language_flags(0), m_value_is_valid(false), m_value_did_change(false), 112 m_children_count_valid(false), m_old_value_valid(false), 113 m_is_deref_of_parent(false), m_is_array_item_for_pointer(false), 114 m_is_bitfield_for_scalar(false), m_is_child_at_offset(false), 115 m_is_getting_summary(false), 116 m_did_calculate_complete_objc_class_type(false), 117 m_is_synthetic_children_generated(false) { 118 m_manager = new ValueObjectManager(); 119 m_manager->ManageObject(this); 120 } 121 122 //---------------------------------------------------------------------- 123 // Destructor 124 //---------------------------------------------------------------------- 125 ValueObject::~ValueObject() {} 126 127 bool ValueObject::UpdateValueIfNeeded(bool update_format) { 128 129 bool did_change_formats = false; 130 131 if (update_format) 132 did_change_formats = UpdateFormatsIfNeeded(); 133 134 // If this is a constant value, then our success is predicated on whether 135 // we have an error or not 136 if (GetIsConstant()) { 137 // if you are constant, things might still have changed behind your back 138 // (e.g. you are a frozen object and things have changed deeper than you 139 // cared to freeze-dry yourself) 140 // in this case, your value has not changed, but "computed" entries might 141 // have, so you might now have 142 // a different summary, or a different object description. clear these so we 143 // will recompute them 144 if (update_format && !did_change_formats) 145 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | 146 eClearUserVisibleDataItemsDescription); 147 return m_error.Success(); 148 } 149 150 bool first_update = IsChecksumEmpty(); 151 152 if (NeedsUpdating()) { 153 m_update_point.SetUpdated(); 154 155 // Save the old value using swap to avoid a string copy which 156 // also will clear our m_value_str 157 if (m_value_str.empty()) { 158 m_old_value_valid = false; 159 } else { 160 m_old_value_valid = true; 161 m_old_value_str.swap(m_value_str); 162 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 163 } 164 165 ClearUserVisibleData(); 166 167 if (IsInScope()) { 168 const bool value_was_valid = GetValueIsValid(); 169 SetValueDidChange(false); 170 171 m_error.Clear(); 172 173 // Call the pure virtual function to update the value 174 175 bool need_compare_checksums = false; 176 llvm::SmallVector<uint8_t, 16> old_checksum; 177 178 if (!first_update && CanProvideValue()) { 179 need_compare_checksums = true; 180 old_checksum.resize(m_value_checksum.size()); 181 std::copy(m_value_checksum.begin(), m_value_checksum.end(), 182 old_checksum.begin()); 183 } 184 185 bool success = UpdateValue(); 186 187 SetValueIsValid(success); 188 189 if (success) { 190 const uint64_t max_checksum_size = 128; 191 m_data.Checksum(m_value_checksum, max_checksum_size); 192 } else { 193 need_compare_checksums = false; 194 m_value_checksum.clear(); 195 } 196 197 assert(!need_compare_checksums || 198 (!old_checksum.empty() && !m_value_checksum.empty())); 199 200 if (first_update) 201 SetValueDidChange(false); 202 else if (!m_value_did_change && success == false) { 203 // The value wasn't gotten successfully, so we mark this 204 // as changed if the value used to be valid and now isn't 205 SetValueDidChange(value_was_valid); 206 } else if (need_compare_checksums) { 207 SetValueDidChange(memcmp(&old_checksum[0], &m_value_checksum[0], 208 m_value_checksum.size())); 209 } 210 211 } else { 212 m_error.SetErrorString("out of scope"); 213 } 214 } 215 return m_error.Success(); 216 } 217 218 bool ValueObject::UpdateFormatsIfNeeded() { 219 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_DATAFORMATTERS)); 220 if (log) 221 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject " 222 "rev: %d - Global rev: %d", 223 GetName().GetCString(), static_cast<void *>(this), 224 m_last_format_mgr_revision, 225 DataVisualization::GetCurrentRevision()); 226 227 bool any_change = false; 228 229 if ((m_last_format_mgr_revision != DataVisualization::GetCurrentRevision())) { 230 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision(); 231 any_change = true; 232 233 SetValueFormat(DataVisualization::GetFormat(*this, eNoDynamicValues)); 234 SetSummaryFormat( 235 DataVisualization::GetSummaryFormat(*this, GetDynamicValueType())); 236 #ifndef LLDB_DISABLE_PYTHON 237 SetSyntheticChildren( 238 DataVisualization::GetSyntheticChildren(*this, GetDynamicValueType())); 239 #endif 240 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType())); 241 } 242 243 return any_change; 244 } 245 246 void ValueObject::SetNeedsUpdate() { 247 m_update_point.SetNeedsUpdate(); 248 // We have to clear the value string here so ConstResult children will notice 249 // if their values are 250 // changed by hand (i.e. with SetValueAsCString). 251 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 252 } 253 254 void ValueObject::ClearDynamicTypeInformation() { 255 m_children_count_valid = false; 256 m_did_calculate_complete_objc_class_type = false; 257 m_last_format_mgr_revision = 0; 258 m_override_type = CompilerType(); 259 SetValueFormat(lldb::TypeFormatImplSP()); 260 SetSummaryFormat(lldb::TypeSummaryImplSP()); 261 SetSyntheticChildren(lldb::SyntheticChildrenSP()); 262 } 263 264 CompilerType ValueObject::MaybeCalculateCompleteType() { 265 CompilerType compiler_type(GetCompilerTypeImpl()); 266 267 if (m_did_calculate_complete_objc_class_type) { 268 if (m_override_type.IsValid()) 269 return m_override_type; 270 else 271 return compiler_type; 272 } 273 274 CompilerType class_type; 275 bool is_pointer_type = false; 276 277 if (ClangASTContext::IsObjCObjectPointerType(compiler_type, &class_type)) { 278 is_pointer_type = true; 279 } else if (ClangASTContext::IsObjCObjectOrInterfaceType(compiler_type)) { 280 class_type = compiler_type; 281 } else { 282 return compiler_type; 283 } 284 285 m_did_calculate_complete_objc_class_type = true; 286 287 if (class_type) { 288 ConstString class_name(class_type.GetConstTypeName()); 289 290 if (class_name) { 291 ProcessSP process_sp( 292 GetUpdatePoint().GetExecutionContextRef().GetProcessSP()); 293 294 if (process_sp) { 295 ObjCLanguageRuntime *objc_language_runtime( 296 process_sp->GetObjCLanguageRuntime()); 297 298 if (objc_language_runtime) { 299 TypeSP complete_objc_class_type_sp = 300 objc_language_runtime->LookupInCompleteClassCache(class_name); 301 302 if (complete_objc_class_type_sp) { 303 CompilerType complete_class( 304 complete_objc_class_type_sp->GetFullCompilerType()); 305 306 if (complete_class.GetCompleteType()) { 307 if (is_pointer_type) { 308 m_override_type = complete_class.GetPointerType(); 309 } else { 310 m_override_type = complete_class; 311 } 312 313 if (m_override_type.IsValid()) 314 return m_override_type; 315 } 316 } 317 } 318 } 319 } 320 } 321 return compiler_type; 322 } 323 324 CompilerType ValueObject::GetCompilerType() { 325 return MaybeCalculateCompleteType(); 326 } 327 328 TypeImpl ValueObject::GetTypeImpl() { return TypeImpl(GetCompilerType()); } 329 330 DataExtractor &ValueObject::GetDataExtractor() { 331 UpdateValueIfNeeded(false); 332 return m_data; 333 } 334 335 const Error &ValueObject::GetError() { 336 UpdateValueIfNeeded(false); 337 return m_error; 338 } 339 340 const ConstString &ValueObject::GetName() const { return m_name; } 341 342 const char *ValueObject::GetLocationAsCString() { 343 return GetLocationAsCStringImpl(m_value, m_data); 344 } 345 346 const char *ValueObject::GetLocationAsCStringImpl(const Value &value, 347 const DataExtractor &data) { 348 if (UpdateValueIfNeeded(false)) { 349 if (m_location_str.empty()) { 350 StreamString sstr; 351 352 Value::ValueType value_type = value.GetValueType(); 353 354 switch (value_type) { 355 case Value::eValueTypeScalar: 356 case Value::eValueTypeVector: 357 if (value.GetContextType() == Value::eContextTypeRegisterInfo) { 358 RegisterInfo *reg_info = value.GetRegisterInfo(); 359 if (reg_info) { 360 if (reg_info->name) 361 m_location_str = reg_info->name; 362 else if (reg_info->alt_name) 363 m_location_str = reg_info->alt_name; 364 if (m_location_str.empty()) 365 m_location_str = (reg_info->encoding == lldb::eEncodingVector) 366 ? "vector" 367 : "scalar"; 368 } 369 } 370 if (m_location_str.empty()) 371 m_location_str = 372 (value_type == Value::eValueTypeVector) ? "vector" : "scalar"; 373 break; 374 375 case Value::eValueTypeLoadAddress: 376 case Value::eValueTypeFileAddress: 377 case Value::eValueTypeHostAddress: { 378 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2; 379 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, 380 value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); 381 m_location_str.swap(sstr.GetString()); 382 } break; 383 } 384 } 385 } 386 return m_location_str.c_str(); 387 } 388 389 Value &ValueObject::GetValue() { return m_value; } 390 391 const Value &ValueObject::GetValue() const { return m_value; } 392 393 bool ValueObject::ResolveValue(Scalar &scalar) { 394 if (UpdateValueIfNeeded( 395 false)) // make sure that you are up to date before returning anything 396 { 397 ExecutionContext exe_ctx(GetExecutionContextRef()); 398 Value tmp_value(m_value); 399 scalar = tmp_value.ResolveValue(&exe_ctx); 400 if (scalar.IsValid()) { 401 const uint32_t bitfield_bit_size = GetBitfieldBitSize(); 402 if (bitfield_bit_size) 403 return scalar.ExtractBitfield(bitfield_bit_size, 404 GetBitfieldBitOffset()); 405 return true; 406 } 407 } 408 return false; 409 } 410 411 bool ValueObject::IsLogicalTrue(Error &error) { 412 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { 413 LazyBool is_logical_true = language->IsLogicalTrue(*this, error); 414 switch (is_logical_true) { 415 case eLazyBoolYes: 416 case eLazyBoolNo: 417 return (is_logical_true == true); 418 case eLazyBoolCalculate: 419 break; 420 } 421 } 422 423 Scalar scalar_value; 424 425 if (!ResolveValue(scalar_value)) { 426 error.SetErrorString("failed to get a scalar result"); 427 return false; 428 } 429 430 bool ret; 431 if (scalar_value.ULongLong(1) == 0) 432 ret = false; 433 else 434 ret = true; 435 error.Clear(); 436 return ret; 437 } 438 439 bool ValueObject::GetValueIsValid() const { return m_value_is_valid; } 440 441 void ValueObject::SetValueIsValid(bool b) { m_value_is_valid = b; } 442 443 bool ValueObject::GetValueDidChange() { return m_value_did_change; } 444 445 void ValueObject::SetValueDidChange(bool value_changed) { 446 m_value_did_change = value_changed; 447 } 448 449 ValueObjectSP ValueObject::GetChildAtIndex(size_t idx, bool can_create) { 450 ValueObjectSP child_sp; 451 // We may need to update our value if we are dynamic 452 if (IsPossibleDynamicType()) 453 UpdateValueIfNeeded(false); 454 if (idx < GetNumChildren()) { 455 // Check if we have already made the child value object? 456 if (can_create && !m_children.HasChildAtIndex(idx)) { 457 // No we haven't created the child at this index, so lets have our 458 // subclass do it and cache the result for quick future access. 459 m_children.SetChildAtIndex(idx, CreateChildAtIndex(idx, false, 0)); 460 } 461 462 ValueObject *child = m_children.GetChildAtIndex(idx); 463 if (child != NULL) 464 return child->GetSP(); 465 } 466 return child_sp; 467 } 468 469 ValueObjectSP 470 ValueObject::GetChildAtIndexPath(const std::initializer_list<size_t> &idxs, 471 size_t *index_of_error) { 472 return GetChildAtIndexPath(std::vector<size_t>(idxs), index_of_error); 473 } 474 475 ValueObjectSP ValueObject::GetChildAtIndexPath( 476 const std::initializer_list<std::pair<size_t, bool>> &idxs, 477 size_t *index_of_error) { 478 return GetChildAtIndexPath(std::vector<std::pair<size_t, bool>>(idxs), 479 index_of_error); 480 } 481 482 lldb::ValueObjectSP 483 ValueObject::GetChildAtIndexPath(const std::vector<size_t> &idxs, 484 size_t *index_of_error) { 485 if (idxs.size() == 0) 486 return GetSP(); 487 ValueObjectSP root(GetSP()); 488 for (size_t idx : idxs) { 489 root = root->GetChildAtIndex(idx, true); 490 if (!root) { 491 if (index_of_error) 492 *index_of_error = idx; 493 return root; 494 } 495 } 496 return root; 497 } 498 499 lldb::ValueObjectSP ValueObject::GetChildAtIndexPath( 500 const std::vector<std::pair<size_t, bool>> &idxs, size_t *index_of_error) { 501 if (idxs.size() == 0) 502 return GetSP(); 503 ValueObjectSP root(GetSP()); 504 for (std::pair<size_t, bool> idx : idxs) { 505 root = root->GetChildAtIndex(idx.first, idx.second); 506 if (!root) { 507 if (index_of_error) 508 *index_of_error = idx.first; 509 return root; 510 } 511 } 512 return root; 513 } 514 515 lldb::ValueObjectSP 516 ValueObject::GetChildAtNamePath(const std::initializer_list<ConstString> &names, 517 ConstString *name_of_error) { 518 return GetChildAtNamePath(std::vector<ConstString>(names), name_of_error); 519 } 520 521 lldb::ValueObjectSP ValueObject::GetChildAtNamePath( 522 const std::initializer_list<std::pair<ConstString, bool>> &names, 523 ConstString *name_of_error) { 524 return GetChildAtNamePath(std::vector<std::pair<ConstString, bool>>(names), 525 name_of_error); 526 } 527 528 lldb::ValueObjectSP 529 ValueObject::GetChildAtNamePath(const std::vector<ConstString> &names, 530 ConstString *name_of_error) { 531 if (names.size() == 0) 532 return GetSP(); 533 ValueObjectSP root(GetSP()); 534 for (ConstString name : names) { 535 root = root->GetChildMemberWithName(name, true); 536 if (!root) { 537 if (name_of_error) 538 *name_of_error = name; 539 return root; 540 } 541 } 542 return root; 543 } 544 545 lldb::ValueObjectSP ValueObject::GetChildAtNamePath( 546 const std::vector<std::pair<ConstString, bool>> &names, 547 ConstString *name_of_error) { 548 if (names.size() == 0) 549 return GetSP(); 550 ValueObjectSP root(GetSP()); 551 for (std::pair<ConstString, bool> name : names) { 552 root = root->GetChildMemberWithName(name.first, name.second); 553 if (!root) { 554 if (name_of_error) 555 *name_of_error = name.first; 556 return root; 557 } 558 } 559 return root; 560 } 561 562 size_t ValueObject::GetIndexOfChildWithName(const ConstString &name) { 563 bool omit_empty_base_classes = true; 564 return GetCompilerType().GetIndexOfChildWithName(name.GetCString(), 565 omit_empty_base_classes); 566 } 567 568 ValueObjectSP ValueObject::GetChildMemberWithName(const ConstString &name, 569 bool can_create) { 570 // when getting a child by name, it could be buried inside some base 571 // classes (which really aren't part of the expression path), so we 572 // need a vector of indexes that can get us down to the correct child 573 ValueObjectSP child_sp; 574 575 // We may need to update our value if we are dynamic 576 if (IsPossibleDynamicType()) 577 UpdateValueIfNeeded(false); 578 579 std::vector<uint32_t> child_indexes; 580 bool omit_empty_base_classes = true; 581 const size_t num_child_indexes = 582 GetCompilerType().GetIndexOfChildMemberWithName( 583 name.GetCString(), omit_empty_base_classes, child_indexes); 584 if (num_child_indexes > 0) { 585 std::vector<uint32_t>::const_iterator pos = child_indexes.begin(); 586 std::vector<uint32_t>::const_iterator end = child_indexes.end(); 587 588 child_sp = GetChildAtIndex(*pos, can_create); 589 for (++pos; pos != end; ++pos) { 590 if (child_sp) { 591 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex(*pos, can_create)); 592 child_sp = new_child_sp; 593 } else { 594 child_sp.reset(); 595 } 596 } 597 } 598 return child_sp; 599 } 600 601 size_t ValueObject::GetNumChildren(uint32_t max) { 602 UpdateValueIfNeeded(); 603 604 if (max < UINT32_MAX) { 605 if (m_children_count_valid) { 606 size_t children_count = m_children.GetChildrenCount(); 607 return children_count <= max ? children_count : max; 608 } else 609 return CalculateNumChildren(max); 610 } 611 612 if (!m_children_count_valid) { 613 SetNumChildren(CalculateNumChildren()); 614 } 615 return m_children.GetChildrenCount(); 616 } 617 618 bool ValueObject::MightHaveChildren() { 619 bool has_children = false; 620 const uint32_t type_info = GetTypeInfo(); 621 if (type_info) { 622 if (type_info & (eTypeHasChildren | eTypeIsPointer | eTypeIsReference)) 623 has_children = true; 624 } else { 625 has_children = GetNumChildren() > 0; 626 } 627 return has_children; 628 } 629 630 // Should only be called by ValueObject::GetNumChildren() 631 void ValueObject::SetNumChildren(size_t num_children) { 632 m_children_count_valid = true; 633 m_children.SetChildrenCount(num_children); 634 } 635 636 void ValueObject::SetName(const ConstString &name) { m_name = name; } 637 638 ValueObject *ValueObject::CreateChildAtIndex(size_t idx, 639 bool synthetic_array_member, 640 int32_t synthetic_index) { 641 ValueObject *valobj = NULL; 642 643 bool omit_empty_base_classes = true; 644 bool ignore_array_bounds = synthetic_array_member; 645 std::string child_name_str; 646 uint32_t child_byte_size = 0; 647 int32_t child_byte_offset = 0; 648 uint32_t child_bitfield_bit_size = 0; 649 uint32_t child_bitfield_bit_offset = 0; 650 bool child_is_base_class = false; 651 bool child_is_deref_of_parent = false; 652 uint64_t language_flags = 0; 653 654 const bool transparent_pointers = synthetic_array_member == false; 655 CompilerType child_compiler_type; 656 657 ExecutionContext exe_ctx(GetExecutionContextRef()); 658 659 child_compiler_type = GetCompilerType().GetChildCompilerTypeAtIndex( 660 &exe_ctx, idx, transparent_pointers, omit_empty_base_classes, 661 ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, 662 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, 663 child_is_deref_of_parent, this, language_flags); 664 if (child_compiler_type) { 665 if (synthetic_index) 666 child_byte_offset += child_byte_size * synthetic_index; 667 668 ConstString child_name; 669 if (!child_name_str.empty()) 670 child_name.SetCString(child_name_str.c_str()); 671 672 valobj = new ValueObjectChild( 673 *this, child_compiler_type, child_name, child_byte_size, 674 child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, 675 child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid, 676 language_flags); 677 // if (valobj) 678 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid); 679 } 680 681 return valobj; 682 } 683 684 bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, 685 std::string &destination, 686 lldb::LanguageType lang) { 687 return GetSummaryAsCString(summary_ptr, destination, 688 TypeSummaryOptions().SetLanguage(lang)); 689 } 690 691 bool ValueObject::GetSummaryAsCString(TypeSummaryImpl *summary_ptr, 692 std::string &destination, 693 const TypeSummaryOptions &options) { 694 destination.clear(); 695 696 // ideally we would like to bail out if passing NULL, but if we do so 697 // we end up not providing the summary for function pointers anymore 698 if (/*summary_ptr == NULL ||*/ m_is_getting_summary) 699 return false; 700 701 m_is_getting_summary = true; 702 703 TypeSummaryOptions actual_options(options); 704 705 if (actual_options.GetLanguage() == lldb::eLanguageTypeUnknown) 706 actual_options.SetLanguage(GetPreferredDisplayLanguage()); 707 708 // this is a hot path in code and we prefer to avoid setting this string all 709 // too often also clearing out other 710 // information that we might care to see in a crash log. might be useful in 711 // very specific situations though. 712 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. 713 Summary provider's description is %s", 714 GetTypeName().GetCString(), 715 GetName().GetCString(), 716 summary_ptr->GetDescription().c_str());*/ 717 718 if (UpdateValueIfNeeded(false) && summary_ptr) { 719 if (HasSyntheticValue()) 720 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on 721 // the synthetic children being 722 // up-to-date (e.g. ${svar%#}) 723 summary_ptr->FormatObject(this, destination, actual_options); 724 } 725 m_is_getting_summary = false; 726 return !destination.empty(); 727 } 728 729 const char *ValueObject::GetSummaryAsCString(lldb::LanguageType lang) { 730 if (UpdateValueIfNeeded(true) && m_summary_str.empty()) { 731 TypeSummaryOptions summary_options; 732 summary_options.SetLanguage(lang); 733 GetSummaryAsCString(GetSummaryFormat().get(), m_summary_str, 734 summary_options); 735 } 736 if (m_summary_str.empty()) 737 return NULL; 738 return m_summary_str.c_str(); 739 } 740 741 bool ValueObject::GetSummaryAsCString(std::string &destination, 742 const TypeSummaryOptions &options) { 743 return GetSummaryAsCString(GetSummaryFormat().get(), destination, options); 744 } 745 746 bool ValueObject::IsCStringContainer(bool check_pointer) { 747 CompilerType pointee_or_element_compiler_type; 748 const Flags type_flags(GetTypeInfo(&pointee_or_element_compiler_type)); 749 bool is_char_arr_ptr(type_flags.AnySet(eTypeIsArray | eTypeIsPointer) && 750 pointee_or_element_compiler_type.IsCharType()); 751 if (!is_char_arr_ptr) 752 return false; 753 if (!check_pointer) 754 return true; 755 if (type_flags.Test(eTypeIsArray)) 756 return true; 757 addr_t cstr_address = LLDB_INVALID_ADDRESS; 758 AddressType cstr_address_type = eAddressTypeInvalid; 759 cstr_address = GetAddressOf(true, &cstr_address_type); 760 return (cstr_address != LLDB_INVALID_ADDRESS); 761 } 762 763 size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx, 764 uint32_t item_count) { 765 CompilerType pointee_or_element_compiler_type; 766 const uint32_t type_info = GetTypeInfo(&pointee_or_element_compiler_type); 767 const bool is_pointer_type = type_info & eTypeIsPointer; 768 const bool is_array_type = type_info & eTypeIsArray; 769 if (!(is_pointer_type || is_array_type)) 770 return 0; 771 772 if (item_count == 0) 773 return 0; 774 775 ExecutionContext exe_ctx(GetExecutionContextRef()); 776 777 const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize( 778 exe_ctx.GetBestExecutionContextScope()); 779 const uint64_t bytes = item_count * item_type_size; 780 const uint64_t offset = item_idx * item_type_size; 781 782 if (item_idx == 0 && item_count == 1) // simply a deref 783 { 784 if (is_pointer_type) { 785 Error error; 786 ValueObjectSP pointee_sp = Dereference(error); 787 if (error.Fail() || pointee_sp.get() == NULL) 788 return 0; 789 return pointee_sp->GetData(data, error); 790 } else { 791 ValueObjectSP child_sp = GetChildAtIndex(0, true); 792 if (child_sp.get() == NULL) 793 return 0; 794 Error error; 795 return child_sp->GetData(data, error); 796 } 797 return true; 798 } else /* (items > 1) */ 799 { 800 Error error; 801 lldb_private::DataBufferHeap *heap_buf_ptr = NULL; 802 lldb::DataBufferSP data_sp(heap_buf_ptr = 803 new lldb_private::DataBufferHeap()); 804 805 AddressType addr_type; 806 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) 807 : GetAddressOf(true, &addr_type); 808 809 switch (addr_type) { 810 case eAddressTypeFile: { 811 ModuleSP module_sp(GetModule()); 812 if (module_sp) { 813 addr = addr + offset; 814 Address so_addr; 815 module_sp->ResolveFileAddress(addr, so_addr); 816 ExecutionContext exe_ctx(GetExecutionContextRef()); 817 Target *target = exe_ctx.GetTargetPtr(); 818 if (target) { 819 heap_buf_ptr->SetByteSize(bytes); 820 size_t bytes_read = target->ReadMemory( 821 so_addr, false, heap_buf_ptr->GetBytes(), bytes, error); 822 if (error.Success()) { 823 data.SetData(data_sp); 824 return bytes_read; 825 } 826 } 827 } 828 } break; 829 case eAddressTypeLoad: { 830 ExecutionContext exe_ctx(GetExecutionContextRef()); 831 Process *process = exe_ctx.GetProcessPtr(); 832 if (process) { 833 heap_buf_ptr->SetByteSize(bytes); 834 size_t bytes_read = process->ReadMemory( 835 addr + offset, heap_buf_ptr->GetBytes(), bytes, error); 836 if (error.Success() || bytes_read > 0) { 837 data.SetData(data_sp); 838 return bytes_read; 839 } 840 } 841 } break; 842 case eAddressTypeHost: { 843 const uint64_t max_bytes = 844 GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); 845 if (max_bytes > offset) { 846 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes); 847 addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 848 if (addr == 0 || addr == LLDB_INVALID_ADDRESS) 849 break; 850 heap_buf_ptr->CopyData((uint8_t *)(addr + offset), bytes_read); 851 data.SetData(data_sp); 852 return bytes_read; 853 } 854 } break; 855 case eAddressTypeInvalid: 856 break; 857 } 858 } 859 return 0; 860 } 861 862 uint64_t ValueObject::GetData(DataExtractor &data, Error &error) { 863 UpdateValueIfNeeded(false); 864 ExecutionContext exe_ctx(GetExecutionContextRef()); 865 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); 866 if (error.Fail()) { 867 if (m_data.GetByteSize()) { 868 data = m_data; 869 error.Clear(); 870 return data.GetByteSize(); 871 } else { 872 return 0; 873 } 874 } 875 data.SetAddressByteSize(m_data.GetAddressByteSize()); 876 data.SetByteOrder(m_data.GetByteOrder()); 877 return data.GetByteSize(); 878 } 879 880 bool ValueObject::SetData(DataExtractor &data, Error &error) { 881 error.Clear(); 882 // Make sure our value is up to date first so that our location and location 883 // type is valid. 884 if (!UpdateValueIfNeeded(false)) { 885 error.SetErrorString("unable to read value"); 886 return false; 887 } 888 889 uint64_t count = 0; 890 const Encoding encoding = GetCompilerType().GetEncoding(count); 891 892 const size_t byte_size = GetByteSize(); 893 894 Value::ValueType value_type = m_value.GetValueType(); 895 896 switch (value_type) { 897 case Value::eValueTypeScalar: { 898 Error set_error = 899 m_value.GetScalar().SetValueFromData(data, encoding, byte_size); 900 901 if (!set_error.Success()) { 902 error.SetErrorStringWithFormat("unable to set scalar value: %s", 903 set_error.AsCString()); 904 return false; 905 } 906 } break; 907 case Value::eValueTypeLoadAddress: { 908 // If it is a load address, then the scalar value is the storage location 909 // of the data, and we have to shove this value down to that load location. 910 ExecutionContext exe_ctx(GetExecutionContextRef()); 911 Process *process = exe_ctx.GetProcessPtr(); 912 if (process) { 913 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 914 size_t bytes_written = process->WriteMemory( 915 target_addr, data.GetDataStart(), byte_size, error); 916 if (!error.Success()) 917 return false; 918 if (bytes_written != byte_size) { 919 error.SetErrorString("unable to write value to memory"); 920 return false; 921 } 922 } 923 } break; 924 case Value::eValueTypeHostAddress: { 925 // If it is a host address, then we stuff the scalar as a DataBuffer into 926 // the Value's data. 927 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0)); 928 m_data.SetData(buffer_sp, 0); 929 data.CopyByteOrderedData(0, byte_size, 930 const_cast<uint8_t *>(m_data.GetDataStart()), 931 byte_size, m_data.GetByteOrder()); 932 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 933 } break; 934 case Value::eValueTypeFileAddress: 935 case Value::eValueTypeVector: 936 break; 937 } 938 939 // If we have reached this point, then we have successfully changed the value. 940 SetNeedsUpdate(); 941 return true; 942 } 943 944 static bool CopyStringDataToBufferSP(const StreamString &source, 945 lldb::DataBufferSP &destination) { 946 destination.reset(new DataBufferHeap(source.GetSize() + 1, 0)); 947 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize()); 948 return true; 949 } 950 951 std::pair<size_t, bool> 952 ValueObject::ReadPointedString(lldb::DataBufferSP &buffer_sp, Error &error, 953 uint32_t max_length, bool honor_array, 954 Format item_format) { 955 bool was_capped = false; 956 StreamString s; 957 ExecutionContext exe_ctx(GetExecutionContextRef()); 958 Target *target = exe_ctx.GetTargetPtr(); 959 960 if (!target) { 961 s << "<no target to read from>"; 962 error.SetErrorString("no target to read from"); 963 CopyStringDataToBufferSP(s, buffer_sp); 964 return {0, was_capped}; 965 } 966 967 if (max_length == 0) 968 max_length = target->GetMaximumSizeOfStringSummary(); 969 970 size_t bytes_read = 0; 971 size_t total_bytes_read = 0; 972 973 CompilerType compiler_type = GetCompilerType(); 974 CompilerType elem_or_pointee_compiler_type; 975 const Flags type_flags(GetTypeInfo(&elem_or_pointee_compiler_type)); 976 if (type_flags.AnySet(eTypeIsArray | eTypeIsPointer) && 977 elem_or_pointee_compiler_type.IsCharType()) { 978 addr_t cstr_address = LLDB_INVALID_ADDRESS; 979 AddressType cstr_address_type = eAddressTypeInvalid; 980 981 size_t cstr_len = 0; 982 bool capped_data = false; 983 const bool is_array = type_flags.Test(eTypeIsArray); 984 if (is_array) { 985 // We have an array 986 uint64_t array_size = 0; 987 if (compiler_type.IsArrayType(NULL, &array_size, NULL)) { 988 cstr_len = array_size; 989 if (cstr_len > max_length) { 990 capped_data = true; 991 cstr_len = max_length; 992 } 993 } 994 cstr_address = GetAddressOf(true, &cstr_address_type); 995 } else { 996 // We have a pointer 997 cstr_address = GetPointerValue(&cstr_address_type); 998 } 999 1000 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS) { 1001 if (cstr_address_type == eAddressTypeHost && is_array) { 1002 const char *cstr = GetDataExtractor().PeekCStr(0); 1003 if (cstr == nullptr) { 1004 s << "<invalid address>"; 1005 error.SetErrorString("invalid address"); 1006 CopyStringDataToBufferSP(s, buffer_sp); 1007 return {0, was_capped}; 1008 } 1009 buffer_sp.reset(new DataBufferHeap(cstr_len, 0)); 1010 memcpy(buffer_sp->GetBytes(), cstr, cstr_len); 1011 return {cstr_len, was_capped}; 1012 } else { 1013 s << "<invalid address>"; 1014 error.SetErrorString("invalid address"); 1015 CopyStringDataToBufferSP(s, buffer_sp); 1016 return {0, was_capped}; 1017 } 1018 } 1019 1020 Address cstr_so_addr(cstr_address); 1021 DataExtractor data; 1022 if (cstr_len > 0 && honor_array) { 1023 // I am using GetPointeeData() here to abstract the fact that some 1024 // ValueObjects are actually frozen pointers in the host 1025 // but the pointed-to data lives in the debuggee, and GetPointeeData() 1026 // automatically takes care of this 1027 GetPointeeData(data, 0, cstr_len); 1028 1029 if ((bytes_read = data.GetByteSize()) > 0) { 1030 total_bytes_read = bytes_read; 1031 for (size_t offset = 0; offset < bytes_read; offset++) 1032 s.Printf("%c", *data.PeekData(offset, 1)); 1033 if (capped_data) 1034 was_capped = true; 1035 } 1036 } else { 1037 cstr_len = max_length; 1038 const size_t k_max_buf_size = 64; 1039 1040 size_t offset = 0; 1041 1042 int cstr_len_displayed = -1; 1043 bool capped_cstr = false; 1044 // I am using GetPointeeData() here to abstract the fact that some 1045 // ValueObjects are actually frozen pointers in the host 1046 // but the pointed-to data lives in the debuggee, and GetPointeeData() 1047 // automatically takes care of this 1048 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0) { 1049 total_bytes_read += bytes_read; 1050 const char *cstr = data.PeekCStr(0); 1051 size_t len = strnlen(cstr, k_max_buf_size); 1052 if (cstr_len_displayed < 0) 1053 cstr_len_displayed = len; 1054 1055 if (len == 0) 1056 break; 1057 cstr_len_displayed += len; 1058 if (len > bytes_read) 1059 len = bytes_read; 1060 if (len > cstr_len) 1061 len = cstr_len; 1062 1063 for (size_t offset = 0; offset < bytes_read; offset++) 1064 s.Printf("%c", *data.PeekData(offset, 1)); 1065 1066 if (len < k_max_buf_size) 1067 break; 1068 1069 if (len >= cstr_len) { 1070 capped_cstr = true; 1071 break; 1072 } 1073 1074 cstr_len -= len; 1075 offset += len; 1076 } 1077 1078 if (cstr_len_displayed >= 0) { 1079 if (capped_cstr) 1080 was_capped = true; 1081 } 1082 } 1083 } else { 1084 error.SetErrorString("not a string object"); 1085 s << "<not a string object>"; 1086 } 1087 CopyStringDataToBufferSP(s, buffer_sp); 1088 return {total_bytes_read, was_capped}; 1089 } 1090 1091 std::pair<TypeValidatorResult, std::string> ValueObject::GetValidationStatus() { 1092 if (!UpdateValueIfNeeded(true)) 1093 return {TypeValidatorResult::Success, 1094 ""}; // not the validator's job to discuss update problems 1095 1096 if (m_validation_result.hasValue()) 1097 return m_validation_result.getValue(); 1098 1099 if (!m_type_validator_sp) 1100 return {TypeValidatorResult::Success, ""}; // no validator no failure 1101 1102 auto outcome = m_type_validator_sp->FormatObject(this); 1103 1104 return (m_validation_result = {outcome.m_result, outcome.m_message}) 1105 .getValue(); 1106 } 1107 1108 const char *ValueObject::GetObjectDescription() { 1109 1110 if (!UpdateValueIfNeeded(true)) 1111 return NULL; 1112 1113 if (!m_object_desc_str.empty()) 1114 return m_object_desc_str.c_str(); 1115 1116 ExecutionContext exe_ctx(GetExecutionContextRef()); 1117 Process *process = exe_ctx.GetProcessPtr(); 1118 if (process == NULL) 1119 return NULL; 1120 1121 StreamString s; 1122 1123 LanguageType language = GetObjectRuntimeLanguage(); 1124 LanguageRuntime *runtime = process->GetLanguageRuntime(language); 1125 1126 if (runtime == NULL) { 1127 // Aw, hell, if the things a pointer, or even just an integer, let's try 1128 // ObjC anyway... 1129 CompilerType compiler_type = GetCompilerType(); 1130 if (compiler_type) { 1131 bool is_signed; 1132 if (compiler_type.IsIntegerType(is_signed) || 1133 compiler_type.IsPointerType()) { 1134 runtime = process->GetLanguageRuntime(eLanguageTypeObjC); 1135 } 1136 } 1137 } 1138 1139 if (runtime && runtime->GetObjectDescription(s, *this)) { 1140 m_object_desc_str.append(s.GetData()); 1141 } 1142 1143 if (m_object_desc_str.empty()) 1144 return NULL; 1145 else 1146 return m_object_desc_str.c_str(); 1147 } 1148 1149 bool ValueObject::GetValueAsCString(const lldb_private::TypeFormatImpl &format, 1150 std::string &destination) { 1151 if (UpdateValueIfNeeded(false)) 1152 return format.FormatObject(this, destination); 1153 else 1154 return false; 1155 } 1156 1157 bool ValueObject::GetValueAsCString(lldb::Format format, 1158 std::string &destination) { 1159 return GetValueAsCString(TypeFormatImpl_Format(format), destination); 1160 } 1161 1162 const char *ValueObject::GetValueAsCString() { 1163 if (UpdateValueIfNeeded(true)) { 1164 lldb::TypeFormatImplSP format_sp; 1165 lldb::Format my_format = GetFormat(); 1166 if (my_format == lldb::eFormatDefault) { 1167 if (m_type_format_sp) 1168 format_sp = m_type_format_sp; 1169 else { 1170 if (m_is_bitfield_for_scalar) 1171 my_format = eFormatUnsigned; 1172 else { 1173 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) { 1174 const RegisterInfo *reg_info = m_value.GetRegisterInfo(); 1175 if (reg_info) 1176 my_format = reg_info->format; 1177 } else { 1178 my_format = GetValue().GetCompilerType().GetFormat(); 1179 } 1180 } 1181 } 1182 } 1183 if (my_format != m_last_format || m_value_str.empty()) { 1184 m_last_format = my_format; 1185 if (!format_sp) 1186 format_sp.reset(new TypeFormatImpl_Format(my_format)); 1187 if (GetValueAsCString(*format_sp.get(), m_value_str)) { 1188 if (!m_value_did_change && m_old_value_valid) { 1189 // The value was gotten successfully, so we consider the 1190 // value as changed if the value string differs 1191 SetValueDidChange(m_old_value_str != m_value_str); 1192 } 1193 } 1194 } 1195 } 1196 if (m_value_str.empty()) 1197 return NULL; 1198 return m_value_str.c_str(); 1199 } 1200 1201 // if > 8bytes, 0 is returned. this method should mostly be used 1202 // to read address values out of pointers 1203 uint64_t ValueObject::GetValueAsUnsigned(uint64_t fail_value, bool *success) { 1204 // If our byte size is zero this is an aggregate type that has children 1205 if (CanProvideValue()) { 1206 Scalar scalar; 1207 if (ResolveValue(scalar)) { 1208 if (success) 1209 *success = true; 1210 return scalar.ULongLong(fail_value); 1211 } 1212 // fallthrough, otherwise... 1213 } 1214 1215 if (success) 1216 *success = false; 1217 return fail_value; 1218 } 1219 1220 int64_t ValueObject::GetValueAsSigned(int64_t fail_value, bool *success) { 1221 // If our byte size is zero this is an aggregate type that has children 1222 if (CanProvideValue()) { 1223 Scalar scalar; 1224 if (ResolveValue(scalar)) { 1225 if (success) 1226 *success = true; 1227 return scalar.SLongLong(fail_value); 1228 } 1229 // fallthrough, otherwise... 1230 } 1231 1232 if (success) 1233 *success = false; 1234 return fail_value; 1235 } 1236 1237 // if any more "special cases" are added to 1238 // ValueObject::DumpPrintableRepresentation() please keep 1239 // this call up to date by returning true for your new special cases. We will 1240 // eventually move 1241 // to checking this call result before trying to display special cases 1242 bool ValueObject::HasSpecialPrintableRepresentation( 1243 ValueObjectRepresentationStyle val_obj_display, Format custom_format) { 1244 Flags flags(GetTypeInfo()); 1245 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && 1246 val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { 1247 if (IsCStringContainer(true) && 1248 (custom_format == eFormatCString || custom_format == eFormatCharArray || 1249 custom_format == eFormatChar || custom_format == eFormatVectorOfChar)) 1250 return true; 1251 1252 if (flags.Test(eTypeIsArray)) { 1253 if ((custom_format == eFormatBytes) || 1254 (custom_format == eFormatBytesWithASCII)) 1255 return true; 1256 1257 if ((custom_format == eFormatVectorOfChar) || 1258 (custom_format == eFormatVectorOfFloat32) || 1259 (custom_format == eFormatVectorOfFloat64) || 1260 (custom_format == eFormatVectorOfSInt16) || 1261 (custom_format == eFormatVectorOfSInt32) || 1262 (custom_format == eFormatVectorOfSInt64) || 1263 (custom_format == eFormatVectorOfSInt8) || 1264 (custom_format == eFormatVectorOfUInt128) || 1265 (custom_format == eFormatVectorOfUInt16) || 1266 (custom_format == eFormatVectorOfUInt32) || 1267 (custom_format == eFormatVectorOfUInt64) || 1268 (custom_format == eFormatVectorOfUInt8)) 1269 return true; 1270 } 1271 } 1272 return false; 1273 } 1274 1275 bool ValueObject::DumpPrintableRepresentation( 1276 Stream &s, ValueObjectRepresentationStyle val_obj_display, 1277 Format custom_format, PrintableRepresentationSpecialCases special, 1278 bool do_dump_error) { 1279 1280 Flags flags(GetTypeInfo()); 1281 1282 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == 1283 ePrintableRepresentationSpecialCasesAllow); 1284 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == 1285 ePrintableRepresentationSpecialCasesOnly); 1286 1287 if (allow_special) { 1288 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && 1289 val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { 1290 // when being asked to get a printable display an array or pointer type 1291 // directly, 1292 // try to "do the right thing" 1293 1294 if (IsCStringContainer(true) && 1295 (custom_format == eFormatCString || 1296 custom_format == eFormatCharArray || custom_format == eFormatChar || 1297 custom_format == 1298 eFormatVectorOfChar)) // print char[] & char* directly 1299 { 1300 Error error; 1301 lldb::DataBufferSP buffer_sp; 1302 std::pair<size_t, bool> read_string = ReadPointedString( 1303 buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) || 1304 (custom_format == eFormatCharArray)); 1305 lldb_private::formatters::StringPrinter:: 1306 ReadBufferAndDumpToStreamOptions options(*this); 1307 options.SetData(DataExtractor( 1308 buffer_sp, lldb::eByteOrderInvalid, 1309 8)); // none of this matters for a string - pass some defaults 1310 options.SetStream(&s); 1311 options.SetPrefixToken(0); 1312 options.SetQuote('"'); 1313 options.SetSourceSize(buffer_sp->GetByteSize()); 1314 options.SetIsTruncated(read_string.second); 1315 formatters::StringPrinter::ReadBufferAndDumpToStream< 1316 lldb_private::formatters::StringPrinter::StringElementType::ASCII>( 1317 options); 1318 return !error.Fail(); 1319 } 1320 1321 if (custom_format == eFormatEnum) 1322 return false; 1323 1324 // this only works for arrays, because I have no way to know when 1325 // the pointed memory ends, and no special \0 end of data marker 1326 if (flags.Test(eTypeIsArray)) { 1327 if ((custom_format == eFormatBytes) || 1328 (custom_format == eFormatBytesWithASCII)) { 1329 const size_t count = GetNumChildren(); 1330 1331 s << '['; 1332 for (size_t low = 0; low < count; low++) { 1333 1334 if (low) 1335 s << ','; 1336 1337 ValueObjectSP child = GetChildAtIndex(low, true); 1338 if (!child.get()) { 1339 s << "<invalid child>"; 1340 continue; 1341 } 1342 child->DumpPrintableRepresentation( 1343 s, ValueObject::eValueObjectRepresentationStyleValue, 1344 custom_format); 1345 } 1346 1347 s << ']'; 1348 1349 return true; 1350 } 1351 1352 if ((custom_format == eFormatVectorOfChar) || 1353 (custom_format == eFormatVectorOfFloat32) || 1354 (custom_format == eFormatVectorOfFloat64) || 1355 (custom_format == eFormatVectorOfSInt16) || 1356 (custom_format == eFormatVectorOfSInt32) || 1357 (custom_format == eFormatVectorOfSInt64) || 1358 (custom_format == eFormatVectorOfSInt8) || 1359 (custom_format == eFormatVectorOfUInt128) || 1360 (custom_format == eFormatVectorOfUInt16) || 1361 (custom_format == eFormatVectorOfUInt32) || 1362 (custom_format == eFormatVectorOfUInt64) || 1363 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes 1364 // with ASCII or any vector 1365 // format should be printed 1366 // directly 1367 { 1368 const size_t count = GetNumChildren(); 1369 1370 Format format = FormatManager::GetSingleItemFormat(custom_format); 1371 1372 s << '['; 1373 for (size_t low = 0; low < count; low++) { 1374 1375 if (low) 1376 s << ','; 1377 1378 ValueObjectSP child = GetChildAtIndex(low, true); 1379 if (!child.get()) { 1380 s << "<invalid child>"; 1381 continue; 1382 } 1383 child->DumpPrintableRepresentation( 1384 s, ValueObject::eValueObjectRepresentationStyleValue, format); 1385 } 1386 1387 s << ']'; 1388 1389 return true; 1390 } 1391 } 1392 1393 if ((custom_format == eFormatBoolean) || 1394 (custom_format == eFormatBinary) || (custom_format == eFormatChar) || 1395 (custom_format == eFormatCharPrintable) || 1396 (custom_format == eFormatComplexFloat) || 1397 (custom_format == eFormatDecimal) || (custom_format == eFormatHex) || 1398 (custom_format == eFormatHexUppercase) || 1399 (custom_format == eFormatFloat) || (custom_format == eFormatOctal) || 1400 (custom_format == eFormatOSType) || 1401 (custom_format == eFormatUnicode16) || 1402 (custom_format == eFormatUnicode32) || 1403 (custom_format == eFormatUnsigned) || 1404 (custom_format == eFormatPointer) || 1405 (custom_format == eFormatComplexInteger) || 1406 (custom_format == eFormatComplex) || 1407 (custom_format == eFormatDefault)) // use the [] operator 1408 return false; 1409 } 1410 } 1411 1412 if (only_special) 1413 return false; 1414 1415 bool var_success = false; 1416 1417 { 1418 const char *cstr = NULL; 1419 1420 // this is a local stream that we are using to ensure that the data pointed 1421 // to by cstr survives 1422 // long enough for us to copy it to its destination - it is necessary to 1423 // have this temporary storage 1424 // area for cases where our desired output is not backed by some other 1425 // longer-term storage 1426 StreamString strm; 1427 1428 if (custom_format != eFormatInvalid) 1429 SetFormat(custom_format); 1430 1431 switch (val_obj_display) { 1432 case eValueObjectRepresentationStyleValue: 1433 cstr = GetValueAsCString(); 1434 break; 1435 1436 case eValueObjectRepresentationStyleSummary: 1437 cstr = GetSummaryAsCString(); 1438 break; 1439 1440 case eValueObjectRepresentationStyleLanguageSpecific: 1441 cstr = GetObjectDescription(); 1442 break; 1443 1444 case eValueObjectRepresentationStyleLocation: 1445 cstr = GetLocationAsCString(); 1446 break; 1447 1448 case eValueObjectRepresentationStyleChildrenCount: 1449 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren()); 1450 cstr = strm.GetString().c_str(); 1451 break; 1452 1453 case eValueObjectRepresentationStyleType: 1454 cstr = GetTypeName().AsCString(); 1455 break; 1456 1457 case eValueObjectRepresentationStyleName: 1458 cstr = GetName().AsCString(); 1459 break; 1460 1461 case eValueObjectRepresentationStyleExpressionPath: 1462 GetExpressionPath(strm, false); 1463 cstr = strm.GetString().c_str(); 1464 break; 1465 } 1466 1467 if (!cstr) { 1468 if (val_obj_display == eValueObjectRepresentationStyleValue) 1469 cstr = GetSummaryAsCString(); 1470 else if (val_obj_display == eValueObjectRepresentationStyleSummary) { 1471 if (!CanProvideValue()) { 1472 strm.Printf("%s @ %s", GetTypeName().AsCString(), 1473 GetLocationAsCString()); 1474 cstr = strm.GetString().c_str(); 1475 } else 1476 cstr = GetValueAsCString(); 1477 } 1478 } 1479 1480 if (cstr) 1481 s.PutCString(cstr); 1482 else { 1483 if (m_error.Fail()) { 1484 if (do_dump_error) 1485 s.Printf("<%s>", m_error.AsCString()); 1486 else 1487 return false; 1488 } else if (val_obj_display == eValueObjectRepresentationStyleSummary) 1489 s.PutCString("<no summary available>"); 1490 else if (val_obj_display == eValueObjectRepresentationStyleValue) 1491 s.PutCString("<no value available>"); 1492 else if (val_obj_display == 1493 eValueObjectRepresentationStyleLanguageSpecific) 1494 s.PutCString("<not a valid Objective-C object>"); // edit this if we 1495 // have other runtimes 1496 // that support a 1497 // description 1498 else 1499 s.PutCString("<no printable representation>"); 1500 } 1501 1502 // we should only return false here if we could not do *anything* 1503 // even if we have an error message as output, that's a success 1504 // from our callers' perspective, so return true 1505 var_success = true; 1506 1507 if (custom_format != eFormatInvalid) 1508 SetFormat(eFormatDefault); 1509 } 1510 1511 return var_success; 1512 } 1513 1514 addr_t ValueObject::GetAddressOf(bool scalar_is_load_address, 1515 AddressType *address_type) { 1516 // Can't take address of a bitfield 1517 if (IsBitfield()) 1518 return LLDB_INVALID_ADDRESS; 1519 1520 if (!UpdateValueIfNeeded(false)) 1521 return LLDB_INVALID_ADDRESS; 1522 1523 switch (m_value.GetValueType()) { 1524 case Value::eValueTypeScalar: 1525 case Value::eValueTypeVector: 1526 if (scalar_is_load_address) { 1527 if (address_type) 1528 *address_type = eAddressTypeLoad; 1529 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1530 } 1531 break; 1532 1533 case Value::eValueTypeLoadAddress: 1534 case Value::eValueTypeFileAddress: { 1535 if (address_type) 1536 *address_type = m_value.GetValueAddressType(); 1537 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1538 } break; 1539 case Value::eValueTypeHostAddress: { 1540 if (address_type) 1541 *address_type = m_value.GetValueAddressType(); 1542 return LLDB_INVALID_ADDRESS; 1543 } break; 1544 } 1545 if (address_type) 1546 *address_type = eAddressTypeInvalid; 1547 return LLDB_INVALID_ADDRESS; 1548 } 1549 1550 addr_t ValueObject::GetPointerValue(AddressType *address_type) { 1551 addr_t address = LLDB_INVALID_ADDRESS; 1552 if (address_type) 1553 *address_type = eAddressTypeInvalid; 1554 1555 if (!UpdateValueIfNeeded(false)) 1556 return address; 1557 1558 switch (m_value.GetValueType()) { 1559 case Value::eValueTypeScalar: 1560 case Value::eValueTypeVector: 1561 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1562 break; 1563 1564 case Value::eValueTypeHostAddress: 1565 case Value::eValueTypeLoadAddress: 1566 case Value::eValueTypeFileAddress: { 1567 lldb::offset_t data_offset = 0; 1568 address = m_data.GetPointer(&data_offset); 1569 } break; 1570 } 1571 1572 if (address_type) 1573 *address_type = GetAddressTypeOfChildren(); 1574 1575 return address; 1576 } 1577 1578 bool ValueObject::SetValueFromCString(const char *value_str, Error &error) { 1579 error.Clear(); 1580 // Make sure our value is up to date first so that our location and location 1581 // type is valid. 1582 if (!UpdateValueIfNeeded(false)) { 1583 error.SetErrorString("unable to read value"); 1584 return false; 1585 } 1586 1587 uint64_t count = 0; 1588 const Encoding encoding = GetCompilerType().GetEncoding(count); 1589 1590 const size_t byte_size = GetByteSize(); 1591 1592 Value::ValueType value_type = m_value.GetValueType(); 1593 1594 if (value_type == Value::eValueTypeScalar) { 1595 // If the value is already a scalar, then let the scalar change itself: 1596 m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); 1597 } else if (byte_size <= 16) { 1598 // If the value fits in a scalar, then make a new scalar and again let the 1599 // scalar code do the conversion, then figure out where to put the new 1600 // value. 1601 Scalar new_scalar; 1602 error = new_scalar.SetValueFromCString(value_str, encoding, byte_size); 1603 if (error.Success()) { 1604 switch (value_type) { 1605 case Value::eValueTypeLoadAddress: { 1606 // If it is a load address, then the scalar value is the storage 1607 // location 1608 // of the data, and we have to shove this value down to that load 1609 // location. 1610 ExecutionContext exe_ctx(GetExecutionContextRef()); 1611 Process *process = exe_ctx.GetProcessPtr(); 1612 if (process) { 1613 addr_t target_addr = 1614 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1615 size_t bytes_written = process->WriteScalarToMemory( 1616 target_addr, new_scalar, byte_size, error); 1617 if (!error.Success()) 1618 return false; 1619 if (bytes_written != byte_size) { 1620 error.SetErrorString("unable to write value to memory"); 1621 return false; 1622 } 1623 } 1624 } break; 1625 case Value::eValueTypeHostAddress: { 1626 // If it is a host address, then we stuff the scalar as a DataBuffer 1627 // into the Value's data. 1628 DataExtractor new_data; 1629 new_data.SetByteOrder(m_data.GetByteOrder()); 1630 1631 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0)); 1632 m_data.SetData(buffer_sp, 0); 1633 bool success = new_scalar.GetData(new_data); 1634 if (success) { 1635 new_data.CopyByteOrderedData( 1636 0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()), 1637 byte_size, m_data.GetByteOrder()); 1638 } 1639 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 1640 1641 } break; 1642 case Value::eValueTypeFileAddress: 1643 case Value::eValueTypeScalar: 1644 case Value::eValueTypeVector: 1645 break; 1646 } 1647 } else { 1648 return false; 1649 } 1650 } else { 1651 // We don't support setting things bigger than a scalar at present. 1652 error.SetErrorString("unable to write aggregate data type"); 1653 return false; 1654 } 1655 1656 // If we have reached this point, then we have successfully changed the value. 1657 SetNeedsUpdate(); 1658 return true; 1659 } 1660 1661 bool ValueObject::GetDeclaration(Declaration &decl) { 1662 decl.Clear(); 1663 return false; 1664 } 1665 1666 ConstString ValueObject::GetTypeName() { 1667 return GetCompilerType().GetConstTypeName(); 1668 } 1669 1670 ConstString ValueObject::GetDisplayTypeName() { return GetTypeName(); } 1671 1672 ConstString ValueObject::GetQualifiedTypeName() { 1673 return GetCompilerType().GetConstQualifiedTypeName(); 1674 } 1675 1676 LanguageType ValueObject::GetObjectRuntimeLanguage() { 1677 return GetCompilerType().GetMinimumLanguage(); 1678 } 1679 1680 void ValueObject::AddSyntheticChild(const ConstString &key, 1681 ValueObject *valobj) { 1682 m_synthetic_children[key] = valobj; 1683 } 1684 1685 ValueObjectSP ValueObject::GetSyntheticChild(const ConstString &key) const { 1686 ValueObjectSP synthetic_child_sp; 1687 std::map<ConstString, ValueObject *>::const_iterator pos = 1688 m_synthetic_children.find(key); 1689 if (pos != m_synthetic_children.end()) 1690 synthetic_child_sp = pos->second->GetSP(); 1691 return synthetic_child_sp; 1692 } 1693 1694 uint32_t 1695 ValueObject::GetTypeInfo(CompilerType *pointee_or_element_compiler_type) { 1696 return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type); 1697 } 1698 1699 bool ValueObject::IsPointerType() { return GetCompilerType().IsPointerType(); } 1700 1701 bool ValueObject::IsArrayType() { 1702 return GetCompilerType().IsArrayType(NULL, NULL, NULL); 1703 } 1704 1705 bool ValueObject::IsScalarType() { return GetCompilerType().IsScalarType(); } 1706 1707 bool ValueObject::IsIntegerType(bool &is_signed) { 1708 return GetCompilerType().IsIntegerType(is_signed); 1709 } 1710 1711 bool ValueObject::IsPointerOrReferenceType() { 1712 return GetCompilerType().IsPointerOrReferenceType(); 1713 } 1714 1715 bool ValueObject::IsPossibleDynamicType() { 1716 ExecutionContext exe_ctx(GetExecutionContextRef()); 1717 Process *process = exe_ctx.GetProcessPtr(); 1718 if (process) 1719 return process->IsPossibleDynamicValue(*this); 1720 else 1721 return GetCompilerType().IsPossibleDynamicType(NULL, true, true); 1722 } 1723 1724 bool ValueObject::IsRuntimeSupportValue() { 1725 Process *process(GetProcessSP().get()); 1726 if (process) { 1727 LanguageRuntime *runtime = 1728 process->GetLanguageRuntime(GetObjectRuntimeLanguage()); 1729 if (!runtime) 1730 runtime = process->GetObjCLanguageRuntime(); 1731 if (runtime) 1732 return runtime->IsRuntimeSupportValue(*this); 1733 } 1734 return false; 1735 } 1736 1737 bool ValueObject::IsNilReference() { 1738 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { 1739 return language->IsNilReference(*this); 1740 } 1741 return false; 1742 } 1743 1744 bool ValueObject::IsUninitializedReference() { 1745 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { 1746 return language->IsUninitializedReference(*this); 1747 } 1748 return false; 1749 } 1750 1751 // This allows you to create an array member using and index 1752 // that doesn't not fall in the normal bounds of the array. 1753 // Many times structure can be defined as: 1754 // struct Collection 1755 // { 1756 // uint32_t item_count; 1757 // Item item_array[0]; 1758 // }; 1759 // The size of the "item_array" is 1, but many times in practice 1760 // there are more items in "item_array". 1761 1762 ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, 1763 bool can_create) { 1764 ValueObjectSP synthetic_child_sp; 1765 if (IsPointerType() || IsArrayType()) { 1766 char index_str[64]; 1767 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); 1768 ConstString index_const_str(index_str); 1769 // Check if we have already created a synthetic array member in this 1770 // valid object. If we have we will re-use it. 1771 synthetic_child_sp = GetSyntheticChild(index_const_str); 1772 if (!synthetic_child_sp) { 1773 ValueObject *synthetic_child; 1774 // We haven't made a synthetic array member for INDEX yet, so 1775 // lets make one and cache it for any future reference. 1776 synthetic_child = CreateChildAtIndex(0, true, index); 1777 1778 // Cache the value if we got one back... 1779 if (synthetic_child) { 1780 AddSyntheticChild(index_const_str, synthetic_child); 1781 synthetic_child_sp = synthetic_child->GetSP(); 1782 synthetic_child_sp->SetName(ConstString(index_str)); 1783 synthetic_child_sp->m_is_array_item_for_pointer = true; 1784 } 1785 } 1786 } 1787 return synthetic_child_sp; 1788 } 1789 1790 ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, 1791 bool can_create) { 1792 ValueObjectSP synthetic_child_sp; 1793 if (IsScalarType()) { 1794 char index_str[64]; 1795 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); 1796 ConstString index_const_str(index_str); 1797 // Check if we have already created a synthetic array member in this 1798 // valid object. If we have we will re-use it. 1799 synthetic_child_sp = GetSyntheticChild(index_const_str); 1800 if (!synthetic_child_sp) { 1801 uint32_t bit_field_size = to - from + 1; 1802 uint32_t bit_field_offset = from; 1803 if (GetDataExtractor().GetByteOrder() == eByteOrderBig) 1804 bit_field_offset = 1805 GetByteSize() * 8 - bit_field_size - bit_field_offset; 1806 // We haven't made a synthetic array member for INDEX yet, so 1807 // lets make one and cache it for any future reference. 1808 ValueObjectChild *synthetic_child = new ValueObjectChild( 1809 *this, GetCompilerType(), index_const_str, GetByteSize(), 0, 1810 bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid, 1811 0); 1812 1813 // Cache the value if we got one back... 1814 if (synthetic_child) { 1815 AddSyntheticChild(index_const_str, synthetic_child); 1816 synthetic_child_sp = synthetic_child->GetSP(); 1817 synthetic_child_sp->SetName(ConstString(index_str)); 1818 synthetic_child_sp->m_is_bitfield_for_scalar = true; 1819 } 1820 } 1821 } 1822 return synthetic_child_sp; 1823 } 1824 1825 ValueObjectSP ValueObject::GetSyntheticChildAtOffset( 1826 uint32_t offset, const CompilerType &type, bool can_create, 1827 ConstString name_const_str) { 1828 1829 ValueObjectSP synthetic_child_sp; 1830 1831 if (name_const_str.IsEmpty()) { 1832 char name_str[64]; 1833 snprintf(name_str, sizeof(name_str), "@%i", offset); 1834 name_const_str.SetCString(name_str); 1835 } 1836 1837 // Check if we have already created a synthetic array member in this 1838 // valid object. If we have we will re-use it. 1839 synthetic_child_sp = GetSyntheticChild(name_const_str); 1840 1841 if (synthetic_child_sp.get()) 1842 return synthetic_child_sp; 1843 1844 if (!can_create) 1845 return ValueObjectSP(); 1846 1847 ExecutionContext exe_ctx(GetExecutionContextRef()); 1848 1849 ValueObjectChild *synthetic_child = new ValueObjectChild( 1850 *this, type, name_const_str, 1851 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, 1852 false, false, eAddressTypeInvalid, 0); 1853 if (synthetic_child) { 1854 AddSyntheticChild(name_const_str, synthetic_child); 1855 synthetic_child_sp = synthetic_child->GetSP(); 1856 synthetic_child_sp->SetName(name_const_str); 1857 synthetic_child_sp->m_is_child_at_offset = true; 1858 } 1859 return synthetic_child_sp; 1860 } 1861 1862 ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, 1863 const CompilerType &type, 1864 bool can_create, 1865 ConstString name_const_str) { 1866 ValueObjectSP synthetic_child_sp; 1867 1868 if (name_const_str.IsEmpty()) { 1869 char name_str[128]; 1870 snprintf(name_str, sizeof(name_str), "base%s@%i", 1871 type.GetTypeName().AsCString("<unknown>"), offset); 1872 name_const_str.SetCString(name_str); 1873 } 1874 1875 // Check if we have already created a synthetic array member in this 1876 // valid object. If we have we will re-use it. 1877 synthetic_child_sp = GetSyntheticChild(name_const_str); 1878 1879 if (synthetic_child_sp.get()) 1880 return synthetic_child_sp; 1881 1882 if (!can_create) 1883 return ValueObjectSP(); 1884 1885 const bool is_base_class = true; 1886 1887 ExecutionContext exe_ctx(GetExecutionContextRef()); 1888 1889 ValueObjectChild *synthetic_child = new ValueObjectChild( 1890 *this, type, name_const_str, 1891 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, 1892 is_base_class, false, eAddressTypeInvalid, 0); 1893 if (synthetic_child) { 1894 AddSyntheticChild(name_const_str, synthetic_child); 1895 synthetic_child_sp = synthetic_child->GetSP(); 1896 synthetic_child_sp->SetName(name_const_str); 1897 } 1898 return synthetic_child_sp; 1899 } 1900 1901 // your expression path needs to have a leading . or -> 1902 // (unless it somehow "looks like" an array, in which case it has 1903 // a leading [ symbol). while the [ is meaningful and should be shown 1904 // to the user, . and -> are just parser design, but by no means 1905 // added information for the user.. strip them off 1906 static const char *SkipLeadingExpressionPathSeparators(const char *expression) { 1907 if (!expression || !expression[0]) 1908 return expression; 1909 if (expression[0] == '.') 1910 return expression + 1; 1911 if (expression[0] == '-' && expression[1] == '>') 1912 return expression + 2; 1913 return expression; 1914 } 1915 1916 ValueObjectSP 1917 ValueObject::GetSyntheticExpressionPathChild(const char *expression, 1918 bool can_create) { 1919 ValueObjectSP synthetic_child_sp; 1920 ConstString name_const_string(expression); 1921 // Check if we have already created a synthetic array member in this 1922 // valid object. If we have we will re-use it. 1923 synthetic_child_sp = GetSyntheticChild(name_const_string); 1924 if (!synthetic_child_sp) { 1925 // We haven't made a synthetic array member for expression yet, so 1926 // lets make one and cache it for any future reference. 1927 synthetic_child_sp = GetValueForExpressionPath( 1928 expression, NULL, NULL, NULL, 1929 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal( 1930 GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 1931 None)); 1932 1933 // Cache the value if we got one back... 1934 if (synthetic_child_sp.get()) { 1935 // FIXME: this causes a "real" child to end up with its name changed to 1936 // the contents of expression 1937 AddSyntheticChild(name_const_string, synthetic_child_sp.get()); 1938 synthetic_child_sp->SetName( 1939 ConstString(SkipLeadingExpressionPathSeparators(expression))); 1940 } 1941 } 1942 return synthetic_child_sp; 1943 } 1944 1945 void ValueObject::CalculateSyntheticValue(bool use_synthetic) { 1946 if (use_synthetic == false) 1947 return; 1948 1949 TargetSP target_sp(GetTargetSP()); 1950 if (target_sp && target_sp->GetEnableSyntheticValue() == false) { 1951 m_synthetic_value = NULL; 1952 return; 1953 } 1954 1955 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp); 1956 1957 if (!UpdateFormatsIfNeeded() && m_synthetic_value) 1958 return; 1959 1960 if (m_synthetic_children_sp.get() == NULL) 1961 return; 1962 1963 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value) 1964 return; 1965 1966 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp); 1967 } 1968 1969 void ValueObject::CalculateDynamicValue(DynamicValueType use_dynamic) { 1970 if (use_dynamic == eNoDynamicValues) 1971 return; 1972 1973 if (!m_dynamic_value && !IsDynamic()) { 1974 ExecutionContext exe_ctx(GetExecutionContextRef()); 1975 Process *process = exe_ctx.GetProcessPtr(); 1976 if (process && process->IsPossibleDynamicValue(*this)) { 1977 ClearDynamicTypeInformation(); 1978 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic); 1979 } 1980 } 1981 } 1982 1983 ValueObjectSP ValueObject::GetDynamicValue(DynamicValueType use_dynamic) { 1984 if (use_dynamic == eNoDynamicValues) 1985 return ValueObjectSP(); 1986 1987 if (!IsDynamic() && m_dynamic_value == NULL) { 1988 CalculateDynamicValue(use_dynamic); 1989 } 1990 if (m_dynamic_value) 1991 return m_dynamic_value->GetSP(); 1992 else 1993 return ValueObjectSP(); 1994 } 1995 1996 ValueObjectSP ValueObject::GetStaticValue() { return GetSP(); } 1997 1998 lldb::ValueObjectSP ValueObject::GetNonSyntheticValue() { return GetSP(); } 1999 2000 ValueObjectSP ValueObject::GetSyntheticValue(bool use_synthetic) { 2001 if (use_synthetic == false) 2002 return ValueObjectSP(); 2003 2004 CalculateSyntheticValue(use_synthetic); 2005 2006 if (m_synthetic_value) 2007 return m_synthetic_value->GetSP(); 2008 else 2009 return ValueObjectSP(); 2010 } 2011 2012 bool ValueObject::HasSyntheticValue() { 2013 UpdateFormatsIfNeeded(); 2014 2015 if (m_synthetic_children_sp.get() == NULL) 2016 return false; 2017 2018 CalculateSyntheticValue(true); 2019 2020 if (m_synthetic_value) 2021 return true; 2022 else 2023 return false; 2024 } 2025 2026 bool ValueObject::GetBaseClassPath(Stream &s) { 2027 if (IsBaseClass()) { 2028 bool parent_had_base_class = 2029 GetParent() && GetParent()->GetBaseClassPath(s); 2030 CompilerType compiler_type = GetCompilerType(); 2031 std::string cxx_class_name; 2032 bool this_had_base_class = 2033 ClangASTContext::GetCXXClassName(compiler_type, cxx_class_name); 2034 if (this_had_base_class) { 2035 if (parent_had_base_class) 2036 s.PutCString("::"); 2037 s.PutCString(cxx_class_name.c_str()); 2038 } 2039 return parent_had_base_class || this_had_base_class; 2040 } 2041 return false; 2042 } 2043 2044 ValueObject *ValueObject::GetNonBaseClassParent() { 2045 if (GetParent()) { 2046 if (GetParent()->IsBaseClass()) 2047 return GetParent()->GetNonBaseClassParent(); 2048 else 2049 return GetParent(); 2050 } 2051 return NULL; 2052 } 2053 2054 bool ValueObject::IsBaseClass(uint32_t &depth) { 2055 if (!IsBaseClass()) { 2056 depth = 0; 2057 return false; 2058 } 2059 if (GetParent()) { 2060 GetParent()->IsBaseClass(depth); 2061 depth = depth + 1; 2062 return true; 2063 } 2064 // TODO: a base of no parent? weird.. 2065 depth = 1; 2066 return true; 2067 } 2068 2069 void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, 2070 GetExpressionPathFormat epformat) { 2071 // synthetic children do not actually "exist" as part of the hierarchy, and 2072 // sometimes they are consed up in ways 2073 // that don't make sense from an underlying language/API standpoint. So, use a 2074 // special code path here to return 2075 // something that can hopefully be used in expression 2076 if (m_is_synthetic_children_generated) { 2077 UpdateValueIfNeeded(); 2078 2079 if (m_value.GetValueType() == Value::eValueTypeLoadAddress) { 2080 if (IsPointerOrReferenceType()) { 2081 s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"), 2082 GetValueAsUnsigned(0)); 2083 return; 2084 } else { 2085 uint64_t load_addr = 2086 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 2087 if (load_addr != LLDB_INVALID_ADDRESS) { 2088 s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"), 2089 load_addr); 2090 return; 2091 } 2092 } 2093 } 2094 2095 if (CanProvideValue()) { 2096 s.Printf("((%s)%s)", GetTypeName().AsCString("void"), 2097 GetValueAsCString()); 2098 return; 2099 } 2100 2101 return; 2102 } 2103 2104 const bool is_deref_of_parent = IsDereferenceOfParent(); 2105 2106 if (is_deref_of_parent && 2107 epformat == eGetExpressionPathFormatDereferencePointers) { 2108 // this is the original format of GetExpressionPath() producing code like 2109 // *(a_ptr).memberName, which is entirely 2110 // fine, until you put this into 2111 // StackFrame::GetValueForVariableExpressionPath() which prefers to see 2112 // a_ptr->memberName. 2113 // the eHonorPointers mode is meant to produce strings in this latter format 2114 s.PutCString("*("); 2115 } 2116 2117 ValueObject *parent = GetParent(); 2118 2119 if (parent) 2120 parent->GetExpressionPath(s, qualify_cxx_base_classes, epformat); 2121 2122 // if we are a deref_of_parent just because we are synthetic array 2123 // members made up to allow ptr[%d] syntax to work in variable 2124 // printing, then add our name ([%d]) to the expression path 2125 if (m_is_array_item_for_pointer && 2126 epformat == eGetExpressionPathFormatHonorPointers) 2127 s.PutCString(m_name.AsCString()); 2128 2129 if (!IsBaseClass()) { 2130 if (!is_deref_of_parent) { 2131 ValueObject *non_base_class_parent = GetNonBaseClassParent(); 2132 if (non_base_class_parent && 2133 !non_base_class_parent->GetName().IsEmpty()) { 2134 CompilerType non_base_class_parent_compiler_type = 2135 non_base_class_parent->GetCompilerType(); 2136 if (non_base_class_parent_compiler_type) { 2137 if (parent && parent->IsDereferenceOfParent() && 2138 epformat == eGetExpressionPathFormatHonorPointers) { 2139 s.PutCString("->"); 2140 } else { 2141 const uint32_t non_base_class_parent_type_info = 2142 non_base_class_parent_compiler_type.GetTypeInfo(); 2143 2144 if (non_base_class_parent_type_info & eTypeIsPointer) { 2145 s.PutCString("->"); 2146 } else if ((non_base_class_parent_type_info & eTypeHasChildren) && 2147 !(non_base_class_parent_type_info & eTypeIsArray)) { 2148 s.PutChar('.'); 2149 } 2150 } 2151 } 2152 } 2153 2154 const char *name = GetName().GetCString(); 2155 if (name) { 2156 if (qualify_cxx_base_classes) { 2157 if (GetBaseClassPath(s)) 2158 s.PutCString("::"); 2159 } 2160 s.PutCString(name); 2161 } 2162 } 2163 } 2164 2165 if (is_deref_of_parent && 2166 epformat == eGetExpressionPathFormatDereferencePointers) { 2167 s.PutChar(')'); 2168 } 2169 } 2170 2171 ValueObjectSP ValueObject::GetValueForExpressionPath( 2172 const char *expression, const char **first_unparsed, 2173 ExpressionPathScanEndReason *reason_to_stop, 2174 ExpressionPathEndResultType *final_value_type, 2175 const GetValueForExpressionPathOptions &options, 2176 ExpressionPathAftermath *final_task_on_target) { 2177 2178 const char *dummy_first_unparsed; 2179 ExpressionPathScanEndReason dummy_reason_to_stop = 2180 ValueObject::eExpressionPathScanEndReasonUnknown; 2181 ExpressionPathEndResultType dummy_final_value_type = 2182 ValueObject::eExpressionPathEndResultTypeInvalid; 2183 ExpressionPathAftermath dummy_final_task_on_target = 2184 ValueObject::eExpressionPathAftermathNothing; 2185 2186 ValueObjectSP ret_val = GetValueForExpressionPath_Impl( 2187 expression, first_unparsed ? first_unparsed : &dummy_first_unparsed, 2188 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2189 final_value_type ? final_value_type : &dummy_final_value_type, options, 2190 final_task_on_target ? final_task_on_target 2191 : &dummy_final_task_on_target); 2192 2193 if (!final_task_on_target || 2194 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) 2195 return ret_val; 2196 2197 if (ret_val.get() && 2198 ((final_value_type ? *final_value_type : dummy_final_value_type) == 2199 eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress 2200 // of plain objects 2201 { 2202 if ((final_task_on_target ? *final_task_on_target 2203 : dummy_final_task_on_target) == 2204 ValueObject::eExpressionPathAftermathDereference) { 2205 Error error; 2206 ValueObjectSP final_value = ret_val->Dereference(error); 2207 if (error.Fail() || !final_value.get()) { 2208 if (reason_to_stop) 2209 *reason_to_stop = 2210 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2211 if (final_value_type) 2212 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2213 return ValueObjectSP(); 2214 } else { 2215 if (final_task_on_target) 2216 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2217 return final_value; 2218 } 2219 } 2220 if (*final_task_on_target == 2221 ValueObject::eExpressionPathAftermathTakeAddress) { 2222 Error error; 2223 ValueObjectSP final_value = ret_val->AddressOf(error); 2224 if (error.Fail() || !final_value.get()) { 2225 if (reason_to_stop) 2226 *reason_to_stop = 2227 ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; 2228 if (final_value_type) 2229 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2230 return ValueObjectSP(); 2231 } else { 2232 if (final_task_on_target) 2233 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2234 return final_value; 2235 } 2236 } 2237 } 2238 return ret_val; // final_task_on_target will still have its original value, so 2239 // you know I did not do it 2240 } 2241 2242 int ValueObject::GetValuesForExpressionPath( 2243 const char *expression, ValueObjectListSP &list, 2244 const char **first_unparsed, ExpressionPathScanEndReason *reason_to_stop, 2245 ExpressionPathEndResultType *final_value_type, 2246 const GetValueForExpressionPathOptions &options, 2247 ExpressionPathAftermath *final_task_on_target) { 2248 const char *dummy_first_unparsed; 2249 ExpressionPathScanEndReason dummy_reason_to_stop; 2250 ExpressionPathEndResultType dummy_final_value_type; 2251 ExpressionPathAftermath dummy_final_task_on_target = 2252 ValueObject::eExpressionPathAftermathNothing; 2253 2254 ValueObjectSP ret_val = GetValueForExpressionPath_Impl( 2255 expression, first_unparsed ? first_unparsed : &dummy_first_unparsed, 2256 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2257 final_value_type ? final_value_type : &dummy_final_value_type, options, 2258 final_task_on_target ? final_task_on_target 2259 : &dummy_final_task_on_target); 2260 2261 if (!ret_val.get()) // if there are errors, I add nothing to the list 2262 return 0; 2263 2264 if ((reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != 2265 eExpressionPathScanEndReasonArrayRangeOperatorMet) { 2266 // I need not expand a range, just post-process the final value and return 2267 if (!final_task_on_target || 2268 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) { 2269 list->Append(ret_val); 2270 return 1; 2271 } 2272 if (ret_val.get() && 2273 (final_value_type ? *final_value_type : dummy_final_value_type) == 2274 eExpressionPathEndResultTypePlain) // I can only deref and 2275 // takeaddress of plain objects 2276 { 2277 if (*final_task_on_target == 2278 ValueObject::eExpressionPathAftermathDereference) { 2279 Error error; 2280 ValueObjectSP final_value = ret_val->Dereference(error); 2281 if (error.Fail() || !final_value.get()) { 2282 if (reason_to_stop) 2283 *reason_to_stop = 2284 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2285 if (final_value_type) 2286 *final_value_type = 2287 ValueObject::eExpressionPathEndResultTypeInvalid; 2288 return 0; 2289 } else { 2290 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2291 list->Append(final_value); 2292 return 1; 2293 } 2294 } 2295 if (*final_task_on_target == 2296 ValueObject::eExpressionPathAftermathTakeAddress) { 2297 Error error; 2298 ValueObjectSP final_value = ret_val->AddressOf(error); 2299 if (error.Fail() || !final_value.get()) { 2300 if (reason_to_stop) 2301 *reason_to_stop = 2302 ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; 2303 if (final_value_type) 2304 *final_value_type = 2305 ValueObject::eExpressionPathEndResultTypeInvalid; 2306 return 0; 2307 } else { 2308 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2309 list->Append(final_value); 2310 return 1; 2311 } 2312 } 2313 } 2314 } else { 2315 return ExpandArraySliceExpression( 2316 first_unparsed ? *first_unparsed : dummy_first_unparsed, 2317 first_unparsed ? first_unparsed : &dummy_first_unparsed, ret_val, list, 2318 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2319 final_value_type ? final_value_type : &dummy_final_value_type, options, 2320 final_task_on_target ? final_task_on_target 2321 : &dummy_final_task_on_target); 2322 } 2323 // in any non-covered case, just do the obviously right thing 2324 list->Append(ret_val); 2325 return 1; 2326 } 2327 2328 ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( 2329 const char *expression_cstr, const char **first_unparsed, 2330 ExpressionPathScanEndReason *reason_to_stop, 2331 ExpressionPathEndResultType *final_result, 2332 const GetValueForExpressionPathOptions &options, 2333 ExpressionPathAftermath *what_next) { 2334 ValueObjectSP root = GetSP(); 2335 2336 if (!root.get()) 2337 return ValueObjectSP(); 2338 2339 *first_unparsed = expression_cstr; 2340 2341 while (true) { 2342 2343 const char *expression_cstr = 2344 *first_unparsed; // hide the top level expression_cstr 2345 2346 CompilerType root_compiler_type = root->GetCompilerType(); 2347 CompilerType pointee_compiler_type; 2348 Flags pointee_compiler_type_info; 2349 2350 Flags root_compiler_type_info( 2351 root_compiler_type.GetTypeInfo(&pointee_compiler_type)); 2352 if (pointee_compiler_type) 2353 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); 2354 2355 if (!expression_cstr || *expression_cstr == '\0') { 2356 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2357 return root; 2358 } 2359 2360 switch (*expression_cstr) { 2361 case '-': { 2362 if (options.m_check_dot_vs_arrow_syntax && 2363 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to 2364 // use -> on a 2365 // non-pointer and I 2366 // must catch the error 2367 { 2368 *first_unparsed = expression_cstr; 2369 *reason_to_stop = 2370 ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot; 2371 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2372 return ValueObjectSP(); 2373 } 2374 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to 2375 // extract an ObjC IVar 2376 // when this is forbidden 2377 root_compiler_type_info.Test(eTypeIsPointer) && 2378 options.m_no_fragile_ivar) { 2379 *first_unparsed = expression_cstr; 2380 *reason_to_stop = 2381 ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed; 2382 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2383 return ValueObjectSP(); 2384 } 2385 if (expression_cstr[1] != '>') { 2386 *first_unparsed = expression_cstr; 2387 *reason_to_stop = 2388 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2389 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2390 return ValueObjectSP(); 2391 } 2392 expression_cstr++; // skip the - 2393 } 2394 LLVM_FALLTHROUGH; 2395 case '.': // or fallthrough from -> 2396 { 2397 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && 2398 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to 2399 // use . on a pointer 2400 // and I must catch the 2401 // error 2402 { 2403 *first_unparsed = expression_cstr; 2404 *reason_to_stop = 2405 ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow; 2406 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2407 return ValueObjectSP(); 2408 } 2409 expression_cstr++; // skip . 2410 const char *next_separator = strpbrk(expression_cstr + 1, "-.["); 2411 ConstString child_name; 2412 if (!next_separator) // if no other separator just expand this last layer 2413 { 2414 child_name.SetCString(expression_cstr); 2415 ValueObjectSP child_valobj_sp = 2416 root->GetChildMemberWithName(child_name, true); 2417 2418 if (child_valobj_sp.get()) // we know we are done, so just return 2419 { 2420 *first_unparsed = ""; 2421 *reason_to_stop = 2422 ValueObject::eExpressionPathScanEndReasonEndOfString; 2423 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2424 return child_valobj_sp; 2425 } else { 2426 switch (options.m_synthetic_children_traversal) { 2427 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2428 None: 2429 break; 2430 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2431 FromSynthetic: 2432 if (root->IsSynthetic()) { 2433 child_valobj_sp = root->GetNonSyntheticValue(); 2434 if (child_valobj_sp.get()) 2435 child_valobj_sp = 2436 child_valobj_sp->GetChildMemberWithName(child_name, true); 2437 } 2438 break; 2439 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2440 ToSynthetic: 2441 if (!root->IsSynthetic()) { 2442 child_valobj_sp = root->GetSyntheticValue(); 2443 if (child_valobj_sp.get()) 2444 child_valobj_sp = 2445 child_valobj_sp->GetChildMemberWithName(child_name, true); 2446 } 2447 break; 2448 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2449 Both: 2450 if (root->IsSynthetic()) { 2451 child_valobj_sp = root->GetNonSyntheticValue(); 2452 if (child_valobj_sp.get()) 2453 child_valobj_sp = 2454 child_valobj_sp->GetChildMemberWithName(child_name, true); 2455 } else { 2456 child_valobj_sp = root->GetSyntheticValue(); 2457 if (child_valobj_sp.get()) 2458 child_valobj_sp = 2459 child_valobj_sp->GetChildMemberWithName(child_name, true); 2460 } 2461 break; 2462 } 2463 } 2464 2465 // if we are here and options.m_no_synthetic_children is true, 2466 // child_valobj_sp is going to be a NULL SP, 2467 // so we hit the "else" branch, and return an error 2468 if (child_valobj_sp.get()) // if it worked, just return 2469 { 2470 *first_unparsed = ""; 2471 *reason_to_stop = 2472 ValueObject::eExpressionPathScanEndReasonEndOfString; 2473 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2474 return child_valobj_sp; 2475 } else { 2476 *first_unparsed = expression_cstr; 2477 *reason_to_stop = 2478 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2479 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2480 return ValueObjectSP(); 2481 } 2482 } else // other layers do expand 2483 { 2484 child_name.SetCStringWithLength(expression_cstr, 2485 next_separator - expression_cstr); 2486 ValueObjectSP child_valobj_sp = 2487 root->GetChildMemberWithName(child_name, true); 2488 if (child_valobj_sp.get()) // store the new root and move on 2489 { 2490 root = child_valobj_sp; 2491 *first_unparsed = next_separator; 2492 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2493 continue; 2494 } else { 2495 switch (options.m_synthetic_children_traversal) { 2496 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2497 None: 2498 break; 2499 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2500 FromSynthetic: 2501 if (root->IsSynthetic()) { 2502 child_valobj_sp = root->GetNonSyntheticValue(); 2503 if (child_valobj_sp.get()) 2504 child_valobj_sp = 2505 child_valobj_sp->GetChildMemberWithName(child_name, true); 2506 } 2507 break; 2508 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2509 ToSynthetic: 2510 if (!root->IsSynthetic()) { 2511 child_valobj_sp = root->GetSyntheticValue(); 2512 if (child_valobj_sp.get()) 2513 child_valobj_sp = 2514 child_valobj_sp->GetChildMemberWithName(child_name, true); 2515 } 2516 break; 2517 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2518 Both: 2519 if (root->IsSynthetic()) { 2520 child_valobj_sp = root->GetNonSyntheticValue(); 2521 if (child_valobj_sp.get()) 2522 child_valobj_sp = 2523 child_valobj_sp->GetChildMemberWithName(child_name, true); 2524 } else { 2525 child_valobj_sp = root->GetSyntheticValue(); 2526 if (child_valobj_sp.get()) 2527 child_valobj_sp = 2528 child_valobj_sp->GetChildMemberWithName(child_name, true); 2529 } 2530 break; 2531 } 2532 } 2533 2534 // if we are here and options.m_no_synthetic_children is true, 2535 // child_valobj_sp is going to be a NULL SP, 2536 // so we hit the "else" branch, and return an error 2537 if (child_valobj_sp.get()) // if it worked, move on 2538 { 2539 root = child_valobj_sp; 2540 *first_unparsed = next_separator; 2541 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2542 continue; 2543 } else { 2544 *first_unparsed = expression_cstr; 2545 *reason_to_stop = 2546 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2547 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2548 return ValueObjectSP(); 2549 } 2550 } 2551 break; 2552 } 2553 case '[': { 2554 if (!root_compiler_type_info.Test(eTypeIsArray) && 2555 !root_compiler_type_info.Test(eTypeIsPointer) && 2556 !root_compiler_type_info.Test( 2557 eTypeIsVector)) // if this is not a T[] nor a T* 2558 { 2559 if (!root_compiler_type_info.Test( 2560 eTypeIsScalar)) // if this is not even a scalar... 2561 { 2562 if (options.m_synthetic_children_traversal == 2563 GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2564 None) // ...only chance left is synthetic 2565 { 2566 *first_unparsed = expression_cstr; 2567 *reason_to_stop = 2568 ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; 2569 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2570 return ValueObjectSP(); 2571 } 2572 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar, 2573 // check that we can 2574 // expand bitfields 2575 { 2576 *first_unparsed = expression_cstr; 2577 *reason_to_stop = 2578 ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; 2579 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2580 return ValueObjectSP(); 2581 } 2582 } 2583 if (*(expression_cstr + 1) == 2584 ']') // if this is an unbounded range it only works for arrays 2585 { 2586 if (!root_compiler_type_info.Test(eTypeIsArray)) { 2587 *first_unparsed = expression_cstr; 2588 *reason_to_stop = 2589 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 2590 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2591 return ValueObjectSP(); 2592 } else // even if something follows, we cannot expand unbounded ranges, 2593 // just let the caller do it 2594 { 2595 *first_unparsed = expression_cstr + 2; 2596 *reason_to_stop = 2597 ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 2598 *final_result = 2599 ValueObject::eExpressionPathEndResultTypeUnboundedRange; 2600 return root; 2601 } 2602 } 2603 const char *separator_position = ::strchr(expression_cstr + 1, '-'); 2604 const char *close_bracket_position = ::strchr(expression_cstr + 1, ']'); 2605 if (!close_bracket_position) // if there is no ], this is a syntax error 2606 { 2607 *first_unparsed = expression_cstr; 2608 *reason_to_stop = 2609 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2610 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2611 return ValueObjectSP(); 2612 } 2613 if (!separator_position || 2614 separator_position > close_bracket_position) // if no separator, this 2615 // is either [] or [N] 2616 { 2617 char *end = NULL; 2618 unsigned long index = ::strtoul(expression_cstr + 1, &end, 0); 2619 if (!end || end != close_bracket_position) // if something weird is in 2620 // our way return an error 2621 { 2622 *first_unparsed = expression_cstr; 2623 *reason_to_stop = 2624 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2625 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2626 return ValueObjectSP(); 2627 } 2628 if (end - expression_cstr == 2629 1) // if this is [], only return a valid value for arrays 2630 { 2631 if (root_compiler_type_info.Test(eTypeIsArray)) { 2632 *first_unparsed = expression_cstr + 2; 2633 *reason_to_stop = 2634 ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 2635 *final_result = 2636 ValueObject::eExpressionPathEndResultTypeUnboundedRange; 2637 return root; 2638 } else { 2639 *first_unparsed = expression_cstr; 2640 *reason_to_stop = 2641 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 2642 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2643 return ValueObjectSP(); 2644 } 2645 } 2646 // from here on we do have a valid index 2647 if (root_compiler_type_info.Test(eTypeIsArray)) { 2648 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); 2649 if (!child_valobj_sp) 2650 child_valobj_sp = root->GetSyntheticArrayMember(index, true); 2651 if (!child_valobj_sp) 2652 if (root->HasSyntheticValue() && 2653 root->GetSyntheticValue()->GetNumChildren() > index) 2654 child_valobj_sp = 2655 root->GetSyntheticValue()->GetChildAtIndex(index, true); 2656 if (child_valobj_sp) { 2657 root = child_valobj_sp; 2658 *first_unparsed = end + 1; // skip ] 2659 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2660 continue; 2661 } else { 2662 *first_unparsed = expression_cstr; 2663 *reason_to_stop = 2664 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2665 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2666 return ValueObjectSP(); 2667 } 2668 } else if (root_compiler_type_info.Test(eTypeIsPointer)) { 2669 if (*what_next == 2670 ValueObject:: 2671 eExpressionPathAftermathDereference && // if this is a 2672 // ptr-to-scalar, I 2673 // am accessing it 2674 // by index and I 2675 // would have 2676 // deref'ed anyway, 2677 // then do it now 2678 // and use this as 2679 // a bitfield 2680 pointee_compiler_type_info.Test(eTypeIsScalar)) { 2681 Error error; 2682 root = root->Dereference(error); 2683 if (error.Fail() || !root.get()) { 2684 *first_unparsed = expression_cstr; 2685 *reason_to_stop = 2686 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2687 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2688 return ValueObjectSP(); 2689 } else { 2690 *what_next = eExpressionPathAftermathNothing; 2691 continue; 2692 } 2693 } else { 2694 if (root->GetCompilerType().GetMinimumLanguage() == 2695 eLanguageTypeObjC && 2696 pointee_compiler_type_info.AllClear(eTypeIsPointer) && 2697 root->HasSyntheticValue() && 2698 (options.m_synthetic_children_traversal == 2699 GetValueForExpressionPathOptions:: 2700 SyntheticChildrenTraversal::ToSynthetic || 2701 options.m_synthetic_children_traversal == 2702 GetValueForExpressionPathOptions:: 2703 SyntheticChildrenTraversal::Both)) { 2704 root = root->GetSyntheticValue()->GetChildAtIndex(index, true); 2705 } else 2706 root = root->GetSyntheticArrayMember(index, true); 2707 if (!root.get()) { 2708 *first_unparsed = expression_cstr; 2709 *reason_to_stop = 2710 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2711 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2712 return ValueObjectSP(); 2713 } else { 2714 *first_unparsed = end + 1; // skip ] 2715 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2716 continue; 2717 } 2718 } 2719 } else if (root_compiler_type_info.Test(eTypeIsScalar)) { 2720 root = root->GetSyntheticBitFieldChild(index, index, true); 2721 if (!root.get()) { 2722 *first_unparsed = expression_cstr; 2723 *reason_to_stop = 2724 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2725 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2726 return ValueObjectSP(); 2727 } else // we do not know how to expand members of bitfields, so we 2728 // just return and let the caller do any further processing 2729 { 2730 *first_unparsed = end + 1; // skip ] 2731 *reason_to_stop = ValueObject:: 2732 eExpressionPathScanEndReasonBitfieldRangeOperatorMet; 2733 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; 2734 return root; 2735 } 2736 } else if (root_compiler_type_info.Test(eTypeIsVector)) { 2737 root = root->GetChildAtIndex(index, true); 2738 if (!root.get()) { 2739 *first_unparsed = expression_cstr; 2740 *reason_to_stop = 2741 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2742 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2743 return ValueObjectSP(); 2744 } else { 2745 *first_unparsed = end + 1; // skip ] 2746 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2747 continue; 2748 } 2749 } else if (options.m_synthetic_children_traversal == 2750 GetValueForExpressionPathOptions:: 2751 SyntheticChildrenTraversal::ToSynthetic || 2752 options.m_synthetic_children_traversal == 2753 GetValueForExpressionPathOptions:: 2754 SyntheticChildrenTraversal::Both) { 2755 if (root->HasSyntheticValue()) 2756 root = root->GetSyntheticValue(); 2757 else if (!root->IsSynthetic()) { 2758 *first_unparsed = expression_cstr; 2759 *reason_to_stop = 2760 ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; 2761 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2762 return ValueObjectSP(); 2763 } 2764 // if we are here, then root itself is a synthetic VO.. should be good 2765 // to go 2766 2767 if (!root.get()) { 2768 *first_unparsed = expression_cstr; 2769 *reason_to_stop = 2770 ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; 2771 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2772 return ValueObjectSP(); 2773 } 2774 root = root->GetChildAtIndex(index, true); 2775 if (!root.get()) { 2776 *first_unparsed = expression_cstr; 2777 *reason_to_stop = 2778 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2779 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2780 return ValueObjectSP(); 2781 } else { 2782 *first_unparsed = end + 1; // skip ] 2783 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2784 continue; 2785 } 2786 } else { 2787 *first_unparsed = expression_cstr; 2788 *reason_to_stop = 2789 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2790 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2791 return ValueObjectSP(); 2792 } 2793 } else // we have a low and a high index 2794 { 2795 char *end = NULL; 2796 unsigned long index_lower = ::strtoul(expression_cstr + 1, &end, 0); 2797 if (!end || end != separator_position) // if something weird is in our 2798 // way return an error 2799 { 2800 *first_unparsed = expression_cstr; 2801 *reason_to_stop = 2802 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2803 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2804 return ValueObjectSP(); 2805 } 2806 unsigned long index_higher = ::strtoul(separator_position + 1, &end, 0); 2807 if (!end || end != close_bracket_position) // if something weird is in 2808 // our way return an error 2809 { 2810 *first_unparsed = expression_cstr; 2811 *reason_to_stop = 2812 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2813 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2814 return ValueObjectSP(); 2815 } 2816 if (index_lower > index_higher) // swap indices if required 2817 { 2818 unsigned long temp = index_lower; 2819 index_lower = index_higher; 2820 index_higher = temp; 2821 } 2822 if (root_compiler_type_info.Test( 2823 eTypeIsScalar)) // expansion only works for scalars 2824 { 2825 root = 2826 root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 2827 if (!root.get()) { 2828 *first_unparsed = expression_cstr; 2829 *reason_to_stop = 2830 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2831 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2832 return ValueObjectSP(); 2833 } else { 2834 *first_unparsed = end + 1; // skip ] 2835 *reason_to_stop = ValueObject:: 2836 eExpressionPathScanEndReasonBitfieldRangeOperatorMet; 2837 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; 2838 return root; 2839 } 2840 } else if (root_compiler_type_info.Test( 2841 eTypeIsPointer) && // if this is a ptr-to-scalar, I am 2842 // accessing it by index and I would 2843 // have deref'ed anyway, then do it 2844 // now and use this as a bitfield 2845 *what_next == 2846 ValueObject::eExpressionPathAftermathDereference && 2847 pointee_compiler_type_info.Test(eTypeIsScalar)) { 2848 Error error; 2849 root = root->Dereference(error); 2850 if (error.Fail() || !root.get()) { 2851 *first_unparsed = expression_cstr; 2852 *reason_to_stop = 2853 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2854 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2855 return ValueObjectSP(); 2856 } else { 2857 *what_next = ValueObject::eExpressionPathAftermathNothing; 2858 continue; 2859 } 2860 } else { 2861 *first_unparsed = expression_cstr; 2862 *reason_to_stop = 2863 ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 2864 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange; 2865 return root; 2866 } 2867 } 2868 break; 2869 } 2870 default: // some non-separator is in the way 2871 { 2872 *first_unparsed = expression_cstr; 2873 *reason_to_stop = 2874 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2875 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2876 return ValueObjectSP(); 2877 break; 2878 } 2879 } 2880 } 2881 } 2882 2883 int ValueObject::ExpandArraySliceExpression( 2884 const char *expression_cstr, const char **first_unparsed, 2885 ValueObjectSP root, ValueObjectListSP &list, 2886 ExpressionPathScanEndReason *reason_to_stop, 2887 ExpressionPathEndResultType *final_result, 2888 const GetValueForExpressionPathOptions &options, 2889 ExpressionPathAftermath *what_next) { 2890 if (!root.get()) 2891 return 0; 2892 2893 *first_unparsed = expression_cstr; 2894 2895 while (true) { 2896 2897 const char *expression_cstr = 2898 *first_unparsed; // hide the top level expression_cstr 2899 2900 CompilerType root_compiler_type = root->GetCompilerType(); 2901 CompilerType pointee_compiler_type; 2902 Flags pointee_compiler_type_info; 2903 Flags root_compiler_type_info( 2904 root_compiler_type.GetTypeInfo(&pointee_compiler_type)); 2905 if (pointee_compiler_type) 2906 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); 2907 2908 if (!expression_cstr || *expression_cstr == '\0') { 2909 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2910 list->Append(root); 2911 return 1; 2912 } 2913 2914 switch (*expression_cstr) { 2915 case '[': { 2916 if (!root_compiler_type_info.Test(eTypeIsArray) && 2917 !root_compiler_type_info.Test( 2918 eTypeIsPointer)) // if this is not a T[] nor a T* 2919 { 2920 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even 2921 // a scalar, this 2922 // syntax is just 2923 // plain wrong! 2924 { 2925 *first_unparsed = expression_cstr; 2926 *reason_to_stop = 2927 ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; 2928 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2929 return 0; 2930 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar, 2931 // check that we can 2932 // expand bitfields 2933 { 2934 *first_unparsed = expression_cstr; 2935 *reason_to_stop = 2936 ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; 2937 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2938 return 0; 2939 } 2940 } 2941 if (*(expression_cstr + 1) == 2942 ']') // if this is an unbounded range it only works for arrays 2943 { 2944 if (!root_compiler_type_info.Test(eTypeIsArray)) { 2945 *first_unparsed = expression_cstr; 2946 *reason_to_stop = 2947 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2949 return 0; 2950 } else // expand this into list 2951 { 2952 const size_t max_index = root->GetNumChildren() - 1; 2953 for (size_t index = 0; index < max_index; index++) { 2954 ValueObjectSP child = root->GetChildAtIndex(index, true); 2955 list->Append(child); 2956 } 2957 *first_unparsed = expression_cstr + 2; 2958 *reason_to_stop = 2959 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 2960 *final_result = 2961 ValueObject::eExpressionPathEndResultTypeValueObjectList; 2962 return max_index; // tell me number of items I added to the VOList 2963 } 2964 } 2965 const char *separator_position = ::strchr(expression_cstr + 1, '-'); 2966 const char *close_bracket_position = ::strchr(expression_cstr + 1, ']'); 2967 if (!close_bracket_position) // if there is no ], this is a syntax error 2968 { 2969 *first_unparsed = expression_cstr; 2970 *reason_to_stop = 2971 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2972 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2973 return 0; 2974 } 2975 if (!separator_position || 2976 separator_position > close_bracket_position) // if no separator, this 2977 // is either [] or [N] 2978 { 2979 char *end = NULL; 2980 unsigned long index = ::strtoul(expression_cstr + 1, &end, 0); 2981 if (!end || end != close_bracket_position) // if something weird is in 2982 // our way return an error 2983 { 2984 *first_unparsed = expression_cstr; 2985 *reason_to_stop = 2986 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2987 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2988 return 0; 2989 } 2990 if (end - expression_cstr == 2991 1) // if this is [], only return a valid value for arrays 2992 { 2993 if (root_compiler_type_info.Test(eTypeIsArray)) { 2994 const size_t max_index = root->GetNumChildren() - 1; 2995 for (size_t index = 0; index < max_index; index++) { 2996 ValueObjectSP child = root->GetChildAtIndex(index, true); 2997 list->Append(child); 2998 } 2999 *first_unparsed = expression_cstr + 2; 3000 *reason_to_stop = 3001 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3002 *final_result = 3003 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3004 return max_index; // tell me number of items I added to the VOList 3005 } else { 3006 *first_unparsed = expression_cstr; 3007 *reason_to_stop = 3008 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 3009 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3010 return 0; 3011 } 3012 } 3013 // from here on we do have a valid index 3014 if (root_compiler_type_info.Test(eTypeIsArray)) { 3015 root = root->GetChildAtIndex(index, true); 3016 if (!root.get()) { 3017 *first_unparsed = expression_cstr; 3018 *reason_to_stop = 3019 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3020 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3021 return 0; 3022 } else { 3023 list->Append(root); 3024 *first_unparsed = end + 1; // skip ] 3025 *reason_to_stop = 3026 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3027 *final_result = 3028 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3029 return 1; 3030 } 3031 } else if (root_compiler_type_info.Test(eTypeIsPointer)) { 3032 if (*what_next == 3033 ValueObject:: 3034 eExpressionPathAftermathDereference && // if this is a 3035 // ptr-to-scalar, I 3036 // am accessing it 3037 // by index and I 3038 // would have 3039 // deref'ed anyway, 3040 // then do it now 3041 // and use this as 3042 // a bitfield 3043 pointee_compiler_type_info.Test(eTypeIsScalar)) { 3044 Error error; 3045 root = root->Dereference(error); 3046 if (error.Fail() || !root.get()) { 3047 *first_unparsed = expression_cstr; 3048 *reason_to_stop = 3049 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3050 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3051 return 0; 3052 } else { 3053 *what_next = eExpressionPathAftermathNothing; 3054 continue; 3055 } 3056 } else { 3057 root = root->GetSyntheticArrayMember(index, true); 3058 if (!root.get()) { 3059 *first_unparsed = expression_cstr; 3060 *reason_to_stop = 3061 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3062 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3063 return 0; 3064 } else { 3065 list->Append(root); 3066 *first_unparsed = end + 1; // skip ] 3067 *reason_to_stop = ValueObject:: 3068 eExpressionPathScanEndReasonRangeOperatorExpanded; 3069 *final_result = 3070 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3071 return 1; 3072 } 3073 } 3074 } else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/ 3075 { 3076 root = root->GetSyntheticBitFieldChild(index, index, true); 3077 if (!root.get()) { 3078 *first_unparsed = expression_cstr; 3079 *reason_to_stop = 3080 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3081 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3082 return 0; 3083 } else // we do not know how to expand members of bitfields, so we 3084 // just return and let the caller do any further processing 3085 { 3086 list->Append(root); 3087 *first_unparsed = end + 1; // skip ] 3088 *reason_to_stop = 3089 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3090 *final_result = 3091 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3092 return 1; 3093 } 3094 } 3095 } else // we have a low and a high index 3096 { 3097 char *end = NULL; 3098 unsigned long index_lower = ::strtoul(expression_cstr + 1, &end, 0); 3099 if (!end || end != separator_position) // if something weird is in our 3100 // way return an error 3101 { 3102 *first_unparsed = expression_cstr; 3103 *reason_to_stop = 3104 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3105 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3106 return 0; 3107 } 3108 unsigned long index_higher = ::strtoul(separator_position + 1, &end, 0); 3109 if (!end || end != close_bracket_position) // if something weird is in 3110 // our way return an error 3111 { 3112 *first_unparsed = expression_cstr; 3113 *reason_to_stop = 3114 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3115 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3116 return 0; 3117 } 3118 if (index_lower > index_higher) // swap indices if required 3119 { 3120 unsigned long temp = index_lower; 3121 index_lower = index_higher; 3122 index_higher = temp; 3123 } 3124 if (root_compiler_type_info.Test( 3125 eTypeIsScalar)) // expansion only works for scalars 3126 { 3127 root = 3128 root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 3129 if (!root.get()) { 3130 *first_unparsed = expression_cstr; 3131 *reason_to_stop = 3132 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3133 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3134 return 0; 3135 } else { 3136 list->Append(root); 3137 *first_unparsed = end + 1; // skip ] 3138 *reason_to_stop = 3139 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3140 *final_result = 3141 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3142 return 1; 3143 } 3144 } else if (root_compiler_type_info.Test( 3145 eTypeIsPointer) && // if this is a ptr-to-scalar, I am 3146 // accessing it by index and I would 3147 // have deref'ed anyway, then do it 3148 // now and use this as a bitfield 3149 *what_next == 3150 ValueObject::eExpressionPathAftermathDereference && 3151 pointee_compiler_type_info.Test(eTypeIsScalar)) { 3152 Error error; 3153 root = root->Dereference(error); 3154 if (error.Fail() || !root.get()) { 3155 *first_unparsed = expression_cstr; 3156 *reason_to_stop = 3157 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3158 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3159 return 0; 3160 } else { 3161 *what_next = ValueObject::eExpressionPathAftermathNothing; 3162 continue; 3163 } 3164 } else { 3165 for (unsigned long index = index_lower; index <= index_higher; 3166 index++) { 3167 ValueObjectSP child = root->GetChildAtIndex(index, true); 3168 list->Append(child); 3169 } 3170 *first_unparsed = end + 1; 3171 *reason_to_stop = 3172 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3173 *final_result = 3174 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3175 return index_higher - index_lower + 3176 1; // tell me number of items I added to the VOList 3177 } 3178 } 3179 break; 3180 } 3181 default: // some non-[ separator, or something entirely wrong, is in the way 3182 { 3183 *first_unparsed = expression_cstr; 3184 *reason_to_stop = 3185 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3186 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3187 return 0; 3188 break; 3189 } 3190 } 3191 } 3192 } 3193 3194 void ValueObject::LogValueObject(Log *log) { 3195 if (log) 3196 return LogValueObject(log, DumpValueObjectOptions(*this)); 3197 } 3198 3199 void ValueObject::LogValueObject(Log *log, 3200 const DumpValueObjectOptions &options) { 3201 if (log) { 3202 StreamString s; 3203 Dump(s, options); 3204 if (s.GetSize()) 3205 log->PutCString(s.GetData()); 3206 } 3207 } 3208 3209 void ValueObject::Dump(Stream &s) { Dump(s, DumpValueObjectOptions(*this)); } 3210 3211 void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) { 3212 ValueObjectPrinter printer(this, &s, options); 3213 printer.PrintValueObject(); 3214 } 3215 3216 ValueObjectSP ValueObject::CreateConstantValue(const ConstString &name) { 3217 ValueObjectSP valobj_sp; 3218 3219 if (UpdateValueIfNeeded(false) && m_error.Success()) { 3220 ExecutionContext exe_ctx(GetExecutionContextRef()); 3221 3222 DataExtractor data; 3223 data.SetByteOrder(m_data.GetByteOrder()); 3224 data.SetAddressByteSize(m_data.GetAddressByteSize()); 3225 3226 if (IsBitfield()) { 3227 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX))); 3228 m_error = v.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); 3229 } else 3230 m_error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); 3231 3232 valobj_sp = ValueObjectConstResult::Create( 3233 exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data, 3234 GetAddressOf()); 3235 } 3236 3237 if (!valobj_sp) { 3238 ExecutionContext exe_ctx(GetExecutionContextRef()); 3239 valobj_sp = ValueObjectConstResult::Create( 3240 exe_ctx.GetBestExecutionContextScope(), m_error); 3241 } 3242 return valobj_sp; 3243 } 3244 3245 ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable( 3246 lldb::DynamicValueType dynValue, bool synthValue) { 3247 ValueObjectSP result_sp(GetSP()); 3248 3249 switch (dynValue) { 3250 case lldb::eDynamicCanRunTarget: 3251 case lldb::eDynamicDontRunTarget: { 3252 if (!result_sp->IsDynamic()) { 3253 if (result_sp->GetDynamicValue(dynValue)) 3254 result_sp = result_sp->GetDynamicValue(dynValue); 3255 } 3256 } break; 3257 case lldb::eNoDynamicValues: { 3258 if (result_sp->IsDynamic()) { 3259 if (result_sp->GetStaticValue()) 3260 result_sp = result_sp->GetStaticValue(); 3261 } 3262 } break; 3263 } 3264 3265 if (synthValue) { 3266 if (!result_sp->IsSynthetic()) { 3267 if (result_sp->GetSyntheticValue()) 3268 result_sp = result_sp->GetSyntheticValue(); 3269 } 3270 } else { 3271 if (result_sp->IsSynthetic()) { 3272 if (result_sp->GetNonSyntheticValue()) 3273 result_sp = result_sp->GetNonSyntheticValue(); 3274 } 3275 } 3276 3277 return result_sp; 3278 } 3279 3280 lldb::addr_t ValueObject::GetCPPVTableAddress(AddressType &address_type) { 3281 CompilerType pointee_type; 3282 CompilerType this_type(GetCompilerType()); 3283 uint32_t type_info = this_type.GetTypeInfo(&pointee_type); 3284 if (type_info) { 3285 bool ptr_or_ref = false; 3286 if (type_info & (eTypeIsPointer | eTypeIsReference)) { 3287 ptr_or_ref = true; 3288 type_info = pointee_type.GetTypeInfo(); 3289 } 3290 3291 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus; 3292 if ((type_info & cpp_class) == cpp_class) { 3293 if (ptr_or_ref) { 3294 address_type = GetAddressTypeOfChildren(); 3295 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS); 3296 } else 3297 return GetAddressOf(false, &address_type); 3298 } 3299 } 3300 3301 address_type = eAddressTypeInvalid; 3302 return LLDB_INVALID_ADDRESS; 3303 } 3304 3305 ValueObjectSP ValueObject::Dereference(Error &error) { 3306 if (m_deref_valobj) 3307 return m_deref_valobj->GetSP(); 3308 3309 const bool is_pointer_or_reference_type = IsPointerOrReferenceType(); 3310 if (is_pointer_or_reference_type) { 3311 bool omit_empty_base_classes = true; 3312 bool ignore_array_bounds = false; 3313 3314 std::string child_name_str; 3315 uint32_t child_byte_size = 0; 3316 int32_t child_byte_offset = 0; 3317 uint32_t child_bitfield_bit_size = 0; 3318 uint32_t child_bitfield_bit_offset = 0; 3319 bool child_is_base_class = false; 3320 bool child_is_deref_of_parent = false; 3321 const bool transparent_pointers = false; 3322 CompilerType compiler_type = GetCompilerType(); 3323 CompilerType child_compiler_type; 3324 uint64_t language_flags; 3325 3326 ExecutionContext exe_ctx(GetExecutionContextRef()); 3327 3328 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex( 3329 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes, 3330 ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, 3331 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, 3332 child_is_deref_of_parent, this, language_flags); 3333 if (child_compiler_type && child_byte_size) { 3334 ConstString child_name; 3335 if (!child_name_str.empty()) 3336 child_name.SetCString(child_name_str.c_str()); 3337 3338 m_deref_valobj = new ValueObjectChild( 3339 *this, child_compiler_type, child_name, child_byte_size, 3340 child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, 3341 child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid, 3342 language_flags); 3343 } 3344 } 3345 3346 if (m_deref_valobj) { 3347 error.Clear(); 3348 return m_deref_valobj->GetSP(); 3349 } else { 3350 StreamString strm; 3351 GetExpressionPath(strm, true); 3352 3353 if (is_pointer_or_reference_type) 3354 error.SetErrorStringWithFormat("dereference failed: (%s) %s", 3355 GetTypeName().AsCString("<invalid type>"), 3356 strm.GetString().c_str()); 3357 else 3358 error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", 3359 GetTypeName().AsCString("<invalid type>"), 3360 strm.GetString().c_str()); 3361 return ValueObjectSP(); 3362 } 3363 } 3364 3365 ValueObjectSP ValueObject::AddressOf(Error &error) { 3366 if (m_addr_of_valobj_sp) 3367 return m_addr_of_valobj_sp; 3368 3369 AddressType address_type = eAddressTypeInvalid; 3370 const bool scalar_is_load_address = false; 3371 addr_t addr = GetAddressOf(scalar_is_load_address, &address_type); 3372 error.Clear(); 3373 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) { 3374 switch (address_type) { 3375 case eAddressTypeInvalid: { 3376 StreamString expr_path_strm; 3377 GetExpressionPath(expr_path_strm, true); 3378 error.SetErrorStringWithFormat("'%s' is not in memory", 3379 expr_path_strm.GetString().c_str()); 3380 } break; 3381 3382 case eAddressTypeFile: 3383 case eAddressTypeLoad: { 3384 CompilerType compiler_type = GetCompilerType(); 3385 if (compiler_type) { 3386 std::string name(1, '&'); 3387 name.append(m_name.AsCString("")); 3388 ExecutionContext exe_ctx(GetExecutionContextRef()); 3389 m_addr_of_valobj_sp = ValueObjectConstResult::Create( 3390 exe_ctx.GetBestExecutionContextScope(), 3391 compiler_type.GetPointerType(), ConstString(name.c_str()), addr, 3392 eAddressTypeInvalid, m_data.GetAddressByteSize()); 3393 } 3394 } break; 3395 default: 3396 break; 3397 } 3398 } else { 3399 StreamString expr_path_strm; 3400 GetExpressionPath(expr_path_strm, true); 3401 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", 3402 expr_path_strm.GetString().c_str()); 3403 } 3404 3405 return m_addr_of_valobj_sp; 3406 } 3407 3408 ValueObjectSP ValueObject::Cast(const CompilerType &compiler_type) { 3409 return ValueObjectCast::Create(*this, GetName(), compiler_type); 3410 } 3411 3412 ValueObjectSP ValueObject::CastPointerType(const char *name, 3413 CompilerType &compiler_type) { 3414 ValueObjectSP valobj_sp; 3415 AddressType address_type; 3416 addr_t ptr_value = GetPointerValue(&address_type); 3417 3418 if (ptr_value != LLDB_INVALID_ADDRESS) { 3419 Address ptr_addr(ptr_value); 3420 ExecutionContext exe_ctx(GetExecutionContextRef()); 3421 valobj_sp = ValueObjectMemory::Create( 3422 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type); 3423 } 3424 return valobj_sp; 3425 } 3426 3427 ValueObjectSP ValueObject::CastPointerType(const char *name, TypeSP &type_sp) { 3428 ValueObjectSP valobj_sp; 3429 AddressType address_type; 3430 addr_t ptr_value = GetPointerValue(&address_type); 3431 3432 if (ptr_value != LLDB_INVALID_ADDRESS) { 3433 Address ptr_addr(ptr_value); 3434 ExecutionContext exe_ctx(GetExecutionContextRef()); 3435 valobj_sp = ValueObjectMemory::Create( 3436 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp); 3437 } 3438 return valobj_sp; 3439 } 3440 3441 ValueObject::EvaluationPoint::EvaluationPoint() 3442 : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) {} 3443 3444 ValueObject::EvaluationPoint::EvaluationPoint(ExecutionContextScope *exe_scope, 3445 bool use_selected) 3446 : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) { 3447 ExecutionContext exe_ctx(exe_scope); 3448 TargetSP target_sp(exe_ctx.GetTargetSP()); 3449 if (target_sp) { 3450 m_exe_ctx_ref.SetTargetSP(target_sp); 3451 ProcessSP process_sp(exe_ctx.GetProcessSP()); 3452 if (!process_sp) 3453 process_sp = target_sp->GetProcessSP(); 3454 3455 if (process_sp) { 3456 m_mod_id = process_sp->GetModID(); 3457 m_exe_ctx_ref.SetProcessSP(process_sp); 3458 3459 ThreadSP thread_sp(exe_ctx.GetThreadSP()); 3460 3461 if (!thread_sp) { 3462 if (use_selected) 3463 thread_sp = process_sp->GetThreadList().GetSelectedThread(); 3464 } 3465 3466 if (thread_sp) { 3467 m_exe_ctx_ref.SetThreadSP(thread_sp); 3468 3469 StackFrameSP frame_sp(exe_ctx.GetFrameSP()); 3470 if (!frame_sp) { 3471 if (use_selected) 3472 frame_sp = thread_sp->GetSelectedFrame(); 3473 } 3474 if (frame_sp) 3475 m_exe_ctx_ref.SetFrameSP(frame_sp); 3476 } 3477 } 3478 } 3479 } 3480 3481 ValueObject::EvaluationPoint::EvaluationPoint( 3482 const ValueObject::EvaluationPoint &rhs) 3483 : m_mod_id(), m_exe_ctx_ref(rhs.m_exe_ctx_ref), m_needs_update(true) {} 3484 3485 ValueObject::EvaluationPoint::~EvaluationPoint() {} 3486 3487 // This function checks the EvaluationPoint against the current process state. 3488 // If the current 3489 // state matches the evaluation point, or the evaluation point is already 3490 // invalid, then we return 3491 // false, meaning "no change". If the current state is different, we update our 3492 // state, and return 3493 // true meaning "yes, change". If we did see a change, we also set 3494 // m_needs_update to true, so 3495 // future calls to NeedsUpdate will return true. 3496 // exe_scope will be set to the current execution context scope. 3497 3498 bool ValueObject::EvaluationPoint::SyncWithProcessState( 3499 bool accept_invalid_exe_ctx) { 3500 // Start with the target, if it is NULL, then we're obviously not going to get 3501 // any further: 3502 const bool thread_and_frame_only_if_stopped = true; 3503 ExecutionContext exe_ctx( 3504 m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); 3505 3506 if (exe_ctx.GetTargetPtr() == NULL) 3507 return false; 3508 3509 // If we don't have a process nothing can change. 3510 Process *process = exe_ctx.GetProcessPtr(); 3511 if (process == NULL) 3512 return false; 3513 3514 // If our stop id is the current stop ID, nothing has changed: 3515 ProcessModID current_mod_id = process->GetModID(); 3516 3517 // If the current stop id is 0, either we haven't run yet, or the process 3518 // state has been cleared. 3519 // In either case, we aren't going to be able to sync with the process state. 3520 if (current_mod_id.GetStopID() == 0) 3521 return false; 3522 3523 bool changed = false; 3524 const bool was_valid = m_mod_id.IsValid(); 3525 if (was_valid) { 3526 if (m_mod_id == current_mod_id) { 3527 // Everything is already up to date in this object, no need to 3528 // update the execution context scope. 3529 changed = false; 3530 } else { 3531 m_mod_id = current_mod_id; 3532 m_needs_update = true; 3533 changed = true; 3534 } 3535 } 3536 3537 // Now re-look up the thread and frame in case the underlying objects have 3538 // gone away & been recreated. 3539 // That way we'll be sure to return a valid exe_scope. 3540 // If we used to have a thread or a frame but can't find it anymore, then mark 3541 // ourselves as invalid. 3542 3543 if (!accept_invalid_exe_ctx) { 3544 if (m_exe_ctx_ref.HasThreadRef()) { 3545 ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP()); 3546 if (thread_sp) { 3547 if (m_exe_ctx_ref.HasFrameRef()) { 3548 StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP()); 3549 if (!frame_sp) { 3550 // We used to have a frame, but now it is gone 3551 SetInvalid(); 3552 changed = was_valid; 3553 } 3554 } 3555 } else { 3556 // We used to have a thread, but now it is gone 3557 SetInvalid(); 3558 changed = was_valid; 3559 } 3560 } 3561 } 3562 3563 return changed; 3564 } 3565 3566 void ValueObject::EvaluationPoint::SetUpdated() { 3567 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); 3568 if (process_sp) 3569 m_mod_id = process_sp->GetModID(); 3570 m_needs_update = false; 3571 } 3572 3573 void ValueObject::ClearUserVisibleData(uint32_t clear_mask) { 3574 if ((clear_mask & eClearUserVisibleDataItemsValue) == 3575 eClearUserVisibleDataItemsValue) 3576 m_value_str.clear(); 3577 3578 if ((clear_mask & eClearUserVisibleDataItemsLocation) == 3579 eClearUserVisibleDataItemsLocation) 3580 m_location_str.clear(); 3581 3582 if ((clear_mask & eClearUserVisibleDataItemsSummary) == 3583 eClearUserVisibleDataItemsSummary) 3584 m_summary_str.clear(); 3585 3586 if ((clear_mask & eClearUserVisibleDataItemsDescription) == 3587 eClearUserVisibleDataItemsDescription) 3588 m_object_desc_str.clear(); 3589 3590 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == 3591 eClearUserVisibleDataItemsSyntheticChildren) { 3592 if (m_synthetic_value) 3593 m_synthetic_value = NULL; 3594 } 3595 3596 if ((clear_mask & eClearUserVisibleDataItemsValidator) == 3597 eClearUserVisibleDataItemsValidator) 3598 m_validation_result.reset(); 3599 } 3600 3601 SymbolContextScope *ValueObject::GetSymbolContextScope() { 3602 if (m_parent) { 3603 if (!m_parent->IsPointerOrReferenceType()) 3604 return m_parent->GetSymbolContextScope(); 3605 } 3606 return NULL; 3607 } 3608 3609 lldb::ValueObjectSP ValueObject::CreateValueObjectFromExpression( 3610 const char *name, const char *expression, const ExecutionContext &exe_ctx) { 3611 return CreateValueObjectFromExpression(name, expression, exe_ctx, 3612 EvaluateExpressionOptions()); 3613 } 3614 3615 lldb::ValueObjectSP ValueObject::CreateValueObjectFromExpression( 3616 const char *name, const char *expression, const ExecutionContext &exe_ctx, 3617 const EvaluateExpressionOptions &options) { 3618 lldb::ValueObjectSP retval_sp; 3619 lldb::TargetSP target_sp(exe_ctx.GetTargetSP()); 3620 if (!target_sp) 3621 return retval_sp; 3622 if (!expression || !*expression) 3623 return retval_sp; 3624 target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(), 3625 retval_sp, options); 3626 if (retval_sp && name && *name) 3627 retval_sp->SetName(ConstString(name)); 3628 return retval_sp; 3629 } 3630 3631 lldb::ValueObjectSP 3632 ValueObject::CreateValueObjectFromAddress(const char *name, uint64_t address, 3633 const ExecutionContext &exe_ctx, 3634 CompilerType type) { 3635 if (type) { 3636 CompilerType pointer_type(type.GetPointerType()); 3637 if (pointer_type) { 3638 lldb::DataBufferSP buffer( 3639 new lldb_private::DataBufferHeap(&address, sizeof(lldb::addr_t))); 3640 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create( 3641 exe_ctx.GetBestExecutionContextScope(), pointer_type, 3642 ConstString(name), buffer, exe_ctx.GetByteOrder(), 3643 exe_ctx.GetAddressByteSize())); 3644 if (ptr_result_valobj_sp) { 3645 ptr_result_valobj_sp->GetValue().SetValueType( 3646 Value::eValueTypeLoadAddress); 3647 Error err; 3648 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err); 3649 if (ptr_result_valobj_sp && name && *name) 3650 ptr_result_valobj_sp->SetName(ConstString(name)); 3651 } 3652 return ptr_result_valobj_sp; 3653 } 3654 } 3655 return lldb::ValueObjectSP(); 3656 } 3657 3658 lldb::ValueObjectSP ValueObject::CreateValueObjectFromData( 3659 const char *name, const DataExtractor &data, 3660 const ExecutionContext &exe_ctx, CompilerType type) { 3661 lldb::ValueObjectSP new_value_sp; 3662 new_value_sp = ValueObjectConstResult::Create( 3663 exe_ctx.GetBestExecutionContextScope(), type, ConstString(name), data, 3664 LLDB_INVALID_ADDRESS); 3665 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); 3666 if (new_value_sp && name && *name) 3667 new_value_sp->SetName(ConstString(name)); 3668 return new_value_sp; 3669 } 3670 3671 ModuleSP ValueObject::GetModule() { 3672 ValueObject *root(GetRoot()); 3673 if (root != this) 3674 return root->GetModule(); 3675 return lldb::ModuleSP(); 3676 } 3677 3678 ValueObject *ValueObject::GetRoot() { 3679 if (m_root) 3680 return m_root; 3681 return (m_root = FollowParentChain([](ValueObject *vo) -> bool { 3682 return (vo->m_parent != nullptr); 3683 })); 3684 } 3685 3686 ValueObject * 3687 ValueObject::FollowParentChain(std::function<bool(ValueObject *)> f) { 3688 ValueObject *vo = this; 3689 while (vo) { 3690 if (f(vo) == false) 3691 break; 3692 vo = vo->m_parent; 3693 } 3694 return vo; 3695 } 3696 3697 AddressType ValueObject::GetAddressTypeOfChildren() { 3698 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) { 3699 ValueObject *root(GetRoot()); 3700 if (root != this) 3701 return root->GetAddressTypeOfChildren(); 3702 } 3703 return m_address_type_of_ptr_or_ref_children; 3704 } 3705 3706 lldb::DynamicValueType ValueObject::GetDynamicValueType() { 3707 ValueObject *with_dv_info = this; 3708 while (with_dv_info) { 3709 if (with_dv_info->HasDynamicValueTypeInfo()) 3710 return with_dv_info->GetDynamicValueTypeImpl(); 3711 with_dv_info = with_dv_info->m_parent; 3712 } 3713 return lldb::eNoDynamicValues; 3714 } 3715 3716 lldb::Format ValueObject::GetFormat() const { 3717 const ValueObject *with_fmt_info = this; 3718 while (with_fmt_info) { 3719 if (with_fmt_info->m_format != lldb::eFormatDefault) 3720 return with_fmt_info->m_format; 3721 with_fmt_info = with_fmt_info->m_parent; 3722 } 3723 return m_format; 3724 } 3725 3726 lldb::LanguageType ValueObject::GetPreferredDisplayLanguage() { 3727 lldb::LanguageType type = m_preferred_display_language; 3728 if (m_preferred_display_language == lldb::eLanguageTypeUnknown) { 3729 if (GetRoot()) { 3730 if (GetRoot() == this) { 3731 if (StackFrameSP frame_sp = GetFrameSP()) { 3732 const SymbolContext &sc( 3733 frame_sp->GetSymbolContext(eSymbolContextCompUnit)); 3734 if (CompileUnit *cu = sc.comp_unit) 3735 type = cu->GetLanguage(); 3736 } 3737 } else { 3738 type = GetRoot()->GetPreferredDisplayLanguage(); 3739 } 3740 } 3741 } 3742 return (m_preferred_display_language = type); // only compute it once 3743 } 3744 3745 void ValueObject::SetPreferredDisplayLanguage(lldb::LanguageType lt) { 3746 m_preferred_display_language = lt; 3747 } 3748 3749 void ValueObject::SetPreferredDisplayLanguageIfNeeded(lldb::LanguageType lt) { 3750 if (m_preferred_display_language == lldb::eLanguageTypeUnknown) 3751 SetPreferredDisplayLanguage(lt); 3752 } 3753 3754 bool ValueObject::CanProvideValue() { 3755 // we need to support invalid types as providers of values because some 3756 // bare-board 3757 // debugging scenarios have no notion of types, but still manage to have raw 3758 // numeric 3759 // values for things like registers. sigh. 3760 const CompilerType &type(GetCompilerType()); 3761 return (false == type.IsValid()) || 3762 (0 != (type.GetTypeInfo() & eTypeHasValue)); 3763 } 3764 3765 bool ValueObject::IsChecksumEmpty() { return m_value_checksum.empty(); } 3766 3767 ValueObjectSP ValueObject::Persist() { 3768 if (!UpdateValueIfNeeded()) 3769 return nullptr; 3770 3771 TargetSP target_sp(GetTargetSP()); 3772 if (!target_sp) 3773 return nullptr; 3774 3775 PersistentExpressionState *persistent_state = 3776 target_sp->GetPersistentExpressionStateForLanguage( 3777 GetPreferredDisplayLanguage()); 3778 3779 if (!persistent_state) 3780 return nullptr; 3781 3782 ConstString name(persistent_state->GetNextPersistentVariableName()); 3783 3784 ValueObjectSP const_result_sp = 3785 ValueObjectConstResult::Create(target_sp.get(), GetValue(), name); 3786 3787 ExpressionVariableSP clang_var_sp = 3788 persistent_state->CreatePersistentVariable(const_result_sp); 3789 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp; 3790 clang_var_sp->m_flags |= ExpressionVariable::EVIsProgramReference; 3791 3792 return clang_var_sp->GetValueObject(); 3793 } 3794 3795 bool ValueObject::IsSyntheticChildrenGenerated() { 3796 return m_is_synthetic_children_generated; 3797 } 3798 3799 void ValueObject::SetSyntheticChildrenGenerated(bool b) { 3800 m_is_synthetic_children_generated = b; 3801 } 3802 3803 uint64_t ValueObject::GetLanguageFlags() { return m_language_flags; } 3804 3805 void ValueObject::SetLanguageFlags(uint64_t flags) { m_language_flags = flags; } 3806