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