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_DATAFORMATTERS_VALUEOBJECTPRINTER_H |
11 | #define LLDB_DATAFORMATTERS_VALUEOBJECTPRINTER_H |
12 | |
13 | #include "lldb/lldb-private.h" |
14 | #include "lldb/lldb-public.h" |
15 | |
16 | #include "lldb/Utility/Flags.h" |
17 | |
18 | #include "lldb/DataFormatters/DumpValueObjectOptions.h" |
19 | #include "lldb/Symbol/CompilerType.h" |
20 | |
21 | namespace lldb_private { |
22 | |
23 | class ValueObjectPrinter { |
24 | /// The ValueObjectPrinter is a one-shot printer for ValueObjects. It |
25 | /// does not retain the ValueObject it is printing, that is the job of |
26 | /// its caller. It also doesn't attempt to track changes in the |
27 | /// ValueObject, e.g. changing synthetic child providers or changing |
28 | /// dynamic vrs. static vrs. synthetic settings. |
29 | public: |
30 | ValueObjectPrinter(ValueObject &valobj, Stream *s); |
31 | |
32 | ValueObjectPrinter(ValueObject &valobj, Stream *s, |
33 | const DumpValueObjectOptions &options); |
34 | |
35 | ~ValueObjectPrinter() = default; |
36 | |
37 | bool PrintValueObject(); |
38 | |
39 | protected: |
40 | typedef std::set<uint64_t> ; |
41 | typedef std::shared_ptr<InstancePointersSet> ; |
42 | |
43 | InstancePointersSetSP m_printed_instance_pointers; |
44 | |
45 | // only this class (and subclasses, if any) should ever be concerned with the |
46 | // depth mechanism |
47 | ValueObjectPrinter(ValueObject &valobj, Stream *s, |
48 | const DumpValueObjectOptions &options, |
49 | const DumpValueObjectOptions::PointerDepth &ptr_depth, |
50 | uint32_t curr_depth, |
51 | InstancePointersSetSP printed_instance_pointers); |
52 | |
53 | // we should actually be using delegating constructors here but some versions |
54 | // of GCC still have trouble with those |
55 | void Init(ValueObject &valobj, Stream *s, |
56 | const DumpValueObjectOptions &options, |
57 | const DumpValueObjectOptions::PointerDepth &ptr_depth, |
58 | uint32_t curr_depth, |
59 | InstancePointersSetSP printed_instance_pointers); |
60 | |
61 | /// Cache the ValueObject we are actually going to print. If this |
62 | /// ValueObject has a Dynamic type, we return that, if either the original |
63 | /// ValueObject or its Dynamic type has a Synthetic provider, return that. |
64 | /// This will never return an empty ValueObject, since we use the ValueObject |
65 | /// to carry errors. |
66 | /// Note, this gets called when making the printer object, and uses the |
67 | /// use dynamic and use synthetic settings of the ValueObject being printed, |
68 | /// so changes made to these settings won't affect already made |
69 | /// ValueObjectPrinters. SetupMostSpecializedValue(); |
70 | |
71 | /// Access the cached "most specialized value" - that is the one to use for |
72 | /// printing the value object's value. However, be sure to use |
73 | /// GetValueForChildGeneration when you are generating the children of this |
74 | /// value. |
75 | ValueObject &GetMostSpecializedValue(); |
76 | |
77 | void SetupMostSpecializedValue(); |
78 | |
79 | const char *GetDescriptionForDisplay(); |
80 | |
81 | const char *GetRootNameForDisplay(); |
82 | |
83 | bool ShouldPrintValueObject(); |
84 | |
85 | bool IsNil(); |
86 | |
87 | bool IsUninitialized(); |
88 | |
89 | bool IsPtr(); |
90 | |
91 | bool IsRef(); |
92 | |
93 | bool IsInstancePointer(); |
94 | |
95 | bool IsAggregate(); |
96 | |
97 | bool PrintLocationIfNeeded(); |
98 | |
99 | void PrintDecl(); |
100 | |
101 | bool CheckScopeIfNeeded(); |
102 | |
103 | bool ShouldPrintEmptyBrackets(bool value_printed, bool summary_printed); |
104 | |
105 | TypeSummaryImpl *GetSummaryFormatter(bool null_if_omitted = true); |
106 | |
107 | void GetValueSummaryError(std::string &value, std::string &summary, |
108 | std::string &error); |
109 | |
110 | bool PrintValueAndSummaryIfNeeded(bool &value_printed, bool &summary_printed); |
111 | |
112 | bool PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed); |
113 | |
114 | bool |
115 | ShouldPrintChildren(DumpValueObjectOptions::PointerDepth &curr_ptr_depth); |
116 | |
117 | bool ShouldExpandEmptyAggregates(); |
118 | |
119 | ValueObject &GetValueObjectForChildrenGeneration(); |
120 | |
121 | void PrintChildrenPreamble(bool value_printed, bool summary_printed); |
122 | |
123 | void PrintChildrenPostamble(bool print_dotdotdot); |
124 | |
125 | lldb::ValueObjectSP GenerateChild(ValueObject &synth_valobj, size_t idx); |
126 | |
127 | void PrintChild(lldb::ValueObjectSP child_sp, |
128 | const DumpValueObjectOptions::PointerDepth &curr_ptr_depth); |
129 | |
130 | uint32_t GetMaxNumChildrenToPrint(bool &print_dotdotdot); |
131 | |
132 | void |
133 | PrintChildren(bool value_printed, bool summary_printed, |
134 | const DumpValueObjectOptions::PointerDepth &curr_ptr_depth); |
135 | |
136 | void PrintChildrenIfNeeded(bool value_printed, bool summary_printed); |
137 | |
138 | bool PrintChildrenOneLiner(bool hide_names); |
139 | |
140 | bool HasReachedMaximumDepth(); |
141 | |
142 | private: |
143 | bool ShouldShowName() const; |
144 | |
145 | ValueObject &m_orig_valobj; |
146 | ValueObject *m_cached_valobj; /// Cache the current "most specialized" value. |
147 | /// Don't use this directly, use |
148 | /// GetMostSpecializedValue. |
149 | Stream *m_stream; |
150 | DumpValueObjectOptions m_options; |
151 | Flags m_type_flags; |
152 | CompilerType m_compiler_type; |
153 | DumpValueObjectOptions::PointerDepth m_ptr_depth; |
154 | uint32_t m_curr_depth; |
155 | LazyBool m_should_print; |
156 | LazyBool m_is_nil; |
157 | LazyBool m_is_uninit; |
158 | LazyBool m_is_ptr; |
159 | LazyBool m_is_ref; |
160 | LazyBool m_is_aggregate; |
161 | LazyBool m_is_instance_ptr; |
162 | std::pair<TypeSummaryImpl *, bool> m_summary_formatter; |
163 | std::string m_value; |
164 | std::string m_summary; |
165 | std::string m_error; |
166 | bool m_val_summary_ok; |
167 | |
168 | friend struct StringSummaryFormat; |
169 | |
170 | ValueObjectPrinter(const ValueObjectPrinter &) = delete; |
171 | const ValueObjectPrinter &operator=(const ValueObjectPrinter &) = delete; |
172 | }; |
173 | |
174 | } // namespace lldb_private |
175 | |
176 | #endif // LLDB_DATAFORMATTERS_VALUEOBJECTPRINTER_H |
177 | |