ValueObject.cpp revision 4e5397c1127d698c61df295f30909e573a1c9876
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(0), 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(0), 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.GetUpdateID() != 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::auto_ptr<char> 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 // keep this out of the local scope so it will only get deleted when 974 // we exit the function (..and we have a copy of the data into the Stream) 975 alloc_mem = std::auto_ptr<char>((char*)(return_value = new char[512])); 976 { 977 int count = GetNumChildren(); 978 snprintf(alloc_mem.get(), 512, "%d", count); 979 break; 980 } 981 default: 982 break; 983 } 984 985 // this code snippet might lead to endless recursion, thus we use a RefCounter here to 986 // check that we are not looping endlessly 987 if (!return_value && (m_dump_printable_counter < 3)) 988 { 989 // try to pick the other choice 990 if (val_obj_display == eDisplayValue) 991 return_value = GetSummaryAsCString(); 992 else if (val_obj_display == eDisplaySummary) 993 { 994 if (ClangASTContext::IsAggregateType (GetClangType()) == true) 995 { 996 // this thing has no value, and it seems to have no summary 997 // some combination of unitialized data and other factors can also 998 // raise this condition, so let's print a nice generic error message 999 return_value = "<no available summary>"; 1000 } 1001 else 1002 return_value = GetValueAsCString(); 1003 } 1004 } 1005 1006 if (return_value) 1007 s.PutCString(return_value); 1008 else 1009 s.PutCString("<no printable representation>"); 1010 1011 // we should only return false here if we could not do *anything* 1012 // even if we have an error message as output, that's a success 1013 // from our callers' perspective, so return true 1014 return true; 1015 1016} 1017 1018bool 1019ValueObject::DumpPrintableRepresentation(Stream& s, 1020 ValueObjectRepresentationStyle val_obj_display, 1021 lldb::Format custom_format) 1022{ 1023 1024 clang_type_t elem_or_pointee_type; 1025 Flags flags(ClangASTContext::GetTypeInfo(GetClangType(), GetClangAST(), &elem_or_pointee_type)); 1026 1027 if (flags.AnySet(ClangASTContext::eTypeIsArray | ClangASTContext::eTypeIsPointer) 1028 && val_obj_display == ValueObject::eDisplayValue) 1029 { 1030 // when being asked to get a printable display an array or pointer type directly, 1031 // try to "do the right thing" 1032 1033 if (IsCStringContainer(true) && 1034 (custom_format == lldb::eFormatCString || 1035 custom_format == lldb::eFormatCharArray || 1036 custom_format == lldb::eFormatChar || 1037 custom_format == lldb::eFormatVectorOfChar)) // print char[] & char* directly 1038 { 1039 Error error; 1040 ReadPointedString(s, 1041 error, 1042 0, 1043 (custom_format == lldb::eFormatVectorOfChar) || 1044 (custom_format == lldb::eFormatCharArray)); 1045 return !error.Fail(); 1046 } 1047 1048 if (custom_format == lldb::eFormatEnum) 1049 return false; 1050 1051 // this only works for arrays, because I have no way to know when 1052 // the pointed memory ends, and no special \0 end of data marker 1053 if (flags.Test(ClangASTContext::eTypeIsArray)) 1054 { 1055 if ((custom_format == lldb::eFormatBytes) || 1056 (custom_format == lldb::eFormatBytesWithASCII)) 1057 { 1058 uint32_t count = GetNumChildren(); 1059 1060 s << '['; 1061 for (uint32_t low = 0; low < count; low++) 1062 { 1063 1064 if (low) 1065 s << ','; 1066 1067 ValueObjectSP child = GetChildAtIndex(low,true); 1068 if (!child.get()) 1069 { 1070 s << "<invalid child>"; 1071 continue; 1072 } 1073 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, custom_format); 1074 } 1075 1076 s << ']'; 1077 1078 return true; 1079 } 1080 1081 if ((custom_format == lldb::eFormatVectorOfChar) || 1082 (custom_format == lldb::eFormatVectorOfFloat32) || 1083 (custom_format == lldb::eFormatVectorOfFloat64) || 1084 (custom_format == lldb::eFormatVectorOfSInt16) || 1085 (custom_format == lldb::eFormatVectorOfSInt32) || 1086 (custom_format == lldb::eFormatVectorOfSInt64) || 1087 (custom_format == lldb::eFormatVectorOfSInt8) || 1088 (custom_format == lldb::eFormatVectorOfUInt128) || 1089 (custom_format == lldb::eFormatVectorOfUInt16) || 1090 (custom_format == lldb::eFormatVectorOfUInt32) || 1091 (custom_format == lldb::eFormatVectorOfUInt64) || 1092 (custom_format == lldb::eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly 1093 { 1094 uint32_t count = GetNumChildren(); 1095 1096 lldb::Format format = FormatManager::GetSingleItemFormat(custom_format); 1097 1098 s << '['; 1099 for (uint32_t low = 0; low < count; low++) 1100 { 1101 1102 if (low) 1103 s << ','; 1104 1105 ValueObjectSP child = GetChildAtIndex(low,true); 1106 if (!child.get()) 1107 { 1108 s << "<invalid child>"; 1109 continue; 1110 } 1111 child->DumpPrintableRepresentation(s, ValueObject::eDisplayValue, format); 1112 } 1113 1114 s << ']'; 1115 1116 return true; 1117 } 1118 } 1119 1120 if ((custom_format == lldb::eFormatBoolean) || 1121 (custom_format == lldb::eFormatBinary) || 1122 (custom_format == lldb::eFormatChar) || 1123 (custom_format == lldb::eFormatCharPrintable) || 1124 (custom_format == lldb::eFormatComplexFloat) || 1125 (custom_format == lldb::eFormatDecimal) || 1126 (custom_format == lldb::eFormatHex) || 1127 (custom_format == lldb::eFormatFloat) || 1128 (custom_format == lldb::eFormatOctal) || 1129 (custom_format == lldb::eFormatOSType) || 1130 (custom_format == lldb::eFormatUnicode16) || 1131 (custom_format == lldb::eFormatUnicode32) || 1132 (custom_format == lldb::eFormatUnsigned) || 1133 (custom_format == lldb::eFormatPointer) || 1134 (custom_format == lldb::eFormatComplexInteger) || 1135 (custom_format == lldb::eFormatComplex) || 1136 (custom_format == lldb::eFormatDefault)) // use the [] operator 1137 return false; 1138 } 1139 bool var_success = GetPrintableRepresentation(s, val_obj_display, custom_format); 1140 if (custom_format != eFormatInvalid) 1141 SetFormat(eFormatDefault); 1142 return var_success; 1143} 1144 1145addr_t 1146ValueObject::GetAddressOf (AddressType &address_type, bool scalar_is_load_address) 1147{ 1148 if (!UpdateValueIfNeeded(false)) 1149 return LLDB_INVALID_ADDRESS; 1150 1151 switch (m_value.GetValueType()) 1152 { 1153 case Value::eValueTypeScalar: 1154 if (scalar_is_load_address) 1155 { 1156 address_type = eAddressTypeLoad; 1157 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1158 } 1159 break; 1160 1161 case Value::eValueTypeLoadAddress: 1162 case Value::eValueTypeFileAddress: 1163 case Value::eValueTypeHostAddress: 1164 { 1165 address_type = m_value.GetValueAddressType (); 1166 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1167 } 1168 break; 1169 } 1170 address_type = eAddressTypeInvalid; 1171 return LLDB_INVALID_ADDRESS; 1172} 1173 1174addr_t 1175ValueObject::GetPointerValue (AddressType &address_type, bool scalar_is_load_address) 1176{ 1177 lldb::addr_t address = LLDB_INVALID_ADDRESS; 1178 address_type = eAddressTypeInvalid; 1179 1180 if (!UpdateValueIfNeeded(false)) 1181 return address; 1182 1183 switch (m_value.GetValueType()) 1184 { 1185 case Value::eValueTypeScalar: 1186 if (scalar_is_load_address) 1187 { 1188 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); 1189 address_type = eAddressTypeLoad; 1190 } 1191 break; 1192 1193 case Value::eValueTypeLoadAddress: 1194 case Value::eValueTypeFileAddress: 1195 case Value::eValueTypeHostAddress: 1196 { 1197 uint32_t data_offset = 0; 1198 address = m_data.GetPointer(&data_offset); 1199 address_type = m_value.GetValueAddressType(); 1200 if (address_type == eAddressTypeInvalid) 1201 address_type = eAddressTypeLoad; 1202 } 1203 break; 1204 } 1205 1206 if (m_pointers_point_to_load_addrs) 1207 address_type = eAddressTypeLoad; 1208 1209 return address; 1210} 1211 1212bool 1213ValueObject::SetValueFromCString (const char *value_str) 1214{ 1215 // Make sure our value is up to date first so that our location and location 1216 // type is valid. 1217 if (!UpdateValueIfNeeded(false)) 1218 return false; 1219 1220 uint32_t count = 0; 1221 lldb::Encoding encoding = ClangASTType::GetEncoding (GetClangType(), count); 1222 1223 char *end = NULL; 1224 const size_t byte_size = GetByteSize(); 1225 switch (encoding) 1226 { 1227 case eEncodingInvalid: 1228 return false; 1229 1230 case eEncodingUint: 1231 if (byte_size > sizeof(unsigned long long)) 1232 { 1233 return false; 1234 } 1235 else 1236 { 1237 unsigned long long ull_val = strtoull(value_str, &end, 0); 1238 if (end && *end != '\0') 1239 return false; 1240 m_value.GetScalar() = ull_val; 1241 // Limit the bytes in our m_data appropriately. 1242 m_value.GetScalar().GetData (m_data, byte_size); 1243 } 1244 break; 1245 1246 case eEncodingSint: 1247 if (byte_size > sizeof(long long)) 1248 { 1249 return false; 1250 } 1251 else 1252 { 1253 long long sll_val = strtoll(value_str, &end, 0); 1254 if (end && *end != '\0') 1255 return false; 1256 m_value.GetScalar() = sll_val; 1257 // Limit the bytes in our m_data appropriately. 1258 m_value.GetScalar().GetData (m_data, byte_size); 1259 } 1260 break; 1261 1262 case eEncodingIEEE754: 1263 { 1264 const off_t byte_offset = GetByteOffset(); 1265 uint8_t *dst = const_cast<uint8_t *>(m_data.PeekData(byte_offset, byte_size)); 1266 if (dst != NULL) 1267 { 1268 // We are decoding a float into host byte order below, so make 1269 // sure m_data knows what it contains. 1270 m_data.SetByteOrder(lldb::endian::InlHostByteOrder()); 1271 const size_t converted_byte_size = ClangASTContext::ConvertStringToFloatValue ( 1272 GetClangAST(), 1273 GetClangType(), 1274 value_str, 1275 dst, 1276 byte_size); 1277 1278 if (converted_byte_size == byte_size) 1279 { 1280 } 1281 } 1282 } 1283 break; 1284 1285 case eEncodingVector: 1286 return false; 1287 1288 default: 1289 return false; 1290 } 1291 1292 // If we have made it here the value is in m_data and we should write it 1293 // out to the target 1294 return Write (); 1295} 1296 1297bool 1298ValueObject::Write () 1299{ 1300 // Clear the update ID so the next time we try and read the value 1301 // we try and read it again. 1302 m_update_point.SetNeedsUpdate(); 1303 1304 // TODO: when Value has a method to write a value back, call it from here. 1305 return false; 1306 1307} 1308 1309lldb::LanguageType 1310ValueObject::GetObjectRuntimeLanguage () 1311{ 1312 return ClangASTType::GetMinimumLanguage (GetClangAST(), 1313 GetClangType()); 1314} 1315 1316void 1317ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj) 1318{ 1319 m_synthetic_children[key] = valobj; 1320} 1321 1322ValueObjectSP 1323ValueObject::GetSyntheticChild (const ConstString &key) const 1324{ 1325 ValueObjectSP synthetic_child_sp; 1326 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key); 1327 if (pos != m_synthetic_children.end()) 1328 synthetic_child_sp = pos->second->GetSP(); 1329 return synthetic_child_sp; 1330} 1331 1332bool 1333ValueObject::IsPointerType () 1334{ 1335 return ClangASTContext::IsPointerType (GetClangType()); 1336} 1337 1338bool 1339ValueObject::IsArrayType () 1340{ 1341 return ClangASTContext::IsArrayType (GetClangType()); 1342} 1343 1344bool 1345ValueObject::IsScalarType () 1346{ 1347 return ClangASTContext::IsScalarType (GetClangType()); 1348} 1349 1350bool 1351ValueObject::IsIntegerType (bool &is_signed) 1352{ 1353 return ClangASTContext::IsIntegerType (GetClangType(), is_signed); 1354} 1355 1356bool 1357ValueObject::IsPointerOrReferenceType () 1358{ 1359 return ClangASTContext::IsPointerOrReferenceType (GetClangType()); 1360} 1361 1362bool 1363ValueObject::IsPossibleCPlusPlusDynamicType () 1364{ 1365 return ClangASTContext::IsPossibleCPlusPlusDynamicType (GetClangAST (), GetClangType()); 1366} 1367 1368bool 1369ValueObject::IsPossibleDynamicType () 1370{ 1371 return ClangASTContext::IsPossibleDynamicType (GetClangAST (), GetClangType()); 1372} 1373 1374ValueObjectSP 1375ValueObject::GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create) 1376{ 1377 ValueObjectSP synthetic_child_sp; 1378 if (IsPointerType ()) 1379 { 1380 char index_str[64]; 1381 snprintf(index_str, sizeof(index_str), "[%i]", index); 1382 ConstString index_const_str(index_str); 1383 // Check if we have already created a synthetic array member in this 1384 // valid object. If we have we will re-use it. 1385 synthetic_child_sp = GetSyntheticChild (index_const_str); 1386 if (!synthetic_child_sp) 1387 { 1388 ValueObject *synthetic_child; 1389 // We haven't made a synthetic array member for INDEX yet, so 1390 // lets make one and cache it for any future reference. 1391 synthetic_child = CreateChildAtIndex(0, true, index); 1392 1393 // Cache the value if we got one back... 1394 if (synthetic_child) 1395 { 1396 AddSyntheticChild(index_const_str, synthetic_child); 1397 synthetic_child_sp = synthetic_child->GetSP(); 1398 synthetic_child_sp->SetName(ConstString(index_str)); 1399 synthetic_child_sp->m_is_array_item_for_pointer = true; 1400 } 1401 } 1402 } 1403 return synthetic_child_sp; 1404} 1405 1406// This allows you to create an array member using and index 1407// that doesn't not fall in the normal bounds of the array. 1408// Many times structure can be defined as: 1409// struct Collection 1410// { 1411// uint32_t item_count; 1412// Item item_array[0]; 1413// }; 1414// The size of the "item_array" is 1, but many times in practice 1415// there are more items in "item_array". 1416 1417ValueObjectSP 1418ValueObject::GetSyntheticArrayMemberFromArray (int32_t index, bool can_create) 1419{ 1420 ValueObjectSP synthetic_child_sp; 1421 if (IsArrayType ()) 1422 { 1423 char index_str[64]; 1424 snprintf(index_str, sizeof(index_str), "[%i]", index); 1425 ConstString index_const_str(index_str); 1426 // Check if we have already created a synthetic array member in this 1427 // valid object. If we have we will re-use it. 1428 synthetic_child_sp = GetSyntheticChild (index_const_str); 1429 if (!synthetic_child_sp) 1430 { 1431 ValueObject *synthetic_child; 1432 // We haven't made a synthetic array member for INDEX yet, so 1433 // lets make one and cache it for any future reference. 1434 synthetic_child = CreateChildAtIndex(0, true, index); 1435 1436 // Cache the value if we got one back... 1437 if (synthetic_child) 1438 { 1439 AddSyntheticChild(index_const_str, synthetic_child); 1440 synthetic_child_sp = synthetic_child->GetSP(); 1441 synthetic_child_sp->SetName(ConstString(index_str)); 1442 synthetic_child_sp->m_is_array_item_for_pointer = true; 1443 } 1444 } 1445 } 1446 return synthetic_child_sp; 1447} 1448 1449ValueObjectSP 1450ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create) 1451{ 1452 ValueObjectSP synthetic_child_sp; 1453 if (IsScalarType ()) 1454 { 1455 char index_str[64]; 1456 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to); 1457 ConstString index_const_str(index_str); 1458 // Check if we have already created a synthetic array member in this 1459 // valid object. If we have we will re-use it. 1460 synthetic_child_sp = GetSyntheticChild (index_const_str); 1461 if (!synthetic_child_sp) 1462 { 1463 ValueObjectChild *synthetic_child; 1464 // We haven't made a synthetic array member for INDEX yet, so 1465 // lets make one and cache it for any future reference. 1466 synthetic_child = new ValueObjectChild(*this, 1467 GetClangAST(), 1468 GetClangType(), 1469 index_const_str, 1470 GetByteSize(), 1471 0, 1472 to-from+1, 1473 from, 1474 false, 1475 false); 1476 1477 // Cache the value if we got one back... 1478 if (synthetic_child) 1479 { 1480 AddSyntheticChild(index_const_str, synthetic_child); 1481 synthetic_child_sp = synthetic_child->GetSP(); 1482 synthetic_child_sp->SetName(ConstString(index_str)); 1483 synthetic_child_sp->m_is_bitfield_for_scalar = true; 1484 } 1485 } 1486 } 1487 return synthetic_child_sp; 1488} 1489 1490lldb::ValueObjectSP 1491ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create) 1492{ 1493 1494 ValueObjectSP synthetic_child_sp; 1495 1496 char name_str[64]; 1497 snprintf(name_str, sizeof(name_str), "@%i", offset); 1498 ConstString name_const_str(name_str); 1499 1500 // Check if we have already created a synthetic array member in this 1501 // valid object. If we have we will re-use it. 1502 synthetic_child_sp = GetSyntheticChild (name_const_str); 1503 1504 if (synthetic_child_sp.get()) 1505 return synthetic_child_sp; 1506 1507 if (!can_create) 1508 return lldb::ValueObjectSP(); 1509 1510 ValueObjectChild *synthetic_child = new ValueObjectChild(*this, 1511 type.GetASTContext(), 1512 type.GetOpaqueQualType(), 1513 name_const_str, 1514 type.GetTypeByteSize(), 1515 offset, 1516 0, 1517 0, 1518 false, 1519 false); 1520 if (synthetic_child) 1521 { 1522 AddSyntheticChild(name_const_str, synthetic_child); 1523 synthetic_child_sp = synthetic_child->GetSP(); 1524 synthetic_child_sp->SetName(name_const_str); 1525 synthetic_child_sp->m_is_child_at_offset = true; 1526 } 1527 return synthetic_child_sp; 1528} 1529 1530// your expression path needs to have a leading . or -> 1531// (unless it somehow "looks like" an array, in which case it has 1532// a leading [ symbol). while the [ is meaningful and should be shown 1533// to the user, . and -> are just parser design, but by no means 1534// added information for the user.. strip them off 1535static const char* 1536SkipLeadingExpressionPathSeparators(const char* expression) 1537{ 1538 if (!expression || !expression[0]) 1539 return expression; 1540 if (expression[0] == '.') 1541 return expression+1; 1542 if (expression[0] == '-' && expression[1] == '>') 1543 return expression+2; 1544 return expression; 1545} 1546 1547lldb::ValueObjectSP 1548ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create) 1549{ 1550 ValueObjectSP synthetic_child_sp; 1551 ConstString name_const_string(expression); 1552 // Check if we have already created a synthetic array member in this 1553 // valid object. If we have we will re-use it. 1554 synthetic_child_sp = GetSyntheticChild (name_const_string); 1555 if (!synthetic_child_sp) 1556 { 1557 // We haven't made a synthetic array member for expression yet, so 1558 // lets make one and cache it for any future reference. 1559 synthetic_child_sp = GetValueForExpressionPath(expression); 1560 1561 // Cache the value if we got one back... 1562 if (synthetic_child_sp.get()) 1563 { 1564 AddSyntheticChild(name_const_string, synthetic_child_sp.get()); 1565 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression))); 1566 synthetic_child_sp->m_is_expression_path_child = true; 1567 } 1568 } 1569 return synthetic_child_sp; 1570} 1571 1572void 1573ValueObject::CalculateSyntheticValue (lldb::SyntheticValueType use_synthetic) 1574{ 1575 if (use_synthetic == lldb::eNoSyntheticFilter) 1576 return; 1577 1578 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1579 1580 if (m_last_synthetic_filter.get() == NULL) 1581 return; 1582 1583 if (m_synthetic_value == NULL) 1584 m_synthetic_value = new ValueObjectSynthetic(*this, m_last_synthetic_filter); 1585 1586} 1587 1588void 1589ValueObject::CalculateDynamicValue (lldb::DynamicValueType use_dynamic) 1590{ 1591 if (use_dynamic == lldb::eNoDynamicValues) 1592 return; 1593 1594 if (!m_dynamic_value && !IsDynamic()) 1595 { 1596 Process *process = m_update_point.GetProcessSP().get(); 1597 bool worth_having_dynamic_value = false; 1598 1599 1600 // FIXME: Process should have some kind of "map over Runtimes" so we don't have to 1601 // hard code this everywhere. 1602 lldb::LanguageType known_type = GetObjectRuntimeLanguage(); 1603 if (known_type != lldb::eLanguageTypeUnknown && known_type != lldb::eLanguageTypeC) 1604 { 1605 LanguageRuntime *runtime = process->GetLanguageRuntime (known_type); 1606 if (runtime) 1607 worth_having_dynamic_value = runtime->CouldHaveDynamicValue(*this); 1608 } 1609 else 1610 { 1611 LanguageRuntime *cpp_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeC_plus_plus); 1612 if (cpp_runtime) 1613 worth_having_dynamic_value = cpp_runtime->CouldHaveDynamicValue(*this); 1614 1615 if (!worth_having_dynamic_value) 1616 { 1617 LanguageRuntime *objc_runtime = process->GetLanguageRuntime (lldb::eLanguageTypeObjC); 1618 if (objc_runtime) 1619 worth_having_dynamic_value = objc_runtime->CouldHaveDynamicValue(*this); 1620 } 1621 } 1622 1623 if (worth_having_dynamic_value) 1624 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic); 1625 1626// if (worth_having_dynamic_value) 1627// printf ("Adding dynamic value %s (%p) to (%p) - manager %p.\n", m_name.GetCString(), m_dynamic_value, this, m_manager); 1628 1629 } 1630} 1631 1632ValueObjectSP 1633ValueObject::GetDynamicValue (DynamicValueType use_dynamic) 1634{ 1635 if (use_dynamic == lldb::eNoDynamicValues) 1636 return ValueObjectSP(); 1637 1638 if (!IsDynamic() && m_dynamic_value == NULL) 1639 { 1640 CalculateDynamicValue(use_dynamic); 1641 } 1642 if (m_dynamic_value) 1643 return m_dynamic_value->GetSP(); 1644 else 1645 return ValueObjectSP(); 1646} 1647 1648// GetDynamicValue() returns a NULL SharedPointer if the object is not dynamic 1649// or we do not really want a dynamic VO. this method instead returns this object 1650// itself when making it synthetic has no meaning. this makes it much simpler 1651// to replace the SyntheticValue for the ValueObject 1652ValueObjectSP 1653ValueObject::GetSyntheticValue (SyntheticValueType use_synthetic) 1654{ 1655 if (use_synthetic == lldb::eNoSyntheticFilter) 1656 return GetSP(); 1657 1658 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1659 1660 if (m_last_synthetic_filter.get() == NULL) 1661 return GetSP(); 1662 1663 CalculateSyntheticValue(use_synthetic); 1664 1665 if (m_synthetic_value) 1666 return m_synthetic_value->GetSP(); 1667 else 1668 return GetSP(); 1669} 1670 1671bool 1672ValueObject::GetBaseClassPath (Stream &s) 1673{ 1674 if (IsBaseClass()) 1675 { 1676 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s); 1677 clang_type_t clang_type = GetClangType(); 1678 std::string cxx_class_name; 1679 bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name); 1680 if (this_had_base_class) 1681 { 1682 if (parent_had_base_class) 1683 s.PutCString("::"); 1684 s.PutCString(cxx_class_name.c_str()); 1685 } 1686 return parent_had_base_class || this_had_base_class; 1687 } 1688 return false; 1689} 1690 1691 1692ValueObject * 1693ValueObject::GetNonBaseClassParent() 1694{ 1695 if (GetParent()) 1696 { 1697 if (GetParent()->IsBaseClass()) 1698 return GetParent()->GetNonBaseClassParent(); 1699 else 1700 return GetParent(); 1701 } 1702 return NULL; 1703} 1704 1705void 1706ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat) 1707{ 1708 const bool is_deref_of_parent = IsDereferenceOfParent (); 1709 1710 if (is_deref_of_parent && epformat == eDereferencePointers) { 1711 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely 1712 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName. 1713 // the eHonorPointers mode is meant to produce strings in this latter format 1714 s.PutCString("*("); 1715 } 1716 1717 ValueObject* parent = GetParent(); 1718 1719 if (parent) 1720 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat); 1721 1722 // if we are a deref_of_parent just because we are synthetic array 1723 // members made up to allow ptr[%d] syntax to work in variable 1724 // printing, then add our name ([%d]) to the expression path 1725 if (m_is_array_item_for_pointer && epformat == eHonorPointers) 1726 s.PutCString(m_name.AsCString()); 1727 1728 if (!IsBaseClass()) 1729 { 1730 if (!is_deref_of_parent) 1731 { 1732 ValueObject *non_base_class_parent = GetNonBaseClassParent(); 1733 if (non_base_class_parent) 1734 { 1735 clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType(); 1736 if (non_base_class_parent_clang_type) 1737 { 1738 const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL); 1739 1740 if (parent && parent->IsDereferenceOfParent() && epformat == eHonorPointers) 1741 { 1742 s.PutCString("->"); 1743 } 1744 else 1745 { 1746 if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer) 1747 { 1748 s.PutCString("->"); 1749 } 1750 else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) && 1751 !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray)) 1752 { 1753 s.PutChar('.'); 1754 } 1755 } 1756 } 1757 } 1758 1759 const char *name = GetName().GetCString(); 1760 if (name) 1761 { 1762 if (qualify_cxx_base_classes) 1763 { 1764 if (GetBaseClassPath (s)) 1765 s.PutCString("::"); 1766 } 1767 s.PutCString(name); 1768 } 1769 } 1770 } 1771 1772 if (is_deref_of_parent && epformat == eDereferencePointers) { 1773 s.PutChar(')'); 1774 } 1775} 1776 1777lldb::ValueObjectSP 1778ValueObject::GetValueForExpressionPath(const char* expression, 1779 const char** first_unparsed, 1780 ExpressionPathScanEndReason* reason_to_stop, 1781 ExpressionPathEndResultType* final_value_type, 1782 const GetValueForExpressionPathOptions& options, 1783 ExpressionPathAftermath* final_task_on_target) 1784{ 1785 1786 const char* dummy_first_unparsed; 1787 ExpressionPathScanEndReason dummy_reason_to_stop; 1788 ExpressionPathEndResultType dummy_final_value_type; 1789 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; 1790 1791 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, 1792 first_unparsed ? first_unparsed : &dummy_first_unparsed, 1793 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 1794 final_value_type ? final_value_type : &dummy_final_value_type, 1795 options, 1796 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); 1797 1798 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) 1799 { 1800 return ret_val; 1801 } 1802 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects 1803 { 1804 if (*final_task_on_target == ValueObject::eDereference) 1805 { 1806 Error error; 1807 ValueObjectSP final_value = ret_val->Dereference(error); 1808 if (error.Fail() || !final_value.get()) 1809 { 1810 *reason_to_stop = ValueObject::eDereferencingFailed; 1811 *final_value_type = ValueObject::eInvalid; 1812 return ValueObjectSP(); 1813 } 1814 else 1815 { 1816 *final_task_on_target = ValueObject::eNothing; 1817 return final_value; 1818 } 1819 } 1820 if (*final_task_on_target == ValueObject::eTakeAddress) 1821 { 1822 Error error; 1823 ValueObjectSP final_value = ret_val->AddressOf(error); 1824 if (error.Fail() || !final_value.get()) 1825 { 1826 *reason_to_stop = ValueObject::eTakingAddressFailed; 1827 *final_value_type = ValueObject::eInvalid; 1828 return ValueObjectSP(); 1829 } 1830 else 1831 { 1832 *final_task_on_target = ValueObject::eNothing; 1833 return final_value; 1834 } 1835 } 1836 } 1837 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it 1838} 1839 1840int 1841ValueObject::GetValuesForExpressionPath(const char* expression, 1842 lldb::ValueObjectListSP& list, 1843 const char** first_unparsed, 1844 ExpressionPathScanEndReason* reason_to_stop, 1845 ExpressionPathEndResultType* final_value_type, 1846 const GetValueForExpressionPathOptions& options, 1847 ExpressionPathAftermath* final_task_on_target) 1848{ 1849 const char* dummy_first_unparsed; 1850 ExpressionPathScanEndReason dummy_reason_to_stop; 1851 ExpressionPathEndResultType dummy_final_value_type; 1852 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eNothing; 1853 1854 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression, 1855 first_unparsed ? first_unparsed : &dummy_first_unparsed, 1856 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 1857 final_value_type ? final_value_type : &dummy_final_value_type, 1858 options, 1859 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); 1860 1861 if (!ret_val.get()) // if there are errors, I add nothing to the list 1862 return 0; 1863 1864 if (*reason_to_stop != eArrayRangeOperatorMet) 1865 { 1866 // I need not expand a range, just post-process the final value and return 1867 if (!final_task_on_target || *final_task_on_target == ValueObject::eNothing) 1868 { 1869 list->Append(ret_val); 1870 return 1; 1871 } 1872 if (ret_val.get() && *final_value_type == ePlain) // I can only deref and takeaddress of plain objects 1873 { 1874 if (*final_task_on_target == ValueObject::eDereference) 1875 { 1876 Error error; 1877 ValueObjectSP final_value = ret_val->Dereference(error); 1878 if (error.Fail() || !final_value.get()) 1879 { 1880 *reason_to_stop = ValueObject::eDereferencingFailed; 1881 *final_value_type = ValueObject::eInvalid; 1882 return 0; 1883 } 1884 else 1885 { 1886 *final_task_on_target = ValueObject::eNothing; 1887 list->Append(final_value); 1888 return 1; 1889 } 1890 } 1891 if (*final_task_on_target == ValueObject::eTakeAddress) 1892 { 1893 Error error; 1894 ValueObjectSP final_value = ret_val->AddressOf(error); 1895 if (error.Fail() || !final_value.get()) 1896 { 1897 *reason_to_stop = ValueObject::eTakingAddressFailed; 1898 *final_value_type = ValueObject::eInvalid; 1899 return 0; 1900 } 1901 else 1902 { 1903 *final_task_on_target = ValueObject::eNothing; 1904 list->Append(final_value); 1905 return 1; 1906 } 1907 } 1908 } 1909 } 1910 else 1911 { 1912 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed, 1913 first_unparsed ? first_unparsed : &dummy_first_unparsed, 1914 ret_val, 1915 list, 1916 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop, 1917 final_value_type ? final_value_type : &dummy_final_value_type, 1918 options, 1919 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target); 1920 } 1921 // in any non-covered case, just do the obviously right thing 1922 list->Append(ret_val); 1923 return 1; 1924} 1925 1926lldb::ValueObjectSP 1927ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr, 1928 const char** first_unparsed, 1929 ExpressionPathScanEndReason* reason_to_stop, 1930 ExpressionPathEndResultType* final_result, 1931 const GetValueForExpressionPathOptions& options, 1932 ExpressionPathAftermath* what_next) 1933{ 1934 ValueObjectSP root = GetSP(); 1935 1936 if (!root.get()) 1937 return ValueObjectSP(); 1938 1939 *first_unparsed = expression_cstr; 1940 1941 while (true) 1942 { 1943 1944 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr 1945 1946 lldb::clang_type_t root_clang_type = root->GetClangType(); 1947 lldb::clang_type_t pointee_clang_type; 1948 Flags root_clang_type_info,pointee_clang_type_info; 1949 1950 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); 1951 if (pointee_clang_type) 1952 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); 1953 1954 if (!expression_cstr || *expression_cstr == '\0') 1955 { 1956 *reason_to_stop = ValueObject::eEndOfString; 1957 return root; 1958 } 1959 1960 switch (*expression_cstr) 1961 { 1962 case '-': 1963 { 1964 if (options.m_check_dot_vs_arrow_syntax && 1965 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error 1966 { 1967 *first_unparsed = expression_cstr; 1968 *reason_to_stop = ValueObject::eArrowInsteadOfDot; 1969 *final_result = ValueObject::eInvalid; 1970 return ValueObjectSP(); 1971 } 1972 if (root_clang_type_info.Test(ClangASTContext::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden 1973 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer) && 1974 options.m_no_fragile_ivar) 1975 { 1976 *first_unparsed = expression_cstr; 1977 *reason_to_stop = ValueObject::eFragileIVarNotAllowed; 1978 *final_result = ValueObject::eInvalid; 1979 return ValueObjectSP(); 1980 } 1981 if (expression_cstr[1] != '>') 1982 { 1983 *first_unparsed = expression_cstr; 1984 *reason_to_stop = ValueObject::eUnexpectedSymbol; 1985 *final_result = ValueObject::eInvalid; 1986 return ValueObjectSP(); 1987 } 1988 expression_cstr++; // skip the - 1989 } 1990 case '.': // or fallthrough from -> 1991 { 1992 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' && 1993 root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error 1994 { 1995 *first_unparsed = expression_cstr; 1996 *reason_to_stop = ValueObject::eDotInsteadOfArrow; 1997 *final_result = ValueObject::eInvalid; 1998 return ValueObjectSP(); 1999 } 2000 expression_cstr++; // skip . 2001 const char *next_separator = strpbrk(expression_cstr+1,"-.["); 2002 ConstString child_name; 2003 if (!next_separator) // if no other separator just expand this last layer 2004 { 2005 child_name.SetCString (expression_cstr); 2006 root = root->GetChildMemberWithName(child_name, true); 2007 if (root.get()) // we know we are done, so just return 2008 { 2009 *first_unparsed = '\0'; 2010 *reason_to_stop = ValueObject::eEndOfString; 2011 *final_result = ValueObject::ePlain; 2012 return root; 2013 } 2014 else 2015 { 2016 *first_unparsed = expression_cstr; 2017 *reason_to_stop = ValueObject::eNoSuchChild; 2018 *final_result = ValueObject::eInvalid; 2019 return ValueObjectSP(); 2020 } 2021 } 2022 else // other layers do expand 2023 { 2024 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr); 2025 root = root->GetChildMemberWithName(child_name, true); 2026 if (root.get()) // store the new root and move on 2027 { 2028 *first_unparsed = next_separator; 2029 *final_result = ValueObject::ePlain; 2030 continue; 2031 } 2032 else 2033 { 2034 *first_unparsed = expression_cstr; 2035 *reason_to_stop = ValueObject::eNoSuchChild; 2036 *final_result = ValueObject::eInvalid; 2037 return ValueObjectSP(); 2038 } 2039 } 2040 break; 2041 } 2042 case '[': 2043 { 2044 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* 2045 { 2046 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! 2047 { 2048 *first_unparsed = expression_cstr; 2049 *reason_to_stop = ValueObject::eRangeOperatorInvalid; 2050 *final_result = ValueObject::eInvalid; 2051 return ValueObjectSP(); 2052 } 2053 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields 2054 { 2055 *first_unparsed = expression_cstr; 2056 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; 2057 *final_result = ValueObject::eInvalid; 2058 return ValueObjectSP(); 2059 } 2060 } 2061 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays 2062 { 2063 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2064 { 2065 *first_unparsed = expression_cstr; 2066 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2067 *final_result = ValueObject::eInvalid; 2068 return ValueObjectSP(); 2069 } 2070 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it 2071 { 2072 *first_unparsed = expression_cstr+2; 2073 *reason_to_stop = ValueObject::eArrayRangeOperatorMet; 2074 *final_result = ValueObject::eUnboundedRange; 2075 return root; 2076 } 2077 } 2078 const char *separator_position = ::strchr(expression_cstr+1,'-'); 2079 const char *close_bracket_position = ::strchr(expression_cstr+1,']'); 2080 if (!close_bracket_position) // if there is no ], this is a syntax error 2081 { 2082 *first_unparsed = expression_cstr; 2083 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2084 *final_result = ValueObject::eInvalid; 2085 return ValueObjectSP(); 2086 } 2087 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] 2088 { 2089 char *end = NULL; 2090 unsigned long index = ::strtoul (expression_cstr+1, &end, 0); 2091 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2092 { 2093 *first_unparsed = expression_cstr; 2094 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2095 *final_result = ValueObject::eInvalid; 2096 return ValueObjectSP(); 2097 } 2098 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays 2099 { 2100 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2101 { 2102 *first_unparsed = expression_cstr+2; 2103 *reason_to_stop = ValueObject::eArrayRangeOperatorMet; 2104 *final_result = ValueObject::eUnboundedRange; 2105 return root; 2106 } 2107 else 2108 { 2109 *first_unparsed = expression_cstr; 2110 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2111 *final_result = ValueObject::eInvalid; 2112 return ValueObjectSP(); 2113 } 2114 } 2115 // from here on we do have a valid index 2116 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2117 { 2118 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true); 2119 if (!child_valobj_sp) 2120 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true); 2121 if (child_valobj_sp) 2122 { 2123 root = child_valobj_sp; 2124 *first_unparsed = end+1; // skip ] 2125 *final_result = ValueObject::ePlain; 2126 continue; 2127 } 2128 else 2129 { 2130 *first_unparsed = expression_cstr; 2131 *reason_to_stop = ValueObject::eNoSuchChild; 2132 *final_result = ValueObject::eInvalid; 2133 return ValueObjectSP(); 2134 } 2135 } 2136 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) 2137 { 2138 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 2139 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2140 { 2141 Error error; 2142 root = root->Dereference(error); 2143 if (error.Fail() || !root.get()) 2144 { 2145 *first_unparsed = expression_cstr; 2146 *reason_to_stop = ValueObject::eDereferencingFailed; 2147 *final_result = ValueObject::eInvalid; 2148 return ValueObjectSP(); 2149 } 2150 else 2151 { 2152 *what_next = eNothing; 2153 continue; 2154 } 2155 } 2156 else 2157 { 2158 root = root->GetSyntheticArrayMemberFromPointer(index, true); 2159 if (!root.get()) 2160 { 2161 *first_unparsed = expression_cstr; 2162 *reason_to_stop = ValueObject::eNoSuchChild; 2163 *final_result = ValueObject::eInvalid; 2164 return ValueObjectSP(); 2165 } 2166 else 2167 { 2168 *first_unparsed = end+1; // skip ] 2169 *final_result = ValueObject::ePlain; 2170 continue; 2171 } 2172 } 2173 } 2174 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ 2175 { 2176 root = root->GetSyntheticBitFieldChild(index, index, true); 2177 if (!root.get()) 2178 { 2179 *first_unparsed = expression_cstr; 2180 *reason_to_stop = ValueObject::eNoSuchChild; 2181 *final_result = ValueObject::eInvalid; 2182 return ValueObjectSP(); 2183 } 2184 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing 2185 { 2186 *first_unparsed = end+1; // skip ] 2187 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; 2188 *final_result = ValueObject::eBitfield; 2189 return root; 2190 } 2191 } 2192 } 2193 else // we have a low and a high index 2194 { 2195 char *end = NULL; 2196 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); 2197 if (!end || end != separator_position) // if something weird is in our way return an error 2198 { 2199 *first_unparsed = expression_cstr; 2200 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2201 *final_result = ValueObject::eInvalid; 2202 return ValueObjectSP(); 2203 } 2204 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); 2205 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2206 { 2207 *first_unparsed = expression_cstr; 2208 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2209 *final_result = ValueObject::eInvalid; 2210 return ValueObjectSP(); 2211 } 2212 if (index_lower > index_higher) // swap indices if required 2213 { 2214 unsigned long temp = index_lower; 2215 index_lower = index_higher; 2216 index_higher = temp; 2217 } 2218 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars 2219 { 2220 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true); 2221 if (!root.get()) 2222 { 2223 *first_unparsed = expression_cstr; 2224 *reason_to_stop = ValueObject::eNoSuchChild; 2225 *final_result = ValueObject::eInvalid; 2226 return ValueObjectSP(); 2227 } 2228 else 2229 { 2230 *first_unparsed = end+1; // skip ] 2231 *reason_to_stop = ValueObject::eBitfieldRangeOperatorMet; 2232 *final_result = ValueObject::eBitfield; 2233 return root; 2234 } 2235 } 2236 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 2237 *what_next == ValueObject::eDereference && 2238 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2239 { 2240 Error error; 2241 root = root->Dereference(error); 2242 if (error.Fail() || !root.get()) 2243 { 2244 *first_unparsed = expression_cstr; 2245 *reason_to_stop = ValueObject::eDereferencingFailed; 2246 *final_result = ValueObject::eInvalid; 2247 return ValueObjectSP(); 2248 } 2249 else 2250 { 2251 *what_next = ValueObject::eNothing; 2252 continue; 2253 } 2254 } 2255 else 2256 { 2257 *first_unparsed = expression_cstr; 2258 *reason_to_stop = ValueObject::eArrayRangeOperatorMet; 2259 *final_result = ValueObject::eBoundedRange; 2260 return root; 2261 } 2262 } 2263 break; 2264 } 2265 default: // some non-separator is in the way 2266 { 2267 *first_unparsed = expression_cstr; 2268 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2269 *final_result = ValueObject::eInvalid; 2270 return ValueObjectSP(); 2271 break; 2272 } 2273 } 2274 } 2275} 2276 2277int 2278ValueObject::ExpandArraySliceExpression(const char* expression_cstr, 2279 const char** first_unparsed, 2280 lldb::ValueObjectSP root, 2281 lldb::ValueObjectListSP& list, 2282 ExpressionPathScanEndReason* reason_to_stop, 2283 ExpressionPathEndResultType* final_result, 2284 const GetValueForExpressionPathOptions& options, 2285 ExpressionPathAftermath* what_next) 2286{ 2287 if (!root.get()) 2288 return 0; 2289 2290 *first_unparsed = expression_cstr; 2291 2292 while (true) 2293 { 2294 2295 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr 2296 2297 lldb::clang_type_t root_clang_type = root->GetClangType(); 2298 lldb::clang_type_t pointee_clang_type; 2299 Flags root_clang_type_info,pointee_clang_type_info; 2300 2301 root_clang_type_info = Flags(ClangASTContext::GetTypeInfo(root_clang_type, GetClangAST(), &pointee_clang_type)); 2302 if (pointee_clang_type) 2303 pointee_clang_type_info = Flags(ClangASTContext::GetTypeInfo(pointee_clang_type, GetClangAST(), NULL)); 2304 2305 if (!expression_cstr || *expression_cstr == '\0') 2306 { 2307 *reason_to_stop = ValueObject::eEndOfString; 2308 list->Append(root); 2309 return 1; 2310 } 2311 2312 switch (*expression_cstr) 2313 { 2314 case '[': 2315 { 2316 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray) && !root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) // if this is not a T[] nor a T* 2317 { 2318 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong! 2319 { 2320 *first_unparsed = expression_cstr; 2321 *reason_to_stop = ValueObject::eRangeOperatorInvalid; 2322 *final_result = ValueObject::eInvalid; 2323 return 0; 2324 } 2325 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields 2326 { 2327 *first_unparsed = expression_cstr; 2328 *reason_to_stop = ValueObject::eRangeOperatorNotAllowed; 2329 *final_result = ValueObject::eInvalid; 2330 return 0; 2331 } 2332 } 2333 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays 2334 { 2335 if (!root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2336 { 2337 *first_unparsed = expression_cstr; 2338 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2339 *final_result = ValueObject::eInvalid; 2340 return 0; 2341 } 2342 else // expand this into list 2343 { 2344 int max_index = root->GetNumChildren() - 1; 2345 for (int index = 0; index < max_index; index++) 2346 { 2347 ValueObjectSP child = 2348 root->GetChildAtIndex(index, true); 2349 list->Append(child); 2350 } 2351 *first_unparsed = expression_cstr+2; 2352 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2353 *final_result = ValueObject::eValueObjectList; 2354 return max_index; // tell me number of items I added to the VOList 2355 } 2356 } 2357 const char *separator_position = ::strchr(expression_cstr+1,'-'); 2358 const char *close_bracket_position = ::strchr(expression_cstr+1,']'); 2359 if (!close_bracket_position) // if there is no ], this is a syntax error 2360 { 2361 *first_unparsed = expression_cstr; 2362 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2363 *final_result = ValueObject::eInvalid; 2364 return 0; 2365 } 2366 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N] 2367 { 2368 char *end = NULL; 2369 unsigned long index = ::strtoul (expression_cstr+1, &end, 0); 2370 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2371 { 2372 *first_unparsed = expression_cstr; 2373 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2374 *final_result = ValueObject::eInvalid; 2375 return 0; 2376 } 2377 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays 2378 { 2379 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2380 { 2381 int max_index = root->GetNumChildren() - 1; 2382 for (int index = 0; index < max_index; index++) 2383 { 2384 ValueObjectSP child = 2385 root->GetChildAtIndex(index, true); 2386 list->Append(child); 2387 } 2388 *first_unparsed = expression_cstr+2; 2389 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2390 *final_result = ValueObject::eValueObjectList; 2391 return max_index; // tell me number of items I added to the VOList 2392 } 2393 else 2394 { 2395 *first_unparsed = expression_cstr; 2396 *reason_to_stop = ValueObject::eEmptyRangeNotAllowed; 2397 *final_result = ValueObject::eInvalid; 2398 return 0; 2399 } 2400 } 2401 // from here on we do have a valid index 2402 if (root_clang_type_info.Test(ClangASTContext::eTypeIsArray)) 2403 { 2404 root = root->GetChildAtIndex(index, true); 2405 if (!root.get()) 2406 { 2407 *first_unparsed = expression_cstr; 2408 *reason_to_stop = ValueObject::eNoSuchChild; 2409 *final_result = ValueObject::eInvalid; 2410 return 0; 2411 } 2412 else 2413 { 2414 list->Append(root); 2415 *first_unparsed = end+1; // skip ] 2416 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2417 *final_result = ValueObject::eValueObjectList; 2418 return 1; 2419 } 2420 } 2421 else if (root_clang_type_info.Test(ClangASTContext::eTypeIsPointer)) 2422 { 2423 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 2424 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2425 { 2426 Error error; 2427 root = root->Dereference(error); 2428 if (error.Fail() || !root.get()) 2429 { 2430 *first_unparsed = expression_cstr; 2431 *reason_to_stop = ValueObject::eDereferencingFailed; 2432 *final_result = ValueObject::eInvalid; 2433 return 0; 2434 } 2435 else 2436 { 2437 *what_next = eNothing; 2438 continue; 2439 } 2440 } 2441 else 2442 { 2443 root = root->GetSyntheticArrayMemberFromPointer(index, true); 2444 if (!root.get()) 2445 { 2446 *first_unparsed = expression_cstr; 2447 *reason_to_stop = ValueObject::eNoSuchChild; 2448 *final_result = ValueObject::eInvalid; 2449 return 0; 2450 } 2451 else 2452 { 2453 list->Append(root); 2454 *first_unparsed = end+1; // skip ] 2455 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2456 *final_result = ValueObject::eValueObjectList; 2457 return 1; 2458 } 2459 } 2460 } 2461 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/ 2462 { 2463 root = root->GetSyntheticBitFieldChild(index, index, true); 2464 if (!root.get()) 2465 { 2466 *first_unparsed = expression_cstr; 2467 *reason_to_stop = ValueObject::eNoSuchChild; 2468 *final_result = ValueObject::eInvalid; 2469 return 0; 2470 } 2471 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing 2472 { 2473 list->Append(root); 2474 *first_unparsed = end+1; // skip ] 2475 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2476 *final_result = ValueObject::eValueObjectList; 2477 return 1; 2478 } 2479 } 2480 } 2481 else // we have a low and a high index 2482 { 2483 char *end = NULL; 2484 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0); 2485 if (!end || end != separator_position) // if something weird is in our way return an error 2486 { 2487 *first_unparsed = expression_cstr; 2488 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2489 *final_result = ValueObject::eInvalid; 2490 return 0; 2491 } 2492 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0); 2493 if (!end || end != close_bracket_position) // if something weird is in our way return an error 2494 { 2495 *first_unparsed = expression_cstr; 2496 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2497 *final_result = ValueObject::eInvalid; 2498 return 0; 2499 } 2500 if (index_lower > index_higher) // swap indices if required 2501 { 2502 unsigned long temp = index_lower; 2503 index_lower = index_higher; 2504 index_higher = temp; 2505 } 2506 if (root_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) // expansion only works for scalars 2507 { 2508 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, 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 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 2526 *what_next == ValueObject::eDereference && 2527 pointee_clang_type_info.Test(ClangASTContext::eTypeIsScalar)) 2528 { 2529 Error error; 2530 root = root->Dereference(error); 2531 if (error.Fail() || !root.get()) 2532 { 2533 *first_unparsed = expression_cstr; 2534 *reason_to_stop = ValueObject::eDereferencingFailed; 2535 *final_result = ValueObject::eInvalid; 2536 return 0; 2537 } 2538 else 2539 { 2540 *what_next = ValueObject::eNothing; 2541 continue; 2542 } 2543 } 2544 else 2545 { 2546 for (unsigned long index = index_lower; 2547 index <= index_higher; index++) 2548 { 2549 ValueObjectSP child = 2550 root->GetChildAtIndex(index, true); 2551 list->Append(child); 2552 } 2553 *first_unparsed = end+1; 2554 *reason_to_stop = ValueObject::eRangeOperatorExpanded; 2555 *final_result = ValueObject::eValueObjectList; 2556 return index_higher-index_lower+1; // tell me number of items I added to the VOList 2557 } 2558 } 2559 break; 2560 } 2561 default: // some non-[ separator, or something entirely wrong, is in the way 2562 { 2563 *first_unparsed = expression_cstr; 2564 *reason_to_stop = ValueObject::eUnexpectedSymbol; 2565 *final_result = ValueObject::eInvalid; 2566 return 0; 2567 break; 2568 } 2569 } 2570 } 2571} 2572 2573void 2574ValueObject::DumpValueObject 2575( 2576 Stream &s, 2577 ValueObject *valobj, 2578 const char *root_valobj_name, 2579 uint32_t ptr_depth, 2580 uint32_t curr_depth, 2581 uint32_t max_depth, 2582 bool show_types, 2583 bool show_location, 2584 bool use_objc, 2585 lldb::DynamicValueType use_dynamic, 2586 bool use_synth, 2587 bool scope_already_checked, 2588 bool flat_output, 2589 uint32_t omit_summary_depth 2590) 2591{ 2592 if (valobj) 2593 { 2594 bool update_success = valobj->UpdateValueIfNeeded (use_dynamic, true); 2595 2596 if (update_success && use_dynamic != lldb::eNoDynamicValues) 2597 { 2598 ValueObject *dynamic_value = valobj->GetDynamicValue(use_dynamic).get(); 2599 if (dynamic_value) 2600 valobj = dynamic_value; 2601 } 2602 2603 clang_type_t clang_type = valobj->GetClangType(); 2604 2605 const Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, NULL)); 2606 const char *err_cstr = NULL; 2607 const bool has_children = type_flags.Test (ClangASTContext::eTypeHasChildren); 2608 const bool has_value = type_flags.Test (ClangASTContext::eTypeHasValue); 2609 2610 const bool print_valobj = flat_output == false || has_value; 2611 2612 if (print_valobj) 2613 { 2614 if (show_location) 2615 { 2616 s.Printf("%s: ", valobj->GetLocationAsCString()); 2617 } 2618 2619 s.Indent(); 2620 2621 // Always show the type for the top level items. 2622 if (show_types || (curr_depth == 0 && !flat_output)) 2623 { 2624 const char* typeName = valobj->GetTypeName().AsCString("<invalid type>"); 2625 s.Printf("(%s", typeName); 2626 // only show dynamic types if the user really wants to see types 2627 if (show_types && use_dynamic != lldb::eNoDynamicValues && 2628 (/*strstr(typeName, "id") == typeName ||*/ 2629 ClangASTType::GetMinimumLanguage(valobj->GetClangAST(), valobj->GetClangType()) == lldb::eLanguageTypeObjC)) 2630 { 2631 Process* process = valobj->GetUpdatePoint().GetProcessSP().get(); 2632 if (process == NULL) 2633 s.Printf(", dynamic type: unknown) "); 2634 else 2635 { 2636 ObjCLanguageRuntime *runtime = process->GetObjCLanguageRuntime(); 2637 if (runtime == NULL) 2638 s.Printf(", dynamic type: unknown) "); 2639 else 2640 { 2641 ObjCLanguageRuntime::ObjCISA isa = runtime->GetISA(*valobj); 2642 if (!runtime->IsValidISA(isa)) 2643 s.Printf(", dynamic type: unknown) "); 2644 else 2645 s.Printf(", dynamic type: %s) ", 2646 runtime->GetActualTypeName(isa).GetCString()); 2647 } 2648 } 2649 } 2650 else 2651 s.Printf(") "); 2652 } 2653 2654 2655 if (flat_output) 2656 { 2657 // If we are showing types, also qualify the C++ base classes 2658 const bool qualify_cxx_base_classes = show_types; 2659 valobj->GetExpressionPath(s, qualify_cxx_base_classes); 2660 s.PutCString(" ="); 2661 } 2662 else 2663 { 2664 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString(""); 2665 s.Printf ("%s =", name_cstr); 2666 } 2667 2668 if (!scope_already_checked && !valobj->IsInScope()) 2669 { 2670 err_cstr = "out of scope"; 2671 } 2672 } 2673 2674 const char *val_cstr = NULL; 2675 const char *sum_cstr = NULL; 2676 SummaryFormat* entry = valobj->GetSummaryFormat().get(); 2677 2678 if (omit_summary_depth > 0) 2679 entry = NULL; 2680 2681 if (err_cstr == NULL) 2682 { 2683 val_cstr = valobj->GetValueAsCString(); 2684 err_cstr = valobj->GetError().AsCString(); 2685 } 2686 2687 if (err_cstr) 2688 { 2689 s.Printf (" <%s>\n", err_cstr); 2690 } 2691 else 2692 { 2693 const bool is_ref = type_flags.Test (ClangASTContext::eTypeIsReference); 2694 if (print_valobj) 2695 { 2696 2697 sum_cstr = (omit_summary_depth == 0) ? valobj->GetSummaryAsCString() : NULL; 2698 2699 // We must calculate this value in realtime because entry might alter this variable's value 2700 // (e.g. by saying ${var%fmt}) and render precached values useless 2701 if (val_cstr && (!entry || entry->DoesPrintValue() || !sum_cstr)) 2702 s.Printf(" %s", valobj->GetValueAsCString()); 2703 2704 if (sum_cstr) 2705 { 2706 // for some reason, using %@ (ObjC description) in a summary string, makes 2707 // us believe we need to reset ourselves, thus invalidating the content of 2708 // sum_cstr. Thus, IF we had a valid sum_cstr before, but it is now empty 2709 // let us recalculate it! 2710 if (sum_cstr[0] == '\0') 2711 s.Printf(" %s", valobj->GetSummaryAsCString()); 2712 else 2713 s.Printf(" %s", sum_cstr); 2714 } 2715 2716 if (use_objc) 2717 { 2718 const char *object_desc = valobj->GetObjectDescription(); 2719 if (object_desc) 2720 s.Printf(" %s\n", object_desc); 2721 else 2722 s.Printf (" [no Objective-C description available]\n"); 2723 return; 2724 } 2725 } 2726 2727 if (curr_depth < max_depth) 2728 { 2729 // We will show children for all concrete types. We won't show 2730 // pointer contents unless a pointer depth has been specified. 2731 // We won't reference contents unless the reference is the 2732 // root object (depth of zero). 2733 bool print_children = true; 2734 2735 // Use a new temporary pointer depth in case we override the 2736 // current pointer depth below... 2737 uint32_t curr_ptr_depth = ptr_depth; 2738 2739 const bool is_ptr = type_flags.Test (ClangASTContext::eTypeIsPointer); 2740 if (is_ptr || is_ref) 2741 { 2742 // We have a pointer or reference whose value is an address. 2743 // Make sure that address is not NULL 2744 AddressType ptr_address_type; 2745 if (valobj->GetPointerValue (ptr_address_type, true) == 0) 2746 print_children = false; 2747 2748 else if (is_ref && curr_depth == 0) 2749 { 2750 // If this is the root object (depth is zero) that we are showing 2751 // and it is a reference, and no pointer depth has been supplied 2752 // print out what it references. Don't do this at deeper depths 2753 // otherwise we can end up with infinite recursion... 2754 curr_ptr_depth = 1; 2755 } 2756 2757 if (curr_ptr_depth == 0) 2758 print_children = false; 2759 } 2760 2761 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr)) 2762 { 2763 ValueObjectSP synth_vobj = valobj->GetSyntheticValue(use_synth ? 2764 lldb::eUseSyntheticFilter : 2765 lldb::eNoSyntheticFilter); 2766 const uint32_t num_children = synth_vobj->GetNumChildren(); 2767 if (num_children) 2768 { 2769 if (flat_output) 2770 { 2771 if (print_valobj) 2772 s.EOL(); 2773 } 2774 else 2775 { 2776 if (print_valobj) 2777 s.PutCString(is_ref ? ": {\n" : " {\n"); 2778 s.IndentMore(); 2779 } 2780 2781 for (uint32_t idx=0; idx<num_children; ++idx) 2782 { 2783 ValueObjectSP child_sp(synth_vobj->GetChildAtIndex(idx, true)); 2784 if (child_sp.get()) 2785 { 2786 DumpValueObject (s, 2787 child_sp.get(), 2788 NULL, 2789 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth, 2790 curr_depth + 1, 2791 max_depth, 2792 show_types, 2793 show_location, 2794 false, 2795 use_dynamic, 2796 use_synth, 2797 true, 2798 flat_output, 2799 omit_summary_depth > 1 ? omit_summary_depth - 1 : 0); 2800 } 2801 } 2802 2803 if (!flat_output) 2804 { 2805 s.IndentLess(); 2806 s.Indent("}\n"); 2807 } 2808 } 2809 else if (has_children) 2810 { 2811 // Aggregate, no children... 2812 if (print_valobj) 2813 s.PutCString(" {}\n"); 2814 } 2815 else 2816 { 2817 if (print_valobj) 2818 s.EOL(); 2819 } 2820 2821 } 2822 else 2823 { 2824 s.EOL(); 2825 } 2826 } 2827 else 2828 { 2829 if (has_children && print_valobj) 2830 { 2831 s.PutCString("{...}\n"); 2832 } 2833 } 2834 } 2835 } 2836} 2837 2838 2839ValueObjectSP 2840ValueObject::CreateConstantValue (const ConstString &name) 2841{ 2842 ValueObjectSP valobj_sp; 2843 2844 if (UpdateValueIfNeeded(false) && m_error.Success()) 2845 { 2846 ExecutionContextScope *exe_scope = GetExecutionContextScope(); 2847 if (exe_scope) 2848 { 2849 ExecutionContext exe_ctx; 2850 exe_scope->CalculateExecutionContext(exe_ctx); 2851 2852 clang::ASTContext *ast = GetClangAST (); 2853 2854 DataExtractor data; 2855 data.SetByteOrder (m_data.GetByteOrder()); 2856 data.SetAddressByteSize(m_data.GetAddressByteSize()); 2857 2858 m_error = m_value.GetValueAsData (&exe_ctx, ast, data, 0, GetModule()); 2859 2860 valobj_sp = ValueObjectConstResult::Create (exe_scope, 2861 ast, 2862 GetClangType(), 2863 name, 2864 data); 2865 } 2866 } 2867 2868 if (!valobj_sp) 2869 { 2870 valobj_sp = ValueObjectConstResult::Create (NULL, m_error); 2871 } 2872 return valobj_sp; 2873} 2874 2875lldb::ValueObjectSP 2876ValueObject::Dereference (Error &error) 2877{ 2878 if (m_deref_valobj) 2879 return m_deref_valobj->GetSP(); 2880 2881 const bool is_pointer_type = IsPointerType(); 2882 if (is_pointer_type) 2883 { 2884 bool omit_empty_base_classes = true; 2885 bool ignore_array_bounds = false; 2886 2887 std::string child_name_str; 2888 uint32_t child_byte_size = 0; 2889 int32_t child_byte_offset = 0; 2890 uint32_t child_bitfield_bit_size = 0; 2891 uint32_t child_bitfield_bit_offset = 0; 2892 bool child_is_base_class = false; 2893 bool child_is_deref_of_parent = false; 2894 const bool transparent_pointers = false; 2895 clang::ASTContext *clang_ast = GetClangAST(); 2896 clang_type_t clang_type = GetClangType(); 2897 clang_type_t child_clang_type; 2898 2899 ExecutionContext exe_ctx; 2900 GetExecutionContextScope()->CalculateExecutionContext (exe_ctx); 2901 2902 child_clang_type = ClangASTContext::GetChildClangTypeAtIndex (&exe_ctx, 2903 clang_ast, 2904 GetName().GetCString(), 2905 clang_type, 2906 0, 2907 transparent_pointers, 2908 omit_empty_base_classes, 2909 ignore_array_bounds, 2910 child_name_str, 2911 child_byte_size, 2912 child_byte_offset, 2913 child_bitfield_bit_size, 2914 child_bitfield_bit_offset, 2915 child_is_base_class, 2916 child_is_deref_of_parent); 2917 if (child_clang_type && child_byte_size) 2918 { 2919 ConstString child_name; 2920 if (!child_name_str.empty()) 2921 child_name.SetCString (child_name_str.c_str()); 2922 2923 m_deref_valobj = new ValueObjectChild (*this, 2924 clang_ast, 2925 child_clang_type, 2926 child_name, 2927 child_byte_size, 2928 child_byte_offset, 2929 child_bitfield_bit_size, 2930 child_bitfield_bit_offset, 2931 child_is_base_class, 2932 child_is_deref_of_parent); 2933 } 2934 } 2935 2936 if (m_deref_valobj) 2937 { 2938 error.Clear(); 2939 return m_deref_valobj->GetSP(); 2940 } 2941 else 2942 { 2943 StreamString strm; 2944 GetExpressionPath(strm, true); 2945 2946 if (is_pointer_type) 2947 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 2948 else 2949 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str()); 2950 return ValueObjectSP(); 2951 } 2952} 2953 2954lldb::ValueObjectSP 2955ValueObject::AddressOf (Error &error) 2956{ 2957 if (m_addr_of_valobj_sp) 2958 return m_addr_of_valobj_sp; 2959 2960 AddressType address_type = eAddressTypeInvalid; 2961 const bool scalar_is_load_address = false; 2962 lldb::addr_t addr = GetAddressOf (address_type, scalar_is_load_address); 2963 error.Clear(); 2964 if (addr != LLDB_INVALID_ADDRESS) 2965 { 2966 switch (address_type) 2967 { 2968 default: 2969 case eAddressTypeInvalid: 2970 { 2971 StreamString expr_path_strm; 2972 GetExpressionPath(expr_path_strm, true); 2973 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str()); 2974 } 2975 break; 2976 2977 case eAddressTypeFile: 2978 case eAddressTypeLoad: 2979 case eAddressTypeHost: 2980 { 2981 clang::ASTContext *ast = GetClangAST(); 2982 clang_type_t clang_type = GetClangType(); 2983 if (ast && clang_type) 2984 { 2985 std::string name (1, '&'); 2986 name.append (m_name.AsCString("")); 2987 m_addr_of_valobj_sp = ValueObjectConstResult::Create (GetExecutionContextScope(), 2988 ast, 2989 ClangASTContext::CreatePointerType (ast, clang_type), 2990 ConstString (name.c_str()), 2991 addr, 2992 eAddressTypeInvalid, 2993 m_data.GetAddressByteSize()); 2994 } 2995 } 2996 break; 2997 } 2998 } 2999 return m_addr_of_valobj_sp; 3000} 3001 3002 3003lldb::ValueObjectSP 3004ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type) 3005{ 3006 lldb::ValueObjectSP valobj_sp; 3007 AddressType address_type; 3008 const bool scalar_is_load_address = true; 3009 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); 3010 3011 if (ptr_value != LLDB_INVALID_ADDRESS) 3012 { 3013 Address ptr_addr (NULL, ptr_value); 3014 3015 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), 3016 name, 3017 ptr_addr, 3018 clang_ast_type); 3019 } 3020 return valobj_sp; 3021} 3022 3023lldb::ValueObjectSP 3024ValueObject::CastPointerType (const char *name, TypeSP &type_sp) 3025{ 3026 lldb::ValueObjectSP valobj_sp; 3027 AddressType address_type; 3028 const bool scalar_is_load_address = true; 3029 lldb::addr_t ptr_value = GetPointerValue (address_type, scalar_is_load_address); 3030 3031 if (ptr_value != LLDB_INVALID_ADDRESS) 3032 { 3033 Address ptr_addr (NULL, ptr_value); 3034 3035 valobj_sp = ValueObjectMemory::Create (GetExecutionContextScope(), 3036 name, 3037 ptr_addr, 3038 type_sp); 3039 } 3040 return valobj_sp; 3041} 3042 3043ValueObject::EvaluationPoint::EvaluationPoint () : 3044 m_thread_id (LLDB_INVALID_UID), 3045 m_stop_id (0) 3046{ 3047} 3048 3049ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected): 3050 m_needs_update (true), 3051 m_first_update (true), 3052 m_thread_id (LLDB_INVALID_THREAD_ID), 3053 m_stop_id (0) 3054 3055{ 3056 ExecutionContext exe_ctx; 3057 ExecutionContextScope *computed_exe_scope = exe_scope; // If use_selected is true, we may find a better scope, 3058 // and if so we want to cache that not the original. 3059 if (exe_scope) 3060 exe_scope->CalculateExecutionContext(exe_ctx); 3061 if (exe_ctx.target != NULL) 3062 { 3063 m_target_sp = exe_ctx.target->GetSP(); 3064 3065 if (exe_ctx.process == NULL) 3066 m_process_sp = exe_ctx.target->GetProcessSP(); 3067 else 3068 m_process_sp = exe_ctx.process->GetSP(); 3069 3070 if (m_process_sp != NULL) 3071 { 3072 m_stop_id = m_process_sp->GetStopID(); 3073 Thread *thread = NULL; 3074 3075 if (exe_ctx.thread == NULL) 3076 { 3077 if (use_selected) 3078 { 3079 thread = m_process_sp->GetThreadList().GetSelectedThread().get(); 3080 if (thread) 3081 computed_exe_scope = thread; 3082 } 3083 } 3084 else 3085 thread = exe_ctx.thread; 3086 3087 if (thread != NULL) 3088 { 3089 m_thread_id = thread->GetIndexID(); 3090 if (exe_ctx.frame == NULL) 3091 { 3092 if (use_selected) 3093 { 3094 StackFrame *frame = exe_ctx.thread->GetSelectedFrame().get(); 3095 if (frame) 3096 { 3097 m_stack_id = frame->GetStackID(); 3098 computed_exe_scope = frame; 3099 } 3100 } 3101 } 3102 else 3103 m_stack_id = exe_ctx.frame->GetStackID(); 3104 } 3105 } 3106 } 3107 m_exe_scope = computed_exe_scope; 3108} 3109 3110ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) : 3111 m_exe_scope (rhs.m_exe_scope), 3112 m_needs_update(true), 3113 m_first_update(true), 3114 m_target_sp (rhs.m_target_sp), 3115 m_process_sp (rhs.m_process_sp), 3116 m_thread_id (rhs.m_thread_id), 3117 m_stack_id (rhs.m_stack_id), 3118 m_stop_id (0) 3119{ 3120} 3121 3122ValueObject::EvaluationPoint::~EvaluationPoint () 3123{ 3124} 3125 3126ExecutionContextScope * 3127ValueObject::EvaluationPoint::GetExecutionContextScope () 3128{ 3129 // We have to update before giving out the scope, or we could be handing out stale pointers. 3130 SyncWithProcessState(); 3131 3132 return m_exe_scope; 3133} 3134 3135// This function checks the EvaluationPoint against the current process state. If the current 3136// state matches the evaluation point, or the evaluation point is already invalid, then we return 3137// false, meaning "no change". If the current state is different, we update our state, and return 3138// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so 3139// future calls to NeedsUpdate will return true. 3140 3141bool 3142ValueObject::EvaluationPoint::SyncWithProcessState() 3143{ 3144 // If we're already invalid, we don't need to do anything, and nothing has changed: 3145 if (m_stop_id == LLDB_INVALID_UID) 3146 { 3147 // Can't update with an invalid state. 3148 m_needs_update = false; 3149 return false; 3150 } 3151 3152 // If we don't have a process nothing can change. 3153 if (!m_process_sp) 3154 return false; 3155 3156 // If our stop id is the current stop ID, nothing has changed: 3157 uint32_t cur_stop_id = m_process_sp->GetStopID(); 3158 if (m_stop_id == cur_stop_id) 3159 return false; 3160 3161 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared. 3162 // In either case, we aren't going to be able to sync with the process state. 3163 if (cur_stop_id == 0) 3164 return false; 3165 3166 m_stop_id = cur_stop_id; 3167 m_needs_update = true; 3168 m_exe_scope = m_process_sp.get(); 3169 3170 // Something has changed, so we will return true. Now make sure the thread & frame still exist, and if either 3171 // doesn't, mark ourselves as invalid. 3172 3173 if (m_thread_id != LLDB_INVALID_THREAD_ID) 3174 { 3175 Thread *our_thread = m_process_sp->GetThreadList().FindThreadByIndexID (m_thread_id).get(); 3176 if (our_thread == NULL) 3177 { 3178 SetInvalid(); 3179 } 3180 else 3181 { 3182 m_exe_scope = our_thread; 3183 3184 if (m_stack_id.IsValid()) 3185 { 3186 StackFrame *our_frame = our_thread->GetFrameWithStackID (m_stack_id).get(); 3187 if (our_frame == NULL) 3188 SetInvalid(); 3189 else 3190 m_exe_scope = our_frame; 3191 } 3192 } 3193 } 3194 return true; 3195} 3196 3197void 3198ValueObject::EvaluationPoint::SetUpdated () 3199{ 3200 m_first_update = false; 3201 m_needs_update = false; 3202 if (m_process_sp) 3203 m_stop_id = m_process_sp->GetStopID(); 3204} 3205 3206 3207bool 3208ValueObject::EvaluationPoint::SetContext (ExecutionContextScope *exe_scope) 3209{ 3210 if (!IsValid()) 3211 return false; 3212 3213 bool needs_update = false; 3214 m_exe_scope = NULL; 3215 3216 // The target has to be non-null, and the 3217 Target *target = exe_scope->CalculateTarget(); 3218 if (target != NULL) 3219 { 3220 Target *old_target = m_target_sp.get(); 3221 assert (target == old_target); 3222 Process *process = exe_scope->CalculateProcess(); 3223 if (process != NULL) 3224 { 3225 // FOR NOW - assume you can't update variable objects across process boundaries. 3226 Process *old_process = m_process_sp.get(); 3227 assert (process == old_process); 3228 3229 lldb::user_id_t stop_id = process->GetStopID(); 3230 if (stop_id != m_stop_id) 3231 { 3232 needs_update = true; 3233 m_stop_id = stop_id; 3234 } 3235 // See if we're switching the thread or stack context. If no thread is given, this is 3236 // being evaluated in a global context. 3237 Thread *thread = exe_scope->CalculateThread(); 3238 if (thread != NULL) 3239 { 3240 lldb::user_id_t new_thread_index = thread->GetIndexID(); 3241 if (new_thread_index != m_thread_id) 3242 { 3243 needs_update = true; 3244 m_thread_id = new_thread_index; 3245 m_stack_id.Clear(); 3246 } 3247 3248 StackFrame *new_frame = exe_scope->CalculateStackFrame(); 3249 if (new_frame != NULL) 3250 { 3251 if (new_frame->GetStackID() != m_stack_id) 3252 { 3253 needs_update = true; 3254 m_stack_id = new_frame->GetStackID(); 3255 } 3256 } 3257 else 3258 { 3259 m_stack_id.Clear(); 3260 needs_update = true; 3261 } 3262 } 3263 else 3264 { 3265 // If this had been given a thread, and now there is none, we should update. 3266 // Otherwise we don't have to do anything. 3267 if (m_thread_id != LLDB_INVALID_UID) 3268 { 3269 m_thread_id = LLDB_INVALID_UID; 3270 m_stack_id.Clear(); 3271 needs_update = true; 3272 } 3273 } 3274 } 3275 else 3276 { 3277 // If there is no process, then we don't need to update anything. 3278 // But if we're switching from having a process to not, we should try to update. 3279 if (m_process_sp.get() != NULL) 3280 { 3281 needs_update = true; 3282 m_process_sp.reset(); 3283 m_thread_id = LLDB_INVALID_UID; 3284 m_stack_id.Clear(); 3285 } 3286 } 3287 } 3288 else 3289 { 3290 // If there's no target, nothing can change so we don't need to update anything. 3291 // But if we're switching from having a target to not, we should try to update. 3292 if (m_target_sp.get() != NULL) 3293 { 3294 needs_update = true; 3295 m_target_sp.reset(); 3296 m_process_sp.reset(); 3297 m_thread_id = LLDB_INVALID_UID; 3298 m_stack_id.Clear(); 3299 } 3300 } 3301 if (!m_needs_update) 3302 m_needs_update = needs_update; 3303 3304 return needs_update; 3305} 3306 3307void 3308ValueObject::ClearUserVisibleData() 3309{ 3310 m_location_str.clear(); 3311 m_value_str.clear(); 3312 m_summary_str.clear(); 3313 m_object_desc_str.clear(); 3314} 3315