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 = 1283 (special == ValueObject::PrintableRepresentationSpecialCases::eAllow); 1284 const bool only_special = false; 1285 1286 if (allow_special) { 1287 if (flags.AnySet(eTypeIsArray | eTypeIsPointer) && 1288 val_obj_display == ValueObject::eValueObjectRepresentationStyleValue) { 1289 // when being asked to get a printable display an array or pointer type 1290 // directly, 1291 // try to "do the right thing" 1292 1293 if (IsCStringContainer(true) && 1294 (custom_format == eFormatCString || 1295 custom_format == eFormatCharArray || custom_format == eFormatChar || 1296 custom_format == 1297 eFormatVectorOfChar)) // print char[] & char* directly 1298 { 1299 Error error; 1300 lldb::DataBufferSP buffer_sp; 1301 std::pair<size_t, bool> read_string = ReadPointedString( 1302 buffer_sp, error, 0, (custom_format == eFormatVectorOfChar) || 1303 (custom_format == eFormatCharArray)); 1304 lldb_private::formatters::StringPrinter:: 1305 ReadBufferAndDumpToStreamOptions options(*this); 1306 options.SetData(DataExtractor( 1307 buffer_sp, lldb::eByteOrderInvalid, 1308 8)); // none of this matters for a string - pass some defaults 1309 options.SetStream(&s); 1310 options.SetPrefixToken(0); 1311 options.SetQuote('"'); 1312 options.SetSourceSize(buffer_sp->GetByteSize()); 1313 options.SetIsTruncated(read_string.second); 1314 formatters::StringPrinter::ReadBufferAndDumpToStream< 1315 lldb_private::formatters::StringPrinter::StringElementType::ASCII>( 1316 options); 1317 return !error.Fail(); 1318 } 1319 1320 if (custom_format == eFormatEnum) 1321 return false; 1322 1323 // this only works for arrays, because I have no way to know when 1324 // the pointed memory ends, and no special \0 end of data marker 1325 if (flags.Test(eTypeIsArray)) { 1326 if ((custom_format == eFormatBytes) || 1327 (custom_format == eFormatBytesWithASCII)) { 1328 const size_t count = GetNumChildren(); 1329 1330 s << '['; 1331 for (size_t low = 0; low < count; low++) { 1332 1333 if (low) 1334 s << ','; 1335 1336 ValueObjectSP child = GetChildAtIndex(low, true); 1337 if (!child.get()) { 1338 s << "<invalid child>"; 1339 continue; 1340 } 1341 child->DumpPrintableRepresentation( 1342 s, ValueObject::eValueObjectRepresentationStyleValue, 1343 custom_format); 1344 } 1345 1346 s << ']'; 1347 1348 return true; 1349 } 1350 1351 if ((custom_format == eFormatVectorOfChar) || 1352 (custom_format == eFormatVectorOfFloat32) || 1353 (custom_format == eFormatVectorOfFloat64) || 1354 (custom_format == eFormatVectorOfSInt16) || 1355 (custom_format == eFormatVectorOfSInt32) || 1356 (custom_format == eFormatVectorOfSInt64) || 1357 (custom_format == eFormatVectorOfSInt8) || 1358 (custom_format == eFormatVectorOfUInt128) || 1359 (custom_format == eFormatVectorOfUInt16) || 1360 (custom_format == eFormatVectorOfUInt32) || 1361 (custom_format == eFormatVectorOfUInt64) || 1362 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes 1363 // with ASCII or any vector 1364 // format should be printed 1365 // directly 1366 { 1367 const size_t count = GetNumChildren(); 1368 1369 Format format = FormatManager::GetSingleItemFormat(custom_format); 1370 1371 s << '['; 1372 for (size_t low = 0; low < count; low++) { 1373 1374 if (low) 1375 s << ','; 1376 1377 ValueObjectSP child = GetChildAtIndex(low, true); 1378 if (!child.get()) { 1379 s << "<invalid child>"; 1380 continue; 1381 } 1382 child->DumpPrintableRepresentation( 1383 s, ValueObject::eValueObjectRepresentationStyleValue, format); 1384 } 1385 1386 s << ']'; 1387 1388 return true; 1389 } 1390 } 1391 1392 if ((custom_format == eFormatBoolean) || 1393 (custom_format == eFormatBinary) || (custom_format == eFormatChar) || 1394 (custom_format == eFormatCharPrintable) || 1395 (custom_format == eFormatComplexFloat) || 1396 (custom_format == eFormatDecimal) || (custom_format == eFormatHex) || 1397 (custom_format == eFormatHexUppercase) || 1398 (custom_format == eFormatFloat) || (custom_format == eFormatOctal) || 1399 (custom_format == eFormatOSType) || 1400 (custom_format == eFormatUnicode16) || 1401 (custom_format == eFormatUnicode32) || 1402 (custom_format == eFormatUnsigned) || 1403 (custom_format == eFormatPointer) || 1404 (custom_format == eFormatComplexInteger) || 1405 (custom_format == eFormatComplex) || 1406 (custom_format == eFormatDefault)) // use the [] operator 1407 return false; 1408 } 1409 } 1410 1411 if (only_special) 1412 return false; 1413 1414 bool var_success = false; 1415 1416 { 1417 const char *cstr = NULL; 1418 1419 // this is a local stream that we are using to ensure that the data pointed 1420 // to by cstr survives 1421 // long enough for us to copy it to its destination - it is necessary to 1422 // have this temporary storage 1423 // area for cases where our desired output is not backed by some other 1424 // longer-term storage 1425 StreamString strm; 1426 1427 if (custom_format != eFormatInvalid) 1428 SetFormat(custom_format); 1429 1430 switch (val_obj_display) { 1431 case eValueObjectRepresentationStyleValue: 1432 cstr = GetValueAsCString(); 1433 break; 1434 1435 case eValueObjectRepresentationStyleSummary: 1436 cstr = GetSummaryAsCString(); 1437 break; 1438 1439 case eValueObjectRepresentationStyleLanguageSpecific: 1440 cstr = GetObjectDescription(); 1441 break; 1442 1443 case eValueObjectRepresentationStyleLocation: 1444 cstr = GetLocationAsCString(); 1445 break; 1446 1447 case eValueObjectRepresentationStyleChildrenCount: 1448 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren()); 1449 cstr = strm.GetString().c_str(); 1450 break; 1451 1452 case eValueObjectRepresentationStyleType: 1453 cstr = GetTypeName().AsCString(); 1454 break; 1455 1456 case eValueObjectRepresentationStyleName: 1457 cstr = GetName().AsCString(); 1458 break; 1459 1460 case eValueObjectRepresentationStyleExpressionPath: 1461 GetExpressionPath(strm, false); 1462 cstr = strm.GetString().c_str(); 1463 break; 1464 } 1465 1466 if (!cstr) { 1467 if (val_obj_display == eValueObjectRepresentationStyleValue) 1468 cstr = GetSummaryAsCString(); 1469 else if (val_obj_display == eValueObjectRepresentationStyleSummary) { 1470 if (!CanProvideValue()) { 1471 strm.Printf("%s @ %s", GetTypeName().AsCString(), 1472 GetLocationAsCString()); 1473 cstr = strm.GetString().c_str(); 1474 } else 1475 cstr = GetValueAsCString(); 1476 } 1477 } 1478 1479 if (cstr) 1480 s.PutCString(cstr); 1481 else { 1482 if (m_error.Fail()) { 1483 if (do_dump_error) 1484 s.Printf("<%s>", m_error.AsCString()); 1485 else 1486 return false; 1487 } else if (val_obj_display == eValueObjectRepresentationStyleSummary) 1488 s.PutCString("<no summary available>"); 1489 else if (val_obj_display == eValueObjectRepresentationStyleValue) 1490 s.PutCString("<no value available>"); 1491 else if (val_obj_display == 1492 eValueObjectRepresentationStyleLanguageSpecific) 1493 s.PutCString("<not a valid Objective-C object>"); // edit this if we 1494 // have other runtimes 1495 // that support a 1496 // description 1497 else 1498 s.PutCString("<no printable representation>"); 1499 } 1500 1501 // we should only return false here if we could not do *anything* 1502 // even if we have an error message as output, that's a success 1503 // from our callers' perspective, so return true 1504 var_success = true; 1505 1506 if (custom_format != eFormatInvalid) 1507 SetFormat(eFormatDefault); 1508 } 1509 1510 return var_success; 1511 } 1512 1513 addr_t ValueObject::GetAddressOf(bool scalar_is_load_address, 1514 AddressType *address_type) { 1515 // Can't take address of a bitfield 1516 if (IsBitfield()) 1517 return LLDB_INVALID_ADDRESS; 1518 1519 if (!UpdateValueIfNeeded(false)) 1520 return LLDB_INVALID_ADDRESS; 1521 1522 switch (m_value.GetValueType()) { 1523 case Value::eValueTypeScalar: 1524 case Value::eValueTypeVector: 1525 if (scalar_is_load_address) { 1526 if (address_type) 1527 *address_type = eAddressTypeLoad; 1528 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1529 } 1530 break; 1531 1532 case Value::eValueTypeLoadAddress: 1533 case Value::eValueTypeFileAddress: { 1534 if (address_type) 1535 *address_type = m_value.GetValueAddressType(); 1536 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1537 } break; 1538 case Value::eValueTypeHostAddress: { 1539 if (address_type) 1540 *address_type = m_value.GetValueAddressType(); 1541 return LLDB_INVALID_ADDRESS; 1542 } break; 1543 } 1544 if (address_type) 1545 *address_type = eAddressTypeInvalid; 1546 return LLDB_INVALID_ADDRESS; 1547 } 1548 1549 addr_t ValueObject::GetPointerValue(AddressType *address_type) { 1550 addr_t address = LLDB_INVALID_ADDRESS; 1551 if (address_type) 1552 *address_type = eAddressTypeInvalid; 1553 1554 if (!UpdateValueIfNeeded(false)) 1555 return address; 1556 1557 switch (m_value.GetValueType()) { 1558 case Value::eValueTypeScalar: 1559 case Value::eValueTypeVector: 1560 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1561 break; 1562 1563 case Value::eValueTypeHostAddress: 1564 case Value::eValueTypeLoadAddress: 1565 case Value::eValueTypeFileAddress: { 1566 lldb::offset_t data_offset = 0; 1567 address = m_data.GetPointer(&data_offset); 1568 } break; 1569 } 1570 1571 if (address_type) 1572 *address_type = GetAddressTypeOfChildren(); 1573 1574 return address; 1575 } 1576 1577 bool ValueObject::SetValueFromCString(const char *value_str, Error &error) { 1578 error.Clear(); 1579 // Make sure our value is up to date first so that our location and location 1580 // type is valid. 1581 if (!UpdateValueIfNeeded(false)) { 1582 error.SetErrorString("unable to read value"); 1583 return false; 1584 } 1585 1586 uint64_t count = 0; 1587 const Encoding encoding = GetCompilerType().GetEncoding(count); 1588 1589 const size_t byte_size = GetByteSize(); 1590 1591 Value::ValueType value_type = m_value.GetValueType(); 1592 1593 if (value_type == Value::eValueTypeScalar) { 1594 // If the value is already a scalar, then let the scalar change itself: 1595 m_value.GetScalar().SetValueFromCString(value_str, encoding, byte_size); 1596 } else if (byte_size <= 16) { 1597 // If the value fits in a scalar, then make a new scalar and again let the 1598 // scalar code do the conversion, then figure out where to put the new 1599 // value. 1600 Scalar new_scalar; 1601 error = new_scalar.SetValueFromCString(value_str, encoding, byte_size); 1602 if (error.Success()) { 1603 switch (value_type) { 1604 case Value::eValueTypeLoadAddress: { 1605 // If it is a load address, then the scalar value is the storage 1606 // location 1607 // of the data, and we have to shove this value down to that load 1608 // location. 1609 ExecutionContext exe_ctx(GetExecutionContextRef()); 1610 Process *process = exe_ctx.GetProcessPtr(); 1611 if (process) { 1612 addr_t target_addr = 1613 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1614 size_t bytes_written = process->WriteScalarToMemory( 1615 target_addr, new_scalar, byte_size, error); 1616 if (!error.Success()) 1617 return false; 1618 if (bytes_written != byte_size) { 1619 error.SetErrorString("unable to write value to memory"); 1620 return false; 1621 } 1622 } 1623 } break; 1624 case Value::eValueTypeHostAddress: { 1625 // If it is a host address, then we stuff the scalar as a DataBuffer 1626 // into the Value's data. 1627 DataExtractor new_data; 1628 new_data.SetByteOrder(m_data.GetByteOrder()); 1629 1630 DataBufferSP buffer_sp(new DataBufferHeap(byte_size, 0)); 1631 m_data.SetData(buffer_sp, 0); 1632 bool success = new_scalar.GetData(new_data); 1633 if (success) { 1634 new_data.CopyByteOrderedData( 1635 0, byte_size, const_cast<uint8_t *>(m_data.GetDataStart()), 1636 byte_size, m_data.GetByteOrder()); 1637 } 1638 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart(); 1639 1640 } break; 1641 case Value::eValueTypeFileAddress: 1642 case Value::eValueTypeScalar: 1643 case Value::eValueTypeVector: 1644 break; 1645 } 1646 } else { 1647 return false; 1648 } 1649 } else { 1650 // We don't support setting things bigger than a scalar at present. 1651 error.SetErrorString("unable to write aggregate data type"); 1652 return false; 1653 } 1654 1655 // If we have reached this point, then we have successfully changed the value. 1656 SetNeedsUpdate(); 1657 return true; 1658 } 1659 1660 bool ValueObject::GetDeclaration(Declaration &decl) { 1661 decl.Clear(); 1662 return false; 1663 } 1664 1665 ConstString ValueObject::GetTypeName() { 1666 return GetCompilerType().GetConstTypeName(); 1667 } 1668 1669 ConstString ValueObject::GetDisplayTypeName() { return GetTypeName(); } 1670 1671 ConstString ValueObject::GetQualifiedTypeName() { 1672 return GetCompilerType().GetConstQualifiedTypeName(); 1673 } 1674 1675 LanguageType ValueObject::GetObjectRuntimeLanguage() { 1676 return GetCompilerType().GetMinimumLanguage(); 1677 } 1678 1679 void ValueObject::AddSyntheticChild(const ConstString &key, 1680 ValueObject *valobj) { 1681 m_synthetic_children[key] = valobj; 1682 } 1683 1684 ValueObjectSP ValueObject::GetSyntheticChild(const ConstString &key) const { 1685 ValueObjectSP synthetic_child_sp; 1686 std::map<ConstString, ValueObject *>::const_iterator pos = 1687 m_synthetic_children.find(key); 1688 if (pos != m_synthetic_children.end()) 1689 synthetic_child_sp = pos->second->GetSP(); 1690 return synthetic_child_sp; 1691 } 1692 1693 uint32_t 1694 ValueObject::GetTypeInfo(CompilerType *pointee_or_element_compiler_type) { 1695 return GetCompilerType().GetTypeInfo(pointee_or_element_compiler_type); 1696 } 1697 1698 bool ValueObject::IsPointerType() { return GetCompilerType().IsPointerType(); } 1699 1700 bool ValueObject::IsArrayType() { 1701 return GetCompilerType().IsArrayType(NULL, NULL, NULL); 1702 } 1703 1704 bool ValueObject::IsScalarType() { return GetCompilerType().IsScalarType(); } 1705 1706 bool ValueObject::IsIntegerType(bool &is_signed) { 1707 return GetCompilerType().IsIntegerType(is_signed); 1708 } 1709 1710 bool ValueObject::IsPointerOrReferenceType() { 1711 return GetCompilerType().IsPointerOrReferenceType(); 1712 } 1713 1714 bool ValueObject::IsPossibleDynamicType() { 1715 ExecutionContext exe_ctx(GetExecutionContextRef()); 1716 Process *process = exe_ctx.GetProcessPtr(); 1717 if (process) 1718 return process->IsPossibleDynamicValue(*this); 1719 else 1720 return GetCompilerType().IsPossibleDynamicType(NULL, true, true); 1721 } 1722 1723 bool ValueObject::IsRuntimeSupportValue() { 1724 Process *process(GetProcessSP().get()); 1725 if (process) { 1726 LanguageRuntime *runtime = 1727 process->GetLanguageRuntime(GetObjectRuntimeLanguage()); 1728 if (!runtime) 1729 runtime = process->GetObjCLanguageRuntime(); 1730 if (runtime) 1731 return runtime->IsRuntimeSupportValue(*this); 1732 } 1733 return false; 1734 } 1735 1736 bool ValueObject::IsNilReference() { 1737 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { 1738 return language->IsNilReference(*this); 1739 } 1740 return false; 1741 } 1742 1743 bool ValueObject::IsUninitializedReference() { 1744 if (Language *language = Language::FindPlugin(GetObjectRuntimeLanguage())) { 1745 return language->IsUninitializedReference(*this); 1746 } 1747 return false; 1748 } 1749 1750 // This allows you to create an array member using and index 1751 // that doesn't not fall in the normal bounds of the array. 1752 // Many times structure can be defined as: 1753 // struct Collection 1754 // { 1755 // uint32_t item_count; 1756 // Item item_array[0]; 1757 // }; 1758 // The size of the "item_array" is 1, but many times in practice 1759 // there are more items in "item_array". 1760 1761 ValueObjectSP ValueObject::GetSyntheticArrayMember(size_t index, 1762 bool can_create) { 1763 ValueObjectSP synthetic_child_sp; 1764 if (IsPointerType() || IsArrayType()) { 1765 char index_str[64]; 1766 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index); 1767 ConstString index_const_str(index_str); 1768 // Check if we have already created a synthetic array member in this 1769 // valid object. If we have we will re-use it. 1770 synthetic_child_sp = GetSyntheticChild(index_const_str); 1771 if (!synthetic_child_sp) { 1772 ValueObject *synthetic_child; 1773 // We haven't made a synthetic array member for INDEX yet, so 1774 // lets make one and cache it for any future reference. 1775 synthetic_child = CreateChildAtIndex(0, true, index); 1776 1777 // Cache the value if we got one back... 1778 if (synthetic_child) { 1779 AddSyntheticChild(index_const_str, synthetic_child); 1780 synthetic_child_sp = synthetic_child->GetSP(); 1781 synthetic_child_sp->SetName(ConstString(index_str)); 1782 synthetic_child_sp->m_is_array_item_for_pointer = true; 1783 } 1784 } 1785 } 1786 return synthetic_child_sp; 1787 } 1788 1789 ValueObjectSP ValueObject::GetSyntheticBitFieldChild(uint32_t from, uint32_t to, 1790 bool can_create) { 1791 ValueObjectSP synthetic_child_sp; 1792 if (IsScalarType()) { 1793 char index_str[64]; 1794 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); 1795 ConstString index_const_str(index_str); 1796 // Check if we have already created a synthetic array member in this 1797 // valid object. If we have we will re-use it. 1798 synthetic_child_sp = GetSyntheticChild(index_const_str); 1799 if (!synthetic_child_sp) { 1800 uint32_t bit_field_size = to - from + 1; 1801 uint32_t bit_field_offset = from; 1802 if (GetDataExtractor().GetByteOrder() == eByteOrderBig) 1803 bit_field_offset = 1804 GetByteSize() * 8 - bit_field_size - bit_field_offset; 1805 // We haven't made a synthetic array member for INDEX yet, so 1806 // lets make one and cache it for any future reference. 1807 ValueObjectChild *synthetic_child = new ValueObjectChild( 1808 *this, GetCompilerType(), index_const_str, GetByteSize(), 0, 1809 bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid, 1810 0); 1811 1812 // Cache the value if we got one back... 1813 if (synthetic_child) { 1814 AddSyntheticChild(index_const_str, synthetic_child); 1815 synthetic_child_sp = synthetic_child->GetSP(); 1816 synthetic_child_sp->SetName(ConstString(index_str)); 1817 synthetic_child_sp->m_is_bitfield_for_scalar = true; 1818 } 1819 } 1820 } 1821 return synthetic_child_sp; 1822 } 1823 1824 ValueObjectSP ValueObject::GetSyntheticChildAtOffset( 1825 uint32_t offset, const CompilerType &type, bool can_create, 1826 ConstString name_const_str) { 1827 1828 ValueObjectSP synthetic_child_sp; 1829 1830 if (name_const_str.IsEmpty()) { 1831 char name_str[64]; 1832 snprintf(name_str, sizeof(name_str), "@%i", offset); 1833 name_const_str.SetCString(name_str); 1834 } 1835 1836 // Check if we have already created a synthetic array member in this 1837 // valid object. If we have we will re-use it. 1838 synthetic_child_sp = GetSyntheticChild(name_const_str); 1839 1840 if (synthetic_child_sp.get()) 1841 return synthetic_child_sp; 1842 1843 if (!can_create) 1844 return ValueObjectSP(); 1845 1846 ExecutionContext exe_ctx(GetExecutionContextRef()); 1847 1848 ValueObjectChild *synthetic_child = new ValueObjectChild( 1849 *this, type, name_const_str, 1850 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, 1851 false, false, eAddressTypeInvalid, 0); 1852 if (synthetic_child) { 1853 AddSyntheticChild(name_const_str, synthetic_child); 1854 synthetic_child_sp = synthetic_child->GetSP(); 1855 synthetic_child_sp->SetName(name_const_str); 1856 synthetic_child_sp->m_is_child_at_offset = true; 1857 } 1858 return synthetic_child_sp; 1859 } 1860 1861 ValueObjectSP ValueObject::GetSyntheticBase(uint32_t offset, 1862 const CompilerType &type, 1863 bool can_create, 1864 ConstString name_const_str) { 1865 ValueObjectSP synthetic_child_sp; 1866 1867 if (name_const_str.IsEmpty()) { 1868 char name_str[128]; 1869 snprintf(name_str, sizeof(name_str), "base%s@%i", 1870 type.GetTypeName().AsCString("<unknown>"), offset); 1871 name_const_str.SetCString(name_str); 1872 } 1873 1874 // Check if we have already created a synthetic array member in this 1875 // valid object. If we have we will re-use it. 1876 synthetic_child_sp = GetSyntheticChild(name_const_str); 1877 1878 if (synthetic_child_sp.get()) 1879 return synthetic_child_sp; 1880 1881 if (!can_create) 1882 return ValueObjectSP(); 1883 1884 const bool is_base_class = true; 1885 1886 ExecutionContext exe_ctx(GetExecutionContextRef()); 1887 1888 ValueObjectChild *synthetic_child = new ValueObjectChild( 1889 *this, type, name_const_str, 1890 type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, 1891 is_base_class, false, eAddressTypeInvalid, 0); 1892 if (synthetic_child) { 1893 AddSyntheticChild(name_const_str, synthetic_child); 1894 synthetic_child_sp = synthetic_child->GetSP(); 1895 synthetic_child_sp->SetName(name_const_str); 1896 } 1897 return synthetic_child_sp; 1898 } 1899 1900 // your expression path needs to have a leading . or -> 1901 // (unless it somehow "looks like" an array, in which case it has 1902 // a leading [ symbol). while the [ is meaningful and should be shown 1903 // to the user, . and -> are just parser design, but by no means 1904 // added information for the user.. strip them off 1905 static const char *SkipLeadingExpressionPathSeparators(const char *expression) { 1906 if (!expression || !expression[0]) 1907 return expression; 1908 if (expression[0] == '.') 1909 return expression + 1; 1910 if (expression[0] == '-' && expression[1] == '>') 1911 return expression + 2; 1912 return expression; 1913 } 1914 1915 ValueObjectSP 1916 ValueObject::GetSyntheticExpressionPathChild(const char *expression, 1917 bool can_create) { 1918 ValueObjectSP synthetic_child_sp; 1919 ConstString name_const_string(expression); 1920 // Check if we have already created a synthetic array member in this 1921 // valid object. If we have we will re-use it. 1922 synthetic_child_sp = GetSyntheticChild(name_const_string); 1923 if (!synthetic_child_sp) { 1924 // We haven't made a synthetic array member for expression yet, so 1925 // lets make one and cache it for any future reference. 1926 synthetic_child_sp = GetValueForExpressionPath( 1927 expression, NULL, NULL, NULL, 1928 GetValueForExpressionPathOptions().SetSyntheticChildrenTraversal( 1929 GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 1930 None)); 1931 1932 // Cache the value if we got one back... 1933 if (synthetic_child_sp.get()) { 1934 // FIXME: this causes a "real" child to end up with its name changed to 1935 // the contents of expression 1936 AddSyntheticChild(name_const_string, synthetic_child_sp.get()); 1937 synthetic_child_sp->SetName( 1938 ConstString(SkipLeadingExpressionPathSeparators(expression))); 1939 } 1940 } 1941 return synthetic_child_sp; 1942 } 1943 1944 void ValueObject::CalculateSyntheticValue(bool use_synthetic) { 1945 if (use_synthetic == false) 1946 return; 1947 1948 TargetSP target_sp(GetTargetSP()); 1949 if (target_sp && target_sp->GetEnableSyntheticValue() == false) { 1950 m_synthetic_value = NULL; 1951 return; 1952 } 1953 1954 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp); 1955 1956 if (!UpdateFormatsIfNeeded() && m_synthetic_value) 1957 return; 1958 1959 if (m_synthetic_children_sp.get() == NULL) 1960 return; 1961 1962 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value) 1963 return; 1964 1965 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp); 1966 } 1967 1968 void ValueObject::CalculateDynamicValue(DynamicValueType use_dynamic) { 1969 if (use_dynamic == eNoDynamicValues) 1970 return; 1971 1972 if (!m_dynamic_value && !IsDynamic()) { 1973 ExecutionContext exe_ctx(GetExecutionContextRef()); 1974 Process *process = exe_ctx.GetProcessPtr(); 1975 if (process && process->IsPossibleDynamicValue(*this)) { 1976 ClearDynamicTypeInformation(); 1977 m_dynamic_value = new ValueObjectDynamicValue(*this, use_dynamic); 1978 } 1979 } 1980 } 1981 1982 ValueObjectSP ValueObject::GetDynamicValue(DynamicValueType use_dynamic) { 1983 if (use_dynamic == eNoDynamicValues) 1984 return ValueObjectSP(); 1985 1986 if (!IsDynamic() && m_dynamic_value == NULL) { 1987 CalculateDynamicValue(use_dynamic); 1988 } 1989 if (m_dynamic_value) 1990 return m_dynamic_value->GetSP(); 1991 else 1992 return ValueObjectSP(); 1993 } 1994 1995 ValueObjectSP ValueObject::GetStaticValue() { return GetSP(); } 1996 1997 lldb::ValueObjectSP ValueObject::GetNonSyntheticValue() { return GetSP(); } 1998 1999 ValueObjectSP ValueObject::GetSyntheticValue(bool use_synthetic) { 2000 if (use_synthetic == false) 2001 return ValueObjectSP(); 2002 2003 CalculateSyntheticValue(use_synthetic); 2004 2005 if (m_synthetic_value) 2006 return m_synthetic_value->GetSP(); 2007 else 2008 return ValueObjectSP(); 2009 } 2010 2011 bool ValueObject::HasSyntheticValue() { 2012 UpdateFormatsIfNeeded(); 2013 2014 if (m_synthetic_children_sp.get() == NULL) 2015 return false; 2016 2017 CalculateSyntheticValue(true); 2018 2019 if (m_synthetic_value) 2020 return true; 2021 else 2022 return false; 2023 } 2024 2025 bool ValueObject::GetBaseClassPath(Stream &s) { 2026 if (IsBaseClass()) { 2027 bool parent_had_base_class = 2028 GetParent() && GetParent()->GetBaseClassPath(s); 2029 CompilerType compiler_type = GetCompilerType(); 2030 std::string cxx_class_name; 2031 bool this_had_base_class = 2032 ClangASTContext::GetCXXClassName(compiler_type, cxx_class_name); 2033 if (this_had_base_class) { 2034 if (parent_had_base_class) 2035 s.PutCString("::"); 2036 s.PutCString(cxx_class_name); 2037 } 2038 return parent_had_base_class || this_had_base_class; 2039 } 2040 return false; 2041 } 2042 2043 ValueObject *ValueObject::GetNonBaseClassParent() { 2044 if (GetParent()) { 2045 if (GetParent()->IsBaseClass()) 2046 return GetParent()->GetNonBaseClassParent(); 2047 else 2048 return GetParent(); 2049 } 2050 return NULL; 2051 } 2052 2053 bool ValueObject::IsBaseClass(uint32_t &depth) { 2054 if (!IsBaseClass()) { 2055 depth = 0; 2056 return false; 2057 } 2058 if (GetParent()) { 2059 GetParent()->IsBaseClass(depth); 2060 depth = depth + 1; 2061 return true; 2062 } 2063 // TODO: a base of no parent? weird.. 2064 depth = 1; 2065 return true; 2066 } 2067 2068 void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, 2069 GetExpressionPathFormat epformat) { 2070 // synthetic children do not actually "exist" as part of the hierarchy, and 2071 // sometimes they are consed up in ways 2072 // that don't make sense from an underlying language/API standpoint. So, use a 2073 // special code path here to return 2074 // something that can hopefully be used in expression 2075 if (m_is_synthetic_children_generated) { 2076 UpdateValueIfNeeded(); 2077 2078 if (m_value.GetValueType() == Value::eValueTypeLoadAddress) { 2079 if (IsPointerOrReferenceType()) { 2080 s.Printf("((%s)0x%" PRIx64 ")", GetTypeName().AsCString("void"), 2081 GetValueAsUnsigned(0)); 2082 return; 2083 } else { 2084 uint64_t load_addr = 2085 m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 2086 if (load_addr != LLDB_INVALID_ADDRESS) { 2087 s.Printf("(*( (%s *)0x%" PRIx64 "))", GetTypeName().AsCString("void"), 2088 load_addr); 2089 return; 2090 } 2091 } 2092 } 2093 2094 if (CanProvideValue()) { 2095 s.Printf("((%s)%s)", GetTypeName().AsCString("void"), 2096 GetValueAsCString()); 2097 return; 2098 } 2099 2100 return; 2101 } 2102 2103 const bool is_deref_of_parent = IsDereferenceOfParent(); 2104 2105 if (is_deref_of_parent && 2106 epformat == eGetExpressionPathFormatDereferencePointers) { 2107 // this is the original format of GetExpressionPath() producing code like 2108 // *(a_ptr).memberName, which is entirely 2109 // fine, until you put this into 2110 // StackFrame::GetValueForVariableExpressionPath() which prefers to see 2111 // a_ptr->memberName. 2112 // the eHonorPointers mode is meant to produce strings in this latter format 2113 s.PutCString("*("); 2114 } 2115 2116 ValueObject *parent = GetParent(); 2117 2118 if (parent) 2119 parent->GetExpressionPath(s, qualify_cxx_base_classes, epformat); 2120 2121 // if we are a deref_of_parent just because we are synthetic array 2122 // members made up to allow ptr[%d] syntax to work in variable 2123 // printing, then add our name ([%d]) to the expression path 2124 if (m_is_array_item_for_pointer && 2125 epformat == eGetExpressionPathFormatHonorPointers) 2126 s.PutCString(m_name.AsCString()); 2127 2128 if (!IsBaseClass()) { 2129 if (!is_deref_of_parent) { 2130 ValueObject *non_base_class_parent = GetNonBaseClassParent(); 2131 if (non_base_class_parent && 2132 !non_base_class_parent->GetName().IsEmpty()) { 2133 CompilerType non_base_class_parent_compiler_type = 2134 non_base_class_parent->GetCompilerType(); 2135 if (non_base_class_parent_compiler_type) { 2136 if (parent && parent->IsDereferenceOfParent() && 2137 epformat == eGetExpressionPathFormatHonorPointers) { 2138 s.PutCString("->"); 2139 } else { 2140 const uint32_t non_base_class_parent_type_info = 2141 non_base_class_parent_compiler_type.GetTypeInfo(); 2142 2143 if (non_base_class_parent_type_info & eTypeIsPointer) { 2144 s.PutCString("->"); 2145 } else if ((non_base_class_parent_type_info & eTypeHasChildren) && 2146 !(non_base_class_parent_type_info & eTypeIsArray)) { 2147 s.PutChar('.'); 2148 } 2149 } 2150 } 2151 } 2152 2153 const char *name = GetName().GetCString(); 2154 if (name) { 2155 if (qualify_cxx_base_classes) { 2156 if (GetBaseClassPath(s)) 2157 s.PutCString("::"); 2158 } 2159 s.PutCString(name); 2160 } 2161 } 2162 } 2163 2164 if (is_deref_of_parent && 2165 epformat == eGetExpressionPathFormatDereferencePointers) { 2166 s.PutChar(')'); 2167 } 2168 } 2169 2170 ValueObjectSP ValueObject::GetValueForExpressionPath( 2171 const char *expression, const char **first_unparsed, 2172 ExpressionPathScanEndReason *reason_to_stop, 2173 ExpressionPathEndResultType *final_value_type, 2174 const GetValueForExpressionPathOptions &options, 2175 ExpressionPathAftermath *final_task_on_target) { 2176 2177 const char *dummy_first_unparsed; 2178 ExpressionPathScanEndReason dummy_reason_to_stop = 2179 ValueObject::eExpressionPathScanEndReasonUnknown; 2180 ExpressionPathEndResultType dummy_final_value_type = 2181 ValueObject::eExpressionPathEndResultTypeInvalid; 2182 ExpressionPathAftermath dummy_final_task_on_target = 2183 ValueObject::eExpressionPathAftermathNothing; 2184 2185 ValueObjectSP ret_val = GetValueForExpressionPath_Impl( 2186 expression, first_unparsed ? first_unparsed : &dummy_first_unparsed, 2187 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2188 final_value_type ? final_value_type : &dummy_final_value_type, options, 2189 final_task_on_target ? final_task_on_target 2190 : &dummy_final_task_on_target); 2191 2192 if (!final_task_on_target || 2193 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) 2194 return ret_val; 2195 2196 if (ret_val.get() && 2197 ((final_value_type ? *final_value_type : dummy_final_value_type) == 2198 eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress 2199 // of plain objects 2200 { 2201 if ((final_task_on_target ? *final_task_on_target 2202 : dummy_final_task_on_target) == 2203 ValueObject::eExpressionPathAftermathDereference) { 2204 Error error; 2205 ValueObjectSP final_value = ret_val->Dereference(error); 2206 if (error.Fail() || !final_value.get()) { 2207 if (reason_to_stop) 2208 *reason_to_stop = 2209 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2210 if (final_value_type) 2211 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2212 return ValueObjectSP(); 2213 } else { 2214 if (final_task_on_target) 2215 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2216 return final_value; 2217 } 2218 } 2219 if (*final_task_on_target == 2220 ValueObject::eExpressionPathAftermathTakeAddress) { 2221 Error error; 2222 ValueObjectSP final_value = ret_val->AddressOf(error); 2223 if (error.Fail() || !final_value.get()) { 2224 if (reason_to_stop) 2225 *reason_to_stop = 2226 ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; 2227 if (final_value_type) 2228 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid; 2229 return ValueObjectSP(); 2230 } else { 2231 if (final_task_on_target) 2232 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2233 return final_value; 2234 } 2235 } 2236 } 2237 return ret_val; // final_task_on_target will still have its original value, so 2238 // you know I did not do it 2239 } 2240 2241 int ValueObject::GetValuesForExpressionPath( 2242 const char *expression, ValueObjectListSP &list, 2243 const char **first_unparsed, ExpressionPathScanEndReason *reason_to_stop, 2244 ExpressionPathEndResultType *final_value_type, 2245 const GetValueForExpressionPathOptions &options, 2246 ExpressionPathAftermath *final_task_on_target) { 2247 const char *dummy_first_unparsed; 2248 ExpressionPathScanEndReason dummy_reason_to_stop; 2249 ExpressionPathEndResultType dummy_final_value_type; 2250 ExpressionPathAftermath dummy_final_task_on_target = 2251 ValueObject::eExpressionPathAftermathNothing; 2252 2253 ValueObjectSP ret_val = GetValueForExpressionPath_Impl( 2254 expression, first_unparsed ? first_unparsed : &dummy_first_unparsed, 2255 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2256 final_value_type ? final_value_type : &dummy_final_value_type, options, 2257 final_task_on_target ? final_task_on_target 2258 : &dummy_final_task_on_target); 2259 2260 if (!ret_val.get()) // if there are errors, I add nothing to the list 2261 return 0; 2262 2263 if ((reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != 2264 eExpressionPathScanEndReasonArrayRangeOperatorMet) { 2265 // I need not expand a range, just post-process the final value and return 2266 if (!final_task_on_target || 2267 *final_task_on_target == ValueObject::eExpressionPathAftermathNothing) { 2268 list->Append(ret_val); 2269 return 1; 2270 } 2271 if (ret_val.get() && 2272 (final_value_type ? *final_value_type : dummy_final_value_type) == 2273 eExpressionPathEndResultTypePlain) // I can only deref and 2274 // takeaddress of plain objects 2275 { 2276 if (*final_task_on_target == 2277 ValueObject::eExpressionPathAftermathDereference) { 2278 Error error; 2279 ValueObjectSP final_value = ret_val->Dereference(error); 2280 if (error.Fail() || !final_value.get()) { 2281 if (reason_to_stop) 2282 *reason_to_stop = 2283 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2284 if (final_value_type) 2285 *final_value_type = 2286 ValueObject::eExpressionPathEndResultTypeInvalid; 2287 return 0; 2288 } else { 2289 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2290 list->Append(final_value); 2291 return 1; 2292 } 2293 } 2294 if (*final_task_on_target == 2295 ValueObject::eExpressionPathAftermathTakeAddress) { 2296 Error error; 2297 ValueObjectSP final_value = ret_val->AddressOf(error); 2298 if (error.Fail() || !final_value.get()) { 2299 if (reason_to_stop) 2300 *reason_to_stop = 2301 ValueObject::eExpressionPathScanEndReasonTakingAddressFailed; 2302 if (final_value_type) 2303 *final_value_type = 2304 ValueObject::eExpressionPathEndResultTypeInvalid; 2305 return 0; 2306 } else { 2307 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing; 2308 list->Append(final_value); 2309 return 1; 2310 } 2311 } 2312 } 2313 } else { 2314 return ExpandArraySliceExpression( 2315 first_unparsed ? *first_unparsed : dummy_first_unparsed, 2316 first_unparsed ? first_unparsed : &dummy_first_unparsed, ret_val, list, 2317 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 2318 final_value_type ? final_value_type : &dummy_final_value_type, options, 2319 final_task_on_target ? final_task_on_target 2320 : &dummy_final_task_on_target); 2321 } 2322 // in any non-covered case, just do the obviously right thing 2323 list->Append(ret_val); 2324 return 1; 2325 } 2326 2327 ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( 2328 const char *expression_cstr, const char **first_unparsed, 2329 ExpressionPathScanEndReason *reason_to_stop, 2330 ExpressionPathEndResultType *final_result, 2331 const GetValueForExpressionPathOptions &options, 2332 ExpressionPathAftermath *what_next) { 2333 ValueObjectSP root = GetSP(); 2334 2335 if (!root.get()) 2336 return ValueObjectSP(); 2337 2338 *first_unparsed = expression_cstr; 2339 2340 while (true) { 2341 2342 const char *expression_cstr = 2343 *first_unparsed; // hide the top level expression_cstr 2344 2345 CompilerType root_compiler_type = root->GetCompilerType(); 2346 CompilerType pointee_compiler_type; 2347 Flags pointee_compiler_type_info; 2348 2349 Flags root_compiler_type_info( 2350 root_compiler_type.GetTypeInfo(&pointee_compiler_type)); 2351 if (pointee_compiler_type) 2352 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); 2353 2354 if (!expression_cstr || *expression_cstr == '\0') { 2355 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2356 return root; 2357 } 2358 2359 switch (*expression_cstr) { 2360 case '-': { 2361 if (options.m_check_dot_vs_arrow_syntax && 2362 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to 2363 // use -> on a 2364 // non-pointer and I 2365 // must catch the error 2366 { 2367 *first_unparsed = expression_cstr; 2368 *reason_to_stop = 2369 ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot; 2370 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2371 return ValueObjectSP(); 2372 } 2373 if (root_compiler_type_info.Test(eTypeIsObjC) && // if yo are trying to 2374 // extract an ObjC IVar 2375 // when this is forbidden 2376 root_compiler_type_info.Test(eTypeIsPointer) && 2377 options.m_no_fragile_ivar) { 2378 *first_unparsed = expression_cstr; 2379 *reason_to_stop = 2380 ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed; 2381 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2382 return ValueObjectSP(); 2383 } 2384 if (expression_cstr[1] != '>') { 2385 *first_unparsed = expression_cstr; 2386 *reason_to_stop = 2387 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2388 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2389 return ValueObjectSP(); 2390 } 2391 expression_cstr++; // skip the - 2392 } 2393 LLVM_FALLTHROUGH; 2394 case '.': // or fallthrough from -> 2395 { 2396 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && 2397 root_compiler_type_info.Test(eTypeIsPointer)) // if you are trying to 2398 // use . on a pointer 2399 // and I must catch the 2400 // error 2401 { 2402 *first_unparsed = expression_cstr; 2403 *reason_to_stop = 2404 ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow; 2405 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2406 return ValueObjectSP(); 2407 } 2408 expression_cstr++; // skip . 2409 const char *next_separator = strpbrk(expression_cstr + 1, "-.["); 2410 ConstString child_name; 2411 if (!next_separator) // if no other separator just expand this last layer 2412 { 2413 child_name.SetCString(expression_cstr); 2414 ValueObjectSP child_valobj_sp = 2415 root->GetChildMemberWithName(child_name, true); 2416 2417 if (child_valobj_sp.get()) // we know we are done, so just return 2418 { 2419 *first_unparsed = ""; 2420 *reason_to_stop = 2421 ValueObject::eExpressionPathScanEndReasonEndOfString; 2422 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2423 return child_valobj_sp; 2424 } else { 2425 switch (options.m_synthetic_children_traversal) { 2426 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2427 None: 2428 break; 2429 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2430 FromSynthetic: 2431 if (root->IsSynthetic()) { 2432 child_valobj_sp = root->GetNonSyntheticValue(); 2433 if (child_valobj_sp.get()) 2434 child_valobj_sp = 2435 child_valobj_sp->GetChildMemberWithName(child_name, true); 2436 } 2437 break; 2438 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2439 ToSynthetic: 2440 if (!root->IsSynthetic()) { 2441 child_valobj_sp = root->GetSyntheticValue(); 2442 if (child_valobj_sp.get()) 2443 child_valobj_sp = 2444 child_valobj_sp->GetChildMemberWithName(child_name, true); 2445 } 2446 break; 2447 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2448 Both: 2449 if (root->IsSynthetic()) { 2450 child_valobj_sp = root->GetNonSyntheticValue(); 2451 if (child_valobj_sp.get()) 2452 child_valobj_sp = 2453 child_valobj_sp->GetChildMemberWithName(child_name, true); 2454 } else { 2455 child_valobj_sp = root->GetSyntheticValue(); 2456 if (child_valobj_sp.get()) 2457 child_valobj_sp = 2458 child_valobj_sp->GetChildMemberWithName(child_name, true); 2459 } 2460 break; 2461 } 2462 } 2463 2464 // if we are here and options.m_no_synthetic_children is true, 2465 // child_valobj_sp is going to be a NULL SP, 2466 // so we hit the "else" branch, and return an error 2467 if (child_valobj_sp.get()) // if it worked, just return 2468 { 2469 *first_unparsed = ""; 2470 *reason_to_stop = 2471 ValueObject::eExpressionPathScanEndReasonEndOfString; 2472 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2473 return child_valobj_sp; 2474 } else { 2475 *first_unparsed = expression_cstr; 2476 *reason_to_stop = 2477 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2478 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2479 return ValueObjectSP(); 2480 } 2481 } else // other layers do expand 2482 { 2483 child_name.SetCStringWithLength(expression_cstr, 2484 next_separator - expression_cstr); 2485 ValueObjectSP child_valobj_sp = 2486 root->GetChildMemberWithName(child_name, true); 2487 if (child_valobj_sp.get()) // store the new root and move on 2488 { 2489 root = child_valobj_sp; 2490 *first_unparsed = next_separator; 2491 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2492 continue; 2493 } else { 2494 switch (options.m_synthetic_children_traversal) { 2495 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2496 None: 2497 break; 2498 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2499 FromSynthetic: 2500 if (root->IsSynthetic()) { 2501 child_valobj_sp = root->GetNonSyntheticValue(); 2502 if (child_valobj_sp.get()) 2503 child_valobj_sp = 2504 child_valobj_sp->GetChildMemberWithName(child_name, true); 2505 } 2506 break; 2507 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2508 ToSynthetic: 2509 if (!root->IsSynthetic()) { 2510 child_valobj_sp = root->GetSyntheticValue(); 2511 if (child_valobj_sp.get()) 2512 child_valobj_sp = 2513 child_valobj_sp->GetChildMemberWithName(child_name, true); 2514 } 2515 break; 2516 case GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2517 Both: 2518 if (root->IsSynthetic()) { 2519 child_valobj_sp = root->GetNonSyntheticValue(); 2520 if (child_valobj_sp.get()) 2521 child_valobj_sp = 2522 child_valobj_sp->GetChildMemberWithName(child_name, true); 2523 } else { 2524 child_valobj_sp = root->GetSyntheticValue(); 2525 if (child_valobj_sp.get()) 2526 child_valobj_sp = 2527 child_valobj_sp->GetChildMemberWithName(child_name, true); 2528 } 2529 break; 2530 } 2531 } 2532 2533 // if we are here and options.m_no_synthetic_children is true, 2534 // child_valobj_sp is going to be a NULL SP, 2535 // so we hit the "else" branch, and return an error 2536 if (child_valobj_sp.get()) // if it worked, move on 2537 { 2538 root = child_valobj_sp; 2539 *first_unparsed = next_separator; 2540 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2541 continue; 2542 } else { 2543 *first_unparsed = expression_cstr; 2544 *reason_to_stop = 2545 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2546 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2547 return ValueObjectSP(); 2548 } 2549 } 2550 break; 2551 } 2552 case '[': { 2553 if (!root_compiler_type_info.Test(eTypeIsArray) && 2554 !root_compiler_type_info.Test(eTypeIsPointer) && 2555 !root_compiler_type_info.Test( 2556 eTypeIsVector)) // if this is not a T[] nor a T* 2557 { 2558 if (!root_compiler_type_info.Test( 2559 eTypeIsScalar)) // if this is not even a scalar... 2560 { 2561 if (options.m_synthetic_children_traversal == 2562 GetValueForExpressionPathOptions::SyntheticChildrenTraversal:: 2563 None) // ...only chance left is synthetic 2564 { 2565 *first_unparsed = expression_cstr; 2566 *reason_to_stop = 2567 ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; 2568 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2569 return ValueObjectSP(); 2570 } 2571 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar, 2572 // check that we can 2573 // expand bitfields 2574 { 2575 *first_unparsed = expression_cstr; 2576 *reason_to_stop = 2577 ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; 2578 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2579 return ValueObjectSP(); 2580 } 2581 } 2582 if (*(expression_cstr + 1) == 2583 ']') // if this is an unbounded range it only works for arrays 2584 { 2585 if (!root_compiler_type_info.Test(eTypeIsArray)) { 2586 *first_unparsed = expression_cstr; 2587 *reason_to_stop = 2588 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 2589 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2590 return ValueObjectSP(); 2591 } else // even if something follows, we cannot expand unbounded ranges, 2592 // just let the caller do it 2593 { 2594 *first_unparsed = expression_cstr + 2; 2595 *reason_to_stop = 2596 ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 2597 *final_result = 2598 ValueObject::eExpressionPathEndResultTypeUnboundedRange; 2599 return root; 2600 } 2601 } 2602 const char *separator_position = ::strchr(expression_cstr + 1, '-'); 2603 const char *close_bracket_position = ::strchr(expression_cstr + 1, ']'); 2604 if (!close_bracket_position) // if there is no ], this is a syntax error 2605 { 2606 *first_unparsed = expression_cstr; 2607 *reason_to_stop = 2608 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2609 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2610 return ValueObjectSP(); 2611 } 2612 if (!separator_position || 2613 separator_position > close_bracket_position) // if no separator, this 2614 // is either [] or [N] 2615 { 2616 char *end = NULL; 2617 unsigned long index = ::strtoul(expression_cstr + 1, &end, 0); 2618 if (!end || end != close_bracket_position) // if something weird is in 2619 // our way return an error 2620 { 2621 *first_unparsed = expression_cstr; 2622 *reason_to_stop = 2623 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2624 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2625 return ValueObjectSP(); 2626 } 2627 if (end - expression_cstr == 2628 1) // if this is [], only return a valid value for arrays 2629 { 2630 if (root_compiler_type_info.Test(eTypeIsArray)) { 2631 *first_unparsed = expression_cstr + 2; 2632 *reason_to_stop = 2633 ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 2634 *final_result = 2635 ValueObject::eExpressionPathEndResultTypeUnboundedRange; 2636 return root; 2637 } else { 2638 *first_unparsed = expression_cstr; 2639 *reason_to_stop = 2640 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 2641 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2642 return ValueObjectSP(); 2643 } 2644 } 2645 // from here on we do have a valid index 2646 if (root_compiler_type_info.Test(eTypeIsArray)) { 2647 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); 2648 if (!child_valobj_sp) 2649 child_valobj_sp = root->GetSyntheticArrayMember(index, true); 2650 if (!child_valobj_sp) 2651 if (root->HasSyntheticValue() && 2652 root->GetSyntheticValue()->GetNumChildren() > index) 2653 child_valobj_sp = 2654 root->GetSyntheticValue()->GetChildAtIndex(index, true); 2655 if (child_valobj_sp) { 2656 root = child_valobj_sp; 2657 *first_unparsed = end + 1; // skip ] 2658 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2659 continue; 2660 } else { 2661 *first_unparsed = expression_cstr; 2662 *reason_to_stop = 2663 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2664 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2665 return ValueObjectSP(); 2666 } 2667 } else if (root_compiler_type_info.Test(eTypeIsPointer)) { 2668 if (*what_next == 2669 ValueObject:: 2670 eExpressionPathAftermathDereference && // if this is a 2671 // ptr-to-scalar, I 2672 // am accessing it 2673 // by index and I 2674 // would have 2675 // deref'ed anyway, 2676 // then do it now 2677 // and use this as 2678 // a bitfield 2679 pointee_compiler_type_info.Test(eTypeIsScalar)) { 2680 Error error; 2681 root = root->Dereference(error); 2682 if (error.Fail() || !root.get()) { 2683 *first_unparsed = expression_cstr; 2684 *reason_to_stop = 2685 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2686 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2687 return ValueObjectSP(); 2688 } else { 2689 *what_next = eExpressionPathAftermathNothing; 2690 continue; 2691 } 2692 } else { 2693 if (root->GetCompilerType().GetMinimumLanguage() == 2694 eLanguageTypeObjC && 2695 pointee_compiler_type_info.AllClear(eTypeIsPointer) && 2696 root->HasSyntheticValue() && 2697 (options.m_synthetic_children_traversal == 2698 GetValueForExpressionPathOptions:: 2699 SyntheticChildrenTraversal::ToSynthetic || 2700 options.m_synthetic_children_traversal == 2701 GetValueForExpressionPathOptions:: 2702 SyntheticChildrenTraversal::Both)) { 2703 root = root->GetSyntheticValue()->GetChildAtIndex(index, true); 2704 } else 2705 root = root->GetSyntheticArrayMember(index, true); 2706 if (!root.get()) { 2707 *first_unparsed = expression_cstr; 2708 *reason_to_stop = 2709 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2710 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2711 return ValueObjectSP(); 2712 } else { 2713 *first_unparsed = end + 1; // skip ] 2714 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2715 continue; 2716 } 2717 } 2718 } else if (root_compiler_type_info.Test(eTypeIsScalar)) { 2719 root = root->GetSyntheticBitFieldChild(index, index, true); 2720 if (!root.get()) { 2721 *first_unparsed = expression_cstr; 2722 *reason_to_stop = 2723 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2724 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2725 return ValueObjectSP(); 2726 } else // we do not know how to expand members of bitfields, so we 2727 // just return and let the caller do any further processing 2728 { 2729 *first_unparsed = end + 1; // skip ] 2730 *reason_to_stop = ValueObject:: 2731 eExpressionPathScanEndReasonBitfieldRangeOperatorMet; 2732 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; 2733 return root; 2734 } 2735 } else if (root_compiler_type_info.Test(eTypeIsVector)) { 2736 root = root->GetChildAtIndex(index, true); 2737 if (!root.get()) { 2738 *first_unparsed = expression_cstr; 2739 *reason_to_stop = 2740 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2741 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2742 return ValueObjectSP(); 2743 } else { 2744 *first_unparsed = end + 1; // skip ] 2745 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2746 continue; 2747 } 2748 } else if (options.m_synthetic_children_traversal == 2749 GetValueForExpressionPathOptions:: 2750 SyntheticChildrenTraversal::ToSynthetic || 2751 options.m_synthetic_children_traversal == 2752 GetValueForExpressionPathOptions:: 2753 SyntheticChildrenTraversal::Both) { 2754 if (root->HasSyntheticValue()) 2755 root = root->GetSyntheticValue(); 2756 else if (!root->IsSynthetic()) { 2757 *first_unparsed = expression_cstr; 2758 *reason_to_stop = 2759 ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; 2760 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2761 return ValueObjectSP(); 2762 } 2763 // if we are here, then root itself is a synthetic VO.. should be good 2764 // to go 2765 2766 if (!root.get()) { 2767 *first_unparsed = expression_cstr; 2768 *reason_to_stop = 2769 ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; 2770 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2771 return ValueObjectSP(); 2772 } 2773 root = root->GetChildAtIndex(index, true); 2774 if (!root.get()) { 2775 *first_unparsed = expression_cstr; 2776 *reason_to_stop = 2777 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2778 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2779 return ValueObjectSP(); 2780 } else { 2781 *first_unparsed = end + 1; // skip ] 2782 *final_result = ValueObject::eExpressionPathEndResultTypePlain; 2783 continue; 2784 } 2785 } else { 2786 *first_unparsed = expression_cstr; 2787 *reason_to_stop = 2788 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2789 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2790 return ValueObjectSP(); 2791 } 2792 } else // we have a low and a high index 2793 { 2794 char *end = NULL; 2795 unsigned long index_lower = ::strtoul(expression_cstr + 1, &end, 0); 2796 if (!end || end != separator_position) // if something weird is in our 2797 // way return an error 2798 { 2799 *first_unparsed = expression_cstr; 2800 *reason_to_stop = 2801 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2802 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2803 return ValueObjectSP(); 2804 } 2805 unsigned long index_higher = ::strtoul(separator_position + 1, &end, 0); 2806 if (!end || end != close_bracket_position) // if something weird is in 2807 // our way return an error 2808 { 2809 *first_unparsed = expression_cstr; 2810 *reason_to_stop = 2811 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2812 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2813 return ValueObjectSP(); 2814 } 2815 if (index_lower > index_higher) // swap indices if required 2816 { 2817 unsigned long temp = index_lower; 2818 index_lower = index_higher; 2819 index_higher = temp; 2820 } 2821 if (root_compiler_type_info.Test( 2822 eTypeIsScalar)) // expansion only works for scalars 2823 { 2824 root = 2825 root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 2826 if (!root.get()) { 2827 *first_unparsed = expression_cstr; 2828 *reason_to_stop = 2829 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 2830 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2831 return ValueObjectSP(); 2832 } else { 2833 *first_unparsed = end + 1; // skip ] 2834 *reason_to_stop = ValueObject:: 2835 eExpressionPathScanEndReasonBitfieldRangeOperatorMet; 2836 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield; 2837 return root; 2838 } 2839 } else if (root_compiler_type_info.Test( 2840 eTypeIsPointer) && // if this is a ptr-to-scalar, I am 2841 // accessing it by index and I would 2842 // have deref'ed anyway, then do it 2843 // now and use this as a bitfield 2844 *what_next == 2845 ValueObject::eExpressionPathAftermathDereference && 2846 pointee_compiler_type_info.Test(eTypeIsScalar)) { 2847 Error error; 2848 root = root->Dereference(error); 2849 if (error.Fail() || !root.get()) { 2850 *first_unparsed = expression_cstr; 2851 *reason_to_stop = 2852 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2854 return ValueObjectSP(); 2855 } else { 2856 *what_next = ValueObject::eExpressionPathAftermathNothing; 2857 continue; 2858 } 2859 } else { 2860 *first_unparsed = expression_cstr; 2861 *reason_to_stop = 2862 ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet; 2863 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange; 2864 return root; 2865 } 2866 } 2867 break; 2868 } 2869 default: // some non-separator is in the way 2870 { 2871 *first_unparsed = expression_cstr; 2872 *reason_to_stop = 2873 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2874 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2875 return ValueObjectSP(); 2876 break; 2877 } 2878 } 2879 } 2880 } 2881 2882 int ValueObject::ExpandArraySliceExpression( 2883 const char *expression_cstr, const char **first_unparsed, 2884 ValueObjectSP root, ValueObjectListSP &list, 2885 ExpressionPathScanEndReason *reason_to_stop, 2886 ExpressionPathEndResultType *final_result, 2887 const GetValueForExpressionPathOptions &options, 2888 ExpressionPathAftermath *what_next) { 2889 if (!root.get()) 2890 return 0; 2891 2892 *first_unparsed = expression_cstr; 2893 2894 while (true) { 2895 2896 const char *expression_cstr = 2897 *first_unparsed; // hide the top level expression_cstr 2898 2899 CompilerType root_compiler_type = root->GetCompilerType(); 2900 CompilerType pointee_compiler_type; 2901 Flags pointee_compiler_type_info; 2902 Flags root_compiler_type_info( 2903 root_compiler_type.GetTypeInfo(&pointee_compiler_type)); 2904 if (pointee_compiler_type) 2905 pointee_compiler_type_info.Reset(pointee_compiler_type.GetTypeInfo()); 2906 2907 if (!expression_cstr || *expression_cstr == '\0') { 2908 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString; 2909 list->Append(root); 2910 return 1; 2911 } 2912 2913 switch (*expression_cstr) { 2914 case '[': { 2915 if (!root_compiler_type_info.Test(eTypeIsArray) && 2916 !root_compiler_type_info.Test( 2917 eTypeIsPointer)) // if this is not a T[] nor a T* 2918 { 2919 if (!root_compiler_type_info.Test(eTypeIsScalar)) // if this is not even 2920 // a scalar, this 2921 // syntax is just 2922 // plain wrong! 2923 { 2924 *first_unparsed = expression_cstr; 2925 *reason_to_stop = 2926 ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid; 2927 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2928 return 0; 2929 } else if (!options.m_allow_bitfields_syntax) // if this is a scalar, 2930 // check that we can 2931 // expand bitfields 2932 { 2933 *first_unparsed = expression_cstr; 2934 *reason_to_stop = 2935 ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed; 2936 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2937 return 0; 2938 } 2939 } 2940 if (*(expression_cstr + 1) == 2941 ']') // if this is an unbounded range it only works for arrays 2942 { 2943 if (!root_compiler_type_info.Test(eTypeIsArray)) { 2944 *first_unparsed = expression_cstr; 2945 *reason_to_stop = 2946 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 2947 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2948 return 0; 2949 } else // expand this into list 2950 { 2951 const size_t max_index = root->GetNumChildren() - 1; 2952 for (size_t index = 0; index < max_index; index++) { 2953 ValueObjectSP child = root->GetChildAtIndex(index, true); 2954 list->Append(child); 2955 } 2956 *first_unparsed = expression_cstr + 2; 2957 *reason_to_stop = 2958 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 2959 *final_result = 2960 ValueObject::eExpressionPathEndResultTypeValueObjectList; 2961 return max_index; // tell me number of items I added to the VOList 2962 } 2963 } 2964 const char *separator_position = ::strchr(expression_cstr + 1, '-'); 2965 const char *close_bracket_position = ::strchr(expression_cstr + 1, ']'); 2966 if (!close_bracket_position) // if there is no ], this is a syntax error 2967 { 2968 *first_unparsed = expression_cstr; 2969 *reason_to_stop = 2970 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2971 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2972 return 0; 2973 } 2974 if (!separator_position || 2975 separator_position > close_bracket_position) // if no separator, this 2976 // is either [] or [N] 2977 { 2978 char *end = NULL; 2979 unsigned long index = ::strtoul(expression_cstr + 1, &end, 0); 2980 if (!end || end != close_bracket_position) // if something weird is in 2981 // our way return an error 2982 { 2983 *first_unparsed = expression_cstr; 2984 *reason_to_stop = 2985 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 2986 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 2987 return 0; 2988 } 2989 if (end - expression_cstr == 2990 1) // if this is [], only return a valid value for arrays 2991 { 2992 if (root_compiler_type_info.Test(eTypeIsArray)) { 2993 const size_t max_index = root->GetNumChildren() - 1; 2994 for (size_t index = 0; index < max_index; index++) { 2995 ValueObjectSP child = root->GetChildAtIndex(index, true); 2996 list->Append(child); 2997 } 2998 *first_unparsed = expression_cstr + 2; 2999 *reason_to_stop = 3000 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3001 *final_result = 3002 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3003 return max_index; // tell me number of items I added to the VOList 3004 } else { 3005 *first_unparsed = expression_cstr; 3006 *reason_to_stop = 3007 ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed; 3008 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3009 return 0; 3010 } 3011 } 3012 // from here on we do have a valid index 3013 if (root_compiler_type_info.Test(eTypeIsArray)) { 3014 root = root->GetChildAtIndex(index, true); 3015 if (!root.get()) { 3016 *first_unparsed = expression_cstr; 3017 *reason_to_stop = 3018 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3020 return 0; 3021 } else { 3022 list->Append(root); 3023 *first_unparsed = end + 1; // skip ] 3024 *reason_to_stop = 3025 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3026 *final_result = 3027 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3028 return 1; 3029 } 3030 } else if (root_compiler_type_info.Test(eTypeIsPointer)) { 3031 if (*what_next == 3032 ValueObject:: 3033 eExpressionPathAftermathDereference && // if this is a 3034 // ptr-to-scalar, I 3035 // am accessing it 3036 // by index and I 3037 // would have 3038 // deref'ed anyway, 3039 // then do it now 3040 // and use this as 3041 // a bitfield 3042 pointee_compiler_type_info.Test(eTypeIsScalar)) { 3043 Error error; 3044 root = root->Dereference(error); 3045 if (error.Fail() || !root.get()) { 3046 *first_unparsed = expression_cstr; 3047 *reason_to_stop = 3048 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3049 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3050 return 0; 3051 } else { 3052 *what_next = eExpressionPathAftermathNothing; 3053 continue; 3054 } 3055 } else { 3056 root = root->GetSyntheticArrayMember(index, true); 3057 if (!root.get()) { 3058 *first_unparsed = expression_cstr; 3059 *reason_to_stop = 3060 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3061 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3062 return 0; 3063 } else { 3064 list->Append(root); 3065 *first_unparsed = end + 1; // skip ] 3066 *reason_to_stop = ValueObject:: 3067 eExpressionPathScanEndReasonRangeOperatorExpanded; 3068 *final_result = 3069 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3070 return 1; 3071 } 3072 } 3073 } else /*if (ClangASTContext::IsScalarType(root_compiler_type))*/ 3074 { 3075 root = root->GetSyntheticBitFieldChild(index, index, true); 3076 if (!root.get()) { 3077 *first_unparsed = expression_cstr; 3078 *reason_to_stop = 3079 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3080 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3081 return 0; 3082 } else // we do not know how to expand members of bitfields, so we 3083 // just return and let the caller do any further processing 3084 { 3085 list->Append(root); 3086 *first_unparsed = end + 1; // skip ] 3087 *reason_to_stop = 3088 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3089 *final_result = 3090 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3091 return 1; 3092 } 3093 } 3094 } else // we have a low and a high index 3095 { 3096 char *end = NULL; 3097 unsigned long index_lower = ::strtoul(expression_cstr + 1, &end, 0); 3098 if (!end || end != separator_position) // if something weird is in our 3099 // way return an error 3100 { 3101 *first_unparsed = expression_cstr; 3102 *reason_to_stop = 3103 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3104 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3105 return 0; 3106 } 3107 unsigned long index_higher = ::strtoul(separator_position + 1, &end, 0); 3108 if (!end || end != close_bracket_position) // if something weird is in 3109 // our way return an error 3110 { 3111 *first_unparsed = expression_cstr; 3112 *reason_to_stop = 3113 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3114 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3115 return 0; 3116 } 3117 if (index_lower > index_higher) // swap indices if required 3118 { 3119 unsigned long temp = index_lower; 3120 index_lower = index_higher; 3121 index_higher = temp; 3122 } 3123 if (root_compiler_type_info.Test( 3124 eTypeIsScalar)) // expansion only works for scalars 3125 { 3126 root = 3127 root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 3128 if (!root.get()) { 3129 *first_unparsed = expression_cstr; 3130 *reason_to_stop = 3131 ValueObject::eExpressionPathScanEndReasonNoSuchChild; 3132 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3133 return 0; 3134 } else { 3135 list->Append(root); 3136 *first_unparsed = end + 1; // skip ] 3137 *reason_to_stop = 3138 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3139 *final_result = 3140 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3141 return 1; 3142 } 3143 } else if (root_compiler_type_info.Test( 3144 eTypeIsPointer) && // if this is a ptr-to-scalar, I am 3145 // accessing it by index and I would 3146 // have deref'ed anyway, then do it 3147 // now and use this as a bitfield 3148 *what_next == 3149 ValueObject::eExpressionPathAftermathDereference && 3150 pointee_compiler_type_info.Test(eTypeIsScalar)) { 3151 Error error; 3152 root = root->Dereference(error); 3153 if (error.Fail() || !root.get()) { 3154 *first_unparsed = expression_cstr; 3155 *reason_to_stop = 3156 ValueObject::eExpressionPathScanEndReasonDereferencingFailed; 3157 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3158 return 0; 3159 } else { 3160 *what_next = ValueObject::eExpressionPathAftermathNothing; 3161 continue; 3162 } 3163 } else { 3164 for (unsigned long index = index_lower; index <= index_higher; 3165 index++) { 3166 ValueObjectSP child = root->GetChildAtIndex(index, true); 3167 list->Append(child); 3168 } 3169 *first_unparsed = end + 1; 3170 *reason_to_stop = 3171 ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded; 3172 *final_result = 3173 ValueObject::eExpressionPathEndResultTypeValueObjectList; 3174 return index_higher - index_lower + 3175 1; // tell me number of items I added to the VOList 3176 } 3177 } 3178 break; 3179 } 3180 default: // some non-[ separator, or something entirely wrong, is in the way 3181 { 3182 *first_unparsed = expression_cstr; 3183 *reason_to_stop = 3184 ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol; 3185 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; 3186 return 0; 3187 break; 3188 } 3189 } 3190 } 3191 } 3192 3193 void ValueObject::LogValueObject(Log *log) { 3194 if (log) 3195 return LogValueObject(log, DumpValueObjectOptions(*this)); 3196 } 3197 3198 void ValueObject::LogValueObject(Log *log, 3199 const DumpValueObjectOptions &options) { 3200 if (log) { 3201 StreamString s; 3202 Dump(s, options); 3203 if (s.GetSize()) 3204 log->PutCString(s.GetData()); 3205 } 3206 } 3207 3208 void ValueObject::Dump(Stream &s) { Dump(s, DumpValueObjectOptions(*this)); } 3209 3210 void ValueObject::Dump(Stream &s, const DumpValueObjectOptions &options) { 3211 ValueObjectPrinter printer(this, &s, options); 3212 printer.PrintValueObject(); 3213 } 3214 3215 ValueObjectSP ValueObject::CreateConstantValue(const ConstString &name) { 3216 ValueObjectSP valobj_sp; 3217 3218 if (UpdateValueIfNeeded(false) && m_error.Success()) { 3219 ExecutionContext exe_ctx(GetExecutionContextRef()); 3220 3221 DataExtractor data; 3222 data.SetByteOrder(m_data.GetByteOrder()); 3223 data.SetAddressByteSize(m_data.GetAddressByteSize()); 3224 3225 if (IsBitfield()) { 3226 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX))); 3227 m_error = v.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); 3228 } else 3229 m_error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); 3230 3231 valobj_sp = ValueObjectConstResult::Create( 3232 exe_ctx.GetBestExecutionContextScope(), GetCompilerType(), name, data, 3233 GetAddressOf()); 3234 } 3235 3236 if (!valobj_sp) { 3237 ExecutionContext exe_ctx(GetExecutionContextRef()); 3238 valobj_sp = ValueObjectConstResult::Create( 3239 exe_ctx.GetBestExecutionContextScope(), m_error); 3240 } 3241 return valobj_sp; 3242 } 3243 3244 ValueObjectSP ValueObject::GetQualifiedRepresentationIfAvailable( 3245 lldb::DynamicValueType dynValue, bool synthValue) { 3246 ValueObjectSP result_sp(GetSP()); 3247 3248 switch (dynValue) { 3249 case lldb::eDynamicCanRunTarget: 3250 case lldb::eDynamicDontRunTarget: { 3251 if (!result_sp->IsDynamic()) { 3252 if (result_sp->GetDynamicValue(dynValue)) 3253 result_sp = result_sp->GetDynamicValue(dynValue); 3254 } 3255 } break; 3256 case lldb::eNoDynamicValues: { 3257 if (result_sp->IsDynamic()) { 3258 if (result_sp->GetStaticValue()) 3259 result_sp = result_sp->GetStaticValue(); 3260 } 3261 } break; 3262 } 3263 3264 if (synthValue) { 3265 if (!result_sp->IsSynthetic()) { 3266 if (result_sp->GetSyntheticValue()) 3267 result_sp = result_sp->GetSyntheticValue(); 3268 } 3269 } else { 3270 if (result_sp->IsSynthetic()) { 3271 if (result_sp->GetNonSyntheticValue()) 3272 result_sp = result_sp->GetNonSyntheticValue(); 3273 } 3274 } 3275 3276 return result_sp; 3277 } 3278 3279 lldb::addr_t ValueObject::GetCPPVTableAddress(AddressType &address_type) { 3280 CompilerType pointee_type; 3281 CompilerType this_type(GetCompilerType()); 3282 uint32_t type_info = this_type.GetTypeInfo(&pointee_type); 3283 if (type_info) { 3284 bool ptr_or_ref = false; 3285 if (type_info & (eTypeIsPointer | eTypeIsReference)) { 3286 ptr_or_ref = true; 3287 type_info = pointee_type.GetTypeInfo(); 3288 } 3289 3290 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus; 3291 if ((type_info & cpp_class) == cpp_class) { 3292 if (ptr_or_ref) { 3293 address_type = GetAddressTypeOfChildren(); 3294 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS); 3295 } else 3296 return GetAddressOf(false, &address_type); 3297 } 3298 } 3299 3300 address_type = eAddressTypeInvalid; 3301 return LLDB_INVALID_ADDRESS; 3302 } 3303 3304 ValueObjectSP ValueObject::Dereference(Error &error) { 3305 if (m_deref_valobj) 3306 return m_deref_valobj->GetSP(); 3307 3308 const bool is_pointer_or_reference_type = IsPointerOrReferenceType(); 3309 if (is_pointer_or_reference_type) { 3310 bool omit_empty_base_classes = true; 3311 bool ignore_array_bounds = false; 3312 3313 std::string child_name_str; 3314 uint32_t child_byte_size = 0; 3315 int32_t child_byte_offset = 0; 3316 uint32_t child_bitfield_bit_size = 0; 3317 uint32_t child_bitfield_bit_offset = 0; 3318 bool child_is_base_class = false; 3319 bool child_is_deref_of_parent = false; 3320 const bool transparent_pointers = false; 3321 CompilerType compiler_type = GetCompilerType(); 3322 CompilerType child_compiler_type; 3323 uint64_t language_flags; 3324 3325 ExecutionContext exe_ctx(GetExecutionContextRef()); 3326 3327 child_compiler_type = compiler_type.GetChildCompilerTypeAtIndex( 3328 &exe_ctx, 0, transparent_pointers, omit_empty_base_classes, 3329 ignore_array_bounds, child_name_str, child_byte_size, child_byte_offset, 3330 child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class, 3331 child_is_deref_of_parent, this, language_flags); 3332 if (child_compiler_type && child_byte_size) { 3333 ConstString child_name; 3334 if (!child_name_str.empty()) 3335 child_name.SetCString(child_name_str.c_str()); 3336 3337 m_deref_valobj = new ValueObjectChild( 3338 *this, child_compiler_type, child_name, child_byte_size, 3339 child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset, 3340 child_is_base_class, child_is_deref_of_parent, eAddressTypeInvalid, 3341 language_flags); 3342 } 3343 } 3344 3345 if (m_deref_valobj) { 3346 error.Clear(); 3347 return m_deref_valobj->GetSP(); 3348 } else { 3349 StreamString strm; 3350 GetExpressionPath(strm, true); 3351 3352 if (is_pointer_or_reference_type) 3353 error.SetErrorStringWithFormat("dereference failed: (%s) %s", 3354 GetTypeName().AsCString("<invalid type>"), 3355 strm.GetString().c_str()); 3356 else 3357 error.SetErrorStringWithFormat("not a pointer or reference type: (%s) %s", 3358 GetTypeName().AsCString("<invalid type>"), 3359 strm.GetString().c_str()); 3360 return ValueObjectSP(); 3361 } 3362 } 3363 3364 ValueObjectSP ValueObject::AddressOf(Error &error) { 3365 if (m_addr_of_valobj_sp) 3366 return m_addr_of_valobj_sp; 3367 3368 AddressType address_type = eAddressTypeInvalid; 3369 const bool scalar_is_load_address = false; 3370 addr_t addr = GetAddressOf(scalar_is_load_address, &address_type); 3371 error.Clear(); 3372 if (addr != LLDB_INVALID_ADDRESS && address_type != eAddressTypeHost) { 3373 switch (address_type) { 3374 case eAddressTypeInvalid: { 3375 StreamString expr_path_strm; 3376 GetExpressionPath(expr_path_strm, true); 3377 error.SetErrorStringWithFormat("'%s' is not in memory", 3378 expr_path_strm.GetString().c_str()); 3379 } break; 3380 3381 case eAddressTypeFile: 3382 case eAddressTypeLoad: { 3383 CompilerType compiler_type = GetCompilerType(); 3384 if (compiler_type) { 3385 std::string name(1, '&'); 3386 name.append(m_name.AsCString("")); 3387 ExecutionContext exe_ctx(GetExecutionContextRef()); 3388 m_addr_of_valobj_sp = ValueObjectConstResult::Create( 3389 exe_ctx.GetBestExecutionContextScope(), 3390 compiler_type.GetPointerType(), ConstString(name.c_str()), addr, 3391 eAddressTypeInvalid, m_data.GetAddressByteSize()); 3392 } 3393 } break; 3394 default: 3395 break; 3396 } 3397 } else { 3398 StreamString expr_path_strm; 3399 GetExpressionPath(expr_path_strm, true); 3400 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", 3401 expr_path_strm.GetString().c_str()); 3402 } 3403 3404 return m_addr_of_valobj_sp; 3405 } 3406 3407 ValueObjectSP ValueObject::Cast(const CompilerType &compiler_type) { 3408 return ValueObjectCast::Create(*this, GetName(), compiler_type); 3409 } 3410 3411 ValueObjectSP ValueObject::CastPointerType(const char *name, 3412 CompilerType &compiler_type) { 3413 ValueObjectSP valobj_sp; 3414 AddressType address_type; 3415 addr_t ptr_value = GetPointerValue(&address_type); 3416 3417 if (ptr_value != LLDB_INVALID_ADDRESS) { 3418 Address ptr_addr(ptr_value); 3419 ExecutionContext exe_ctx(GetExecutionContextRef()); 3420 valobj_sp = ValueObjectMemory::Create( 3421 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, compiler_type); 3422 } 3423 return valobj_sp; 3424 } 3425 3426 ValueObjectSP ValueObject::CastPointerType(const char *name, TypeSP &type_sp) { 3427 ValueObjectSP valobj_sp; 3428 AddressType address_type; 3429 addr_t ptr_value = GetPointerValue(&address_type); 3430 3431 if (ptr_value != LLDB_INVALID_ADDRESS) { 3432 Address ptr_addr(ptr_value); 3433 ExecutionContext exe_ctx(GetExecutionContextRef()); 3434 valobj_sp = ValueObjectMemory::Create( 3435 exe_ctx.GetBestExecutionContextScope(), name, ptr_addr, type_sp); 3436 } 3437 return valobj_sp; 3438 } 3439 3440 ValueObject::EvaluationPoint::EvaluationPoint() 3441 : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) {} 3442 3443 ValueObject::EvaluationPoint::EvaluationPoint(ExecutionContextScope *exe_scope, 3444 bool use_selected) 3445 : m_mod_id(), m_exe_ctx_ref(), m_needs_update(true) { 3446 ExecutionContext exe_ctx(exe_scope); 3447 TargetSP target_sp(exe_ctx.GetTargetSP()); 3448 if (target_sp) { 3449 m_exe_ctx_ref.SetTargetSP(target_sp); 3450 ProcessSP process_sp(exe_ctx.GetProcessSP()); 3451 if (!process_sp) 3452 process_sp = target_sp->GetProcessSP(); 3453 3454 if (process_sp) { 3455 m_mod_id = process_sp->GetModID(); 3456 m_exe_ctx_ref.SetProcessSP(process_sp); 3457 3458 ThreadSP thread_sp(exe_ctx.GetThreadSP()); 3459 3460 if (!thread_sp) { 3461 if (use_selected) 3462 thread_sp = process_sp->GetThreadList().GetSelectedThread(); 3463 } 3464 3465 if (thread_sp) { 3466 m_exe_ctx_ref.SetThreadSP(thread_sp); 3467 3468 StackFrameSP frame_sp(exe_ctx.GetFrameSP()); 3469 if (!frame_sp) { 3470 if (use_selected) 3471 frame_sp = thread_sp->GetSelectedFrame(); 3472 } 3473 if (frame_sp) 3474 m_exe_ctx_ref.SetFrameSP(frame_sp); 3475 } 3476 } 3477 } 3478 } 3479 3480 ValueObject::EvaluationPoint::EvaluationPoint( 3481 const ValueObject::EvaluationPoint &rhs) 3482 : m_mod_id(), m_exe_ctx_ref(rhs.m_exe_ctx_ref), m_needs_update(true) {} 3483 3484 ValueObject::EvaluationPoint::~EvaluationPoint() {} 3485 3486 // This function checks the EvaluationPoint against the current process state. 3487 // If the current 3488 // state matches the evaluation point, or the evaluation point is already 3489 // invalid, then we return 3490 // false, meaning "no change". If the current state is different, we update our 3491 // state, and return 3492 // true meaning "yes, change". If we did see a change, we also set 3493 // m_needs_update to true, so 3494 // future calls to NeedsUpdate will return true. 3495 // exe_scope will be set to the current execution context scope. 3496 3497 bool ValueObject::EvaluationPoint::SyncWithProcessState( 3498 bool accept_invalid_exe_ctx) { 3499 // Start with the target, if it is NULL, then we're obviously not going to get 3500 // any further: 3501 const bool thread_and_frame_only_if_stopped = true; 3502 ExecutionContext exe_ctx( 3503 m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped)); 3504 3505 if (exe_ctx.GetTargetPtr() == NULL) 3506 return false; 3507 3508 // If we don't have a process nothing can change. 3509 Process *process = exe_ctx.GetProcessPtr(); 3510 if (process == NULL) 3511 return false; 3512 3513 // If our stop id is the current stop ID, nothing has changed: 3514 ProcessModID current_mod_id = process->GetModID(); 3515 3516 // If the current stop id is 0, either we haven't run yet, or the process 3517 // state has been cleared. 3518 // In either case, we aren't going to be able to sync with the process state. 3519 if (current_mod_id.GetStopID() == 0) 3520 return false; 3521 3522 bool changed = false; 3523 const bool was_valid = m_mod_id.IsValid(); 3524 if (was_valid) { 3525 if (m_mod_id == current_mod_id) { 3526 // Everything is already up to date in this object, no need to 3527 // update the execution context scope. 3528 changed = false; 3529 } else { 3530 m_mod_id = current_mod_id; 3531 m_needs_update = true; 3532 changed = true; 3533 } 3534 } 3535 3536 // Now re-look up the thread and frame in case the underlying objects have 3537 // gone away & been recreated. 3538 // That way we'll be sure to return a valid exe_scope. 3539 // If we used to have a thread or a frame but can't find it anymore, then mark 3540 // ourselves as invalid. 3541 3542 if (!accept_invalid_exe_ctx) { 3543 if (m_exe_ctx_ref.HasThreadRef()) { 3544 ThreadSP thread_sp(m_exe_ctx_ref.GetThreadSP()); 3545 if (thread_sp) { 3546 if (m_exe_ctx_ref.HasFrameRef()) { 3547 StackFrameSP frame_sp(m_exe_ctx_ref.GetFrameSP()); 3548 if (!frame_sp) { 3549 // We used to have a frame, but now it is gone 3550 SetInvalid(); 3551 changed = was_valid; 3552 } 3553 } 3554 } else { 3555 // We used to have a thread, but now it is gone 3556 SetInvalid(); 3557 changed = was_valid; 3558 } 3559 } 3560 } 3561 3562 return changed; 3563 } 3564 3565 void ValueObject::EvaluationPoint::SetUpdated() { 3566 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); 3567 if (process_sp) 3568 m_mod_id = process_sp->GetModID(); 3569 m_needs_update = false; 3570 } 3571 3572 void ValueObject::ClearUserVisibleData(uint32_t clear_mask) { 3573 if ((clear_mask & eClearUserVisibleDataItemsValue) == 3574 eClearUserVisibleDataItemsValue) 3575 m_value_str.clear(); 3576 3577 if ((clear_mask & eClearUserVisibleDataItemsLocation) == 3578 eClearUserVisibleDataItemsLocation) 3579 m_location_str.clear(); 3580 3581 if ((clear_mask & eClearUserVisibleDataItemsSummary) == 3582 eClearUserVisibleDataItemsSummary) 3583 m_summary_str.clear(); 3584 3585 if ((clear_mask & eClearUserVisibleDataItemsDescription) == 3586 eClearUserVisibleDataItemsDescription) 3587 m_object_desc_str.clear(); 3588 3589 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == 3590 eClearUserVisibleDataItemsSyntheticChildren) { 3591 if (m_synthetic_value) 3592 m_synthetic_value = NULL; 3593 } 3594 3595 if ((clear_mask & eClearUserVisibleDataItemsValidator) == 3596 eClearUserVisibleDataItemsValidator) 3597 m_validation_result.reset(); 3598 } 3599 3600 SymbolContextScope *ValueObject::GetSymbolContextScope() { 3601 if (m_parent) { 3602 if (!m_parent->IsPointerOrReferenceType()) 3603 return m_parent->GetSymbolContextScope(); 3604 } 3605 return NULL; 3606 } 3607 3608 lldb::ValueObjectSP 3609 ValueObject::CreateValueObjectFromExpression(llvm::StringRef name, 3610 llvm::StringRef expression, 3611 const ExecutionContext &exe_ctx) { 3612 return CreateValueObjectFromExpression(name, expression, exe_ctx, 3613 EvaluateExpressionOptions()); 3614 } 3615 3616 lldb::ValueObjectSP ValueObject::CreateValueObjectFromExpression( 3617 llvm::StringRef name, llvm::StringRef expression, 3618 const ExecutionContext &exe_ctx, const EvaluateExpressionOptions &options) { 3619 lldb::ValueObjectSP retval_sp; 3620 lldb::TargetSP target_sp(exe_ctx.GetTargetSP()); 3621 if (!target_sp) 3622 return retval_sp; 3623 if (expression.empty()) 3624 return retval_sp; 3625 target_sp->EvaluateExpression(expression, exe_ctx.GetFrameSP().get(), 3626 retval_sp, options); 3627 if (retval_sp && !name.empty()) 3628 retval_sp->SetName(ConstString(name)); 3629 return retval_sp; 3630 } 3631 3632 lldb::ValueObjectSP ValueObject::CreateValueObjectFromAddress( 3633 llvm::StringRef name, uint64_t address, 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.empty()) 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 llvm::StringRef 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.empty()) 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