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