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