blob: 41adc2d2b5b2265b741611edeca159902370bd18 [file] [log] [blame]
Andrew Walbran3d2c1972020-04-07 12:24:26 +01001//===-- 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
22namespace lldb_private {
23
24class ValueObjectPrinter {
25public:
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
35protected:
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 ShouldPrintValidation();
66
67 bool IsNil();
68
69 bool IsUninitialized();
70
71 bool IsPtr();
72
73 bool IsRef();
74
75 bool IsInstancePointer();
76
77 bool IsAggregate();
78
79 bool PrintValidationMarkerIfNeeded();
80
81 bool PrintValidationErrorIfNeeded();
82
83 bool PrintLocationIfNeeded();
84
85 void PrintDecl();
86
87 bool CheckScopeIfNeeded();
88
89 bool ShouldPrintEmptyBrackets(bool value_printed, bool summary_printed);
90
91 TypeSummaryImpl *GetSummaryFormatter(bool null_if_omitted = true);
92
93 void GetValueSummaryError(std::string &value, std::string &summary,
94 std::string &error);
95
96 bool PrintValueAndSummaryIfNeeded(bool &value_printed, bool &summary_printed);
97
98 bool PrintObjectDescriptionIfNeeded(bool value_printed, bool summary_printed);
99
100 bool
101 ShouldPrintChildren(bool is_failed_description,
102 DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
103
104 bool ShouldExpandEmptyAggregates();
105
106 ValueObject *GetValueObjectForChildrenGeneration();
107
108 void PrintChildrenPreamble();
109
110 void PrintChildrenPostamble(bool print_dotdotdot);
111
112 lldb::ValueObjectSP GenerateChild(ValueObject *synth_valobj, size_t idx);
113
114 void PrintChild(lldb::ValueObjectSP child_sp,
115 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
116
117 uint32_t GetMaxNumChildrenToPrint(bool &print_dotdotdot);
118
119 void
120 PrintChildren(bool value_printed, bool summary_printed,
121 const DumpValueObjectOptions::PointerDepth &curr_ptr_depth);
122
123 void PrintChildrenIfNeeded(bool value_printed, bool summary_printed);
124
125 bool PrintChildrenOneLiner(bool hide_names);
126
127private:
128 ValueObject *m_orig_valobj;
129 ValueObject *m_valobj;
130 Stream *m_stream;
131 DumpValueObjectOptions m_options;
132 Flags m_type_flags;
133 CompilerType m_compiler_type;
134 DumpValueObjectOptions::PointerDepth m_ptr_depth;
135 uint32_t m_curr_depth;
136 LazyBool m_should_print;
137 LazyBool m_is_nil;
138 LazyBool m_is_uninit;
139 LazyBool m_is_ptr;
140 LazyBool m_is_ref;
141 LazyBool m_is_aggregate;
142 LazyBool m_is_instance_ptr;
143 std::pair<TypeSummaryImpl *, bool> m_summary_formatter;
144 std::string m_value;
145 std::string m_summary;
146 std::string m_error;
147 bool m_val_summary_ok;
148 std::pair<TypeValidatorResult, std::string> m_validation;
149
150 friend struct StringSummaryFormat;
151
152 DISALLOW_COPY_AND_ASSIGN(ValueObjectPrinter);
153};
154
155} // namespace lldb_private
156
157#endif // lldb_ValueObjectPrinter_h_