ValueObject.h revision b01000fd063629facd45044f137446fb748ee179
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 lldb::clang_type_t
48    GetClangType () = 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    IsBaseClass ()
86    {
87        return false;
88    }
89
90    virtual void
91    GetExpressionPath (Stream &s, bool qualify_cxx_base_classes);
92
93    virtual bool
94    IsInScope (StackFrame *frame)
95    {
96        return true;
97    }
98
99    virtual off_t
100    GetByteOffset()
101    {
102        return 0;
103    }
104
105    virtual uint32_t
106    GetBitfieldBitSize()
107    {
108        return 0;
109    }
110
111    virtual uint32_t
112    GetBitfieldBitOffset()
113    {
114        return 0;
115    }
116
117    virtual bool
118    SetClangAST (clang::ASTContext *ast)
119    {
120        return false;
121    }
122
123    virtual const char *
124    GetValueAsCString (ExecutionContextScope *exe_scope);
125
126    virtual bool
127    SetValueFromCString (ExecutionContextScope *exe_scope, const char *value_str);
128
129    //------------------------------------------------------------------
130    // The functions below should NOT be modified by sublasses
131    //------------------------------------------------------------------
132    const Error &
133    GetError() const;
134
135    const ConstString &
136    GetName() const;
137
138    lldb::ValueObjectSP
139    GetChildAtIndex (uint32_t idx, bool can_create);
140
141    lldb::ValueObjectSP
142    GetChildMemberWithName (const ConstString &name, bool can_create);
143
144    uint32_t
145    GetIndexOfChildWithName (const ConstString &name);
146
147    uint32_t
148    GetNumChildren ();
149
150    const Value &
151    GetValue() const;
152
153    Value &
154    GetValue();
155
156    bool
157    ResolveValue (ExecutionContextScope *exe_scope, Scalar &scalar);
158
159    const char *
160    GetLocationAsCString (ExecutionContextScope *exe_scope);
161
162    const char *
163    GetSummaryAsCString (ExecutionContextScope *exe_scope);
164
165    const char *
166    GetObjectDescription (ExecutionContextScope *exe_scope);
167
168
169    lldb::user_id_t
170    GetUpdateID() const;
171
172    bool
173    GetValueIsValid () const;
174
175    bool
176    GetValueDidChange (ExecutionContextScope *exe_scope);
177
178    bool
179    UpdateValueIfNeeded (ExecutionContextScope *exe_scope);
180
181    const DataExtractor &
182    GetDataExtractor () const;
183
184    DataExtractor &
185    GetDataExtractor ();
186
187    bool
188    Write ();
189
190    void
191    AddSyntheticChild (const ConstString &key,
192                       lldb::ValueObjectSP& valobj_sp);
193
194    lldb::ValueObjectSP
195    GetSyntheticChild (const ConstString &key) const;
196
197    lldb::ValueObjectSP
198    GetSyntheticArrayMemberFromPointer (int32_t index, bool can_create);
199
200    lldb::ValueObjectSP
201    GetDynamicValue ()
202    {
203        return m_dynamic_value_sp;
204    }
205
206    virtual lldb::ValueObjectSP
207    CreateConstantValue (ExecutionContextScope *exe_scope, const ConstString &name);
208
209    virtual lldb::ValueObjectSP
210    Dereference (Error &error);
211
212    virtual lldb::ValueObjectSP
213    AddressOf (Error &error);
214
215    // The backing bits of this value object were updated, clear any value
216    // values, summaries or descriptions so we refetch them.
217    virtual void
218    ValueUpdated ()
219    {
220        m_value_str.clear();
221        m_summary_str.clear();
222        m_object_desc_str.clear();
223    }
224
225    bool
226    SetDynamicValue ();
227
228    static void
229    DumpValueObject (Stream &s,
230                     ExecutionContextScope *exe_scope,
231                     ValueObject *valobj,
232                     const char *root_valobj_name,
233                     uint32_t ptr_depth,
234                     uint32_t curr_depth,
235                     uint32_t max_depth,
236                     bool show_types,
237                     bool show_location,
238                     bool use_objc,
239                     bool scope_already_checked,
240                     bool flat_output);
241
242    bool
243    GetIsConstant () const
244    {
245        return m_update_id == LLDB_INVALID_UID;
246    }
247
248    void
249    SetIsConstant ()
250    {
251        m_update_id = LLDB_INVALID_UID;
252    }
253
254    lldb::Format
255    GetFormat () const
256    {
257        return m_format;
258    }
259
260    void
261    SetFormat (lldb::Format format)
262    {
263        if (format != m_format)
264            m_value_str.clear();
265        m_format = format;
266    }
267
268    ValueObject *
269    GetParent()
270    {
271        return m_parent;
272    }
273
274    const ValueObject *
275    GetParent() const
276    {
277        return m_parent;
278    }
279
280    void
281    SetPointersPointToLoadAddrs (bool b)
282    {
283        m_pointers_point_to_load_addrs = b;
284    }
285
286protected:
287    //------------------------------------------------------------------
288    // Classes that inherit from ValueObject can see and modify these
289    //------------------------------------------------------------------
290    ValueObject*        m_parent;       // The parent value object, or NULL if this has no parent
291    lldb::user_id_t     m_update_id;    // An integer that specifies the update number for this value in
292                                        // this value object list. If this value object is asked to update itself
293                                        // it will first check if the update ID match the value object
294                                        // list update number. If the update numbers match, no update is
295                                        // needed, if it does not match, this value object should update its
296                                        // the next time it is asked.
297    ConstString         m_name;         // The name of this object
298    DataExtractor       m_data;         // A data extractor that can be used to extract the value.
299    Value               m_value;
300    Error               m_error;        // An error object that can describe any errors that occur when updating values.
301    std::string         m_value_str;    // Cached value string that will get cleared if/when the value is updated.
302    std::string         m_old_value_str;// Cached old value string from the last time the value was gotten
303    std::string         m_location_str; // Cached location string that will get cleared if/when the value is updated.
304    std::string         m_summary_str;  // Cached summary string that will get cleared if/when the value is updated.
305    std::string         m_object_desc_str; // Cached result of the "object printer".  This differs from the summary
306                                              // in that the summary is consed up by us, the object_desc_string is builtin.
307    std::vector<lldb::ValueObjectSP> m_children;
308    std::map<ConstString, lldb::ValueObjectSP> m_synthetic_children;
309    lldb::ValueObjectSP m_dynamic_value_sp;
310    lldb::Format        m_format;
311    bool                m_value_is_valid:1,
312                        m_value_did_change:1,
313                        m_children_count_valid:1,
314                        m_old_value_valid:1,
315                        m_pointers_point_to_load_addrs:1;
316
317    friend class CommandObjectExpression;
318    friend class ClangExpressionVariable;
319    friend class Target;
320    //------------------------------------------------------------------
321    // Constructors and Destructors
322    //------------------------------------------------------------------
323    ValueObject (ValueObject *parent);
324
325    void
326    SetName (const char *name);
327
328    void
329    SetName (const ConstString &name);
330
331    void
332    SetNumChildren (uint32_t num_children);
333
334    void
335    SetValueDidChange (bool value_changed);
336
337    void
338    SetValueIsValid (bool valid);
339
340
341    lldb::addr_t
342    GetPointerValue (lldb::AddressType &address_type,
343                     bool scalar_is_load_address);
344
345    lldb::addr_t
346    GetAddressOf (lldb::AddressType &address_type,
347                  bool scalar_is_load_address);
348private:
349    //------------------------------------------------------------------
350    // For ValueObject only
351    //------------------------------------------------------------------
352    DISALLOW_COPY_AND_ASSIGN (ValueObject);
353
354};
355
356} // namespace lldb_private
357
358#endif  // liblldb_ValueObject_h_
359