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