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