ValueObject.h revision 4758a3ced524198d2cf9c50bab9b088adcbda9cb
1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch//===-- ValueObject.h -------------------------------------------*- C++ -*-===// 2116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 3116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// The LLVM Compiler Infrastructure 4116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// This file is distributed under the University of Illinois Open Source 6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// License. See LICENSE.TXT for details. 7116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch//===----------------------------------------------------------------------===// 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef liblldb_ValueObject_h_ 11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define liblldb_ValueObject_h_ 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// C Includes 14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// C++ Includes 15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <map> 16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <vector> 17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Other libraries and framework includes 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Project includes 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/lldb-private.h" 21116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Core/DataExtractor.h" 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Core/Error.h" 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Core/Flags.h" 24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Core/ConstString.h" 25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Core/UserID.h" 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Core/Value.h" 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Target/ExecutionContext.h" 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Target/ExecutionContextScope.h" 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Target/Process.h" 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Target/StackID.h" 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "lldb/Utility/SharedCluster.h" 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace lldb_private { 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// ValueObject: 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// This abstract class provides an interface to a particular value, be it a register, a local or global variable, 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// that is evaluated in some particular scope. The ValueObject also has the capibility of being the "child" of 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// some other variable object, and in turn of having children. 40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// If a ValueObject is a root variable object - having no parent - then it must be constructed with respect to some 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// particular ExecutionContextScope. If it is a child, it inherits the ExecutionContextScope from its parent. 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// The ValueObject will update itself if necessary before fetching its value, summary, object description, etc. 43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// But it will always update itself in the ExecutionContextScope with which it was originally created. 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// A brief note on life cycle management for ValueObjects. This is a little tricky because a ValueObject can contain 46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// various other ValueObjects - the Dynamic Value, its children, the dereference value, etc. Any one of these can be 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// handed out as a shared pointer, but for that contained value object to be valid, the root object and potentially other 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// of the value objects need to stay around. 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/// We solve this problem by handing out shared pointers to the Value Object and any of its dependents using a shared 50/// ClusterManager. This treats each shared pointer handed out for the entire cluster as a reference to the whole 51/// cluster. The whole cluster will stay around until the last reference is released. 52/// 53/// The ValueObject mostly handle this automatically, if a value object is made with a Parent ValueObject, then it adds 54/// itself to the ClusterManager of the parent. 55 56/// It does mean that external to the ValueObjects we should only ever make available ValueObjectSP's, never ValueObjects 57/// or pointers to them. So all the "Root level" ValueObject derived constructors should be private, and 58/// should implement a Create function that new's up object and returns a Shared Pointer that it gets from the GetSP() method. 59/// 60/// However, if you are making an derived ValueObject that will be contained in a parent value object, you should just 61/// hold onto a pointer to it internally, and by virtue of passing the parent ValueObject into its constructor, it will 62/// be added to the ClusterManager for the parent. Then if you ever hand out a Shared Pointer to the contained ValueObject, 63/// just do so by calling GetSP() on the contained object. 64 65class ValueObject : public UserID 66{ 67public: 68 69 enum GetExpressionPathFormat 70 { 71 eGetExpressionPathFormatDereferencePointers = 1, 72 eGetExpressionPathFormatHonorPointers 73 }; 74 75 enum ValueObjectRepresentationStyle 76 { 77 eValueObjectRepresentationStyleValue = 1, 78 eValueObjectRepresentationStyleSummary, 79 eValueObjectRepresentationStyleLanguageSpecific, 80 eValueObjectRepresentationStyleLocation, 81 eValueObjectRepresentationStyleChildrenCount, 82 eValueObjectRepresentationStyleType 83 }; 84 85 enum ExpressionPathScanEndReason 86 { 87 eExpressionPathScanEndReasonEndOfString = 1, // out of data to parse 88 eExpressionPathScanEndReasonNoSuchChild, // child element not found 89 eExpressionPathScanEndReasonEmptyRangeNotAllowed, // [] only allowed for arrays 90 eExpressionPathScanEndReasonDotInsteadOfArrow, // . used when -> should be used 91 eExpressionPathScanEndReasonArrowInsteadOfDot, // -> used when . should be used 92 eExpressionPathScanEndReasonFragileIVarNotAllowed, // ObjC ivar expansion not allowed 93 eExpressionPathScanEndReasonRangeOperatorNotAllowed, // [] not allowed by options 94 eExpressionPathScanEndReasonRangeOperatorInvalid, // [] not valid on objects other than scalars, pointers or arrays 95 eExpressionPathScanEndReasonArrayRangeOperatorMet, // [] is good for arrays, but I cannot parse it 96 eExpressionPathScanEndReasonBitfieldRangeOperatorMet, // [] is good for bitfields, but I cannot parse after it 97 eExpressionPathScanEndReasonUnexpectedSymbol, // something is malformed in the expression 98 eExpressionPathScanEndReasonTakingAddressFailed, // impossible to apply & operator 99 eExpressionPathScanEndReasonDereferencingFailed, // impossible to apply * operator 100 eExpressionPathScanEndReasonRangeOperatorExpanded, // [] was expanded into a VOList 101 eExpressionPathScanEndReasonSyntheticValueMissing, // getting the synthetic children failed 102 eExpressionPathScanEndReasonUnknown = 0xFFFF 103 }; 104 105 enum ExpressionPathEndResultType 106 { 107 eExpressionPathEndResultTypePlain = 1, // anything but... 108 eExpressionPathEndResultTypeBitfield, // a bitfield 109 eExpressionPathEndResultTypeBoundedRange, // a range [low-high] 110 eExpressionPathEndResultTypeUnboundedRange, // a range [] 111 eExpressionPathEndResultTypeValueObjectList, // several items in a VOList 112 eExpressionPathEndResultTypeInvalid = 0xFFFF 113 }; 114 115 enum ExpressionPathAftermath 116 { 117 eExpressionPathAftermathNothing = 1, // just return it 118 eExpressionPathAftermathDereference, // dereference the target 119 eExpressionPathAftermathTakeAddress // take target's address 120 }; 121 122 enum ClearUserVisibleDataItems 123 { 124 eClearUserVisibleDataItemsNothing = 1u << 0, 125 eClearUserVisibleDataItemsValue = 1u << 1, 126 eClearUserVisibleDataItemsSummary = 1u << 2, 127 eClearUserVisibleDataItemsLocation = 1u << 3, 128 eClearUserVisibleDataItemsDescription = 1u << 4, 129 eClearUserVisibleDataItemsSyntheticChildren = 1u << 5, 130 eClearUserVisibleDataItemsAllStrings = eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsLocation | eClearUserVisibleDataItemsDescription, 131 eClearUserVisibleDataItemsAll = 0xFFFF 132 }; 133 134 struct GetValueForExpressionPathOptions 135 { 136 bool m_check_dot_vs_arrow_syntax; 137 bool m_no_fragile_ivar; 138 bool m_allow_bitfields_syntax; 139 bool m_no_synthetic_children; 140 141 GetValueForExpressionPathOptions(bool dot = false, 142 bool no_ivar = false, 143 bool bitfield = true, 144 bool no_synth = false) : 145 m_check_dot_vs_arrow_syntax(dot), 146 m_no_fragile_ivar(no_ivar), 147 m_allow_bitfields_syntax(bitfield), 148 m_no_synthetic_children(no_synth) 149 { 150 } 151 152 GetValueForExpressionPathOptions& 153 DoCheckDotVsArrowSyntax() 154 { 155 m_check_dot_vs_arrow_syntax = true; 156 return *this; 157 } 158 159 GetValueForExpressionPathOptions& 160 DontCheckDotVsArrowSyntax() 161 { 162 m_check_dot_vs_arrow_syntax = false; 163 return *this; 164 } 165 166 GetValueForExpressionPathOptions& 167 DoAllowFragileIVar() 168 { 169 m_no_fragile_ivar = false; 170 return *this; 171 } 172 173 GetValueForExpressionPathOptions& 174 DontAllowFragileIVar() 175 { 176 m_no_fragile_ivar = true; 177 return *this; 178 } 179 180 GetValueForExpressionPathOptions& 181 DoAllowBitfieldSyntax() 182 { 183 m_allow_bitfields_syntax = true; 184 return *this; 185 } 186 187 GetValueForExpressionPathOptions& 188 DontAllowBitfieldSyntax() 189 { 190 m_allow_bitfields_syntax = false; 191 return *this; 192 } 193 194 GetValueForExpressionPathOptions& 195 DoAllowSyntheticChildren() 196 { 197 m_no_synthetic_children = false; 198 return *this; 199 } 200 201 GetValueForExpressionPathOptions& 202 DontAllowSyntheticChildren() 203 { 204 m_no_synthetic_children = true; 205 return *this; 206 } 207 208 static const GetValueForExpressionPathOptions 209 DefaultOptions() 210 { 211 static GetValueForExpressionPathOptions g_default_options; 212 213 return g_default_options; 214 } 215 216 }; 217 218 struct DumpValueObjectOptions 219 { 220 uint32_t m_max_ptr_depth; 221 uint32_t m_max_depth; 222 bool m_show_types; 223 bool m_show_location; 224 bool m_use_objc; 225 lldb::DynamicValueType m_use_dynamic; 226 bool m_use_synthetic; 227 bool m_scope_already_checked; 228 bool m_flat_output; 229 uint32_t m_omit_summary_depth; 230 bool m_ignore_cap; 231 lldb::Format m_format; 232 lldb::TypeSummaryImplSP m_summary_sp; 233 std::string m_root_valobj_name; 234 235 DumpValueObjectOptions() : 236 m_max_ptr_depth(0), 237 m_max_depth(UINT32_MAX), 238 m_show_types(false), 239 m_show_location(false), 240 m_use_objc(false), 241 m_use_dynamic(lldb::eNoDynamicValues), 242 m_use_synthetic(true), 243 m_scope_already_checked(false), 244 m_flat_output(false), 245 m_omit_summary_depth(0), 246 m_ignore_cap(false), 247 m_format (lldb::eFormatDefault), 248 m_summary_sp(), 249 m_root_valobj_name() 250 {} 251 252 static const DumpValueObjectOptions 253 DefaultOptions() 254 { 255 static DumpValueObjectOptions g_default_options; 256 257 return g_default_options; 258 } 259 260 DumpValueObjectOptions (const DumpValueObjectOptions& rhs) : 261 m_max_ptr_depth(rhs.m_max_ptr_depth), 262 m_max_depth(rhs.m_max_depth), 263 m_show_types(rhs.m_show_types), 264 m_show_location(rhs.m_show_location), 265 m_use_objc(rhs.m_use_objc), 266 m_use_dynamic(rhs.m_use_dynamic), 267 m_use_synthetic(rhs.m_use_synthetic), 268 m_scope_already_checked(rhs.m_scope_already_checked), 269 m_flat_output(rhs.m_flat_output), 270 m_omit_summary_depth(rhs.m_omit_summary_depth), 271 m_ignore_cap(rhs.m_ignore_cap), 272 m_format(rhs.m_format), 273 m_summary_sp(rhs.m_summary_sp), 274 m_root_valobj_name(rhs.m_root_valobj_name) 275 {} 276 277 DumpValueObjectOptions& 278 SetMaximumPointerDepth(uint32_t depth = 0) 279 { 280 m_max_ptr_depth = depth; 281 return *this; 282 } 283 284 DumpValueObjectOptions& 285 SetMaximumDepth(uint32_t depth = 0) 286 { 287 m_max_depth = depth; 288 return *this; 289 } 290 291 DumpValueObjectOptions& 292 SetShowTypes(bool show = false) 293 { 294 m_show_types = show; 295 return *this; 296 } 297 298 DumpValueObjectOptions& 299 SetShowLocation(bool show = false) 300 { 301 m_show_location = show; 302 return *this; 303 } 304 305 DumpValueObjectOptions& 306 SetUseObjectiveC(bool use = false) 307 { 308 m_use_objc = use; 309 return *this; 310 } 311 312 DumpValueObjectOptions& 313 SetShowSummary(bool show = true) 314 { 315 if (show == false) 316 SetOmitSummaryDepth(UINT32_MAX); 317 else 318 SetOmitSummaryDepth(0); 319 return *this; 320 } 321 322 DumpValueObjectOptions& 323 SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues) 324 { 325 m_use_dynamic = dyn; 326 return *this; 327 } 328 329 DumpValueObjectOptions& 330 SetUseSyntheticValue(bool use_synthetic = true) 331 { 332 m_use_synthetic = use_synthetic; 333 return *this; 334 } 335 336 DumpValueObjectOptions& 337 SetScopeChecked(bool check = true) 338 { 339 m_scope_already_checked = check; 340 return *this; 341 } 342 343 DumpValueObjectOptions& 344 SetFlatOutput(bool flat = false) 345 { 346 m_flat_output = flat; 347 return *this; 348 } 349 350 DumpValueObjectOptions& 351 SetOmitSummaryDepth(uint32_t depth = 0) 352 { 353 m_omit_summary_depth = depth; 354 return *this; 355 } 356 357 DumpValueObjectOptions& 358 SetIgnoreCap(bool ignore = false) 359 { 360 m_ignore_cap = ignore; 361 return *this; 362 } 363 364 DumpValueObjectOptions& 365 SetRawDisplay(bool raw = false) 366 { 367 if (raw) 368 { 369 SetUseSyntheticValue(false); 370 SetOmitSummaryDepth(UINT32_MAX); 371 SetIgnoreCap(true); 372 } 373 else 374 { 375 SetUseSyntheticValue(true); 376 SetOmitSummaryDepth(0); 377 SetIgnoreCap(false); 378 } 379 return *this; 380 } 381 382 DumpValueObjectOptions& 383 SetFormat (lldb::Format format = lldb::eFormatDefault) 384 { 385 m_format = format; 386 return *this; 387 } 388 389 DumpValueObjectOptions& 390 SetSummary (lldb::TypeSummaryImplSP summary = lldb::TypeSummaryImplSP()) 391 { 392 m_summary_sp = summary; 393 return *this; 394 } 395 396 DumpValueObjectOptions& 397 SetRootValueObjectName (const char* name = NULL) 398 { 399 if (name) 400 m_root_valobj_name.assign(name); 401 else 402 m_root_valobj_name.clear(); 403 return *this; 404 } 405 406 }; 407 408 class EvaluationPoint 409 { 410 public: 411 412 EvaluationPoint (); 413 414 EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected = false); 415 416 EvaluationPoint (const EvaluationPoint &rhs); 417 418 ~EvaluationPoint (); 419 420 const ExecutionContextRef & 421 GetExecutionContextRef() const 422 { 423 return m_exe_ctx_ref; 424 } 425 426 // Set the EvaluationPoint to the values in exe_scope, 427 // Return true if the Evaluation Point changed. 428 // Since the ExecutionContextScope is always going to be valid currently, 429 // the Updated Context will also always be valid. 430 431// bool 432// SetContext (ExecutionContextScope *exe_scope); 433 434 void 435 SetIsConstant () 436 { 437 SetUpdated(); 438 m_mod_id.SetInvalid(); 439 } 440 441 bool 442 IsConstant () const 443 { 444 return !m_mod_id.IsValid(); 445 } 446 447 ProcessModID 448 GetModID () const 449 { 450 return m_mod_id; 451 } 452 453 void 454 SetUpdateID (ProcessModID new_id) 455 { 456 m_mod_id = new_id; 457 } 458 459 bool 460 IsFirstEvaluation () const 461 { 462 return m_first_update; 463 } 464 465 void 466 SetNeedsUpdate () 467 { 468 m_needs_update = true; 469 } 470 471 void 472 SetUpdated (); 473 474 bool 475 NeedsUpdating() 476 { 477 SyncWithProcessState(); 478 return m_needs_update; 479 } 480 481 bool 482 IsValid () 483 { 484 if (!m_mod_id.IsValid()) 485 return false; 486 else if (SyncWithProcessState ()) 487 { 488 if (!m_mod_id.IsValid()) 489 return false; 490 } 491 return true; 492 } 493 494 void 495 SetInvalid () 496 { 497 // Use the stop id to mark us as invalid, leave the thread id and the stack id around for logging and 498 // history purposes. 499 m_mod_id.SetInvalid(); 500 501 // Can't update an invalid state. 502 m_needs_update = false; 503 504 } 505 506 private: 507 bool 508 SyncWithProcessState (); 509 510 ProcessModID m_mod_id; // This is the stop id when this ValueObject was last evaluated. 511 ExecutionContextRef m_exe_ctx_ref; 512 bool m_needs_update; 513 bool m_first_update; 514 }; 515 516 const EvaluationPoint & 517 GetUpdatePoint () const 518 { 519 return m_update_point; 520 } 521 522 EvaluationPoint & 523 GetUpdatePoint () 524 { 525 return m_update_point; 526 } 527 528 const ExecutionContextRef & 529 GetExecutionContextRef() const 530 { 531 return m_update_point.GetExecutionContextRef(); 532 } 533 534 lldb::TargetSP 535 GetTargetSP() const 536 { 537 return m_update_point.GetExecutionContextRef().GetTargetSP(); 538 } 539 540 lldb::ProcessSP 541 GetProcessSP() const 542 { 543 return m_update_point.GetExecutionContextRef().GetProcessSP(); 544 } 545 546 lldb::ThreadSP 547 GetThreadSP() const 548 { 549 return m_update_point.GetExecutionContextRef().GetThreadSP(); 550 } 551 552 lldb::StackFrameSP 553 GetFrameSP() const 554 { 555 return m_update_point.GetExecutionContextRef().GetFrameSP(); 556 } 557 558 void 559 SetNeedsUpdate (); 560 561 virtual ~ValueObject(); 562 563 clang::ASTContext * 564 GetClangAST (); 565 566 lldb::clang_type_t 567 GetClangType (); 568 569 //------------------------------------------------------------------ 570 // Sublasses must implement the functions below. 571 //------------------------------------------------------------------ 572 virtual size_t 573 GetByteSize() = 0; 574 575 virtual lldb::ValueType 576 GetValueType() const = 0; 577 578 //------------------------------------------------------------------ 579 // Sublasses can implement the functions below. 580 //------------------------------------------------------------------ 581 virtual ConstString 582 GetTypeName(); 583 584 virtual ConstString 585 GetQualifiedTypeName(); 586 587 virtual lldb::LanguageType 588 GetObjectRuntimeLanguage(); 589 590 virtual bool 591 IsPointerType (); 592 593 virtual bool 594 IsArrayType (); 595 596 virtual bool 597 IsScalarType (); 598 599 virtual bool 600 IsPointerOrReferenceType (); 601 602 virtual bool 603 IsPossibleCPlusPlusDynamicType (); 604 605 virtual bool 606 IsPossibleDynamicType (); 607 608 virtual bool 609 IsBaseClass () 610 { 611 return false; 612 } 613 614 virtual bool 615 IsDereferenceOfParent () 616 { 617 return false; 618 } 619 620 bool 621 IsIntegerType (bool &is_signed); 622 623 virtual bool 624 GetBaseClassPath (Stream &s); 625 626 virtual void 627 GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers); 628 629 lldb::ValueObjectSP 630 GetValueForExpressionPath(const char* expression, 631 const char** first_unparsed = NULL, 632 ExpressionPathScanEndReason* reason_to_stop = NULL, 633 ExpressionPathEndResultType* final_value_type = NULL, 634 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 635 ExpressionPathAftermath* final_task_on_target = NULL); 636 637 int 638 GetValuesForExpressionPath(const char* expression, 639 lldb::ValueObjectListSP& list, 640 const char** first_unparsed = NULL, 641 ExpressionPathScanEndReason* reason_to_stop = NULL, 642 ExpressionPathEndResultType* final_value_type = NULL, 643 const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(), 644 ExpressionPathAftermath* final_task_on_target = NULL); 645 646 virtual bool 647 IsInScope () 648 { 649 return true; 650 } 651 652 virtual off_t 653 GetByteOffset() 654 { 655 return 0; 656 } 657 658 virtual uint32_t 659 GetBitfieldBitSize () 660 { 661 return 0; 662 } 663 664 virtual uint32_t 665 GetBitfieldBitOffset () 666 { 667 return 0; 668 } 669 670 bool 671 IsBitfield () 672 { 673 return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0); 674 } 675 676 virtual bool 677 IsArrayItemForPointer() 678 { 679 return m_is_array_item_for_pointer; 680 } 681 682 virtual bool 683 SetClangAST (clang::ASTContext *ast) 684 { 685 return false; 686 } 687 688 virtual const char * 689 GetValueAsCString (); 690 691 virtual bool 692 GetValueAsCString (lldb::Format format, 693 std::string& destination); 694 695 virtual uint64_t 696 GetValueAsUnsigned (uint64_t fail_value); 697 698 virtual bool 699 SetValueFromCString (const char *value_str); 700 701 // Return the module associated with this value object in case the 702 // value is from an executable file and might have its data in 703 // sections of the file. This can be used for variables. 704 virtual lldb::ModuleSP 705 GetModule() 706 { 707 if (m_parent) 708 return m_parent->GetModule(); 709 return lldb::ModuleSP(); 710 } 711 712 virtual bool 713 GetDeclaration (Declaration &decl); 714 715 //------------------------------------------------------------------ 716 // The functions below should NOT be modified by sublasses 717 //------------------------------------------------------------------ 718 const Error & 719 GetError(); 720 721 const ConstString & 722 GetName() const; 723 724 virtual lldb::ValueObjectSP 725 GetChildAtIndex (uint32_t idx, bool can_create); 726 727 virtual lldb::ValueObjectSP 728 GetChildMemberWithName (const ConstString &name, bool can_create); 729 730 virtual uint32_t 731 GetIndexOfChildWithName (const ConstString &name); 732 733 uint32_t 734 GetNumChildren (); 735 736 const Value & 737 GetValue() const; 738 739 Value & 740 GetValue(); 741 742 virtual bool 743 ResolveValue (Scalar &scalar); 744 745 const char * 746 GetLocationAsCString (); 747 748 const char * 749 GetSummaryAsCString (); 750 751 bool 752 GetSummaryAsCString (TypeSummaryImpl* summary_ptr, 753 std::string& destination); 754 755 const char * 756 GetObjectDescription (); 757 758 bool 759 HasSpecialPrintableRepresentation (ValueObjectRepresentationStyle val_obj_display, 760 lldb::Format custom_format); 761 762 enum PrintableRepresentationSpecialCases 763 { 764 ePrintableRepresentationSpecialCasesDisable = 0, 765 ePrintableRepresentationSpecialCasesAllow = 1, 766 ePrintableRepresentationSpecialCasesOnly = 3 767 }; 768 769 bool 770 DumpPrintableRepresentation (Stream& s, 771 ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary, 772 lldb::Format custom_format = lldb::eFormatInvalid, 773 PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow); 774 bool 775 GetValueIsValid () const; 776 777 bool 778 GetValueDidChange (); 779 780 bool 781 UpdateValueIfNeeded (bool update_format = true); 782 783 bool 784 UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true); 785 786 bool 787 UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues); 788 789 lldb::ValueObjectSP 790 GetSP () 791 { 792 return m_manager->GetSharedPointer(this); 793 } 794 795 void 796 SetName (const ConstString &name); 797 798 virtual lldb::addr_t 799 GetAddressOf (bool scalar_is_load_address = true, 800 AddressType *address_type = NULL); 801 802 lldb::addr_t 803 GetPointerValue (AddressType *address_type = NULL); 804 805 lldb::ValueObjectSP 806 GetSyntheticChild (const ConstString &key) const; 807 808 lldb::ValueObjectSP 809 GetSyntheticArrayMember (int32_t index, bool can_create); 810 811 lldb::ValueObjectSP 812 GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create); 813 814 lldb::ValueObjectSP 815 GetSyntheticArrayMemberFromArray (int32_t index, bool can_create); 816 817 lldb::ValueObjectSP 818 GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create); 819 820 lldb::ValueObjectSP 821 GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create); 822 823 lldb::ValueObjectSP 824 GetSyntheticExpressionPathChild(const char* expression, bool can_create); 825 826 virtual lldb::ValueObjectSP 827 GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create); 828 829 lldb::ValueObjectSP 830 GetDynamicValue (lldb::DynamicValueType valueType); 831 832 virtual lldb::ValueObjectSP 833 GetStaticValue (); 834 835 virtual lldb::ValueObjectSP 836 GetNonSyntheticValue (); 837 838 lldb::ValueObjectSP 839 GetSyntheticValue (bool use_synthetic = true); 840 841 virtual bool 842 HasSyntheticValue(); 843 844 virtual bool 845 IsSynthetic() { return false; } 846 847 virtual lldb::ValueObjectSP 848 CreateConstantValue (const ConstString &name); 849 850 virtual lldb::ValueObjectSP 851 Dereference (Error &error); 852 853 virtual lldb::ValueObjectSP 854 AddressOf (Error &error); 855 856 virtual lldb::addr_t 857 GetLiveAddress() 858 { 859 return LLDB_INVALID_ADDRESS; 860 } 861 862 virtual void 863 SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS, 864 AddressType address_type = eAddressTypeLoad) 865 { 866 } 867 868 virtual lldb::ValueObjectSP 869 Cast (const ClangASTType &clang_ast_type); 870 871 virtual lldb::ValueObjectSP 872 CastPointerType (const char *name, 873 ClangASTType &ast_type); 874 875 virtual lldb::ValueObjectSP 876 CastPointerType (const char *name, 877 lldb::TypeSP &type_sp); 878 879 // The backing bits of this value object were updated, clear any 880 // descriptive string, so we know we have to refetch them 881 virtual void 882 ValueUpdated () 883 { 884 ClearUserVisibleData(eClearUserVisibleDataItemsValue | 885 eClearUserVisibleDataItemsSummary | 886 eClearUserVisibleDataItemsDescription); 887 } 888 889 virtual bool 890 IsDynamic () 891 { 892 return false; 893 } 894 895 virtual SymbolContextScope * 896 GetSymbolContextScope(); 897 898 static void 899 DumpValueObject (Stream &s, 900 ValueObject *valobj); 901 static void 902 DumpValueObject (Stream &s, 903 ValueObject *valobj, 904 const DumpValueObjectOptions& options); 905 906 static void 907 LogValueObject (Log *log, 908 ValueObject *valobj); 909 910 static void 911 LogValueObject (Log *log, 912 ValueObject *valobj, 913 const DumpValueObjectOptions& options); 914 915 916 // returns true if this is a char* or a char[] 917 // if it is a char* and check_pointer is true, 918 // it also checks that the pointer is valid 919 bool 920 IsCStringContainer (bool check_pointer = false); 921 922 void 923 ReadPointedString (Stream& s, 924 Error& error, 925 uint32_t max_length = 0, 926 bool honor_array = true, 927 lldb::Format item_format = lldb::eFormatCharArray); 928 929 virtual size_t 930 GetPointeeData (DataExtractor& data, 931 uint32_t item_idx = 0, 932 uint32_t item_count = 1); 933 934 virtual size_t 935 GetData (DataExtractor& data); 936 937 bool 938 GetIsConstant () const 939 { 940 return m_update_point.IsConstant(); 941 } 942 943 void 944 SetIsConstant () 945 { 946 m_update_point.SetIsConstant(); 947 } 948 949 lldb::Format 950 GetFormat () const 951 { 952 if (m_parent && m_format == lldb::eFormatDefault) 953 return m_parent->GetFormat(); 954 return m_format; 955 } 956 957 void 958 SetFormat (lldb::Format format) 959 { 960 if (format != m_format) 961 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 962 m_format = format; 963 } 964 965 lldb::TypeSummaryImplSP 966 GetSummaryFormat() 967 { 968 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 969 return m_type_summary_sp; 970 } 971 972 void 973 SetSummaryFormat(lldb::TypeSummaryImplSP format) 974 { 975 m_type_summary_sp = format; 976 ClearUserVisibleData(eClearUserVisibleDataItemsSummary); 977 } 978 979 void 980 SetValueFormat(lldb::TypeFormatImplSP format) 981 { 982 m_type_format_sp = format; 983 ClearUserVisibleData(eClearUserVisibleDataItemsValue); 984 } 985 986 lldb::TypeFormatImplSP 987 GetValueFormat() 988 { 989 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 990 return m_type_format_sp; 991 } 992 993 void 994 SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp) 995 { 996 if (synth_sp.get() == m_synthetic_children_sp.get()) 997 return; 998 ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren); 999 m_synthetic_children_sp = synth_sp; 1000 } 1001 1002 lldb::SyntheticChildrenSP 1003 GetSyntheticChildren() 1004 { 1005 UpdateFormatsIfNeeded(m_last_format_mgr_dynamic); 1006 return m_synthetic_children_sp; 1007 } 1008 1009 // Use GetParent for display purposes, but if you want to tell the parent to update itself 1010 // then use m_parent. The ValueObjectDynamicValue's parent is not the correct parent for 1011 // displaying, they are really siblings, so for display it needs to route through to its grandparent. 1012 virtual ValueObject * 1013 GetParent() 1014 { 1015 return m_parent; 1016 } 1017 1018 virtual const ValueObject * 1019 GetParent() const 1020 { 1021 return m_parent; 1022 } 1023 1024 ValueObject * 1025 GetNonBaseClassParent(); 1026 1027 void 1028 SetAddressTypeOfChildren(AddressType at) 1029 { 1030 m_address_type_of_ptr_or_ref_children = at; 1031 } 1032 1033 AddressType 1034 GetAddressTypeOfChildren() 1035 { 1036 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid) 1037 { 1038 if (m_parent) 1039 return m_parent->GetAddressTypeOfChildren(); 1040 } 1041 return m_address_type_of_ptr_or_ref_children; 1042 } 1043 1044protected: 1045 typedef ClusterManager<ValueObject> ValueObjectManager; 1046 1047 class ChildrenManager 1048 { 1049 public: 1050 ChildrenManager() : 1051 m_mutex(Mutex::eMutexTypeRecursive), 1052 m_children(), 1053 m_children_count(0) 1054 {} 1055 1056 bool 1057 HasChildAtIndex (uint32_t idx) 1058 { 1059 Mutex::Locker(m_mutex); 1060 ChildrenIterator iter = m_children.find(idx); 1061 ChildrenIterator end = m_children.end(); 1062 return (iter != end); 1063 } 1064 1065 ValueObject* 1066 GetChildAtIndex (uint32_t idx) 1067 { 1068 Mutex::Locker(m_mutex); 1069 ChildrenIterator iter = m_children.find(idx); 1070 ChildrenIterator end = m_children.end(); 1071 if (iter == end) 1072 return NULL; 1073 else 1074 return iter->second; 1075 } 1076 1077 void 1078 SetChildAtIndex (uint32_t idx, ValueObject* valobj) 1079 { 1080 ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair 1081 Mutex::Locker(m_mutex); 1082 m_children.insert(pair); 1083 } 1084 1085 void 1086 SetChildrenCount (uint32_t count) 1087 { 1088 m_children_count = count; 1089 } 1090 1091 uint32_t 1092 GetChildrenCount () 1093 { 1094 return m_children_count; 1095 } 1096 1097 void 1098 Clear() 1099 { 1100 m_children_count = 0; 1101 Mutex::Locker(m_mutex); 1102 m_children.clear(); 1103 } 1104 1105 private: 1106 typedef std::map<uint32_t, ValueObject*> ChildrenMap; 1107 typedef ChildrenMap::iterator ChildrenIterator; 1108 typedef ChildrenMap::value_type ChildrenPair; 1109 Mutex m_mutex; 1110 ChildrenMap m_children; 1111 uint32_t m_children_count; 1112 }; 1113 1114 //------------------------------------------------------------------ 1115 // Classes that inherit from ValueObject can see and modify these 1116 //------------------------------------------------------------------ 1117 ValueObject * m_parent; // The parent value object, or NULL if this has no parent 1118 EvaluationPoint m_update_point; // Stores both the stop id and the full context at which this value was last 1119 // updated. When we are asked to update the value object, we check whether 1120 // the context & stop id are the same before updating. 1121 ConstString m_name; // The name of this object 1122 DataExtractor m_data; // A data extractor that can be used to extract the value. 1123 Value m_value; 1124 Error m_error; // An error object that can describe any errors that occur when updating values. 1125 std::string m_value_str; // Cached value string that will get cleared if/when the value is updated. 1126 std::string m_old_value_str;// Cached old value string from the last time the value was gotten 1127 std::string m_location_str; // Cached location string that will get cleared if/when the value is updated. 1128 std::string m_summary_str; // Cached summary string that will get cleared if/when the value is updated. 1129 std::string m_object_desc_str; // Cached result of the "object printer". This differs from the summary 1130 // in that the summary is consed up by us, the object_desc_string is builtin. 1131 1132 ClangASTType m_override_type;// If the type of the value object should be overridden, the type to impose. 1133 1134 ValueObjectManager *m_manager; // This object is managed by the root object (any ValueObject that gets created 1135 // without a parent.) The manager gets passed through all the generations of 1136 // dependent objects, and will keep the whole cluster of objects alive as long 1137 // as a shared pointer to any of them has been handed out. Shared pointers to 1138 // value objects must always be made with the GetSP method. 1139 1140 ChildrenManager m_children; 1141 std::map<ConstString, ValueObject *> m_synthetic_children; 1142 1143 ValueObject* m_dynamic_value; 1144 ValueObject* m_synthetic_value; 1145 ValueObject* m_deref_valobj; 1146 1147 lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created 1148 // as an independent ValueObjectConstResult, which isn't managed by us. 1149 1150 lldb::Format m_format; 1151 uint32_t m_last_format_mgr_revision; 1152 lldb::DynamicValueType m_last_format_mgr_dynamic; 1153 lldb::TypeSummaryImplSP m_type_summary_sp; 1154 lldb::TypeFormatImplSP m_type_format_sp; 1155 lldb::SyntheticChildrenSP m_synthetic_children_sp; 1156 ProcessModID m_user_id_of_forced_summary; 1157 AddressType m_address_type_of_ptr_or_ref_children; 1158 1159 bool m_value_is_valid:1, 1160 m_value_did_change:1, 1161 m_children_count_valid:1, 1162 m_old_value_valid:1, 1163 m_is_deref_of_parent:1, 1164 m_is_array_item_for_pointer:1, 1165 m_is_bitfield_for_scalar:1, 1166 m_is_expression_path_child:1, 1167 m_is_child_at_offset:1, 1168 m_is_getting_summary:1, 1169 m_did_calculate_complete_objc_class_type:1; 1170 1171 friend class ClangExpressionDeclMap; // For GetValue 1172 friend class ClangExpressionVariable; // For SetName 1173 friend class Target; // For SetName 1174 friend class ValueObjectConstResultImpl; 1175 1176 //------------------------------------------------------------------ 1177 // Constructors and Destructors 1178 //------------------------------------------------------------------ 1179 1180 // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.) 1181 1182 ValueObject(); 1183 1184 // Use this constructor to create a "root variable object". The ValueObject will be locked to this context 1185 // through-out its lifespan. 1186 1187 ValueObject (ExecutionContextScope *exe_scope, 1188 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad); 1189 1190 // Use this constructor to create a ValueObject owned by another ValueObject. It will inherit the ExecutionContext 1191 // of its parent. 1192 1193 ValueObject (ValueObject &parent); 1194 1195 ValueObjectManager * 1196 GetManager() 1197 { 1198 return m_manager; 1199 } 1200 1201 virtual bool 1202 UpdateValue () = 0; 1203 1204 virtual void 1205 CalculateDynamicValue (lldb::DynamicValueType use_dynamic); 1206 1207 virtual void 1208 CalculateSyntheticValue (bool use_synthetic = true); 1209 1210 // Should only be called by ValueObject::GetChildAtIndex() 1211 // Returns a ValueObject managed by this ValueObject's manager. 1212 virtual ValueObject * 1213 CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index); 1214 1215 // Should only be called by ValueObject::GetNumChildren() 1216 virtual uint32_t 1217 CalculateNumChildren() = 0; 1218 1219 void 1220 SetNumChildren (uint32_t num_children); 1221 1222 void 1223 SetValueDidChange (bool value_changed); 1224 1225 void 1226 SetValueIsValid (bool valid); 1227 1228 void 1229 ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings); 1230 1231 void 1232 AddSyntheticChild (const ConstString &key, 1233 ValueObject *valobj); 1234 1235 DataExtractor & 1236 GetDataExtractor (); 1237 1238 //------------------------------------------------------------------ 1239 // Sublasses must implement the functions below. 1240 //------------------------------------------------------------------ 1241 1242 virtual clang::ASTContext * 1243 GetClangASTImpl () = 0; 1244 1245 virtual lldb::clang_type_t 1246 GetClangTypeImpl () = 0; 1247 1248private: 1249 //------------------------------------------------------------------ 1250 // For ValueObject only 1251 //------------------------------------------------------------------ 1252 1253 virtual ClangASTType 1254 MaybeCalculateCompleteType (); 1255 1256 lldb::ValueObjectSP 1257 GetValueForExpressionPath_Impl(const char* expression_cstr, 1258 const char** first_unparsed, 1259 ExpressionPathScanEndReason* reason_to_stop, 1260 ExpressionPathEndResultType* final_value_type, 1261 const GetValueForExpressionPathOptions& options, 1262 ExpressionPathAftermath* final_task_on_target); 1263 1264 // this method will ONLY expand [] expressions into a VOList and return 1265 // the number of elements it added to the VOList 1266 // it will NOT loop through expanding the follow-up of the expression_cstr 1267 // for all objects in the list 1268 int 1269 ExpandArraySliceExpression(const char* expression_cstr, 1270 const char** first_unparsed, 1271 lldb::ValueObjectSP root, 1272 lldb::ValueObjectListSP& list, 1273 ExpressionPathScanEndReason* reason_to_stop, 1274 ExpressionPathEndResultType* final_value_type, 1275 const GetValueForExpressionPathOptions& options, 1276 ExpressionPathAftermath* final_task_on_target); 1277 1278 1279 DISALLOW_COPY_AND_ASSIGN (ValueObject); 1280 1281}; 1282 1283} // namespace lldb_private 1284 1285#endif // liblldb_ValueObject_h_ 1286