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