ValueObject.cpp revision 21f37ad875d4f50d1b4b3d307e120f6d27103730
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 50using namespace lldb; 51using namespace lldb_private; 52using namespace lldb_utility; 53 54static lldb::user_id_t g_value_obj_uid = 0; 55 56//---------------------------------------------------------------------- 57// ValueObject constructor 58//---------------------------------------------------------------------- 59ValueObject::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//---------------------------------------------------------------------- 105ValueObject::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//---------------------------------------------------------------------- 152ValueObject::~ValueObject () 153{ 154} 155 156bool 157ValueObject::UpdateValueIfNeeded (bool update_format) 158{ 159 return UpdateValueIfNeeded(m_last_format_mgr_dynamic, update_format); 160} 161 162bool 163ValueObject::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 217void 218ValueObject::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 254DataExtractor & 255ValueObject::GetDataExtractor () 256{ 257 UpdateValueIfNeeded(false); 258 return m_data; 259} 260 261const Error & 262ValueObject::GetError() 263{ 264 UpdateValueIfNeeded(false); 265 return m_error; 266} 267 268const ConstString & 269ValueObject::GetName() const 270{ 271 return m_name; 272} 273 274const char * 275ValueObject::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 319Value & 320ValueObject::GetValue() 321{ 322 return m_value; 323} 324 325const Value & 326ValueObject::GetValue() const 327{ 328 return m_value; 329} 330 331bool 332ValueObject::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 347bool 348ValueObject::GetValueIsValid () const 349{ 350 return m_value_is_valid; 351} 352 353 354void 355ValueObject::SetValueIsValid (bool b) 356{ 357 m_value_is_valid = b; 358} 359 360bool 361ValueObject::GetValueDidChange () 362{ 363 GetValueAsCString (); 364 return m_value_did_change; 365} 366 367void 368ValueObject::SetValueDidChange (bool value_changed) 369{ 370 m_value_did_change = value_changed; 371} 372 373ValueObjectSP 374ValueObject::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 396uint32_t 397ValueObject::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 406ValueObjectSP 407ValueObject::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 451uint32_t 452ValueObject::GetNumChildren () 453{ 454 if (!m_children_count_valid) 455 { 456 SetNumChildren (CalculateNumChildren()); 457 } 458 return m_children.size(); 459} 460void 461ValueObject::SetNumChildren (uint32_t num_children) 462{ 463 m_children_count_valid = true; 464 m_children.resize(num_children); 465} 466 467void 468ValueObject::SetName (const ConstString &name) 469{ 470 m_name = name; 471} 472 473ValueObject * 474ValueObject::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 537const char * 538ValueObject::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 617bool 618ValueObject::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 638void 639ValueObject::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 792const char * 793ValueObject::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 841const char * 842ValueObject::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 928unsigned long long 929ValueObject::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 944bool 945ValueObject::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 1017bool 1018ValueObject::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 1144addr_t 1145ValueObject::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 1173addr_t 1174ValueObject::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 1211bool 1212ValueObject::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 1310bool 1311ValueObject::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 1322lldb::LanguageType 1323ValueObject::GetObjectRuntimeLanguage () 1324{ 1325 return ClangASTType::GetMinimumLanguage (GetClangAST(), 1326 GetClangType()); 1327} 1328 1329void 1330ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) 1331{ 1332 m_synthetic_children[key] = valobj; 1333} 1334 1335ValueObjectSP 1336ValueObject::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 1345bool 1346ValueObject::IsPointerType () 1347{ 1348 return ClangASTContext::IsPointerType (GetClangType()); 1349} 1350 1351bool 1352ValueObject::IsArrayType () 1353{ 1354 return ClangASTContext::IsArrayType (GetClangType()); 1355} 1356 1357bool 1358ValueObject::IsScalarType () 1359{ 1360 return ClangASTContext::IsScalarType (GetClangType()); 1361} 1362 1363bool 1364ValueObject::IsIntegerType (bool &is_signed) 1365{ 1366 return ClangASTContext::IsIntegerType (GetClangType(), is_signed); 1367} 1368 1369bool 1370ValueObject::IsPointerOrReferenceType () 1371{ 1372 return ClangASTContext::IsPointerOrReferenceType (GetClangType()); 1373} 1374 1375bool 1376ValueObject::IsPossibleCPlusPlusDynamicType () 1377{ 1378 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType()); 1379} 1380 1381bool 1382ValueObject::IsPossibleDynamicType () 1383{ 1384 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); 1385} 1386 1387ValueObjectSP 1388ValueObject::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 1430ValueObjectSP 1431ValueObject::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 1462ValueObjectSP 1463ValueObject::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 1503lldb::ValueObjectSP 1504ValueObject::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 1548static const char* 1549SkipLeadingExpressionPathSeparators(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 1560lldb::ValueObjectSP 1561ValueObject::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 1585void 1586ValueObject::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 1601void 1602ValueObject::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 1645ValueObjectSP 1646ValueObject::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 1665ValueObjectSP 1666ValueObject::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 1684bool 1685ValueObject::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 1700bool 1701ValueObject::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 1721ValueObject * 1722ValueObject::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 1734void 1735ValueObject::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 1806lldb::ValueObjectSP 1807ValueObject::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 1869int 1870ValueObject::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 1955lldb::ValueObjectSP 1956ValueObject::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 root = root->GetChildMemberWithName(child_name, true); 2036 if (root.get()) // we know we are done, so just return 2037 { 2038 *first_unparsed = '\0'; 2039 *reason_to_stop = ValueObject::eEndOfString; 2040 *final_result = ValueObject::ePlain; 2041 return root; 2042 } 2043 else 2044 { 2045 *first_unparsed = expression_cstr; 2046 *reason_to_stop = ValueObject::eNoSuchChild; 2047 *final_result = ValueObject::eInvalid; 2048 return ValueObjectSP(); 2049 } 2050 } 2051 else // other layers do expand 2052 { 2053 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); 2054 root = root->GetChildMemberWithName(child_name, true); 2055 if (root.get()) // store the new root and move on 2056 { 2057 *first_unparsed = next_separator; 2058 *final_result = ValueObject::ePlain; 2059 continue; 2060 } 2061 else 2062 { 2063 *first_unparsed = expression_cstr; 2064 *reason_to_stop = ValueObject::eNoSuchChild; 2065 *final_result = ValueObject::eInvalid; 2066 return ValueObjectSP(); 2067 } 2068 } 2069 break; 2070 } 2071 case '[': 2072 { 2073 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* 2074 { 2075 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar... 2076 { 2077 if (options.m_no_synthetic_children) // ...only chance left is synthetic 2078 { 2079 *first_unparsed = expression_cstr; 2080 *reason_to_stop = ValueObject::eRangeOperatorInvalid; 2081 *final_result = ValueObject::eInvalid; 2082 return ValueObjectSP(); 2083 } 2084 } 2085 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields 2086 { 2087 *first_unparsed = expression_cstr; 2088 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; 2089 *final_result = ValueObject::eInvalid; 2090 return ValueObjectSP(); 2091 } 2092 } 2093 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays 2094 { 2095 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2096 { 2097 *first_unparsed = expression_cstr; 2098 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2099 *final_result = ValueObject::eInvalid; 2100 return ValueObjectSP(); 2101 } 2102 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it 2103 { 2104 *first_unparsed = expression_cstr+2; 2105 *reason_to_stop = ValueObject::eArrayRangeOperatorMet; 2106 *final_result = ValueObject::eUnboundedRange; 2107 return root; 2108 } 2109 } 2110 const char *separator_position = ::strchr(expression_cstr+1,'-'); 2111 const char *close_bracket_position = ::strchr(expression_cstr+1,']'); 2112 if (!close_bracket_position) // if there is no ], this is a syntax error 2113 { 2114 *first_unparsed = expression_cstr; 2115 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2116 *final_result = ValueObject::eInvalid; 2117 return ValueObjectSP(); 2118 } 2119 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] 2120 { 2121 char *end = NULL; 2122 unsigned long index = ::strtoul (expression_cstr+1, &end, 0); 2123 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2124 { 2125 *first_unparsed = expression_cstr; 2126 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2127 *final_result = ValueObject::eInvalid; 2128 return ValueObjectSP(); 2129 } 2130 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays 2131 { 2132 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2133 { 2134 *first_unparsed = expression_cstr+2; 2135 *reason_to_stop = ValueObject::eArrayRangeOperatorMet; 2136 *final_result = ValueObject::eUnboundedRange; 2137 return root; 2138 } 2139 else 2140 { 2141 *first_unparsed = expression_cstr; 2142 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2143 *final_result = ValueObject::eInvalid; 2144 return ValueObjectSP(); 2145 } 2146 } 2147 // from here on we do have a valid index 2148 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2149 { 2150 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); 2151 if (!child_valobj_sp) 2152 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true); 2153 if (!child_valobj_sp) 2154 if (root->HasSyntheticValue() && root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetNumChildren() > index) 2155 child_valobj_sp = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true); 2156 if (child_valobj_sp) 2157 { 2158 root = child_valobj_sp; 2159 *first_unparsed = end+1; // skip ] 2160 *final_result = ValueObject::ePlain; 2161 continue; 2162 } 2163 else 2164 { 2165 *first_unparsed = expression_cstr; 2166 *reason_to_stop = ValueObject::eNoSuchChild; 2167 *final_result = ValueObject::eInvalid; 2168 return ValueObjectSP(); 2169 } 2170 } 2171 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) 2172 { 2173 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 2174 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2175 { 2176 Error error; 2177 root = root->Dereference(error); 2178 if (error.Fail() || !root.get()) 2179 { 2180 *first_unparsed = expression_cstr; 2181 *reason_to_stop = ValueObject::eDereferencingFailed; 2182 *final_result = ValueObject::eInvalid; 2183 return ValueObjectSP(); 2184 } 2185 else 2186 { 2187 *what_next = eNothing; 2188 continue; 2189 } 2190 } 2191 else 2192 { 2193 if (ClangASTType::GetMinimumLanguage(root->GetClangAST(), 2194 root->GetClangType()) == lldb::eLanguageTypeObjC 2195 && 2196 ClangASTContext::IsPointerType(ClangASTType::GetPointeeType(root->GetClangType())) == false 2197 && 2198 root->HasSyntheticValue() 2199 && 2200 options.m_no_synthetic_children == false) 2201 { 2202 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true); 2203 } 2204 else 2205 root = root->GetSyntheticArrayMemberFromPointer(index, true); 2206 if (!root.get()) 2207 { 2208 *first_unparsed = expression_cstr; 2209 *reason_to_stop = ValueObject::eNoSuchChild; 2210 *final_result = ValueObject::eInvalid; 2211 return ValueObjectSP(); 2212 } 2213 else 2214 { 2215 *first_unparsed = end+1; // skip ] 2216 *final_result = ValueObject::ePlain; 2217 continue; 2218 } 2219 } 2220 } 2221 else if (ClangASTContext::IsScalarType(root_clang_type)) 2222 { 2223 root = root->GetSyntheticBitFieldChild(index, index, true); 2224 if (!root.get()) 2225 { 2226 *first_unparsed = expression_cstr; 2227 *reason_to_stop = ValueObject::eNoSuchChild; 2228 *final_result = ValueObject::eInvalid; 2229 return ValueObjectSP(); 2230 } 2231 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing 2232 { 2233 *first_unparsed = end+1; // skip ] 2234 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; 2235 *final_result = ValueObject::eBitfield; 2236 return root; 2237 } 2238 } 2239 else if (root->HasSyntheticValue() && options.m_no_synthetic_children) 2240 { 2241 root = root->GetSyntheticValue(lldb::eUseSyntheticFilter)->GetChildAtIndex(index, true); 2242 if (!root.get()) 2243 { 2244 *first_unparsed = expression_cstr; 2245 *reason_to_stop = ValueObject::eNoSuchChild; 2246 *final_result = ValueObject::eInvalid; 2247 return ValueObjectSP(); 2248 } 2249 } 2250 else 2251 { 2252 *first_unparsed = expression_cstr; 2253 *reason_to_stop = ValueObject::eNoSuchChild; 2254 *final_result = ValueObject::eInvalid; 2255 return ValueObjectSP(); 2256 } 2257 } 2258 else // we have a low and a high index 2259 { 2260 char *end = NULL; 2261 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); 2262 if (!end || end != separator_position) // if something weird is in our way return an error 2263 { 2264 *first_unparsed = expression_cstr; 2265 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2266 *final_result = ValueObject::eInvalid; 2267 return ValueObjectSP(); 2268 } 2269 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); 2270 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2271 { 2272 *first_unparsed = expression_cstr; 2273 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2274 *final_result = ValueObject::eInvalid; 2275 return ValueObjectSP(); 2276 } 2277 if (index_lower > index_higher) // swap indices if required 2278 { 2279 unsigned long temp = index_lower; 2280 index_lower = index_higher; 2281 index_higher = temp; 2282 } 2283 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars 2284 { 2285 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 2286 if (!root.get()) 2287 { 2288 *first_unparsed = expression_cstr; 2289 *reason_to_stop = ValueObject::eNoSuchChild; 2290 *final_result = ValueObject::eInvalid; 2291 return ValueObjectSP(); 2292 } 2293 else 2294 { 2295 *first_unparsed = end+1; // skip ] 2296 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; 2297 *final_result = ValueObject::eBitfield; 2298 return root; 2299 } 2300 } 2301 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 2302 *what_next == ValueObject::eDereference && 2303 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2304 { 2305 Error error; 2306 root = root->Dereference(error); 2307 if (error.Fail() || !root.get()) 2308 { 2309 *first_unparsed = expression_cstr; 2310 *reason_to_stop = ValueObject::eDereferencingFailed; 2311 *final_result = ValueObject::eInvalid; 2312 return ValueObjectSP(); 2313 } 2314 else 2315 { 2316 *what_next = ValueObject::eNothing; 2317 continue; 2318 } 2319 } 2320 else 2321 { 2322 *first_unparsed = expression_cstr; 2323 *reason_to_stop = ValueObject::eArrayRangeOperatorMet; 2324 *final_result = ValueObject::eBoundedRange; 2325 return root; 2326 } 2327 } 2328 break; 2329 } 2330 default: // some non-separator is in the way 2331 { 2332 *first_unparsed = expression_cstr; 2333 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2334 *final_result = ValueObject::eInvalid; 2335 return ValueObjectSP(); 2336 break; 2337 } 2338 } 2339 } 2340} 2341 2342int 2343ValueObject::ExpandArraySliceExpression(const char* expression_cstr, 2344 const char** first_unparsed, 2345 lldb::ValueObjectSP root, 2346 lldb::ValueObjectListSP& list, 2347 ExpressionPathScanEndReason* reason_to_stop, 2348 ExpressionPathEndResultType* final_result, 2349 const GetValueForExpressionPathOptions& options, 2350 ExpressionPathAftermath* what_next) 2351{ 2352 if (!root.get()) 2353 return 0; 2354 2355 *first_unparsed = expression_cstr; 2356 2357 while (true) 2358 { 2359 2360 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr 2361 2362 lldb::clang_type_t root_clang_type = root->GetClangType(); 2363 lldb::clang_type_t pointee_clang_type; 2364 Flags root_clang_type_info,pointee_clang_type_info; 2365 2366 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); 2367 if (pointee_clang_type) 2368 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); 2369 2370 if (!expression_cstr || *expression_cstr == '\0') 2371 { 2372 *reason_to_stop = ValueObject::eEndOfString; 2373 list->Append(root); 2374 return 1; 2375 } 2376 2377 switch (*expression_cstr) 2378 { 2379 case '[': 2380 { 2381 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* 2382 { 2383 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! 2384 { 2385 *first_unparsed = expression_cstr; 2386 *reason_to_stop = ValueObject::eRangeOperatorInvalid; 2387 *final_result = ValueObject::eInvalid; 2388 return 0; 2389 } 2390 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields 2391 { 2392 *first_unparsed = expression_cstr; 2393 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; 2394 *final_result = ValueObject::eInvalid; 2395 return 0; 2396 } 2397 } 2398 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays 2399 { 2400 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2401 { 2402 *first_unparsed = expression_cstr; 2403 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2404 *final_result = ValueObject::eInvalid; 2405 return 0; 2406 } 2407 else // expand this into list 2408 { 2409 int max_index = root->GetNumChildren() - 1; 2410 for (int index = 0; index < max_index; index++) 2411 { 2412 ValueObjectSP child = 2413 root->GetChildAtIndex(index, true); 2414 list->Append(child); 2415 } 2416 *first_unparsed = expression_cstr+2; 2417 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2418 *final_result = ValueObject::eValueObjectList; 2419 return max_index; // tell me number of items I added to the VOList 2420 } 2421 } 2422 const char *separator_position = ::strchr(expression_cstr+1,'-'); 2423 const char *close_bracket_position = ::strchr(expression_cstr+1,']'); 2424 if (!close_bracket_position) // if there is no ], this is a syntax error 2425 { 2426 *first_unparsed = expression_cstr; 2427 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2428 *final_result = ValueObject::eInvalid; 2429 return 0; 2430 } 2431 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] 2432 { 2433 char *end = NULL; 2434 unsigned long index = ::strtoul (expression_cstr+1, &end, 0); 2435 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2436 { 2437 *first_unparsed = expression_cstr; 2438 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2439 *final_result = ValueObject::eInvalid; 2440 return 0; 2441 } 2442 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays 2443 { 2444 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2445 { 2446 int max_index = root->GetNumChildren() - 1; 2447 for (int index = 0; index < max_index; index++) 2448 { 2449 ValueObjectSP child = 2450 root->GetChildAtIndex(index, true); 2451 list->Append(child); 2452 } 2453 *first_unparsed = expression_cstr+2; 2454 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2455 *final_result = ValueObject::eValueObjectList; 2456 return max_index; // tell me number of items I added to the VOList 2457 } 2458 else 2459 { 2460 *first_unparsed = expression_cstr; 2461 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2462 *final_result = ValueObject::eInvalid; 2463 return 0; 2464 } 2465 } 2466 // from here on we do have a valid index 2467 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2468 { 2469 root = root->GetChildAtIndex(index, true); 2470 if (!root.get()) 2471 { 2472 *first_unparsed = expression_cstr; 2473 *reason_to_stop = ValueObject::eNoSuchChild; 2474 *final_result = ValueObject::eInvalid; 2475 return 0; 2476 } 2477 else 2478 { 2479 list->Append(root); 2480 *first_unparsed = end+1; // skip ] 2481 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2482 *final_result = ValueObject::eValueObjectList; 2483 return 1; 2484 } 2485 } 2486 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) 2487 { 2488 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 2489 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2490 { 2491 Error error; 2492 root = root->Dereference(error); 2493 if (error.Fail() || !root.get()) 2494 { 2495 *first_unparsed = expression_cstr; 2496 *reason_to_stop = ValueObject::eDereferencingFailed; 2497 *final_result = ValueObject::eInvalid; 2498 return 0; 2499 } 2500 else 2501 { 2502 *what_next = eNothing; 2503 continue; 2504 } 2505 } 2506 else 2507 { 2508 root = root->GetSyntheticArrayMemberFromPointer(index, true); 2509 if (!root.get()) 2510 { 2511 *first_unparsed = expression_cstr; 2512 *reason_to_stop = ValueObject::eNoSuchChild; 2513 *final_result = ValueObject::eInvalid; 2514 return 0; 2515 } 2516 else 2517 { 2518 list->Append(root); 2519 *first_unparsed = end+1; // skip ] 2520 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2521 *final_result = ValueObject::eValueObjectList; 2522 return 1; 2523 } 2524 } 2525 } 2526 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ 2527 { 2528 root = root->GetSyntheticBitFieldChild(index, index, true); 2529 if (!root.get()) 2530 { 2531 *first_unparsed = expression_cstr; 2532 *reason_to_stop = ValueObject::eNoSuchChild; 2533 *final_result = ValueObject::eInvalid; 2534 return 0; 2535 } 2536 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing 2537 { 2538 list->Append(root); 2539 *first_unparsed = end+1; // skip ] 2540 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2541 *final_result = ValueObject::eValueObjectList; 2542 return 1; 2543 } 2544 } 2545 } 2546 else // we have a low and a high index 2547 { 2548 char *end = NULL; 2549 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); 2550 if (!end || end != separator_position) // if something weird is in our way return an error 2551 { 2552 *first_unparsed = expression_cstr; 2553 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2554 *final_result = ValueObject::eInvalid; 2555 return 0; 2556 } 2557 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); 2558 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2559 { 2560 *first_unparsed = expression_cstr; 2561 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2562 *final_result = ValueObject::eInvalid; 2563 return 0; 2564 } 2565 if (index_lower > index_higher) // swap indices if required 2566 { 2567 unsigned long temp = index_lower; 2568 index_lower = index_higher; 2569 index_higher = temp; 2570 } 2571 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars 2572 { 2573 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 2574 if (!root.get()) 2575 { 2576 *first_unparsed = expression_cstr; 2577 *reason_to_stop = ValueObject::eNoSuchChild; 2578 *final_result = ValueObject::eInvalid; 2579 return 0; 2580 } 2581 else 2582 { 2583 list->Append(root); 2584 *first_unparsed = end+1; // skip ] 2585 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2586 *final_result = ValueObject::eValueObjectList; 2587 return 1; 2588 } 2589 } 2590 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 2591 *what_next == ValueObject::eDereference && 2592 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2593 { 2594 Error error; 2595 root = root->Dereference(error); 2596 if (error.Fail() || !root.get()) 2597 { 2598 *first_unparsed = expression_cstr; 2599 *reason_to_stop = ValueObject::eDereferencingFailed; 2600 *final_result = ValueObject::eInvalid; 2601 return 0; 2602 } 2603 else 2604 { 2605 *what_next = ValueObject::eNothing; 2606 continue; 2607 } 2608 } 2609 else 2610 { 2611 for (unsigned long index = index_lower; 2612 index <= index_higher; index++) 2613 { 2614 ValueObjectSP child = 2615 root->GetChildAtIndex(index, true); 2616 list->Append(child); 2617 } 2618 *first_unparsed = end+1; 2619 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2620 *final_result = ValueObject::eValueObjectList; 2621 return index_higher-index_lower+1; // tell me number of items I added to the VOList 2622 } 2623 } 2624 break; 2625 } 2626 default: // some non-[ separator, or something entirely wrong, is in the way 2627 { 2628 *first_unparsed = expression_cstr; 2629 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2630 *final_result = ValueObject::eInvalid; 2631 return 0; 2632 break; 2633 } 2634 } 2635 } 2636} 2637 2638void 2639ValueObject::DumpValueObject 2640( 2641 Stream &s, 2642 ValueObject *valobj, 2643 const char *root_valobj_name, 2644 uint32_t ptr_depth, 2645 uint32_t curr_depth, 2646 uint32_t max_depth, 2647 bool show_types, 2648 bool show_location, 2649 bool use_objc, 2650 lldb::DynamicValueType use_dynamic, 2651 bool use_synth, 2652 bool scope_already_checked, 2653 bool flat_output, 2654 uint32_t omit_summary_depth 2655) 2656{ 2657 if (valobj) 2658 { 2659 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true); 2660 2661 if (update_success && use_dynamic != lldb::eNoDynamicValues) 2662 { 2663 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); 2664 if (dynamic_value) 2665 valobj = dynamic_value; 2666 } 2667 2668 clang_type_t clang_type = valobj->GetClangType(); 2669 2670 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); 2671 const char *err_cstr = NULL; 2672 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); 2673 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); 2674 2675 const bool print_valobj = flat_output == false || has_value; 2676 2677 if (print_valobj) 2678 { 2679 if (show_location) 2680 { 2681 s.Printf("%s: ", valobj->GetLocationAsCString()); 2682 } 2683 2684 s.Indent(); 2685 2686 // Always show the type for the top level items. 2687 if (show_types || (curr_depth == 0 && !flat_output)) 2688 { 2689 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>"); 2690 s.Printf("(%s", typeName); 2691 // only show dynamic types if the user really wants to see types 2692 if (show_types && use_dynamic != lldb::eNoDynamicValues && 2693 (/*strstr(typeName, "id") == typeName ||*/ 2694 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC)) 2695 { 2696 Process* process = valobj->GetUpdatePoint().GetProcessSP().get(); 2697 if (process == NULL) 2698 s.Printf(", dynamic type: unknown) "); 2699 else 2700 { 2701 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime(); 2702 if (runtime == NULL) 2703 s.Printf(", dynamic type: unknown) "); 2704 else 2705 { 2706 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj); 2707 if (!runtime->IsValidISA(isa)) 2708 s.Printf(", dynamic type: unknown) "); 2709 else 2710 s.Printf(", dynamic type: %s) ", 2711 runtime->GetActualTypeName(isa).GetCString()); 2712 } 2713 } 2714 } 2715 else 2716 s.Printf(") "); 2717 } 2718 2719 2720 if (flat_output) 2721 { 2722 // If we are showing types, also qualify the C++ base classes 2723 const bool qualify_cxx_base_classes = show_types; 2724 valobj->GetExpressionPath(s, qualify_cxx_base_classes); 2725 s.PutCString(" ="); 2726 } 2727 else 2728 { 2729 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); 2730 s.Printf ("%s =", name_cstr); 2731 } 2732 2733 if (!scope_already_checked && !valobj->IsInScope()) 2734 { 2735 err_cstr = "out of scope"; 2736 } 2737 } 2738 2739 const char *val_cstr = NULL; 2740 const char *sum_cstr = NULL; 2741 SummaryFormat* entry = valobj->GetSummaryFormat().get(); 2742 2743 if (omit_summary_depth > 0) 2744 entry = NULL; 2745 2746 if (err_cstr == NULL) 2747 { 2748 val_cstr = valobj->GetValueAsCString(); 2749 err_cstr = valobj->GetError().AsCString(); 2750 } 2751 2752 if (err_cstr) 2753 { 2754 s.Printf (" <%s>\n", err_cstr); 2755 } 2756 else 2757 { 2758 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); 2759 if (print_valobj) 2760 { 2761 2762 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL; 2763 2764 // We must calculate this value in realtime because entry might alter this variable's value 2765 // (e.g. by saying ${var%fmt}) and render precached values useless 2766 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr)) 2767 s.Printf(" %s", valobj->GetValueAsCString()); 2768 2769 if (sum_cstr) 2770 { 2771 // for some reason, using %@ (ObjC description) in a summary string, makes 2772 // us believe we need to reset ourselves, thus invalidating the content of 2773 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty 2774 // let us recalculate it! 2775 if (sum_cstr[0] == '\0') 2776 s.Printf(" %s", valobj->GetSummaryAsCString()); 2777 else 2778 s.Printf(" %s", sum_cstr); 2779 } 2780 2781 if (use_objc) 2782 { 2783 const char *object_desc = valobj->GetObjectDescription(); 2784 if (object_desc) 2785 s.Printf(" %s\n", object_desc); 2786 else 2787 s.Printf (" [no Objective-C description available]\n"); 2788 return; 2789 } 2790 } 2791 2792 if (curr_depth < max_depth) 2793 { 2794 // We will show children for all concrete types. We won't show 2795 // pointer contents unless a pointer depth has been specified. 2796 // We won't reference contents unless the reference is the 2797 // root object (depth of zero). 2798 bool print_children = true; 2799 2800 // Use a new temporary pointer depth in case we override the 2801 // current pointer depth below... 2802 uint32_t curr_ptr_depth = ptr_depth; 2803 2804 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer); 2805 if (is_ptr || is_ref) 2806 { 2807 // We have a pointer or reference whose value is an address. 2808 // Make sure that address is not NULL 2809 AddressType ptr_address_type; 2810 if (valobj->GetPointerValue (ptr_address_type, true) == 0) 2811 print_children = false; 2812 2813 else if (is_ref && curr_depth == 0) 2814 { 2815 // If this is the root object (depth is zero) that we are showing 2816 // and it is a reference, and no pointer depth has been supplied 2817 // print out what it references. Don't do this at deeper depths 2818 // otherwise we can end up with infinite recursion... 2819 curr_ptr_depth = 1; 2820 } 2821 2822 if (curr_ptr_depth == 0) 2823 print_children = false; 2824 } 2825 2826 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) 2827 { 2828 ValueObjectSP synth_vobj = valobj->GetSyntheticValue(use_synth ? 2829 lldb::eUseSyntheticFilter : 2830 lldb::eNoSyntheticFilter); 2831 const uint32_t num_children = synth_vobj->GetNumChildren(); 2832 if (num_children) 2833 { 2834 if (flat_output) 2835 { 2836 if (print_valobj) 2837 s.EOL(); 2838 } 2839 else 2840 { 2841 if (print_valobj) 2842 s.PutCString(is_ref ? ": {\n" : " {\n"); 2843 s.IndentMore(); 2844 } 2845 2846 for (uint32_t idx=0; idx<num_children; ++idx) 2847 { 2848 ValueObjectSP child_sp(synth_vobj->GetChildAtIndex(idx, true)); 2849 if (child_sp.get()) 2850 { 2851 DumpValueObject (s, 2852 child_sp.get(), 2853 NULL, 2854 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, 2855 curr_depth + 1, 2856 max_depth, 2857 show_types, 2858 show_location, 2859 false, 2860 use_dynamic, 2861 use_synth, 2862 true, 2863 flat_output, 2864 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0); 2865 } 2866 } 2867 2868 if (!flat_output) 2869 { 2870 s.IndentLess(); 2871 s.Indent("}\n"); 2872 } 2873 } 2874 else if (has_children) 2875 { 2876 // Aggregate, no children... 2877 if (print_valobj) 2878 s.PutCString(" {}\n"); 2879 } 2880 else 2881 { 2882 if (print_valobj) 2883 s.EOL(); 2884 } 2885 2886 } 2887 else 2888 { 2889 s.EOL(); 2890 } 2891 } 2892 else 2893 { 2894 if (has_children && print_valobj) 2895 { 2896 s.PutCString("{...}\n"); 2897 } 2898 } 2899 } 2900 } 2901} 2902 2903 2904ValueObjectSP 2905ValueObject::CreateConstantValue (const ConstString &name) 2906{ 2907 ValueObjectSP valobj_sp; 2908 2909 if (UpdateValueIfNeeded(false) && m_error.Success()) 2910 { 2911 ExecutionContextScope *exe_scope = GetExecutionContextScope(); 2912 if (exe_scope) 2913 { 2914 ExecutionContext exe_ctx; 2915 exe_scope->CalculateExecutionContext(exe_ctx); 2916 2917 clang::ASTContext *ast = GetClangAST (); 2918 2919 DataExtractor data; 2920 data.SetByteOrder (m_data.GetByteOrder()); 2921 data.SetAddressByteSize(m_data.GetAddressByteSize()); 2922 2923 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); 2924 2925 valobj_sp = ValueObjectConstResult::Create (exe_scope, 2926 ast, 2927 GetClangType(), 2928 name, 2929 data); 2930 } 2931 } 2932 2933 if (!valobj_sp) 2934 { 2935 valobj_sp = ValueObjectConstResult::Create (NULL, m_error); 2936 } 2937 return valobj_sp; 2938} 2939 2940lldb::ValueObjectSP 2941ValueObject::Dereference (Error &error) 2942{ 2943 if (m_deref_valobj) 2944 return m_deref_valobj->GetSP(); 2945 2946 const bool is_pointer_type = IsPointerType(); 2947 if (is_pointer_type) 2948 { 2949 bool omit_empty_base_classes = true; 2950 bool ignore_array_bounds = false; 2951 2952 std::string child_name_str; 2953 uint32_t child_byte_size = 0; 2954 int32_t child_byte_offset = 0; 2955 uint32_t child_bitfield_bit_size = 0; 2956 uint32_t child_bitfield_bit_offset = 0; 2957 bool child_is_base_class = false; 2958 bool child_is_deref_of_parent = false; 2959 const bool transparent_pointers = false; 2960 clang::ASTContext *clang_ast = GetClangAST(); 2961 clang_type_t clang_type = GetClangType(); 2962 clang_type_t child_clang_type; 2963 2964 ExecutionContext exe_ctx; 2965 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); 2966 2967 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, 2968 clang_ast, 2969 GetName().GetCString(), 2970 clang_type, 2971 0, 2972 transparent_pointers, 2973 omit_empty_base_classes, 2974 ignore_array_bounds, 2975 child_name_str, 2976 child_byte_size, 2977 child_byte_offset, 2978 child_bitfield_bit_size, 2979 child_bitfield_bit_offset, 2980 child_is_base_class, 2981 child_is_deref_of_parent); 2982 if (child_clang_type && child_byte_size) 2983 { 2984 ConstString child_name; 2985 if (!child_name_str.empty()) 2986 child_name.SetCString (child_name_str.c_str()); 2987 2988 m_deref_valobj = new ValueObjectChild (*this, 2989 clang_ast, 2990 child_clang_type, 2991 child_name, 2992 child_byte_size, 2993 child_byte_offset, 2994 child_bitfield_bit_size, 2995 child_bitfield_bit_offset, 2996 child_is_base_class, 2997 child_is_deref_of_parent); 2998 } 2999 } 3000 3001 if (m_deref_valobj) 3002 { 3003 error.Clear(); 3004 return m_deref_valobj->GetSP(); 3005 } 3006 else 3007 { 3008 StreamString strm; 3009 GetExpressionPath(strm, true); 3010 3011 if (is_pointer_type) 3012 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 3013 else 3014 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 3015 return ValueObjectSP(); 3016 } 3017} 3018 3019lldb::ValueObjectSP 3020ValueObject::AddressOf (Error &error) 3021{ 3022 if (m_addr_of_valobj_sp) 3023 return m_addr_of_valobj_sp; 3024 3025 AddressType address_type = eAddressTypeInvalid; 3026 const bool scalar_is_load_address = false; 3027 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); 3028 error.Clear(); 3029 if (addr != LLDB_INVALID_ADDRESS) 3030 { 3031 switch (address_type) 3032 { 3033 default: 3034 case eAddressTypeInvalid: 3035 { 3036 StreamString expr_path_strm; 3037 GetExpressionPath(expr_path_strm, true); 3038 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); 3039 } 3040 break; 3041 3042 case eAddressTypeFile: 3043 case eAddressTypeLoad: 3044 case eAddressTypeHost: 3045 { 3046 clang::ASTContext *ast = GetClangAST(); 3047 clang_type_t clang_type = GetClangType(); 3048 if (ast && clang_type) 3049 { 3050 std::string name (1, '&'); 3051 name.append (m_name.AsCString("")); 3052 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(), 3053 ast, 3054 ClangASTContext::CreatePointerType (ast, clang_type), 3055 ConstString (name.c_str()), 3056 addr, 3057 eAddressTypeInvalid, 3058 m_data.GetAddressByteSize()); 3059 } 3060 } 3061 break; 3062 } 3063 } 3064 return m_addr_of_valobj_sp; 3065} 3066 3067 3068lldb::ValueObjectSP 3069ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) 3070{ 3071 lldb::ValueObjectSP valobj_sp; 3072 AddressType address_type; 3073 const bool scalar_is_load_address = true; 3074 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); 3075 3076 if (ptr_value != LLDB_INVALID_ADDRESS) 3077 { 3078 Address ptr_addr (NULL, ptr_value); 3079 3080 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), 3081 name, 3082 ptr_addr, 3083 clang_ast_type); 3084 } 3085 return valobj_sp; 3086} 3087 3088lldb::ValueObjectSP 3089ValueObject::CastPointerType (const char *name, TypeSP &type_sp) 3090{ 3091 lldb::ValueObjectSP valobj_sp; 3092 AddressType address_type; 3093 const bool scalar_is_load_address = true; 3094 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); 3095 3096 if (ptr_value != LLDB_INVALID_ADDRESS) 3097 { 3098 Address ptr_addr (NULL, ptr_value); 3099 3100 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), 3101 name, 3102 ptr_addr, 3103 type_sp); 3104 } 3105 return valobj_sp; 3106} 3107 3108ValueObject::EvaluationPoint::EvaluationPoint () : 3109 m_thread_id (LLDB_INVALID_UID), 3110 m_mod_id () 3111{ 3112} 3113 3114ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): 3115 m_needs_update (true), 3116 m_first_update (true), 3117 m_thread_id (LLDB_INVALID_THREAD_ID), 3118 m_mod_id () 3119 3120{ 3121 ExecutionContext exe_ctx; 3122 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope, 3123 // and if so we want to cache that not the original. 3124 if (exe_scope) 3125 exe_scope->CalculateExecutionContext(exe_ctx); 3126 if (exe_ctx.target != NULL) 3127 { 3128 m_target_sp = exe_ctx.target->GetSP(); 3129 3130 if (exe_ctx.process == NULL) 3131 m_process_sp = exe_ctx.target->GetProcessSP(); 3132 else 3133 m_process_sp = exe_ctx.process->GetSP(); 3134 3135 if (m_process_sp != NULL) 3136 { 3137 m_mod_id = m_process_sp->GetModID(); 3138 3139 Thread *thread = NULL; 3140 3141 if (exe_ctx.thread == NULL) 3142 { 3143 if (use_selected) 3144 { 3145 thread = m_process_sp->GetThreadList().GetSelectedThread().get(); 3146 if (thread) 3147 computed_exe_scope = thread; 3148 } 3149 } 3150 else 3151 thread = exe_ctx.thread; 3152 3153 if (thread != NULL) 3154 { 3155 m_thread_id = thread->GetIndexID(); 3156 if (exe_ctx.frame == NULL) 3157 { 3158 if (use_selected) 3159 { 3160 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get(); 3161 if (frame) 3162 { 3163 m_stack_id = frame->GetStackID(); 3164 computed_exe_scope = frame; 3165 } 3166 } 3167 } 3168 else 3169 m_stack_id = exe_ctx.frame->GetStackID(); 3170 } 3171 } 3172 } 3173 m_exe_scope = computed_exe_scope; 3174} 3175 3176ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : 3177 m_exe_scope (rhs.m_exe_scope), 3178 m_needs_update(true), 3179 m_first_update(true), 3180 m_target_sp (rhs.m_target_sp), 3181 m_process_sp (rhs.m_process_sp), 3182 m_thread_id (rhs.m_thread_id), 3183 m_stack_id (rhs.m_stack_id), 3184 m_mod_id () 3185{ 3186} 3187 3188ValueObject::EvaluationPoint::~EvaluationPoint () 3189{ 3190} 3191 3192ExecutionContextScope * 3193ValueObject::EvaluationPoint::GetExecutionContextScope () 3194{ 3195 // We have to update before giving out the scope, or we could be handing out stale pointers. 3196 SyncWithProcessState(); 3197 3198 return m_exe_scope; 3199} 3200 3201// This function checks the EvaluationPoint against the current process state. If the current 3202// state matches the evaluation point, or the evaluation point is already invalid, then we return 3203// false, meaning "no change". If the current state is different, we update our state, and return 3204// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so 3205// future calls to NeedsUpdate will return true. 3206 3207bool 3208ValueObject::EvaluationPoint::SyncWithProcessState() 3209{ 3210 // If we're already invalid, we don't need to do anything, and nothing has changed: 3211 if (!m_mod_id.IsValid()) 3212 { 3213 // Can't update with an invalid state. 3214 m_needs_update = false; 3215 return false; 3216 } 3217 3218 // If we don't have a process nothing can change. 3219 if (!m_process_sp) 3220 return false; 3221 3222 // If our stop id is the current stop ID, nothing has changed: 3223 ProcessModID current_mod_id = m_process_sp->GetModID(); 3224 3225 if (m_mod_id == current_mod_id) 3226 return false; 3227 3228 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. 3229 // In either case, we aren't going to be able to sync with the process state. 3230 if (current_mod_id.GetStopID() == 0) 3231 return false; 3232 3233 m_mod_id = current_mod_id; 3234 m_needs_update = true; 3235 m_exe_scope = m_process_sp.get(); 3236 3237 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either 3238 // doesn't, mark ourselves as invalid. 3239 3240 if (m_thread_id != LLDB_INVALID_THREAD_ID) 3241 { 3242 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); 3243 if (our_thread == NULL) 3244 { 3245 SetInvalid(); 3246 } 3247 else 3248 { 3249 m_exe_scope = our_thread; 3250 3251 if (m_stack_id.IsValid()) 3252 { 3253 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); 3254 if (our_frame == NULL) 3255 SetInvalid(); 3256 else 3257 m_exe_scope = our_frame; 3258 } 3259 } 3260 } 3261 return true; 3262} 3263 3264void 3265ValueObject::EvaluationPoint::SetUpdated () 3266{ 3267 m_first_update = false; 3268 m_needs_update = false; 3269 if (m_process_sp) 3270 { 3271 m_mod_id = m_process_sp->GetModID(); 3272 } 3273} 3274 3275 3276bool 3277ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) 3278{ 3279 if (!IsValid()) 3280 return false; 3281 3282 bool needs_update = false; 3283 m_exe_scope = NULL; 3284 3285 // The target has to be non-null, and the 3286 Target *target = exe_scope->CalculateTarget(); 3287 if (target != NULL) 3288 { 3289 Target *old_target = m_target_sp.get(); 3290 assert (target == old_target); 3291 Process *process = exe_scope->CalculateProcess(); 3292 if (process != NULL) 3293 { 3294 // FOR NOW - assume you can't update variable objects across process boundaries. 3295 Process *old_process = m_process_sp.get(); 3296 assert (process == old_process); 3297 ProcessModID current_mod_id = process->GetModID(); 3298 if (m_mod_id != current_mod_id) 3299 { 3300 needs_update = true; 3301 m_mod_id = current_mod_id; 3302 } 3303 // See if we're switching the thread or stack context. If no thread is given, this is 3304 // being evaluated in a global context. 3305 Thread *thread = exe_scope->CalculateThread(); 3306 if (thread != NULL) 3307 { 3308 lldb::user_id_t new_thread_index = thread->GetIndexID(); 3309 if (new_thread_index != m_thread_id) 3310 { 3311 needs_update = true; 3312 m_thread_id = new_thread_index; 3313 m_stack_id.Clear(); 3314 } 3315 3316 StackFrame *new_frame = exe_scope->CalculateStackFrame(); 3317 if (new_frame != NULL) 3318 { 3319 if (new_frame->GetStackID() != m_stack_id) 3320 { 3321 needs_update = true; 3322 m_stack_id = new_frame->GetStackID(); 3323 } 3324 } 3325 else 3326 { 3327 m_stack_id.Clear(); 3328 needs_update = true; 3329 } 3330 } 3331 else 3332 { 3333 // If this had been given a thread, and now there is none, we should update. 3334 // Otherwise we don't have to do anything. 3335 if (m_thread_id != LLDB_INVALID_UID) 3336 { 3337 m_thread_id = LLDB_INVALID_UID; 3338 m_stack_id.Clear(); 3339 needs_update = true; 3340 } 3341 } 3342 } 3343 else 3344 { 3345 // If there is no process, then we don't need to update anything. 3346 // But if we're switching from having a process to not, we should try to update. 3347 if (m_process_sp.get() != NULL) 3348 { 3349 needs_update = true; 3350 m_process_sp.reset(); 3351 m_thread_id = LLDB_INVALID_UID; 3352 m_stack_id.Clear(); 3353 } 3354 } 3355 } 3356 else 3357 { 3358 // If there's no target, nothing can change so we don't need to update anything. 3359 // But if we're switching from having a target to not, we should try to update. 3360 if (m_target_sp.get() != NULL) 3361 { 3362 needs_update = true; 3363 m_target_sp.reset(); 3364 m_process_sp.reset(); 3365 m_thread_id = LLDB_INVALID_UID; 3366 m_stack_id.Clear(); 3367 } 3368 } 3369 if (!m_needs_update) 3370 m_needs_update = needs_update; 3371 3372 return needs_update; 3373} 3374 3375void 3376ValueObject::ClearUserVisibleData() 3377{ 3378 m_location_str.clear(); 3379 m_value_str.clear(); 3380 m_summary_str.clear(); 3381 m_object_desc_str.clear(); 3382} 3383