]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/ValueObjectPrinter.h
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / ValueObjectPrinter.h
1 //===-- ValueObjectPrinter.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 lldb_ValueObjectPrinter_h_
11 #define lldb_ValueObjectPrinter_h_
12
13 // C Includes
14 // C++ Includes
15
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/lldb-private.h"
19 #include "lldb/lldb-public.h"
20
21 #include "lldb/Core/Stream.h"
22 #include "lldb/Core/ValueObject.h"
23 #include "lldb/DataFormatters/TypeSummary.h"
24
25 namespace lldb_private {
26
27 struct DumpValueObjectOptions
28 {
29     uint32_t m_max_ptr_depth = 0;
30     uint32_t m_max_depth = UINT32_MAX;
31     lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues;
32     uint32_t m_omit_summary_depth = 0;
33     lldb::Format m_format = lldb::eFormatDefault;
34     lldb::TypeSummaryImplSP m_summary_sp;
35     std::string m_root_valobj_name;
36     bool m_use_synthetic : 1;
37     bool m_scope_already_checked : 1;
38     bool m_flat_output : 1;
39     bool m_ignore_cap : 1;
40     bool m_show_types : 1;
41     bool m_show_location : 1;
42     bool m_use_objc : 1;
43     bool m_hide_root_type : 1;
44     bool m_hide_name : 1;
45     bool m_hide_value : 1;
46     bool m_run_validator : 1;
47     bool m_use_type_display_name : 1;
48     bool m_allow_oneliner_mode : 1;
49     
50     DumpValueObjectOptions() :
51     m_summary_sp(),
52     m_root_valobj_name(),
53     m_use_synthetic(true),
54     m_scope_already_checked(false),
55     m_flat_output(false),
56     m_ignore_cap(false),
57     m_show_types(false),
58     m_show_location(false),
59     m_use_objc(false),
60     m_hide_root_type(false),
61     m_hide_name(false),
62     m_hide_value(false),
63     m_run_validator(false),
64     m_use_type_display_name(true),
65     m_allow_oneliner_mode(true)
66     {}
67     
68     static const DumpValueObjectOptions
69     DefaultOptions()
70     {
71         static DumpValueObjectOptions g_default_options;
72         
73         return g_default_options;
74     }
75     
76     DumpValueObjectOptions (const DumpValueObjectOptions& rhs) = default;
77     
78     DumpValueObjectOptions&
79     SetMaximumPointerDepth(uint32_t depth = 0)
80     {
81         m_max_ptr_depth = depth;
82         return *this;
83     }
84     
85     DumpValueObjectOptions&
86     SetMaximumDepth(uint32_t depth = 0)
87     {
88         m_max_depth = depth;
89         return *this;
90     }
91     
92     DumpValueObjectOptions&
93     SetShowTypes(bool show = false)
94     {
95         m_show_types = show;
96         return *this;
97     }
98     
99     DumpValueObjectOptions&
100     SetShowLocation(bool show = false)
101     {
102         m_show_location = show;
103         return *this;
104     }
105     
106     DumpValueObjectOptions&
107     SetUseObjectiveC(bool use = false)
108     {
109         m_use_objc = use;
110         return *this;
111     }
112     
113     DumpValueObjectOptions&
114     SetShowSummary(bool show = true)
115     {
116         if (show == false)
117             SetOmitSummaryDepth(UINT32_MAX);
118         else
119             SetOmitSummaryDepth(0);
120         return *this;
121     }
122     
123     DumpValueObjectOptions&
124     SetUseDynamicType(lldb::DynamicValueType dyn = lldb::eNoDynamicValues)
125     {
126         m_use_dynamic = dyn;
127         return *this;
128     }
129     
130     DumpValueObjectOptions&
131     SetUseSyntheticValue(bool use_synthetic = true)
132     {
133         m_use_synthetic = use_synthetic;
134         return *this;
135     }
136     
137     DumpValueObjectOptions&
138     SetScopeChecked(bool check = true)
139     {
140         m_scope_already_checked = check;
141         return *this;
142     }
143     
144     DumpValueObjectOptions&
145     SetFlatOutput(bool flat = false)
146     {
147         m_flat_output = flat;
148         return *this;
149     }
150     
151     DumpValueObjectOptions&
152     SetOmitSummaryDepth(uint32_t depth = 0)
153     {
154         m_omit_summary_depth = depth;
155         return *this;
156     }
157     
158     DumpValueObjectOptions&
159     SetIgnoreCap(bool ignore = false)
160     {
161         m_ignore_cap = ignore;
162         return *this;
163     }
164     
165     DumpValueObjectOptions&
166     SetRawDisplay()
167     {
168         SetUseSyntheticValue(false);
169         SetOmitSummaryDepth(UINT32_MAX);
170         SetIgnoreCap(true);
171         SetHideName(false);
172         SetHideValue(false);
173         SetUseTypeDisplayName(false);
174         SetAllowOnelinerMode(false);
175         return *this;
176     }
177     
178     DumpValueObjectOptions&
179     SetFormat (lldb::Format format = lldb::eFormatDefault)
180     {
181         m_format = format;
182         return *this;
183     }
184     
185     DumpValueObjectOptions&
186     SetSummary (lldb::TypeSummaryImplSP summary = lldb::TypeSummaryImplSP())
187     {
188         m_summary_sp = summary;
189         return *this;
190     }
191     
192     DumpValueObjectOptions&
193     SetRootValueObjectName (const char* name = NULL)
194     {
195         if (name)
196             m_root_valobj_name.assign(name);
197         else
198             m_root_valobj_name.clear();
199         return *this;
200     }
201     
202     DumpValueObjectOptions&
203     SetHideRootType (bool hide_root_type = false)
204     {
205         m_hide_root_type = hide_root_type;
206         return *this;
207     }
208     
209     DumpValueObjectOptions&
210     SetHideName (bool hide_name = false)
211     {
212         m_hide_name = hide_name;
213         return *this;
214     }
215     
216     DumpValueObjectOptions&
217     SetHideValue (bool hide_value = false)
218     {
219         m_hide_value = hide_value;
220         return *this;
221     }
222     
223     DumpValueObjectOptions&
224     SetRunValidator (bool run = true)
225     {
226         m_run_validator = run;
227         return *this;
228     }
229     
230     DumpValueObjectOptions&
231     SetUseTypeDisplayName (bool dis = false)
232     {
233         m_use_type_display_name = dis;
234         return *this;
235     }
236     
237     DumpValueObjectOptions&
238     SetAllowOnelinerMode (bool oneliner = false)
239     {
240         m_allow_oneliner_mode = oneliner;
241         return *this;
242     }
243     
244 };
245
246 class ValueObjectPrinter
247 {
248 public:
249     
250     ValueObjectPrinter (ValueObject* valobj,
251                         Stream* s,
252                         const DumpValueObjectOptions& options);
253     
254     ~ValueObjectPrinter () {}
255     
256     bool
257     PrintValueObject ();
258     
259 protected:
260     
261     // only this class (and subclasses, if any) should ever be concerned with
262     // the depth mechanism
263     ValueObjectPrinter (ValueObject* valobj,
264                         Stream* s,
265                         const DumpValueObjectOptions& options,
266                         uint32_t ptr_depth,
267                         uint32_t curr_depth);
268     
269     // we should actually be using delegating constructors here
270     // but some versions of GCC still have trouble with those
271     void
272     Init (ValueObject* valobj,
273           Stream* s,
274           const DumpValueObjectOptions& options,
275           uint32_t ptr_depth,
276           uint32_t curr_depth);
277     
278     bool
279     GetMostSpecializedValue ();
280     
281     const char*
282     GetDescriptionForDisplay ();
283     
284     const char*
285     GetRootNameForDisplay (const char* if_fail = nullptr);
286     
287     bool
288     ShouldPrintValueObject ();
289     
290     bool
291     ShouldPrintValidation ();
292     
293     bool
294     IsNil ();
295     
296     bool
297     IsPtr ();
298     
299     bool
300     IsRef ();
301     
302     bool
303     IsAggregate ();
304     
305     bool
306     PrintValidationMarkerIfNeeded ();
307     
308     bool
309     PrintValidationErrorIfNeeded ();
310     
311     bool
312     PrintLocationIfNeeded ();
313     
314     bool
315     PrintTypeIfNeeded ();
316     
317     bool
318     PrintNameIfNeeded (bool show_type);
319     
320     bool
321     CheckScopeIfNeeded ();
322     
323     TypeSummaryImpl*
324     GetSummaryFormatter ();
325     
326     void
327     GetValueSummaryError (std::string& value,
328                           std::string& summary,
329                           std::string& error);
330     
331     bool
332     PrintValueAndSummaryIfNeeded (bool& value_printed,
333                                   bool& summary_printed);
334     
335     bool
336     PrintObjectDescriptionIfNeeded (bool value_printed,
337                                     bool summary_printed);
338     
339     bool
340     ShouldPrintChildren (bool is_failed_description,
341                          uint32_t& curr_ptr_depth);
342     
343     ValueObject*
344     GetValueObjectForChildrenGeneration ();
345     
346     void
347     PrintChildrenPreamble ();
348     
349     void
350     PrintChildrenPostamble (bool print_dotdotdot);
351     
352     void
353     PrintChild (lldb::ValueObjectSP child_sp,
354                 uint32_t curr_ptr_depth);
355     
356     uint32_t
357     GetMaxNumChildrenToPrint (bool& print_dotdotdot);
358     
359     void
360     PrintChildren (uint32_t curr_ptr_depth);
361     
362     void
363     PrintChildrenIfNeeded (bool value_printed,
364                            bool summary_printed);
365     
366     bool
367     PrintChildrenOneLiner (bool hide_names);
368     
369 private:
370     
371     ValueObject *m_orig_valobj;
372     ValueObject *m_valobj;
373     Stream *m_stream;
374     DumpValueObjectOptions options;
375     Flags m_type_flags;
376     ClangASTType m_clang_type;
377     uint32_t m_ptr_depth;
378     uint32_t m_curr_depth;
379     LazyBool m_should_print;
380     LazyBool m_is_nil;
381     LazyBool m_is_ptr;
382     LazyBool m_is_ref;
383     LazyBool m_is_aggregate;
384     std::pair<TypeSummaryImpl*,bool> m_summary_formatter;
385     std::string m_value;
386     std::string m_summary;
387     std::string m_error;
388     std::pair<TypeValidatorResult,std::string> m_validation;
389     
390     friend struct StringSummaryFormat;
391     
392     DISALLOW_COPY_AND_ASSIGN(ValueObjectPrinter);
393 };
394     
395 } // namespace lldb_private
396
397 #endif  // lldb_ValueObjectPrinter_h_