ValueObject.h revision 6b1763b5ab8f182029807293d74a66e1e1c6bafd
145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org//===-- ValueObject.h -------------------------------------------*- C++ -*-===//
245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org//
345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org//                     The LLVM Compiler Infrastructure
445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org//
545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// This file is distributed under the University of Illinois Open Source
645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// License. See LICENSE.TXT for details.
745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org//
845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org//===----------------------------------------------------------------------===//
945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef liblldb_ValueObject_h_
1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define liblldb_ValueObject_h_
1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// C Includes
1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// C++ Includes
1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <map>
1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include <vector>
1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Other libraries and framework includes
1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org// Project includes
1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/lldb-private.h"
2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Core/DataExtractor.h"
2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Core/Error.h"
2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Core/Flags.h"
2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Core/ConstString.h"
2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Core/UserID.h"
2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Core/Value.h"
2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Target/ExecutionContext.h"
2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Target/ExecutionContextScope.h"
2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Target/Process.h"
3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Target/StackID.h"
3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#include "lldb/Utility/SharedCluster.h"
3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgnamespace lldb_private {
3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// ValueObject:
3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org///
3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// This abstract class provides an interface to a particular value, be it a register, a local or global variable,
3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// that is evaluated in some particular scope.  The ValueObject also has the capibility of being the "child" of
3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// some other variable object, and in turn of having children.
4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// If a ValueObject is a root variable object - having no parent - then it must be constructed with respect to some
4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// particular ExecutionContextScope.  If it is a child, it inherits the ExecutionContextScope from its parent.
4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// The ValueObject will update itself if necessary before fetching its value, summary, object description, etc.
4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// But it will always update itself in the ExecutionContextScope with which it was originally created.
4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// A brief note on life cycle management for ValueObjects.  This is a little tricky because a ValueObject can contain
4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// various other ValueObjects - the Dynamic Value, its children, the dereference value, etc.  Any one of these can be
4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// handed out as a shared pointer, but for that contained value object to be valid, the root object and potentially other
4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// of the value objects need to stay around.
4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// We solve this problem by handing out shared pointers to the Value Object and any of its dependents using a shared
5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// ClusterManager.  This treats each shared pointer handed out for the entire cluster as a reference to the whole
5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// cluster.  The whole cluster will stay around until the last reference is released.
5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org///
5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// The ValueObject mostly handle this automatically, if a value object is made with a Parent ValueObject, then it adds
5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// itself to the ClusterManager of the parent.
5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// It does mean that external to the ValueObjects we should only ever make available ValueObjectSP's, never ValueObjects
5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// or pointers to them.  So all the "Root level" ValueObject derived constructors should be private, and
5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// should implement a Create function that new's up object and returns a Shared Pointer that it gets from the GetSP() method.
5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org///
6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// However, if you are making an derived ValueObject that will be contained in a parent value object, you should just
6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// hold onto a pointer to it internally, and by virtue of passing the parent ValueObject into its constructor, it will
6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// be added to the ClusterManager for the parent.  Then if you ever hand out a Shared Pointer to the contained ValueObject,
6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/// just do so by calling GetSP() on the contained object.
6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgclass ValueObject : public UserID
6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org{
6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgpublic:
6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum GetExpressionPathFormat
7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eGetExpressionPathFormatDereferencePointers = 1,
7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eGetExpressionPathFormatHonorPointers
7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum ValueObjectRepresentationStyle
7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eValueObjectRepresentationStyleValue = 1,
7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eValueObjectRepresentationStyleSummary,
7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eValueObjectRepresentationStyleLanguageSpecific,
8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eValueObjectRepresentationStyleLocation,
8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eValueObjectRepresentationStyleChildrenCount,
8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eValueObjectRepresentationStyleType
8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum ExpressionPathScanEndReason
8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonEndOfString = 1,           // out of data to parse
8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonNoSuchChild,               // child element not found
8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonEmptyRangeNotAllowed,      // [] only allowed for arrays
9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonDotInsteadOfArrow,         // . used when -> should be used
9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonArrowInsteadOfDot,         // -> used when . should be used
9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonFragileIVarNotAllowed,     // ObjC ivar expansion not allowed
9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonRangeOperatorNotAllowed,   // [] not allowed by options
9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonRangeOperatorInvalid,      // [] not valid on objects other than scalars, pointers or arrays
9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonArrayRangeOperatorMet,     // [] is good for arrays, but I cannot parse it
9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonBitfieldRangeOperatorMet,  // [] is good for bitfields, but I cannot parse after it
9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonUnexpectedSymbol,          // something is malformed in the expression
9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonTakingAddressFailed,       // impossible to apply & operator
9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonDereferencingFailed,       // impossible to apply * operator
10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonRangeOperatorExpanded,     // [] was expanded into a VOList
10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonSyntheticValueMissing,     // getting the synthetic children failed
10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathScanEndReasonUnknown = 0xFFFF
10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum ExpressionPathEndResultType
10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathEndResultTypePlain = 1,                 // anything but...
10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathEndResultTypeBitfield,                  // a bitfield
10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathEndResultTypeBoundedRange,              // a range [low-high]
11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathEndResultTypeUnboundedRange,            // a range []
11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathEndResultTypeValueObjectList,           // several items in a VOList
11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathEndResultTypeInvalid = 0xFFFF
11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum ExpressionPathAftermath
11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathAftermathNothing = 1,               // just return it
11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathAftermathDereference,               // dereference the target
11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eExpressionPathAftermathTakeAddress                // take target's address
12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    enum ClearUserVisibleDataItems
12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsNothing = 1u << 0,
12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsValue = 1u << 1,
12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsSummary = 1u << 2,
12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsLocation = 1u << 3,
12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsDescription = 1u << 4,
12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsSyntheticChildren = 1u << 5,
13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsAllStrings = eClearUserVisibleDataItemsValue | eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsLocation | eClearUserVisibleDataItemsDescription,
13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        eClearUserVisibleDataItemsAll = 0xFFFF
13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    struct GetValueForExpressionPathOptions
13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_check_dot_vs_arrow_syntax;
13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_no_fragile_ivar;
13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_allow_bitfields_syntax;
13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_no_synthetic_children;
14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions(bool dot = false,
14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                         bool no_ivar = false,
14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                         bool bitfield = true,
14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org                                         bool no_synth = false) :
14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_check_dot_vs_arrow_syntax(dot),
14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_no_fragile_ivar(no_ivar),
14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_allow_bitfields_syntax(bitfield),
14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_no_synthetic_children(no_synth)
14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DoCheckDotVsArrowSyntax()
15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_check_dot_vs_arrow_syntax = true;
15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DontCheckDotVsArrowSyntax()
16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_check_dot_vs_arrow_syntax = false;
16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DoAllowFragileIVar()
16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_no_fragile_ivar = false;
17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DontAllowFragileIVar()
17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_no_fragile_ivar = true;
17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DoAllowBitfieldSyntax()
18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_allow_bitfields_syntax = true;
18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DontAllowBitfieldSyntax()
18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_allow_bitfields_syntax = false;
19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DoAllowSyntheticChildren()
19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_no_synthetic_children = false;
19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        GetValueForExpressionPathOptions&
20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DontAllowSyntheticChildren()
20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_no_synthetic_children = true;
20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return *this;
20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        static const GetValueForExpressionPathOptions
20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DefaultOptions()
21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        {
21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            static GetValueForExpressionPathOptions g_default_options;
21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            return g_default_options;
21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        }
21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    };
21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    struct DumpValueObjectOptions
21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org    {
22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        uint32_t m_max_ptr_depth;
22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        uint32_t m_max_depth;
22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_show_types;
22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_show_location;
22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_use_objc;
22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        lldb::DynamicValueType m_use_dynamic;
22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_use_synthetic;
22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_scope_already_checked;
22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_flat_output;
22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        uint32_t m_omit_summary_depth;
23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        bool m_ignore_cap;
23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        lldb::Format m_format;
23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        lldb::TypeSummaryImplSP m_summary_sp;
23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        std::string m_root_valobj_name;
23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org
23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org        DumpValueObjectOptions() :
23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_max_ptr_depth(0),
23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_max_depth(UINT32_MAX),
23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_show_types(false),
23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_show_location(false),
24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_use_objc(false),
24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_use_dynamic(lldb::eNoDynamicValues),
24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_use_synthetic(true),
24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_scope_already_checked(false),
24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_flat_output(false),
24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_omit_summary_depth(0),
24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_ignore_cap(false),
24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            m_format (lldb::eFormatDefault),
24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org            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    IsPossibleDynamicType ();
604
605    virtual bool
606    IsBaseClass ()
607    {
608        return false;
609    }
610
611    virtual bool
612    IsDereferenceOfParent ()
613    {
614        return false;
615    }
616
617    bool
618    IsIntegerType (bool &is_signed);
619
620    virtual bool
621    GetBaseClassPath (Stream &s);
622
623    virtual void
624    GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers);
625
626    lldb::ValueObjectSP
627    GetValueForExpressionPath(const char* expression,
628                              const char** first_unparsed = NULL,
629                              ExpressionPathScanEndReason* reason_to_stop = NULL,
630                              ExpressionPathEndResultType* final_value_type = NULL,
631                              const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
632                              ExpressionPathAftermath* final_task_on_target = NULL);
633
634    int
635    GetValuesForExpressionPath(const char* expression,
636                               lldb::ValueObjectListSP& list,
637                               const char** first_unparsed = NULL,
638                               ExpressionPathScanEndReason* reason_to_stop = NULL,
639                               ExpressionPathEndResultType* final_value_type = NULL,
640                               const GetValueForExpressionPathOptions& options = GetValueForExpressionPathOptions::DefaultOptions(),
641                               ExpressionPathAftermath* final_task_on_target = NULL);
642
643    virtual bool
644    IsInScope ()
645    {
646        return true;
647    }
648
649    virtual off_t
650    GetByteOffset()
651    {
652        return 0;
653    }
654
655    virtual uint32_t
656    GetBitfieldBitSize ()
657    {
658        return 0;
659    }
660
661    virtual uint32_t
662    GetBitfieldBitOffset ()
663    {
664        return 0;
665    }
666
667    bool
668    IsBitfield ()
669    {
670        return (GetBitfieldBitSize() != 0) || (GetBitfieldBitOffset() != 0);
671    }
672
673    virtual bool
674    IsArrayItemForPointer()
675    {
676        return m_is_array_item_for_pointer;
677    }
678
679    virtual bool
680    SetClangAST (clang::ASTContext *ast)
681    {
682        return false;
683    }
684
685    virtual const char *
686    GetValueAsCString ();
687
688    virtual bool
689    GetValueAsCString (lldb::Format format,
690                       std::string& destination);
691
692    virtual uint64_t
693    GetValueAsUnsigned (uint64_t fail_value);
694
695    virtual bool
696    SetValueFromCString (const char *value_str, Error& error);
697
698    // Return the module associated with this value object in case the
699    // value is from an executable file and might have its data in
700    // sections of the file. This can be used for variables.
701    virtual lldb::ModuleSP
702    GetModule()
703    {
704        if (m_parent)
705            return m_parent->GetModule();
706        return lldb::ModuleSP();
707    }
708
709    virtual bool
710    GetDeclaration (Declaration &decl);
711
712    //------------------------------------------------------------------
713    // The functions below should NOT be modified by sublasses
714    //------------------------------------------------------------------
715    const Error &
716    GetError();
717
718    const ConstString &
719    GetName() const;
720
721    virtual lldb::ValueObjectSP
722    GetChildAtIndex (uint32_t idx, bool can_create);
723
724    virtual lldb::ValueObjectSP
725    GetChildMemberWithName (const ConstString &name, bool can_create);
726
727    virtual uint32_t
728    GetIndexOfChildWithName (const ConstString &name);
729
730    uint32_t
731    GetNumChildren ();
732
733    const Value &
734    GetValue() const;
735
736    Value &
737    GetValue();
738
739    virtual bool
740    ResolveValue (Scalar &scalar);
741
742    const char *
743    GetLocationAsCString ();
744
745    const char *
746    GetSummaryAsCString ();
747
748    bool
749    GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
750                         std::string& destination);
751
752    const char *
753    GetObjectDescription ();
754
755    bool
756    HasSpecialPrintableRepresentation (ValueObjectRepresentationStyle val_obj_display,
757                                       lldb::Format custom_format);
758
759    enum PrintableRepresentationSpecialCases
760    {
761        ePrintableRepresentationSpecialCasesDisable = 0,
762        ePrintableRepresentationSpecialCasesAllow = 1,
763        ePrintableRepresentationSpecialCasesOnly = 3
764    };
765
766    bool
767    DumpPrintableRepresentation (Stream& s,
768                                 ValueObjectRepresentationStyle val_obj_display = eValueObjectRepresentationStyleSummary,
769                                 lldb::Format custom_format = lldb::eFormatInvalid,
770                                 PrintableRepresentationSpecialCases special = ePrintableRepresentationSpecialCasesAllow);
771    bool
772    GetValueIsValid () const;
773
774    bool
775    GetValueDidChange ();
776
777    bool
778    UpdateValueIfNeeded (bool update_format = true);
779
780    bool
781    UpdateValueIfNeeded (lldb::DynamicValueType use_dynamic, bool update_format = true);
782
783    bool
784    UpdateFormatsIfNeeded(lldb::DynamicValueType use_dynamic = lldb::eNoDynamicValues);
785
786    lldb::ValueObjectSP
787    GetSP ()
788    {
789        return m_manager->GetSharedPointer(this);
790    }
791
792    void
793    SetName (const ConstString &name);
794
795    virtual lldb::addr_t
796    GetAddressOf (bool scalar_is_load_address = true,
797                  AddressType *address_type = NULL);
798
799    lldb::addr_t
800    GetPointerValue (AddressType *address_type = NULL);
801
802    lldb::ValueObjectSP
803    GetSyntheticChild (const ConstString &key) const;
804
805    lldb::ValueObjectSP
806    GetSyntheticArrayMember (int32_t index, bool can_create);
807
808    lldb::ValueObjectSP
809    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
810
811    lldb::ValueObjectSP
812    GetSyntheticArrayMemberFromArray (int32_t index, bool can_create);
813
814    lldb::ValueObjectSP
815    GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create);
816
817    lldb::ValueObjectSP
818    GetSyntheticArrayRangeChild (uint32_t from, uint32_t to, bool can_create);
819
820    lldb::ValueObjectSP
821    GetSyntheticExpressionPathChild(const char* expression, bool can_create);
822
823    virtual lldb::ValueObjectSP
824    GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create);
825
826    lldb::ValueObjectSP
827    GetDynamicValue (lldb::DynamicValueType valueType);
828
829    virtual lldb::ValueObjectSP
830    GetStaticValue ();
831
832    virtual lldb::ValueObjectSP
833    GetNonSyntheticValue ();
834
835    lldb::ValueObjectSP
836    GetSyntheticValue (bool use_synthetic = true);
837
838    virtual bool
839    HasSyntheticValue();
840
841    virtual bool
842    IsSynthetic() { return false; }
843
844    virtual lldb::ValueObjectSP
845    CreateConstantValue (const ConstString &name);
846
847    virtual lldb::ValueObjectSP
848    Dereference (Error &error);
849
850    virtual lldb::ValueObjectSP
851    AddressOf (Error &error);
852
853    virtual lldb::addr_t
854    GetLiveAddress()
855    {
856        return LLDB_INVALID_ADDRESS;
857    }
858
859    virtual void
860    SetLiveAddress(lldb::addr_t addr = LLDB_INVALID_ADDRESS,
861                   AddressType address_type = eAddressTypeLoad)
862    {
863    }
864
865    virtual lldb::ValueObjectSP
866    Cast (const ClangASTType &clang_ast_type);
867
868    virtual lldb::ValueObjectSP
869    CastPointerType (const char *name,
870                     ClangASTType &ast_type);
871
872    virtual lldb::ValueObjectSP
873    CastPointerType (const char *name,
874                     lldb::TypeSP &type_sp);
875
876    // The backing bits of this value object were updated, clear any
877    // descriptive string, so we know we have to refetch them
878    virtual void
879    ValueUpdated ()
880    {
881        ClearUserVisibleData(eClearUserVisibleDataItemsValue |
882                             eClearUserVisibleDataItemsSummary |
883                             eClearUserVisibleDataItemsDescription);
884    }
885
886    virtual bool
887    IsDynamic ()
888    {
889        return false;
890    }
891
892    virtual SymbolContextScope *
893    GetSymbolContextScope();
894
895    static void
896    DumpValueObject (Stream &s,
897                     ValueObject *valobj);
898    static void
899    DumpValueObject (Stream &s,
900                     ValueObject *valobj,
901                     const DumpValueObjectOptions& options);
902
903    static void
904    LogValueObject (Log *log,
905                    ValueObject *valobj);
906
907    static void
908    LogValueObject (Log *log,
909                    ValueObject *valobj,
910                    const DumpValueObjectOptions& options);
911
912
913    // returns true if this is a char* or a char[]
914    // if it is a char* and check_pointer is true,
915    // it also checks that the pointer is valid
916    bool
917    IsCStringContainer (bool check_pointer = false);
918
919    void
920    ReadPointedString (Stream& s,
921                       Error& error,
922                       uint32_t max_length = 0,
923                       bool honor_array = true,
924                       lldb::Format item_format = lldb::eFormatCharArray);
925
926    virtual size_t
927    GetPointeeData (DataExtractor& data,
928                    uint32_t item_idx = 0,
929					uint32_t item_count = 1);
930
931    virtual size_t
932    GetData (DataExtractor& data);
933
934    bool
935    GetIsConstant () const
936    {
937        return m_update_point.IsConstant();
938    }
939
940    void
941    SetIsConstant ()
942    {
943        m_update_point.SetIsConstant();
944    }
945
946    lldb::Format
947    GetFormat () const
948    {
949        if (m_parent && m_format == lldb::eFormatDefault)
950            return m_parent->GetFormat();
951        return m_format;
952    }
953
954    void
955    SetFormat (lldb::Format format)
956    {
957        if (format != m_format)
958            ClearUserVisibleData(eClearUserVisibleDataItemsValue);
959        m_format = format;
960    }
961
962    lldb::TypeSummaryImplSP
963    GetSummaryFormat()
964    {
965        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
966        return m_type_summary_sp;
967    }
968
969    void
970    SetSummaryFormat(lldb::TypeSummaryImplSP format)
971    {
972        m_type_summary_sp = format;
973        ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
974    }
975
976    void
977    SetValueFormat(lldb::TypeFormatImplSP format)
978    {
979        m_type_format_sp = format;
980        ClearUserVisibleData(eClearUserVisibleDataItemsValue);
981    }
982
983    lldb::TypeFormatImplSP
984    GetValueFormat()
985    {
986        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
987        return m_type_format_sp;
988    }
989
990    void
991    SetSyntheticChildren(const lldb::SyntheticChildrenSP &synth_sp)
992    {
993        if (synth_sp.get() == m_synthetic_children_sp.get())
994            return;
995        ClearUserVisibleData(eClearUserVisibleDataItemsSyntheticChildren);
996        m_synthetic_children_sp = synth_sp;
997    }
998
999    lldb::SyntheticChildrenSP
1000    GetSyntheticChildren()
1001    {
1002        UpdateFormatsIfNeeded(m_last_format_mgr_dynamic);
1003        return m_synthetic_children_sp;
1004    }
1005
1006    // Use GetParent for display purposes, but if you want to tell the parent to update itself
1007    // then use m_parent.  The ValueObjectDynamicValue's parent is not the correct parent for
1008    // displaying, they are really siblings, so for display it needs to route through to its grandparent.
1009    virtual ValueObject *
1010    GetParent()
1011    {
1012        return m_parent;
1013    }
1014
1015    virtual const ValueObject *
1016    GetParent() const
1017    {
1018        return m_parent;
1019    }
1020
1021    ValueObject *
1022    GetNonBaseClassParent();
1023
1024    void
1025    SetAddressTypeOfChildren(AddressType at)
1026    {
1027        m_address_type_of_ptr_or_ref_children = at;
1028    }
1029
1030    AddressType
1031    GetAddressTypeOfChildren()
1032    {
1033        if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
1034        {
1035            if (m_parent)
1036                return m_parent->GetAddressTypeOfChildren();
1037        }
1038        return m_address_type_of_ptr_or_ref_children;
1039    }
1040
1041protected:
1042    typedef ClusterManager<ValueObject> ValueObjectManager;
1043
1044    class ChildrenManager
1045    {
1046    public:
1047        ChildrenManager() :
1048        m_mutex(Mutex::eMutexTypeRecursive),
1049        m_children(),
1050        m_children_count(0)
1051        {}
1052
1053        bool
1054        HasChildAtIndex (uint32_t idx)
1055        {
1056            Mutex::Locker(m_mutex);
1057            ChildrenIterator iter = m_children.find(idx);
1058            ChildrenIterator end = m_children.end();
1059            return (iter != end);
1060        }
1061
1062        ValueObject*
1063        GetChildAtIndex (uint32_t idx)
1064        {
1065            Mutex::Locker(m_mutex);
1066            ChildrenIterator iter = m_children.find(idx);
1067            ChildrenIterator end = m_children.end();
1068            if (iter == end)
1069                return NULL;
1070            else
1071                return iter->second;
1072        }
1073
1074        void
1075        SetChildAtIndex (uint32_t idx, ValueObject* valobj)
1076        {
1077            ChildrenPair pair(idx,valobj); // we do not need to be mutex-protected to make a pair
1078            Mutex::Locker(m_mutex);
1079            m_children.insert(pair);
1080        }
1081
1082        void
1083        SetChildrenCount (uint32_t count)
1084        {
1085            m_children_count = count;
1086        }
1087
1088        uint32_t
1089        GetChildrenCount ()
1090        {
1091            return m_children_count;
1092        }
1093
1094        void
1095        Clear()
1096        {
1097            m_children_count = 0;
1098            Mutex::Locker(m_mutex);
1099            m_children.clear();
1100        }
1101
1102    private:
1103        typedef std::map<uint32_t, ValueObject*> ChildrenMap;
1104        typedef ChildrenMap::iterator ChildrenIterator;
1105        typedef ChildrenMap::value_type ChildrenPair;
1106        Mutex m_mutex;
1107        ChildrenMap m_children;
1108        uint32_t m_children_count;
1109    };
1110
1111    //------------------------------------------------------------------
1112    // Classes that inherit from ValueObject can see and modify these
1113    //------------------------------------------------------------------
1114    ValueObject  *      m_parent;       // The parent value object, or NULL if this has no parent
1115    EvaluationPoint     m_update_point; // Stores both the stop id and the full context at which this value was last
1116                                        // updated.  When we are asked to update the value object, we check whether
1117                                        // the context & stop id are the same before updating.
1118    ConstString         m_name;         // The name of this object
1119    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
1120    Value               m_value;
1121    Error               m_error;        // An error object that can describe any errors that occur when updating values.
1122    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
1123    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
1124    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
1125    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
1126    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
1127                                              // in that the summary is consed up by us, the object_desc_string is builtin.
1128
1129    ClangASTType        m_override_type;// If the type of the value object should be overridden, the type to impose.
1130
1131    ValueObjectManager *m_manager;      // This object is managed by the root object (any ValueObject that gets created
1132                                        // without a parent.)  The manager gets passed through all the generations of
1133                                        // dependent objects, and will keep the whole cluster of objects alive as long
1134                                        // as a shared pointer to any of them has been handed out.  Shared pointers to
1135                                        // value objects must always be made with the GetSP method.
1136
1137    ChildrenManager                      m_children;
1138    std::map<ConstString, ValueObject *> m_synthetic_children;
1139
1140    ValueObject*                         m_dynamic_value;
1141    ValueObject*                         m_synthetic_value;
1142    ValueObject*                         m_deref_valobj;
1143
1144    lldb::ValueObjectSP m_addr_of_valobj_sp; // We have to hold onto a shared pointer to this one because it is created
1145                                             // as an independent ValueObjectConstResult, which isn't managed by us.
1146
1147    lldb::Format                m_format;
1148    uint32_t                    m_last_format_mgr_revision;
1149    lldb::DynamicValueType      m_last_format_mgr_dynamic;
1150    lldb::TypeSummaryImplSP     m_type_summary_sp;
1151    lldb::TypeFormatImplSP      m_type_format_sp;
1152    lldb::SyntheticChildrenSP   m_synthetic_children_sp;
1153    ProcessModID                m_user_id_of_forced_summary;
1154    AddressType                 m_address_type_of_ptr_or_ref_children;
1155
1156    bool                m_value_is_valid:1,
1157                        m_value_did_change:1,
1158                        m_children_count_valid:1,
1159                        m_old_value_valid:1,
1160                        m_is_deref_of_parent:1,
1161                        m_is_array_item_for_pointer:1,
1162                        m_is_bitfield_for_scalar:1,
1163                        m_is_expression_path_child:1,
1164                        m_is_child_at_offset:1,
1165                        m_is_getting_summary:1,
1166                        m_did_calculate_complete_objc_class_type:1;
1167
1168    friend class ClangExpressionDeclMap;  // For GetValue
1169    friend class ClangExpressionVariable; // For SetName
1170    friend class Target;                  // For SetName
1171    friend class ValueObjectConstResultImpl;
1172
1173    //------------------------------------------------------------------
1174    // Constructors and Destructors
1175    //------------------------------------------------------------------
1176
1177    // Use the no-argument constructor to make a constant variable object (with no ExecutionContextScope.)
1178
1179    ValueObject();
1180
1181    // Use this constructor to create a "root variable object".  The ValueObject will be locked to this context
1182    // through-out its lifespan.
1183
1184    ValueObject (ExecutionContextScope *exe_scope,
1185                 AddressType child_ptr_or_ref_addr_type = eAddressTypeLoad);
1186
1187    // Use this constructor to create a ValueObject owned by another ValueObject.  It will inherit the ExecutionContext
1188    // of its parent.
1189
1190    ValueObject (ValueObject &parent);
1191
1192    ValueObjectManager *
1193    GetManager()
1194    {
1195        return m_manager;
1196    }
1197
1198    virtual bool
1199    UpdateValue () = 0;
1200
1201    virtual void
1202    CalculateDynamicValue (lldb::DynamicValueType use_dynamic);
1203
1204    virtual void
1205    CalculateSyntheticValue (bool use_synthetic = true);
1206
1207    // Should only be called by ValueObject::GetChildAtIndex()
1208    // Returns a ValueObject managed by this ValueObject's manager.
1209    virtual ValueObject *
1210    CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index);
1211
1212    // Should only be called by ValueObject::GetNumChildren()
1213    virtual uint32_t
1214    CalculateNumChildren() = 0;
1215
1216    void
1217    SetNumChildren (uint32_t num_children);
1218
1219    void
1220    SetValueDidChange (bool value_changed);
1221
1222    void
1223    SetValueIsValid (bool valid);
1224
1225    void
1226    ClearUserVisibleData(uint32_t items = ValueObject::eClearUserVisibleDataItemsAllStrings);
1227
1228    void
1229    AddSyntheticChild (const ConstString &key,
1230                       ValueObject *valobj);
1231
1232    DataExtractor &
1233    GetDataExtractor ();
1234
1235    //------------------------------------------------------------------
1236    // Sublasses must implement the functions below.
1237    //------------------------------------------------------------------
1238
1239    virtual clang::ASTContext *
1240    GetClangASTImpl () = 0;
1241
1242    virtual lldb::clang_type_t
1243    GetClangTypeImpl () = 0;
1244
1245private:
1246    //------------------------------------------------------------------
1247    // For ValueObject only
1248    //------------------------------------------------------------------
1249
1250    virtual ClangASTType
1251    MaybeCalculateCompleteType ();
1252
1253    lldb::ValueObjectSP
1254    GetValueForExpressionPath_Impl(const char* expression_cstr,
1255                                   const char** first_unparsed,
1256                                   ExpressionPathScanEndReason* reason_to_stop,
1257                                   ExpressionPathEndResultType* final_value_type,
1258                                   const GetValueForExpressionPathOptions& options,
1259                                   ExpressionPathAftermath* final_task_on_target);
1260
1261    // this method will ONLY expand [] expressions into a VOList and return
1262    // the number of elements it added to the VOList
1263    // it will NOT loop through expanding the follow-up of the expression_cstr
1264    // for all objects in the list
1265    int
1266    ExpandArraySliceExpression(const char* expression_cstr,
1267                               const char** first_unparsed,
1268                               lldb::ValueObjectSP root,
1269                               lldb::ValueObjectListSP& list,
1270                               ExpressionPathScanEndReason* reason_to_stop,
1271                               ExpressionPathEndResultType* final_value_type,
1272                               const GetValueForExpressionPathOptions& options,
1273                               ExpressionPathAftermath* final_task_on_target);
1274
1275
1276    DISALLOW_COPY_AND_ASSIGN (ValueObject);
1277
1278};
1279
1280} // namespace lldb_private
1281
1282#endif  // liblldb_ValueObject_h_
1283