ValueObject.h revision b66cd074ec097b5b0a6f2ce292f5072aa1217ca6
1//===-- ValueObject.h -------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ValueObject_h_
11#define liblldb_ValueObject_h_
12
13// C Includes
14// C++ Includes
15#include <map>
16#include <vector>
17// Other libraries and framework includes
18// Project includes
19
20#include "lldb/lldb-private.h"
21#include "lldb/Core/DataExtractor.h"
22#include "lldb/Core/Error.h"
23#include "lldb/Core/Flags.h"
24#include "lldb/Core/ConstString.h"
25#include "lldb/Core/UserID.h"
26#include "lldb/Core/Value.h"
27#include "lldb/Target/ExecutionContextScope.h"
28
29namespace lldb_private {
30
31class ValueObject : public UserID
32{
33public:
34    friend class ValueObjectList;
35
36    virtual ~ValueObject();
37
38    //------------------------------------------------------------------
39    // Sublasses must implement the functions below.
40    //------------------------------------------------------------------
41    virtual size_t
42    GetByteSize() = 0;
43
44    virtual clang::ASTContext *
45    GetClangAST () = 0;
46
47    virtual void *
48    GetOpaqueClangQualType () = 0;
49
50    virtual lldb::ValueType
51    GetValueType() const = 0;
52
53protected:
54    // Should only be called by ValueObject::GetNumChildren()
55    virtual uint32_t
56    CalculateNumChildren() = 0;
57
58public:
59    virtual ConstString
60    GetTypeName() = 0;
61
62    virtual lldb::LanguageType
63    GetObjectRuntimeLanguage();
64
65    virtual void
66    UpdateValue (ExecutionContextScope *exe_scope) = 0;
67
68    //------------------------------------------------------------------
69    // Sublasses can implement the functions below if they need to.
70    //------------------------------------------------------------------
71protected:
72    // Should only be called by ValueObject::GetChildAtIndex()
73    virtual lldb::ValueObjectSP
74    CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int32_t synthetic_index);
75
76public:
77
78    virtual bool
79    IsPointerType ();
80
81    virtual bool
82    IsPointerOrReferenceType ();
83
84    virtual bool
85    IsInScope (StackFrame *frame)
86    {
87        return true;
88    }
89
90    virtual off_t
91    GetByteOffset()
92    {
93        return 0;
94    }
95
96    virtual uint32_t
97    GetBitfieldBitSize()
98    {
99        return 0;
100    }
101
102    virtual uint32_t
103    GetBitfieldBitOffset()
104    {
105        return 0;
106    }
107
108    virtual const char *
109    GetValueAsCString (ExecutionContextScope *exe_scope);
110
111    virtual bool
112    SetValueFromCString (ExecutionContextScope *exe_scope, const char *value_str);
113
114    //------------------------------------------------------------------
115    // The functions below should NOT be modified by sublasses
116    //------------------------------------------------------------------
117    const Error &
118    GetError() const;
119
120    const ConstString &
121    GetName() const;
122
123    lldb::ValueObjectSP
124    GetChildAtIndex (uint32_t idx, bool can_create);
125
126    lldb::ValueObjectSP
127    GetChildMemberWithName (const ConstString &name, bool can_create);
128
129    uint32_t
130    GetIndexOfChildWithName (const ConstString &name);
131
132    uint32_t
133    GetNumChildren ();
134
135    const Value &
136    GetValue() const;
137
138    Value &
139    GetValue();
140
141    const char *
142    GetLocationAsCString (ExecutionContextScope *exe_scope);
143
144    const char *
145    GetSummaryAsCString (ExecutionContextScope *exe_scope);
146
147    const char *
148    GetObjectDescription (ExecutionContextScope *exe_scope);
149
150
151    lldb::user_id_t
152    GetUpdateID() const;
153
154    bool
155    GetValueIsValid () const;
156
157    bool
158    GetValueDidChange (ExecutionContextScope *exe_scope);
159
160    bool
161    UpdateValueIfNeeded (ExecutionContextScope *exe_scope);
162
163    const DataExtractor &
164    GetDataExtractor () const;
165
166    DataExtractor &
167    GetDataExtractor ();
168
169    bool
170    Write ();
171
172    void
173    AddSyntheticChild (const ConstString &key,
174                       lldb::ValueObjectSP& valobj_sp);
175
176    lldb::ValueObjectSP
177    GetSyntheticChild (const ConstString &key) const;
178
179    lldb::ValueObjectSP
180    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
181
182    lldb::ValueObjectSP
183    GetDynamicValue ()
184    {
185        return m_dynamic_value_sp;
186    }
187
188    bool
189    SetDynamicValue ();
190
191protected:
192    //------------------------------------------------------------------
193    // Classes that inherit from ValueObject can see and modify these
194    //------------------------------------------------------------------
195    lldb::user_id_t     m_update_id;    // An integer that specifies the update number for this value in
196                                        // this value object list. If this value object is asked to update itself
197                                        // it will first check if the update ID match the value object
198                                        // list update number. If the update numbers match, no update is
199                                        // needed, if it does not match, this value object should update its
200                                        // the next time it is asked.
201    ConstString         m_name;         // The name of this object
202    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
203    Value               m_value;
204    Error               m_error;        // An error object that can describe any errors that occur when updating values.
205    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
206    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
207    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
208    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
209    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
210                                              // in that the summary is consed up by us, the object_desc_string is builtin.
211    std::vector<lldb::ValueObjectSP> m_children;
212    std::map<ConstString, lldb::ValueObjectSP> m_synthetic_children;
213    lldb::ValueObjectSP m_dynamic_value_sp;
214    bool                m_value_is_valid:1,
215                        m_value_did_change:1,
216                        m_children_count_valid:1,
217                        m_old_value_valid:1;
218
219    //------------------------------------------------------------------
220    // Constructors and Destructors
221    //------------------------------------------------------------------
222    ValueObject ();
223
224    void
225    SetName (const char *name);
226
227    void
228    SetName (const ConstString &name);
229
230    void
231    SetNumChildren (uint32_t num_children);
232
233    void
234    SetValueDidChange (bool value_changed);
235
236    void
237    SetValueIsValid (bool valid);
238
239
240    lldb::addr_t
241    GetPointerValue (lldb::AddressType &address_type,
242                     bool scalar_is_load_address);
243private:
244    //------------------------------------------------------------------
245    // For ValueObject only
246    //------------------------------------------------------------------
247    DISALLOW_COPY_AND_ASSIGN (ValueObject);
248
249};
250
251} // namespace lldb_private
252
253#endif  // liblldb_ValueObject_h_
254