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