1 //===-- ValueObjectPrinter.h ---------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #ifndef lldb_ValueObjectPrinter_h_
12 #define lldb_ValueObjectPrinter_h_
13 
14 
15 #include "lldb/lldb-private.h"
16 #include "lldb/lldb-public.h"
17 
18 #include "lldb/Utility/Flags.h"
19 
20 #include "lldb/DataFormatters/DumpValueObjectOptions.h"
21 #include "lldb/Symbol/CompilerType.h"
22 
23 namespace lldb_private {
24 
25 class ValueObjectPrinter {
26 public:
27   ValueObjectPrinter(ValueObject *valobj, Stream *s);
28 
29   ValueObjectPrinter(ValueObject *valobj, Stream *s,
30                      const DumpValueObjectOptions &options);
31 
~ValueObjectPrinter()32   ~ValueObjectPrinter() {}
33 
34   bool PrintValueObject();
35 
36 protected:
37   typedef std::set<uint64_t> InstancePointersSet;
38   typedef std::shared_ptr<InstancePointersSet> InstancePointersSetSP;
39 
40   InstancePointersSetSP m_printed_instance_pointers;
41 
42   // only this class (and subclasses, if any) should ever be concerned with the
43   // depth mechanism
44   ValueObjectPrinter(ValueObject *valobj, Stream *s,
45                      const DumpValueObjectOptions &options,
46                      const DumpValueObjectOptions::PointerDepth &ptr_depth,
47                      uint32_t curr_depth,
48                      InstancePointersSetSP printed_instance_pointers);
49 
50   // we should actually be using delegating constructors here but some versions
51   // of GCC still have trouble with those
52   void Init(ValueObject *valobj, Stream *s,
53             const DumpValueObjectOptions &options,
54             const DumpValueObjectOptions::PointerDepth &ptr_depth,
55             uint32_t curr_depth,
56             InstancePointersSetSP printed_instance_pointers);
57 
58   bool GetMostSpecializedValue();
59 
60   const char *GetDescriptionForDisplay();
61 
62   const char *GetRootNameForDisplay(const char *if_fail = nullptr);
63 
64   bool ShouldPrintValueObject();
65 
66   bool ShouldPrintValidation();
67 
68   bool IsNil();
69 
70   bool IsUninitialized();
71 
72   bool IsPtr();
73 
74   bool IsRef();
75 
76   bool IsInstancePointer();
77 
78   bool IsAggregate();
79 
80   bool PrintValidationMarkerIfNeeded();
81 
82   bool PrintValidationErrorIfNeeded();
83 
84   bool PrintLocationIfNeeded();
85 
86   void PrintDecl();
87 
88   bool CheckScopeIfNeeded();
89 
90   bool ShouldPrintEmptyBrackets(bool value_printed, bool summary_printed);
91 
92   TypeSummaryImpl *GetSummaryFormatter(bool null_if_omitted = true);
93 
94   void GetValueSummaryError(std::string &value, std::string &summary,
95                             std::string &error);
96 
97   bool PrintValueAndSummaryIfNeeded(bool &value_printed, bool &summary_printed);
98 
99   bool PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed);
100 
101   bool
102   ShouldPrintChildren(bool is_failed_description,
103                       DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
104 
105   bool ShouldExpandEmptyAggregates();
106 
107   ValueObject *GetValueObjectForChildrenGeneration();
108 
109   void PrintChildrenPreamble();
110 
111   void PrintChildrenPostamble(bool print_dotdotdot);
112 
113   lldb::ValueObjectSP GenerateChild(ValueObject *synth_valobj, size_t idx);
114 
115   void PrintChild(lldb::ValueObjectSP child_sp,
116                   const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
117 
118   uint32_t GetMaxNumChildrenToPrint(bool &print_dotdotdot);
119 
120   void
121   PrintChildren(bool value_printed, bool summary_printed,
122                 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
123 
124   void PrintChildrenIfNeeded(bool value_printed, bool summary_printed);
125 
126   bool PrintChildrenOneLiner(bool hide_names);
127 
128 private:
129   ValueObject *m_orig_valobj;
130   ValueObject *m_valobj;
131   Stream *m_stream;
132   DumpValueObjectOptions m_options;
133   Flags m_type_flags;
134   CompilerType m_compiler_type;
135   DumpValueObjectOptions::PointerDepth m_ptr_depth;
136   uint32_t m_curr_depth;
137   LazyBool m_should_print;
138   LazyBool m_is_nil;
139   LazyBool m_is_uninit;
140   LazyBool m_is_ptr;
141   LazyBool m_is_ref;
142   LazyBool m_is_aggregate;
143   LazyBool m_is_instance_ptr;
144   std::pair<TypeSummaryImpl *, bool> m_summary_formatter;
145   std::string m_value;
146   std::string m_summary;
147   std::string m_error;
148   bool m_val_summary_ok;
149   std::pair<TypeValidatorResult, std::string> m_validation;
150 
151   friend struct StringSummaryFormat;
152 
153   DISALLOW_COPY_AND_ASSIGN(ValueObjectPrinter);
154 };
155 
156 } // namespace lldb_private
157 
158 #endif // lldb_ValueObjectPrinter_h_
159