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