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