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