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