1 //===-- LibCxx.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_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_LIBCXX_H
11 #define LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_LIBCXX_H
12 
13 #include "lldb/Core/ValueObject.h"
14 #include "lldb/DataFormatters/TypeSummary.h"
15 #include "lldb/DataFormatters/TypeSynthetic.h"
16 #include "lldb/Utility/Stream.h"
17 
18 namespace lldb_private {
19 namespace formatters {
20 
21 /// Find a child member of \c obj_sp, trying all alternative names in order.
22 lldb::ValueObjectSP
23 GetChildMemberWithName(ValueObject &obj,
24                        llvm::ArrayRef<ConstString> alternative_names);
25 
26 lldb::ValueObjectSP GetFirstValueOfLibCXXCompressedPair(ValueObject &pair);
27 lldb::ValueObjectSP GetSecondValueOfLibCXXCompressedPair(ValueObject &pair);
28 
29 
30 bool LibcxxStringSummaryProviderASCII(
31     ValueObject &valobj, Stream &stream,
32     const TypeSummaryOptions &summary_options); // libc++ std::string
33 
34 bool LibcxxStringSummaryProviderUTF16(
35     ValueObject &valobj, Stream &stream,
36     const TypeSummaryOptions &summary_options); // libc++ std::u16string
37 
38 bool LibcxxStringSummaryProviderUTF32(
39     ValueObject &valobj, Stream &stream,
40     const TypeSummaryOptions &summary_options); // libc++ std::u32string
41 
42 bool LibcxxWStringSummaryProvider(
43     ValueObject &valobj, Stream &stream,
44     const TypeSummaryOptions &options); // libc++ std::wstring
45 
46 bool LibcxxStringViewSummaryProviderASCII(
47     ValueObject &valueObj, Stream &stream,
48     const TypeSummaryOptions &summary_options); // libc++ std::string_view
49 
50 bool LibcxxStringViewSummaryProviderUTF16(
51     ValueObject &valobj, Stream &stream,
52     const TypeSummaryOptions &summary_options); // libc++ std::u16string_view
53 
54 bool LibcxxStringViewSummaryProviderUTF32(
55     ValueObject &valobj, Stream &stream,
56     const TypeSummaryOptions &summary_options); // libc++ std::u32string_view
57 
58 bool LibcxxWStringViewSummaryProvider(
59     ValueObject &valobj, Stream &stream,
60     const TypeSummaryOptions &options); // libc++ std::wstring_view
61 
62 bool LibcxxSmartPointerSummaryProvider(
63     ValueObject &valobj, Stream &stream,
64     const TypeSummaryOptions
65         &options); // libc++ std::shared_ptr<> and std::weak_ptr<>
66 
67 // libc++ std::unique_ptr<>
68 bool LibcxxUniquePointerSummaryProvider(ValueObject &valobj, Stream &stream,
69                                         const TypeSummaryOptions &options);
70 
71 bool LibcxxFunctionSummaryProvider(
72     ValueObject &valobj, Stream &stream,
73     const TypeSummaryOptions &options); // libc++ std::function<>
74 
75 SyntheticChildrenFrontEnd *
76 LibcxxVectorBoolSyntheticFrontEndCreator(CXXSyntheticChildren *,
77                                          lldb::ValueObjectSP);
78 
79 bool LibcxxContainerSummaryProvider(ValueObject &valobj, Stream &stream,
80                                     const TypeSummaryOptions &options);
81 
82 /// Formatter for libc++ std::span<>.
83 bool LibcxxSpanSummaryProvider(ValueObject &valobj, Stream &stream,
84                                const TypeSummaryOptions &options);
85 
86 class LibCxxMapIteratorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
87 public:
88   LibCxxMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
89 
90   size_t CalculateNumChildren() override;
91 
92   lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
93 
94   bool Update() override;
95 
96   bool MightHaveChildren() override;
97 
98   size_t GetIndexOfChildWithName(ConstString name) override;
99 
100   ~LibCxxMapIteratorSyntheticFrontEnd() override;
101 
102 private:
103   ValueObject *m_pair_ptr;
104   lldb::ValueObjectSP m_pair_sp;
105 };
106 
107 SyntheticChildrenFrontEnd *
108 LibCxxMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
109                                           lldb::ValueObjectSP);
110 
111 /// Formats libcxx's std::unordered_map iterators
112 ///
113 /// In raw form a std::unordered_map::iterator is represented as follows:
114 ///
115 /// (lldb) var it --raw --ptr-depth 1
116 /// (std::__1::__hash_map_iterator<
117 ///    std::__1::__hash_iterator<
118 ///      std::__1::__hash_node<
119 ///        std::__1::__hash_value_type<
120 ///            std::__1::basic_string<char, std::__1::char_traits<char>,
121 ///            std::__1::allocator<char> >, std::__1::basic_string<char,
122 ///            std::__1::char_traits<char>, std::__1::allocator<char> > >,
123 ///        void *> *> >)
124 ///  it = {
125 ///   __i_ = {
126 ///     __node_ = 0x0000600001700040 {
127 ///       __next_ = 0x0000600001704000
128 ///     }
129 ///   }
130 /// }
131 class LibCxxUnorderedMapIteratorSyntheticFrontEnd
132     : public SyntheticChildrenFrontEnd {
133 public:
134   LibCxxUnorderedMapIteratorSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
135 
136   ~LibCxxUnorderedMapIteratorSyntheticFrontEnd() override = default;
137 
138   size_t CalculateNumChildren() override;
139 
140   lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
141 
142   bool Update() override;
143 
144   bool MightHaveChildren() override;
145 
146   size_t GetIndexOfChildWithName(ConstString name) override;
147 
148 private:
149   ValueObject *m_iter_ptr = nullptr; ///< Held, not owned. Child of iterator
150                                      ///< ValueObject supplied at construction.
151 
152   lldb::ValueObjectSP m_pair_sp; ///< ValueObject for the key/value pair
153                                  ///< that the iterator currently points
154                                  ///< to.
155 };
156 
157 SyntheticChildrenFrontEnd *
158 LibCxxUnorderedMapIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
159                                                    lldb::ValueObjectSP);
160 
161 SyntheticChildrenFrontEnd *
162 LibCxxVectorIteratorSyntheticFrontEndCreator(CXXSyntheticChildren *,
163                                              lldb::ValueObjectSP);
164 
165 class LibcxxSharedPtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
166 public:
167   LibcxxSharedPtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
168 
169   size_t CalculateNumChildren() override;
170 
171   lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
172 
173   bool Update() override;
174 
175   bool MightHaveChildren() override;
176 
177   size_t GetIndexOfChildWithName(ConstString name) override;
178 
179   ~LibcxxSharedPtrSyntheticFrontEnd() override;
180 
181 private:
182   ValueObject *m_cntrl;
183 };
184 
185 class LibcxxUniquePtrSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
186 public:
187   LibcxxUniquePtrSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp);
188 
189   size_t CalculateNumChildren() override;
190 
191   lldb::ValueObjectSP GetChildAtIndex(size_t idx) override;
192 
193   bool Update() override;
194 
195   bool MightHaveChildren() override;
196 
197   size_t GetIndexOfChildWithName(ConstString name) override;
198 
199   ~LibcxxUniquePtrSyntheticFrontEnd() override;
200 
201 private:
202   lldb::ValueObjectSP m_value_ptr_sp;
203   lldb::ValueObjectSP m_deleter_sp;
204 };
205 
206 SyntheticChildrenFrontEnd *
207 LibcxxBitsetSyntheticFrontEndCreator(CXXSyntheticChildren *,
208                                      lldb::ValueObjectSP);
209 
210 SyntheticChildrenFrontEnd *
211 LibcxxSharedPtrSyntheticFrontEndCreator(CXXSyntheticChildren *,
212                                         lldb::ValueObjectSP);
213 
214 SyntheticChildrenFrontEnd *
215 LibcxxUniquePtrSyntheticFrontEndCreator(CXXSyntheticChildren *,
216                                         lldb::ValueObjectSP);
217 
218 SyntheticChildrenFrontEnd *
219 LibcxxStdVectorSyntheticFrontEndCreator(CXXSyntheticChildren *,
220                                         lldb::ValueObjectSP);
221 
222 SyntheticChildrenFrontEnd *
223 LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
224                                       lldb::ValueObjectSP);
225 
226 SyntheticChildrenFrontEnd *
227 LibcxxStdForwardListSyntheticFrontEndCreator(CXXSyntheticChildren *,
228                                              lldb::ValueObjectSP);
229 
230 SyntheticChildrenFrontEnd *
231 LibcxxStdMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
232                                      lldb::ValueObjectSP);
233 
234 SyntheticChildrenFrontEnd *
235 LibcxxStdUnorderedMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
236                                               lldb::ValueObjectSP);
237 
238 SyntheticChildrenFrontEnd *
239 LibcxxInitializerListSyntheticFrontEndCreator(CXXSyntheticChildren *,
240                                               lldb::ValueObjectSP);
241 
242 SyntheticChildrenFrontEnd *LibcxxQueueFrontEndCreator(CXXSyntheticChildren *,
243                                                       lldb::ValueObjectSP);
244 
245 SyntheticChildrenFrontEnd *LibcxxTupleFrontEndCreator(CXXSyntheticChildren *,
246                                                       lldb::ValueObjectSP);
247 
248 SyntheticChildrenFrontEnd *
249 LibcxxOptionalSyntheticFrontEndCreator(CXXSyntheticChildren *,
250                                        lldb::ValueObjectSP valobj_sp);
251 
252 SyntheticChildrenFrontEnd *
253 LibcxxVariantFrontEndCreator(CXXSyntheticChildren *,
254                              lldb::ValueObjectSP valobj_sp);
255 
256 SyntheticChildrenFrontEnd *
257 LibcxxStdSpanSyntheticFrontEndCreator(CXXSyntheticChildren *,
258                                       lldb::ValueObjectSP);
259 
260 SyntheticChildrenFrontEnd *
261 LibcxxStdRangesRefViewSyntheticFrontEndCreator(CXXSyntheticChildren *,
262                                                lldb::ValueObjectSP);
263 
264 bool LibcxxChronoSysSecondsSummaryProvider(
265     ValueObject &valobj, Stream &stream,
266     const TypeSummaryOptions &options); // libc++ std::chrono::sys_seconds
267 
268 bool LibcxxChronoSysDaysSummaryProvider(
269     ValueObject &valobj, Stream &stream,
270     const TypeSummaryOptions &options); // libc++ std::chrono::sys_days
271 
272 bool LibcxxChronoMonthSummaryProvider(
273     ValueObject &valobj, Stream &stream,
274     const TypeSummaryOptions &options); // libc++ std::chrono::month
275 
276 bool LibcxxChronoWeekdaySummaryProvider(
277     ValueObject &valobj, Stream &stream,
278     const TypeSummaryOptions &options); // libc++ std::chrono::weekday
279 
280 bool LibcxxChronoYearMonthDaySummaryProvider(
281     ValueObject &valobj, Stream &stream,
282     const TypeSummaryOptions &options); // libc++ std::chrono::year_month_day
283 
284 } // namespace formatters
285 } // namespace lldb_private
286 
287 #endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_LIBCXX_H
288