1 //===-- ValueObject.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Core/ValueObject.h" 11 12 // C Includes 13 #include <stdlib.h> 14 15 // C++ Includes 16 // Other libraries and framework includes 17 #include "llvm/Support/raw_ostream.h" 18 #include "clang/AST/Type.h" 19 20 // Project includes 21 #include "lldb/Core/DataBufferHeap.h" 22 #include "lldb/Core/StreamString.h" 23 #include "lldb/Core/ValueObjectChild.h" 24 #include "lldb/Core/ValueObjectConstResult.h" 25 #include "lldb/Core/ValueObjectList.h" 26 27 #include "lldb/Host/Endian.h" 28 29 #include "lldb/Symbol/ClangASTType.h" 30 #include "lldb/Symbol/ClangASTContext.h" 31 #include "lldb/Symbol/Type.h" 32 33 #include "lldb/Target/ExecutionContext.h" 34 #include "lldb/Target/LanguageRuntime.h" 35 #include "lldb/Target/Process.h" 36 #include "lldb/Target/RegisterContext.h" 37 #include "lldb/Target/Target.h" 38 #include "lldb/Target/Thread.h" 39 40 using namespace lldb; 41 using namespace lldb_private; 42 43 static lldb::user_id_t g_value_obj_uid = 0; 44 45 //---------------------------------------------------------------------- 46 // ValueObject constructor 47 //---------------------------------------------------------------------- 48 ValueObject::ValueObject (ValueObject &parent) : 49 UserID (++g_value_obj_uid), // Unique identifier for every value object 50 m_parent (&parent), 51 m_update_point (parent.GetUpdatePoint ()), 52 m_name (), 53 m_data (), 54 m_value (), 55 m_error (), 56 m_value_str (), 57 m_old_value_str (), 58 m_location_str (), 59 m_summary_str (), 60 m_object_desc_str (), 61 m_children (), 62 m_synthetic_children (), 63 m_dynamic_value_sp (), 64 m_format (eFormatDefault), 65 m_value_is_valid (false), 66 m_value_did_change (false), 67 m_children_count_valid (false), 68 m_old_value_valid (false), 69 m_pointers_point_to_load_addrs (false), 70 m_is_deref_of_parent (false) 71 { 72 } 73 74 //---------------------------------------------------------------------- 75 // ValueObject constructor 76 //---------------------------------------------------------------------- 77 ValueObject::ValueObject (ExecutionContextScope *exe_scope) : 78 UserID (++g_value_obj_uid), // Unique identifier for every value object 79 m_parent (NULL), 80 m_update_point (exe_scope), 81 m_name (), 82 m_data (), 83 m_value (), 84 m_error (), 85 m_value_str (), 86 m_old_value_str (), 87 m_location_str (), 88 m_summary_str (), 89 m_object_desc_str (), 90 m_children (), 91 m_synthetic_children (), 92 m_dynamic_value_sp (), 93 m_format (eFormatDefault), 94 m_value_is_valid (false), 95 m_value_did_change (false), 96 m_children_count_valid (false), 97 m_old_value_valid (false), 98 m_pointers_point_to_load_addrs (false), 99 m_is_deref_of_parent (false) 100 { 101 } 102 103 //---------------------------------------------------------------------- 104 // Destructor 105 //---------------------------------------------------------------------- 106 ValueObject::~ValueObject () 107 { 108 } 109 110 bool 111 ValueObject::UpdateValueIfNeeded () 112 { 113 // If this is a constant value, then our success is predicated on whether 114 // we have an error or not 115 if (GetIsConstant()) 116 return m_error.Success(); 117 118 bool first_update = m_update_point.IsFirstEvaluation(); 119 120 if (m_update_point.NeedsUpdating()) 121 { 122 m_update_point.SetUpdated(); 123 124 // Save the old value using swap to avoid a string copy which 125 // also will clear our m_value_str 126 if (m_value_str.empty()) 127 { 128 m_old_value_valid = false; 129 } 130 else 131 { 132 m_old_value_valid = true; 133 m_old_value_str.swap (m_value_str); 134 m_value_str.clear(); 135 } 136 m_location_str.clear(); 137 m_summary_str.clear(); 138 m_object_desc_str.clear(); 139 140 const bool value_was_valid = GetValueIsValid(); 141 SetValueDidChange (false); 142 143 m_error.Clear(); 144 145 // Call the pure virtual function to update the value 146 bool success = UpdateValue (); 147 148 SetValueIsValid (success); 149 150 if (first_update) 151 SetValueDidChange (false); 152 else if (!m_value_did_change && success == false) 153 { 154 // The value wasn't gotten successfully, so we mark this 155 // as changed if the value used to be valid and now isn't 156 SetValueDidChange (value_was_valid); 157 } 158 } 159 return m_error.Success(); 160 } 161 162 const DataExtractor & 163 ValueObject::GetDataExtractor () const 164 { 165 return m_data; 166 } 167 168 DataExtractor & 169 ValueObject::GetDataExtractor () 170 { 171 return m_data; 172 } 173 174 const Error & 175 ValueObject::GetError() const 176 { 177 return m_error; 178 } 179 180 const ConstString & 181 ValueObject::GetName() const 182 { 183 return m_name; 184 } 185 186 const char * 187 ValueObject::GetLocationAsCString () 188 { 189 if (UpdateValueIfNeeded()) 190 { 191 if (m_location_str.empty()) 192 { 193 StreamString sstr; 194 195 switch (m_value.GetValueType()) 196 { 197 default: 198 break; 199 200 case Value::eValueTypeScalar: 201 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo) 202 { 203 RegisterInfo *reg_info = m_value.GetRegisterInfo(); 204 if (reg_info) 205 { 206 if (reg_info->name) 207 m_location_str = reg_info->name; 208 else if (reg_info->alt_name) 209 m_location_str = reg_info->alt_name; 210 break; 211 } 212 } 213 m_location_str = "scalar"; 214 break; 215 216 case Value::eValueTypeLoadAddress: 217 case Value::eValueTypeFileAddress: 218 case Value::eValueTypeHostAddress: 219 { 220 uint32_t addr_nibble_size = m_data.GetAddressByteSize() * 2; 221 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS)); 222 m_location_str.swap(sstr.GetString()); 223 } 224 break; 225 } 226 } 227 } 228 return m_location_str.c_str(); 229 } 230 231 Value & 232 ValueObject::GetValue() 233 { 234 return m_value; 235 } 236 237 const Value & 238 ValueObject::GetValue() const 239 { 240 return m_value; 241 } 242 243 bool 244 ValueObject::ResolveValue (Scalar &scalar) 245 { 246 ExecutionContext exe_ctx; 247 ExecutionContextScope *exe_scope = GetExecutionContextScope(); 248 if (exe_scope) 249 exe_scope->CalculateExecutionContext(exe_ctx); 250 scalar = m_value.ResolveValue(&exe_ctx, GetClangAST ()); 251 return scalar.IsValid(); 252 } 253 254 bool 255 ValueObject::GetValueIsValid () const 256 { 257 return m_value_is_valid; 258 } 259 260 261 void 262 ValueObject::SetValueIsValid (bool b) 263 { 264 m_value_is_valid = b; 265 } 266 267 bool 268 ValueObject::GetValueDidChange () 269 { 270 GetValueAsCString (); 271 return m_value_did_change; 272 } 273 274 void 275 ValueObject::SetValueDidChange (bool value_changed) 276 { 277 m_value_did_change = value_changed; 278 } 279 280 ValueObjectSP 281 ValueObject::GetChildAtIndex (uint32_t idx, bool can_create) 282 { 283 ValueObjectSP child_sp; 284 if (idx < GetNumChildren()) 285 { 286 // Check if we have already made the child value object? 287 if (can_create && m_children[idx].get() == NULL) 288 { 289 // No we haven't created the child at this index, so lets have our 290 // subclass do it and cache the result for quick future access. 291 m_children[idx] = CreateChildAtIndex (idx, false, 0); 292 } 293 294 child_sp = m_children[idx]; 295 } 296 return child_sp; 297 } 298 299 uint32_t 300 ValueObject::GetIndexOfChildWithName (const ConstString &name) 301 { 302 bool omit_empty_base_classes = true; 303 return ClangASTContext::GetIndexOfChildWithName (GetClangAST(), 304 GetClangType(), 305 name.GetCString(), 306 omit_empty_base_classes); 307 } 308 309 ValueObjectSP 310 ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create) 311 { 312 // when getting a child by name, it could be buried inside some base 313 // classes (which really aren't part of the expression path), so we 314 // need a vector of indexes that can get us down to the correct child 315 std::vector<uint32_t> child_indexes; 316 clang::ASTContext *clang_ast = GetClangAST(); 317 void *clang_type = GetClangType(); 318 bool omit_empty_base_classes = true; 319 const size_t num_child_indexes = ClangASTContext::GetIndexOfChildMemberWithName (clang_ast, 320 clang_type, 321 name.GetCString(), 322 omit_empty_base_classes, 323 child_indexes); 324 ValueObjectSP child_sp; 325 if (num_child_indexes > 0) 326 { 327 std::vector<uint32_t>::const_iterator pos = child_indexes.begin (); 328 std::vector<uint32_t>::const_iterator end = child_indexes.end (); 329 330 child_sp = GetChildAtIndex(*pos, can_create); 331 for (++pos; pos != end; ++pos) 332 { 333 if (child_sp) 334 { 335 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create)); 336 child_sp = new_child_sp; 337 } 338 else 339 { 340 child_sp.reset(); 341 } 342 343 } 344 } 345 return child_sp; 346 } 347 348 349 uint32_t 350 ValueObject::GetNumChildren () 351 { 352 if (!m_children_count_valid) 353 { 354 SetNumChildren (CalculateNumChildren()); 355 } 356 return m_children.size(); 357 } 358 void 359 ValueObject::SetNumChildren (uint32_t num_children) 360 { 361 m_children_count_valid = true; 362 m_children.resize(num_children); 363 } 364 365 void 366 ValueObject::SetName (const char *name) 367 { 368 m_name.SetCString(name); 369 } 370 371 void 372 ValueObject::SetName (const ConstString &name) 373 { 374 m_name = name; 375 } 376 377 ValueObjectSP 378 ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index) 379 { 380 ValueObjectSP valobj_sp; 381 bool omit_empty_base_classes = true; 382 383 std::string child_name_str; 384 uint32_t child_byte_size = 0; 385 int32_t child_byte_offset = 0; 386 uint32_t child_bitfield_bit_size = 0; 387 uint32_t child_bitfield_bit_offset = 0; 388 bool child_is_base_class = false; 389 bool child_is_deref_of_parent = false; 390 391 const bool transparent_pointers = synthetic_array_member == false; 392 clang::ASTContext *clang_ast = GetClangAST(); 393 clang_type_t clang_type = GetClangType(); 394 clang_type_t child_clang_type; 395 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (clang_ast, 396 GetName().GetCString(), 397 clang_type, 398 idx, 399 transparent_pointers, 400 omit_empty_base_classes, 401 child_name_str, 402 child_byte_size, 403 child_byte_offset, 404 child_bitfield_bit_size, 405 child_bitfield_bit_offset, 406 child_is_base_class, 407 child_is_deref_of_parent); 408 if (child_clang_type && child_byte_size) 409 { 410 if (synthetic_index) 411 child_byte_offset += child_byte_size * synthetic_index; 412 413 ConstString child_name; 414 if (!child_name_str.empty()) 415 child_name.SetCString (child_name_str.c_str()); 416 417 valobj_sp.reset (new ValueObjectChild (*this, 418 clang_ast, 419 child_clang_type, 420 child_name, 421 child_byte_size, 422 child_byte_offset, 423 child_bitfield_bit_size, 424 child_bitfield_bit_offset, 425 child_is_base_class, 426 child_is_deref_of_parent)); 427 if (m_pointers_point_to_load_addrs) 428 valobj_sp->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs); 429 } 430 return valobj_sp; 431 } 432 433 const char * 434 ValueObject::GetSummaryAsCString () 435 { 436 if (UpdateValueIfNeeded ()) 437 { 438 if (m_summary_str.empty()) 439 { 440 clang_type_t clang_type = GetClangType(); 441 442 // See if this is a pointer to a C string? 443 if (clang_type) 444 { 445 StreamString sstr; 446 clang_type_t elem_or_pointee_clang_type; 447 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, 448 GetClangAST(), 449 &elem_or_pointee_clang_type)); 450 451 ExecutionContextScope *exe_scope = GetExecutionContextScope(); 452 if (exe_scope) 453 { 454 if (type_flags.AnySet (ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) && 455 ClangASTContext::IsCharType (elem_or_pointee_clang_type)) 456 { 457 Process *process = exe_scope->CalculateProcess(); 458 if (process != NULL) 459 { 460 lldb::addr_t cstr_address = LLDB_INVALID_ADDRESS; 461 AddressType cstr_address_type = eAddressTypeInvalid; 462 463 size_t cstr_len = 0; 464 if (type_flags.Test (ClangASTContext::eTypeIsArray)) 465 { 466 // We have an array 467 cstr_len = ClangASTContext::GetArraySize (clang_type); 468 cstr_address = GetAddressOf (cstr_address_type, true); 469 } 470 else 471 { 472 // We have a pointer 473 cstr_address = GetPointerValue (cstr_address_type, true); 474 } 475 if (cstr_address != LLDB_INVALID_ADDRESS) 476 { 477 DataExtractor data; 478 size_t bytes_read = 0; 479 std::vector<char> data_buffer; 480 Error error; 481 if (cstr_len > 0) 482 { 483 data_buffer.resize(cstr_len); 484 data.SetData (&data_buffer.front(), data_buffer.size(), lldb::endian::InlHostByteOrder()); 485 bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), cstr_len, error); 486 if (bytes_read > 0) 487 { 488 sstr << '"'; 489 data.Dump (&sstr, 490 0, // Start offset in "data" 491 eFormatChar, // Print as characters 492 1, // Size of item (1 byte for a char!) 493 bytes_read, // How many bytes to print? 494 UINT32_MAX, // num per line 495 LLDB_INVALID_ADDRESS,// base address 496 0, // bitfield bit size 497 0); // bitfield bit offset 498 sstr << '"'; 499 } 500 } 501 else 502 { 503 const size_t k_max_buf_size = 256; 504 data_buffer.resize (k_max_buf_size + 1); 505 // NULL terminate in case we don't get the entire C string 506 data_buffer.back() = '\0'; 507 508 sstr << '"'; 509 510 data.SetData (&data_buffer.front(), data_buffer.size(), endian::InlHostByteOrder()); 511 while ((bytes_read = process->ReadMemory (cstr_address, &data_buffer.front(), k_max_buf_size, error)) > 0) 512 { 513 size_t len = strlen(&data_buffer.front()); 514 if (len == 0) 515 break; 516 if (len > bytes_read) 517 len = bytes_read; 518 519 data.Dump (&sstr, 520 0, // Start offset in "data" 521 eFormatChar, // Print as characters 522 1, // Size of item (1 byte for a char!) 523 len, // How many bytes to print? 524 UINT32_MAX, // num per line 525 LLDB_INVALID_ADDRESS,// base address 526 0, // bitfield bit size 527 0); // bitfield bit offset 528 529 if (len < k_max_buf_size) 530 break; 531 cstr_address += k_max_buf_size; 532 } 533 sstr << '"'; 534 } 535 } 536 } 537 538 if (sstr.GetSize() > 0) 539 m_summary_str.assign (sstr.GetData(), sstr.GetSize()); 540 } 541 else if (ClangASTContext::IsFunctionPointerType (clang_type)) 542 { 543 AddressType func_ptr_address_type = eAddressTypeInvalid; 544 lldb::addr_t func_ptr_address = GetPointerValue (func_ptr_address_type, true); 545 546 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS) 547 { 548 switch (func_ptr_address_type) 549 { 550 case eAddressTypeInvalid: 551 case eAddressTypeFile: 552 break; 553 554 case eAddressTypeLoad: 555 { 556 Address so_addr; 557 Target *target = exe_scope->CalculateTarget(); 558 if (target && target->GetSectionLoadList().IsEmpty() == false) 559 { 560 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr)) 561 { 562 so_addr.Dump (&sstr, 563 exe_scope, 564 Address::DumpStyleResolvedDescription, 565 Address::DumpStyleSectionNameOffset); 566 } 567 } 568 } 569 break; 570 571 case eAddressTypeHost: 572 break; 573 } 574 } 575 if (sstr.GetSize() > 0) 576 { 577 m_summary_str.assign (1, '('); 578 m_summary_str.append (sstr.GetData(), sstr.GetSize()); 579 m_summary_str.append (1, ')'); 580 } 581 } 582 } 583 } 584 } 585 } 586 if (m_summary_str.empty()) 587 return NULL; 588 return m_summary_str.c_str(); 589 } 590 591 const char * 592 ValueObject::GetObjectDescription () 593 { 594 if (!m_object_desc_str.empty()) 595 return m_object_desc_str.c_str(); 596 597 if (!UpdateValueIfNeeded ()) 598 return NULL; 599 600 ExecutionContextScope *exe_scope = GetExecutionContextScope(); 601 if (exe_scope == NULL) 602 return NULL; 603 604 Process *process = exe_scope->CalculateProcess(); 605 if (process == NULL) 606 return NULL; 607 608 StreamString s; 609 610 lldb::LanguageType language = GetObjectRuntimeLanguage(); 611 LanguageRuntime *runtime = process->GetLanguageRuntime(language); 612 613 if (runtime == NULL) 614 { 615 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway... 616 clang_type_t opaque_qual_type = GetClangType(); 617 if (opaque_qual_type != NULL) 618 { 619 bool is_signed; 620 if (ClangASTContext::IsIntegerType (opaque_qual_type, is_signed) 621 || ClangASTContext::IsPointerType (opaque_qual_type)) 622 { 623 runtime = process->GetLanguageRuntime(lldb::eLanguageTypeObjC); 624 } 625 } 626 } 627 628 if (runtime && runtime->GetObjectDescription(s, *this)) 629 { 630 m_object_desc_str.append (s.GetData()); 631 } 632 633 if (m_object_desc_str.empty()) 634 return NULL; 635 else 636 return m_object_desc_str.c_str(); 637 } 638 639 const char * 640 ValueObject::GetValueAsCString () 641 { 642 // If our byte size is zero this is an aggregate type that has children 643 if (ClangASTContext::IsAggregateType (GetClangType()) == false) 644 { 645 if (UpdateValueIfNeeded()) 646 { 647 if (m_value_str.empty()) 648 { 649 const Value::ContextType context_type = m_value.GetContextType(); 650 651 switch (context_type) 652 { 653 case Value::eContextTypeClangType: 654 case Value::eContextTypeLLDBType: 655 case Value::eContextTypeVariable: 656 { 657 clang_type_t clang_type = GetClangType (); 658 if (clang_type) 659 { 660 StreamString sstr; 661 if (m_format == eFormatDefault) 662 m_format = ClangASTType::GetFormat(clang_type); 663 664 if (ClangASTType::DumpTypeValue (GetClangAST(), // The clang AST 665 clang_type, // The clang type to display 666 &sstr, 667 m_format, // Format to display this type with 668 m_data, // Data to extract from 669 0, // Byte offset into "m_data" 670 GetByteSize(), // Byte size of item in "m_data" 671 GetBitfieldBitSize(), // Bitfield bit size 672 GetBitfieldBitOffset())) // Bitfield bit offset 673 m_value_str.swap(sstr.GetString()); 674 else 675 m_value_str.clear(); 676 } 677 } 678 break; 679 680 case Value::eContextTypeRegisterInfo: 681 { 682 const RegisterInfo *reg_info = m_value.GetRegisterInfo(); 683 if (reg_info) 684 { 685 StreamString reg_sstr; 686 m_data.Dump(®_sstr, 0, reg_info->format, reg_info->byte_size, 1, UINT32_MAX, LLDB_INVALID_ADDRESS, 0, 0); 687 m_value_str.swap(reg_sstr.GetString()); 688 } 689 } 690 break; 691 692 default: 693 break; 694 } 695 } 696 697 if (!m_value_did_change && m_old_value_valid) 698 { 699 // The value was gotten successfully, so we consider the 700 // value as changed if the value string differs 701 SetValueDidChange (m_old_value_str != m_value_str); 702 } 703 } 704 } 705 if (m_value_str.empty()) 706 return NULL; 707 return m_value_str.c_str(); 708 } 709 710 addr_t 711 ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address) 712 { 713 switch (m_value.GetValueType()) 714 { 715 case Value::eValueTypeScalar: 716 if (scalar_is_load_address) 717 { 718 address_type = eAddressTypeLoad; 719 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 720 } 721 break; 722 723 case Value::eValueTypeLoadAddress: 724 case Value::eValueTypeFileAddress: 725 case Value::eValueTypeHostAddress: 726 { 727 address_type = m_value.GetValueAddressType (); 728 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 729 } 730 break; 731 } 732 address_type = eAddressTypeInvalid; 733 return LLDB_INVALID_ADDRESS; 734 } 735 736 addr_t 737 ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address) 738 { 739 lldb::addr_t address = LLDB_INVALID_ADDRESS; 740 address_type = eAddressTypeInvalid; 741 switch (m_value.GetValueType()) 742 { 743 case Value::eValueTypeScalar: 744 if (scalar_is_load_address) 745 { 746 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 747 address_type = eAddressTypeLoad; 748 } 749 break; 750 751 case Value::eValueTypeLoadAddress: 752 case Value::eValueTypeFileAddress: 753 case Value::eValueTypeHostAddress: 754 { 755 uint32_t data_offset = 0; 756 address = m_data.GetPointer(&data_offset); 757 address_type = m_value.GetValueAddressType(); 758 if (address_type == eAddressTypeInvalid) 759 address_type = eAddressTypeLoad; 760 } 761 break; 762 } 763 764 if (m_pointers_point_to_load_addrs) 765 address_type = eAddressTypeLoad; 766 767 return address; 768 } 769 770 bool 771 ValueObject::SetValueFromCString (const char *value_str) 772 { 773 // Make sure our value is up to date first so that our location and location 774 // type is valid. 775 if (!UpdateValueIfNeeded()) 776 return false; 777 778 uint32_t count = 0; 779 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); 780 781 char *end = NULL; 782 const size_t byte_size = GetByteSize(); 783 switch (encoding) 784 { 785 case eEncodingInvalid: 786 return false; 787 788 case eEncodingUint: 789 if (byte_size > sizeof(unsigned long long)) 790 { 791 return false; 792 } 793 else 794 { 795 unsigned long long ull_val = strtoull(value_str, &end, 0); 796 if (end && *end != '\0') 797 return false; 798 m_value = ull_val; 799 // Limit the bytes in our m_data appropriately. 800 m_value.GetScalar().GetData (m_data, byte_size); 801 } 802 break; 803 804 case eEncodingSint: 805 if (byte_size > sizeof(long long)) 806 { 807 return false; 808 } 809 else 810 { 811 long long sll_val = strtoll(value_str, &end, 0); 812 if (end && *end != '\0') 813 return false; 814 m_value = sll_val; 815 // Limit the bytes in our m_data appropriately. 816 m_value.GetScalar().GetData (m_data, byte_size); 817 } 818 break; 819 820 case eEncodingIEEE754: 821 { 822 const off_t byte_offset = GetByteOffset(); 823 uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size)); 824 if (dst != NULL) 825 { 826 // We are decoding a float into host byte order below, so make 827 // sure m_data knows what it contains. 828 m_data.SetByteOrder(lldb::endian::InlHostByteOrder()); 829 const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue ( 830 GetClangAST(), 831 GetClangType(), 832 value_str, 833 dst, 834 byte_size); 835 836 if (converted_byte_size == byte_size) 837 { 838 } 839 } 840 } 841 break; 842 843 case eEncodingVector: 844 return false; 845 846 default: 847 return false; 848 } 849 850 // If we have made it here the value is in m_data and we should write it 851 // out to the target 852 return Write (); 853 } 854 855 bool 856 ValueObject::Write () 857 { 858 // Clear the update ID so the next time we try and read the value 859 // we try and read it again. 860 m_update_point.SetNeedsUpdate(); 861 862 // TODO: when Value has a method to write a value back, call it from here. 863 return false; 864 865 } 866 867 lldb::LanguageType 868 ValueObject::GetObjectRuntimeLanguage () 869 { 870 clang_type_t opaque_qual_type = GetClangType(); 871 if (opaque_qual_type == NULL) 872 return lldb::eLanguageTypeC; 873 874 // If the type is a reference, then resolve it to what it refers to first: 875 clang::QualType qual_type (clang::QualType::getFromOpaquePtr(opaque_qual_type).getNonReferenceType()); 876 if (qual_type->isAnyPointerType()) 877 { 878 if (qual_type->isObjCObjectPointerType()) 879 return lldb::eLanguageTypeObjC; 880 881 clang::QualType pointee_type (qual_type->getPointeeType()); 882 if (pointee_type->getCXXRecordDeclForPointerType() != NULL) 883 return lldb::eLanguageTypeC_plus_plus; 884 if (pointee_type->isObjCObjectOrInterfaceType()) 885 return lldb::eLanguageTypeObjC; 886 if (pointee_type->isObjCClassType()) 887 return lldb::eLanguageTypeObjC; 888 } 889 else 890 { 891 if (ClangASTContext::IsObjCClassType (opaque_qual_type)) 892 return lldb::eLanguageTypeObjC; 893 if (ClangASTContext::IsCXXClassType (opaque_qual_type)) 894 return lldb::eLanguageTypeC_plus_plus; 895 } 896 897 return lldb::eLanguageTypeC; 898 } 899 900 void 901 ValueObject::AddSyntheticChild (const ConstString &key, ValueObjectSP& valobj_sp) 902 { 903 m_synthetic_children[key] = valobj_sp; 904 } 905 906 ValueObjectSP 907 ValueObject::GetSyntheticChild (const ConstString &key) const 908 { 909 ValueObjectSP synthetic_child_sp; 910 std::map<ConstString, ValueObjectSP>::const_iterator pos = m_synthetic_children.find (key); 911 if (pos != m_synthetic_children.end()) 912 synthetic_child_sp = pos->second; 913 return synthetic_child_sp; 914 } 915 916 bool 917 ValueObject::IsPointerType () 918 { 919 return ClangASTContext::IsPointerType (GetClangType()); 920 } 921 922 bool 923 ValueObject::IsIntegerType (bool &is_signed) 924 { 925 return ClangASTContext::IsIntegerType (GetClangType(), is_signed); 926 } 927 928 bool 929 ValueObject::IsPointerOrReferenceType () 930 { 931 return ClangASTContext::IsPointerOrReferenceType(GetClangType()); 932 } 933 934 ValueObjectSP 935 ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create) 936 { 937 ValueObjectSP synthetic_child_sp; 938 if (IsPointerType ()) 939 { 940 char index_str[64]; 941 snprintf(index_str, sizeof(index_str), "[%i]", index); 942 ConstString index_const_str(index_str); 943 // Check if we have already created a synthetic array member in this 944 // valid object. If we have we will re-use it. 945 synthetic_child_sp = GetSyntheticChild (index_const_str); 946 if (!synthetic_child_sp) 947 { 948 // We haven't made a synthetic array member for INDEX yet, so 949 // lets make one and cache it for any future reference. 950 synthetic_child_sp = CreateChildAtIndex(0, true, index); 951 952 // Cache the value if we got one back... 953 if (synthetic_child_sp) 954 AddSyntheticChild(index_const_str, synthetic_child_sp); 955 } 956 } 957 return synthetic_child_sp; 958 } 959 960 bool 961 ValueObject::SetDynamicValue () 962 { 963 if (!IsPointerOrReferenceType()) 964 return false; 965 966 // Check that the runtime class is correct for determining the most specific class. 967 // If it is a C++ class, see if it is dynamic: 968 969 return true; 970 } 971 972 bool 973 ValueObject::GetBaseClassPath (Stream &s) 974 { 975 if (IsBaseClass()) 976 { 977 bool parent_had_base_class = m_parent && m_parent->GetBaseClassPath (s); 978 clang_type_t clang_type = GetClangType(); 979 std::string cxx_class_name; 980 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name); 981 if (this_had_base_class) 982 { 983 if (parent_had_base_class) 984 s.PutCString("::"); 985 s.PutCString(cxx_class_name.c_str()); 986 } 987 return parent_had_base_class || this_had_base_class; 988 } 989 return false; 990 } 991 992 993 ValueObject * 994 ValueObject::GetNonBaseClassParent() 995 { 996 if (m_parent) 997 { 998 if (m_parent->IsBaseClass()) 999 return m_parent->GetNonBaseClassParent(); 1000 else 1001 return m_parent; 1002 } 1003 return NULL; 1004 } 1005 1006 void 1007 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes) 1008 { 1009 const bool is_deref_of_parent = IsDereferenceOfParent (); 1010 1011 if (is_deref_of_parent) 1012 s.PutCString("*("); 1013 1014 if (m_parent) 1015 m_parent->GetExpressionPath (s, qualify_cxx_base_classes); 1016 1017 if (!IsBaseClass()) 1018 { 1019 if (!is_deref_of_parent) 1020 { 1021 ValueObject *non_base_class_parent = GetNonBaseClassParent(); 1022 if (non_base_class_parent) 1023 { 1024 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType(); 1025 if (non_base_class_parent_clang_type) 1026 { 1027 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL); 1028 1029 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer) 1030 { 1031 s.PutCString("->"); 1032 } 1033 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) && 1034 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray)) 1035 { 1036 s.PutChar('.'); 1037 } 1038 } 1039 } 1040 1041 const char *name = GetName().GetCString(); 1042 if (name) 1043 { 1044 if (qualify_cxx_base_classes) 1045 { 1046 if (GetBaseClassPath (s)) 1047 s.PutCString("::"); 1048 } 1049 s.PutCString(name); 1050 } 1051 } 1052 } 1053 1054 if (is_deref_of_parent) 1055 s.PutChar(')'); 1056 } 1057 1058 void 1059 ValueObject::DumpValueObject 1060 ( 1061 Stream &s, 1062 ValueObject *valobj, 1063 const char *root_valobj_name, 1064 uint32_t ptr_depth, 1065 uint32_t curr_depth, 1066 uint32_t max_depth, 1067 bool show_types, 1068 bool show_location, 1069 bool use_objc, 1070 bool scope_already_checked, 1071 bool flat_output 1072 ) 1073 { 1074 if (valobj && valobj->UpdateValueIfNeeded ()) 1075 { 1076 clang_type_t clang_type = valobj->GetClangType(); 1077 1078 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); 1079 const char *err_cstr = NULL; 1080 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); 1081 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); 1082 1083 const bool print_valobj = flat_output == false || has_value; 1084 1085 if (print_valobj) 1086 { 1087 if (show_location) 1088 { 1089 s.Printf("%s: ", valobj->GetLocationAsCString()); 1090 } 1091 1092 s.Indent(); 1093 1094 // Always show the type for the top level items. 1095 if (show_types || (curr_depth == 0 && !flat_output)) 1096 s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>")); 1097 1098 1099 if (flat_output) 1100 { 1101 // If we are showing types, also qualify the C++ base classes 1102 const bool qualify_cxx_base_classes = show_types; 1103 valobj->GetExpressionPath(s, qualify_cxx_base_classes); 1104 s.PutCString(" ="); 1105 } 1106 else 1107 { 1108 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); 1109 s.Printf ("%s =", name_cstr); 1110 } 1111 1112 if (!scope_already_checked && !valobj->IsInScope()) 1113 { 1114 err_cstr = "error: out of scope"; 1115 } 1116 } 1117 1118 const char *val_cstr = NULL; 1119 1120 if (err_cstr == NULL) 1121 { 1122 val_cstr = valobj->GetValueAsCString(); 1123 err_cstr = valobj->GetError().AsCString(); 1124 } 1125 1126 if (err_cstr) 1127 { 1128 s.Printf (" error: %s\n", err_cstr); 1129 } 1130 else 1131 { 1132 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); 1133 if (print_valobj) 1134 { 1135 const char *sum_cstr = valobj->GetSummaryAsCString(); 1136 1137 if (val_cstr) 1138 s.Printf(" %s", val_cstr); 1139 1140 if (sum_cstr) 1141 s.Printf(" %s", sum_cstr); 1142 1143 if (use_objc) 1144 { 1145 const char *object_desc = valobj->GetObjectDescription(); 1146 if (object_desc) 1147 s.Printf(" %s\n", object_desc); 1148 else 1149 s.Printf (" [no Objective-C description available]\n"); 1150 return; 1151 } 1152 } 1153 1154 if (curr_depth < max_depth) 1155 { 1156 // We will show children for all concrete types. We won't show 1157 // pointer contents unless a pointer depth has been specified. 1158 // We won't reference contents unless the reference is the 1159 // root object (depth of zero). 1160 bool print_children = true; 1161 1162 // Use a new temporary pointer depth in case we override the 1163 // current pointer depth below... 1164 uint32_t curr_ptr_depth = ptr_depth; 1165 1166 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer); 1167 if (is_ptr || is_ref) 1168 { 1169 // We have a pointer or reference whose value is an address. 1170 // Make sure that address is not NULL 1171 AddressType ptr_address_type; 1172 if (valobj->GetPointerValue (ptr_address_type, true) == 0) 1173 print_children = false; 1174 1175 else if (is_ref && curr_depth == 0) 1176 { 1177 // If this is the root object (depth is zero) that we are showing 1178 // and it is a reference, and no pointer depth has been supplied 1179 // print out what it references. Don't do this at deeper depths 1180 // otherwise we can end up with infinite recursion... 1181 curr_ptr_depth = 1; 1182 } 1183 1184 if (curr_ptr_depth == 0) 1185 print_children = false; 1186 } 1187 1188 if (print_children) 1189 { 1190 const uint32_t num_children = valobj->GetNumChildren(); 1191 if (num_children) 1192 { 1193 if (flat_output) 1194 { 1195 if (print_valobj) 1196 s.EOL(); 1197 } 1198 else 1199 { 1200 if (print_valobj) 1201 s.PutCString(is_ref ? ": {\n" : " {\n"); 1202 s.IndentMore(); 1203 } 1204 1205 for (uint32_t idx=0; idx<num_children; ++idx) 1206 { 1207 ValueObjectSP child_sp(valobj->GetChildAtIndex(idx, true)); 1208 if (child_sp.get()) 1209 { 1210 DumpValueObject (s, 1211 child_sp.get(), 1212 NULL, 1213 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, 1214 curr_depth + 1, 1215 max_depth, 1216 show_types, 1217 show_location, 1218 false, 1219 true, 1220 flat_output); 1221 } 1222 } 1223 1224 if (!flat_output) 1225 { 1226 s.IndentLess(); 1227 s.Indent("}\n"); 1228 } 1229 } 1230 else if (has_children) 1231 { 1232 // Aggregate, no children... 1233 if (print_valobj) 1234 s.PutCString(" {}\n"); 1235 } 1236 else 1237 { 1238 if (print_valobj) 1239 s.EOL(); 1240 } 1241 1242 } 1243 else 1244 { 1245 s.EOL(); 1246 } 1247 } 1248 else 1249 { 1250 if (has_children && print_valobj) 1251 { 1252 s.PutCString("{...}\n"); 1253 } 1254 } 1255 } 1256 } 1257 } 1258 1259 1260 ValueObjectSP 1261 ValueObject::CreateConstantValue (const ConstString &name) 1262 { 1263 ValueObjectSP valobj_sp; 1264 1265 if (UpdateValueIfNeeded() && m_error.Success()) 1266 { 1267 ExecutionContextScope *exe_scope = GetExecutionContextScope(); 1268 if (exe_scope) 1269 { 1270 ExecutionContext exe_ctx; 1271 exe_scope->CalculateExecutionContext(exe_ctx); 1272 1273 clang::ASTContext *ast = GetClangAST (); 1274 1275 DataExtractor data; 1276 data.SetByteOrder (m_data.GetByteOrder()); 1277 data.SetAddressByteSize(m_data.GetAddressByteSize()); 1278 1279 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0); 1280 1281 valobj_sp.reset (new ValueObjectConstResult (exe_scope, 1282 ast, 1283 GetClangType(), 1284 name, 1285 data)); 1286 } 1287 } 1288 1289 if (!valobj_sp) 1290 { 1291 valobj_sp.reset (new ValueObjectConstResult (NULL, m_error)); 1292 } 1293 return valobj_sp; 1294 } 1295 1296 lldb::ValueObjectSP 1297 ValueObject::Dereference (Error &error) 1298 { 1299 lldb::ValueObjectSP valobj_sp; 1300 const bool is_pointer_type = IsPointerType(); 1301 if (is_pointer_type) 1302 { 1303 bool omit_empty_base_classes = true; 1304 1305 std::string child_name_str; 1306 uint32_t child_byte_size = 0; 1307 int32_t child_byte_offset = 0; 1308 uint32_t child_bitfield_bit_size = 0; 1309 uint32_t child_bitfield_bit_offset = 0; 1310 bool child_is_base_class = false; 1311 bool child_is_deref_of_parent = false; 1312 const bool transparent_pointers = false; 1313 clang::ASTContext *clang_ast = GetClangAST(); 1314 clang_type_t clang_type = GetClangType(); 1315 clang_type_t child_clang_type; 1316 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (clang_ast, 1317 GetName().GetCString(), 1318 clang_type, 1319 0, 1320 transparent_pointers, 1321 omit_empty_base_classes, 1322 child_name_str, 1323 child_byte_size, 1324 child_byte_offset, 1325 child_bitfield_bit_size, 1326 child_bitfield_bit_offset, 1327 child_is_base_class, 1328 child_is_deref_of_parent); 1329 if (child_clang_type && child_byte_size) 1330 { 1331 ConstString child_name; 1332 if (!child_name_str.empty()) 1333 child_name.SetCString (child_name_str.c_str()); 1334 1335 valobj_sp.reset (new ValueObjectChild (*this, 1336 clang_ast, 1337 child_clang_type, 1338 child_name, 1339 child_byte_size, 1340 child_byte_offset, 1341 child_bitfield_bit_size, 1342 child_bitfield_bit_offset, 1343 child_is_base_class, 1344 child_is_deref_of_parent)); 1345 } 1346 } 1347 1348 if (valobj_sp) 1349 { 1350 error.Clear(); 1351 } 1352 else 1353 { 1354 StreamString strm; 1355 GetExpressionPath(strm, true); 1356 1357 if (is_pointer_type) 1358 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 1359 else 1360 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 1361 } 1362 1363 return valobj_sp; 1364 } 1365 1366 lldb::ValueObjectSP 1367 ValueObject::AddressOf (Error &error) 1368 { 1369 lldb::ValueObjectSP valobj_sp; 1370 AddressType address_type = eAddressTypeInvalid; 1371 const bool scalar_is_load_address = false; 1372 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); 1373 error.Clear(); 1374 if (addr != LLDB_INVALID_ADDRESS) 1375 { 1376 switch (address_type) 1377 { 1378 default: 1379 case eAddressTypeInvalid: 1380 { 1381 StreamString expr_path_strm; 1382 GetExpressionPath(expr_path_strm, true); 1383 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); 1384 } 1385 break; 1386 1387 case eAddressTypeFile: 1388 case eAddressTypeLoad: 1389 case eAddressTypeHost: 1390 { 1391 clang::ASTContext *ast = GetClangAST(); 1392 clang_type_t clang_type = GetClangType(); 1393 if (ast && clang_type) 1394 { 1395 std::string name (1, '&'); 1396 name.append (m_name.AsCString("")); 1397 valobj_sp.reset (new ValueObjectConstResult (GetExecutionContextScope(), 1398 ast, 1399 ClangASTContext::CreatePointerType (ast, clang_type), 1400 ConstString (name.c_str()), 1401 addr, 1402 eAddressTypeInvalid, 1403 m_data.GetAddressByteSize())); 1404 } 1405 } 1406 break; 1407 } 1408 } 1409 return valobj_sp; 1410 } 1411 1412 ValueObject::EvaluationPoint::EvaluationPoint () : 1413 m_thread_id (LLDB_INVALID_UID), 1414 m_stop_id (0) 1415 { 1416 } 1417 1418 ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): 1419 m_needs_update (true), 1420 m_first_update (true), 1421 m_thread_id (LLDB_INVALID_UID), 1422 m_stop_id (0) 1423 1424 { 1425 ExecutionContext exe_ctx; 1426 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope, 1427 // and if so we want to cache that not the original. 1428 if (exe_scope) 1429 exe_scope->CalculateExecutionContext(exe_ctx); 1430 if (exe_ctx.target != NULL) 1431 { 1432 m_target_sp = exe_ctx.target->GetSP(); 1433 1434 if (exe_ctx.process == NULL) 1435 m_process_sp = exe_ctx.target->GetProcessSP(); 1436 else 1437 m_process_sp = exe_ctx.process->GetSP(); 1438 1439 if (m_process_sp != NULL) 1440 { 1441 m_stop_id = m_process_sp->GetStopID(); 1442 Thread *thread = NULL; 1443 1444 if (exe_ctx.thread == NULL) 1445 { 1446 if (use_selected) 1447 { 1448 thread = m_process_sp->GetThreadList().GetSelectedThread().get(); 1449 if (thread) 1450 computed_exe_scope = thread; 1451 } 1452 } 1453 else 1454 thread = exe_ctx.thread; 1455 1456 if (thread != NULL) 1457 { 1458 m_thread_id = thread->GetIndexID(); 1459 if (exe_ctx.frame == NULL) 1460 { 1461 if (use_selected) 1462 { 1463 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get(); 1464 if (frame) 1465 { 1466 m_stack_id = frame->GetStackID(); 1467 computed_exe_scope = frame; 1468 } 1469 } 1470 } 1471 else 1472 m_stack_id = exe_ctx.frame->GetStackID(); 1473 } 1474 } 1475 } 1476 m_exe_scope = computed_exe_scope; 1477 } 1478 1479 ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : 1480 m_exe_scope (rhs.m_exe_scope), 1481 m_needs_update(true), 1482 m_first_update(true), 1483 m_target_sp (rhs.m_target_sp), 1484 m_process_sp (rhs.m_process_sp), 1485 m_thread_id (rhs.m_thread_id), 1486 m_stack_id (rhs.m_stack_id), 1487 m_stop_id (0) 1488 { 1489 } 1490 1491 ValueObject::EvaluationPoint::~EvaluationPoint () 1492 { 1493 } 1494 1495 ExecutionContextScope * 1496 ValueObject::EvaluationPoint::GetExecutionContextScope () 1497 { 1498 // We have to update before giving out the scope, or we could be handing out stale pointers. 1499 SyncWithProcessState(); 1500 1501 return m_exe_scope; 1502 } 1503 1504 // This function checks the EvaluationPoint against the current process state. If the current 1505 // state matches the evaluation point, or the evaluation point is already invalid, then we return 1506 // false, meaning "no change". If the current state is different, we update our state, and return 1507 // true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so 1508 // future calls to NeedsUpdate will return true. 1509 1510 bool 1511 ValueObject::EvaluationPoint::SyncWithProcessState() 1512 { 1513 // If we're already invalid, we don't need to do anything, and nothing has changed: 1514 if (m_stop_id == LLDB_INVALID_UID) 1515 { 1516 // Can't update with an invalid state. 1517 m_needs_update = false; 1518 return false; 1519 } 1520 1521 // If we don't have a process nothing can change. 1522 if (!m_process_sp) 1523 return false; 1524 1525 // If our stop id is the current stop ID, nothing has changed: 1526 if (m_stop_id == m_process_sp->GetStopID()) 1527 return false; 1528 1529 m_stop_id = m_process_sp->GetStopID(); 1530 m_needs_update = true; 1531 m_exe_scope = m_process_sp.get(); 1532 1533 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either 1534 // doesn't, mark ourselves as invalid. 1535 1536 if (m_thread_id != LLDB_INVALID_THREAD_ID) 1537 { 1538 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); 1539 if (our_thread == NULL) 1540 SetInvalid(); 1541 else 1542 { 1543 m_exe_scope = our_thread; 1544 1545 if (m_stack_id.IsValid()) 1546 { 1547 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); 1548 if (our_frame == NULL) 1549 SetInvalid(); 1550 else 1551 m_exe_scope = our_frame; 1552 } 1553 } 1554 } 1555 return true; 1556 } 1557 1558 bool 1559 ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) 1560 { 1561 if (!IsValid()) 1562 return false; 1563 1564 bool needs_update = false; 1565 m_exe_scope = NULL; 1566 1567 // The target has to be non-null, and the 1568 Target *target = exe_scope->CalculateTarget(); 1569 if (target != NULL) 1570 { 1571 Target *old_target = m_target_sp.get(); 1572 assert (target == old_target); 1573 Process *process = exe_scope->CalculateProcess(); 1574 if (process != NULL) 1575 { 1576 // FOR NOW - assume you can't update variable objects across process boundaries. 1577 Process *old_process = m_process_sp.get(); 1578 assert (process == old_process); 1579 1580 lldb::user_id_t stop_id = process->GetStopID(); 1581 if (stop_id != m_stop_id) 1582 { 1583 needs_update = true; 1584 m_stop_id = stop_id; 1585 } 1586 // See if we're switching the thread or stack context. If no thread is given, this is 1587 // being evaluated in a global context. 1588 Thread *thread = exe_scope->CalculateThread(); 1589 if (thread != NULL) 1590 { 1591 lldb::user_id_t new_thread_index = thread->GetIndexID(); 1592 if (new_thread_index != m_thread_id) 1593 { 1594 needs_update = true; 1595 m_thread_id = new_thread_index; 1596 m_stack_id.Clear(); 1597 } 1598 1599 StackFrame *new_frame = exe_scope->CalculateStackFrame(); 1600 if (new_frame != NULL) 1601 { 1602 if (new_frame->GetStackID() != m_stack_id) 1603 { 1604 needs_update = true; 1605 m_stack_id = new_frame->GetStackID(); 1606 } 1607 } 1608 else 1609 { 1610 m_stack_id.Clear(); 1611 needs_update = true; 1612 } 1613 } 1614 else 1615 { 1616 // If this had been given a thread, and now there is none, we should update. 1617 // Otherwise we don't have to do anything. 1618 if (m_thread_id != LLDB_INVALID_UID) 1619 { 1620 m_thread_id = LLDB_INVALID_UID; 1621 m_stack_id.Clear(); 1622 needs_update = true; 1623 } 1624 } 1625 } 1626 else 1627 { 1628 // If there is no process, then we don't need to update anything. 1629 // But if we're switching from having a process to not, we should try to update. 1630 if (m_process_sp.get() != NULL) 1631 { 1632 needs_update = true; 1633 m_process_sp.reset(); 1634 m_thread_id = LLDB_INVALID_UID; 1635 m_stack_id.Clear(); 1636 } 1637 } 1638 } 1639 else 1640 { 1641 // If there's no target, nothing can change so we don't need to update anything. 1642 // But if we're switching from having a target to not, we should try to update. 1643 if (m_target_sp.get() != NULL) 1644 { 1645 needs_update = true; 1646 m_target_sp.reset(); 1647 m_process_sp.reset(); 1648 m_thread_id = LLDB_INVALID_UID; 1649 m_stack_id.Clear(); 1650 } 1651 } 1652 if (!m_needs_update) 1653 m_needs_update = needs_update; 1654 1655 return needs_update; 1656 } 1657