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 bool LibcxxStringSummaryProviderASCII(
27     ValueObject &valobj, Stream &stream,
28     const TypeSummaryOptions &summary_options); // libc++ std::string
29 
30 bool LibcxxStringSummaryProviderUTF16(
31     ValueObject &valobj, Stream &stream,
32     const TypeSummaryOptions &summary_options); // libc++ std::u16string
33 
34 bool LibcxxStringSummaryProviderUTF32(
35     ValueObject &valobj, Stream &stream,
36     const TypeSummaryOptions &summary_options); // libc++ std::u32string
37 
38 bool LibcxxWStringSummaryProvider(
39     ValueObject &valobj, Stream &stream,
40     const TypeSummaryOptions &options); // libc++ std::wstring
41 
42 bool LibcxxStringViewSummaryProviderASCII(
43     ValueObject &valueObj, Stream &stream,
44     const TypeSummaryOptions &summary_options); // libc++ std::string_view
45 
46 bool LibcxxStringViewSummaryProviderUTF16(
47     ValueObject &valobj, Stream &stream,
48     const TypeSummaryOptions &summary_options); // libc++ std::u16string_view
49 
50 bool LibcxxStringViewSummaryProviderUTF32(
51     ValueObject &valobj, Stream &stream,
52     const TypeSummaryOptions &summary_options); // libc++ std::u32string_view
53 
54 bool LibcxxWStringViewSummaryProvider(
55     ValueObject &valobj, Stream &stream,
56     const TypeSummaryOptions &options); // libc++ std::wstring_view
57 
58 bool LibcxxOptionalSummaryProvider(
59     ValueObject &valobj, Stream &stream,
60     const TypeSummaryOptions &options); // libc++ std::optional<>
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 };
204 
205 SyntheticChildrenFrontEnd *
206 LibcxxBitsetSyntheticFrontEndCreator(CXXSyntheticChildren *,
207                                      lldb::ValueObjectSP);
208 
209 SyntheticChildrenFrontEnd *
210 LibcxxSharedPtrSyntheticFrontEndCreator(CXXSyntheticChildren *,
211                                         lldb::ValueObjectSP);
212 
213 SyntheticChildrenFrontEnd *
214 LibcxxUniquePtrSyntheticFrontEndCreator(CXXSyntheticChildren *,
215                                         lldb::ValueObjectSP);
216 
217 SyntheticChildrenFrontEnd *
218 LibcxxStdVectorSyntheticFrontEndCreator(CXXSyntheticChildren *,
219                                         lldb::ValueObjectSP);
220 
221 SyntheticChildrenFrontEnd *
222 LibcxxStdListSyntheticFrontEndCreator(CXXSyntheticChildren *,
223                                       lldb::ValueObjectSP);
224 
225 SyntheticChildrenFrontEnd *
226 LibcxxStdForwardListSyntheticFrontEndCreator(CXXSyntheticChildren *,
227                                              lldb::ValueObjectSP);
228 
229 SyntheticChildrenFrontEnd *
230 LibcxxStdMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
231                                      lldb::ValueObjectSP);
232 
233 SyntheticChildrenFrontEnd *
234 LibcxxStdUnorderedMapSyntheticFrontEndCreator(CXXSyntheticChildren *,
235                                               lldb::ValueObjectSP);
236 
237 SyntheticChildrenFrontEnd *
238 LibcxxInitializerListSyntheticFrontEndCreator(CXXSyntheticChildren *,
239                                               lldb::ValueObjectSP);
240 
241 SyntheticChildrenFrontEnd *LibcxxQueueFrontEndCreator(CXXSyntheticChildren *,
242                                                       lldb::ValueObjectSP);
243 
244 SyntheticChildrenFrontEnd *LibcxxTupleFrontEndCreator(CXXSyntheticChildren *,
245                                                       lldb::ValueObjectSP);
246 
247 SyntheticChildrenFrontEnd *
248 LibcxxOptionalSyntheticFrontEndCreator(CXXSyntheticChildren *,
249                                        lldb::ValueObjectSP valobj_sp);
250 
251 SyntheticChildrenFrontEnd *
252 LibcxxVariantFrontEndCreator(CXXSyntheticChildren *,
253                              lldb::ValueObjectSP valobj_sp);
254 
255 SyntheticChildrenFrontEnd *
256 LibcxxStdSpanSyntheticFrontEndCreator(CXXSyntheticChildren *,
257                                       lldb::ValueObjectSP);
258 
259 SyntheticChildrenFrontEnd *
260 LibcxxStdRangesRefViewSyntheticFrontEndCreator(CXXSyntheticChildren *,
261                                                lldb::ValueObjectSP);
262 
263 } // namespace formatters
264 } // namespace lldb_private
265 
266 #endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_LIBCXX_H
267