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

source code of lldb/source/Plugins/Language/CPlusPlus/LibCxx.h