xref: /src/contrib/llvm-project/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1cfca06d7SDimitry Andric //===-- CPlusPlusLanguage.cpp ---------------------------------------------===//
2e81d9d49SDimitry Andric //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e81d9d49SDimitry Andric //
7e81d9d49SDimitry Andric //===----------------------------------------------------------------------===//
8e81d9d49SDimitry Andric 
9e81d9d49SDimitry Andric #include "CPlusPlusLanguage.h"
10e81d9d49SDimitry Andric 
11f3fbd1c0SDimitry Andric #include <cctype>
1214f1b3e8SDimitry Andric #include <cstring>
1314f1b3e8SDimitry Andric 
14f3fbd1c0SDimitry Andric #include <functional>
1514f1b3e8SDimitry Andric #include <memory>
16f3fbd1c0SDimitry Andric #include <mutex>
1714f1b3e8SDimitry Andric #include <set>
18e81d9d49SDimitry Andric 
19e81d9d49SDimitry Andric #include "llvm/ADT/StringRef.h"
2094994d37SDimitry Andric #include "llvm/Demangle/ItaniumDemangle.h"
21e81d9d49SDimitry Andric 
22706b4fc4SDimitry Andric #include "lldb/Core/Mangled.h"
23c0981da4SDimitry Andric #include "lldb/Core/Module.h"
24e81d9d49SDimitry Andric #include "lldb/Core/PluginManager.h"
25e81d9d49SDimitry Andric #include "lldb/Core/UniqueCStringMap.h"
26e3b55780SDimitry Andric #include "lldb/Core/ValueObjectVariable.h"
27e81d9d49SDimitry Andric #include "lldb/DataFormatters/CXXFunctionPointer.h"
28e81d9d49SDimitry Andric #include "lldb/DataFormatters/DataVisualization.h"
29e81d9d49SDimitry Andric #include "lldb/DataFormatters/FormattersHelpers.h"
30e81d9d49SDimitry Andric #include "lldb/DataFormatters/VectorType.h"
31c0981da4SDimitry Andric #include "lldb/Symbol/SymbolFile.h"
32e3b55780SDimitry Andric #include "lldb/Symbol/VariableList.h"
3374a628f7SDimitry Andric #include "lldb/Utility/ConstString.h"
34145449b1SDimitry Andric #include "lldb/Utility/LLDBLog.h"
3574a628f7SDimitry Andric #include "lldb/Utility/Log.h"
3674a628f7SDimitry Andric #include "lldb/Utility/RegularExpression.h"
37e81d9d49SDimitry Andric 
38f3fbd1c0SDimitry Andric #include "BlockPointer.h"
3974a628f7SDimitry Andric #include "CPlusPlusNameParser.h"
40e3b55780SDimitry Andric #include "Coroutines.h"
41e81d9d49SDimitry Andric #include "CxxStringTypes.h"
4277fc4c14SDimitry Andric #include "Generic.h"
43e81d9d49SDimitry Andric #include "LibCxx.h"
44f3fbd1c0SDimitry Andric #include "LibCxxAtomic.h"
4594994d37SDimitry Andric #include "LibCxxVariant.h"
46e81d9d49SDimitry Andric #include "LibStdcpp.h"
4794994d37SDimitry Andric #include "MSVCUndecoratedNameParser.h"
48b1c73532SDimitry Andric #include "lldb/lldb-enumerations.h"
49e81d9d49SDimitry Andric 
50e81d9d49SDimitry Andric using namespace lldb;
51e81d9d49SDimitry Andric using namespace lldb_private;
52e81d9d49SDimitry Andric using namespace lldb_private::formatters;
53e81d9d49SDimitry Andric 
LLDB_PLUGIN_DEFINE(CPlusPlusLanguage)54cfca06d7SDimitry Andric LLDB_PLUGIN_DEFINE(CPlusPlusLanguage)
55cfca06d7SDimitry Andric 
5614f1b3e8SDimitry Andric void CPlusPlusLanguage::Initialize() {
5714f1b3e8SDimitry Andric   PluginManager::RegisterPlugin(GetPluginNameStatic(), "C++ Language",
58e81d9d49SDimitry Andric                                 CreateInstance);
59e81d9d49SDimitry Andric }
60e81d9d49SDimitry Andric 
Terminate()6114f1b3e8SDimitry Andric void CPlusPlusLanguage::Terminate() {
62e81d9d49SDimitry Andric   PluginManager::UnregisterPlugin(CreateInstance);
63e81d9d49SDimitry Andric }
64e81d9d49SDimitry Andric 
SymbolNameFitsToLanguage(Mangled mangled) const65344a3780SDimitry Andric bool CPlusPlusLanguage::SymbolNameFitsToLanguage(Mangled mangled) const {
66344a3780SDimitry Andric   const char *mangled_name = mangled.GetMangledName().GetCString();
67344a3780SDimitry Andric   return mangled_name && CPlusPlusLanguage::IsCPPMangledName(mangled_name);
68344a3780SDimitry Andric }
69344a3780SDimitry Andric 
GetDemangledFunctionNameWithoutArguments(Mangled mangled) const70c0981da4SDimitry Andric ConstString CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments(
71c0981da4SDimitry Andric     Mangled mangled) const {
72c0981da4SDimitry Andric   const char *mangled_name_cstr = mangled.GetMangledName().GetCString();
73c0981da4SDimitry Andric   ConstString demangled_name = mangled.GetDemangledName();
74c0981da4SDimitry Andric   if (demangled_name && mangled_name_cstr && mangled_name_cstr[0]) {
75c0981da4SDimitry Andric     if (mangled_name_cstr[0] == '_' && mangled_name_cstr[1] == 'Z' &&
76c0981da4SDimitry Andric         (mangled_name_cstr[2] != 'T' && // avoid virtual table, VTT structure,
77c0981da4SDimitry Andric                                         // typeinfo structure, and typeinfo
78c0981da4SDimitry Andric                                         // mangled_name
79c0981da4SDimitry Andric          mangled_name_cstr[2] != 'G' && // avoid guard variables
80c0981da4SDimitry Andric          mangled_name_cstr[2] != 'Z'))  // named local entities (if we
81c0981da4SDimitry Andric                                         // eventually handle eSymbolTypeData,
82c0981da4SDimitry Andric                                         // we will want this back)
83c0981da4SDimitry Andric     {
84c0981da4SDimitry Andric       CPlusPlusLanguage::MethodName cxx_method(demangled_name);
85c0981da4SDimitry Andric       if (!cxx_method.GetBasename().empty()) {
86c0981da4SDimitry Andric         std::string shortname;
87c0981da4SDimitry Andric         if (!cxx_method.GetContext().empty())
88c0981da4SDimitry Andric           shortname = cxx_method.GetContext().str() + "::";
89c0981da4SDimitry Andric         shortname += cxx_method.GetBasename().str();
90c0981da4SDimitry Andric         return ConstString(shortname);
91e81d9d49SDimitry Andric       }
92c0981da4SDimitry Andric     }
93c0981da4SDimitry Andric   }
94c0981da4SDimitry Andric   if (demangled_name)
95c0981da4SDimitry Andric     return demangled_name;
96c0981da4SDimitry Andric   return mangled.GetMangledName();
97c0981da4SDimitry Andric }
98e81d9d49SDimitry Andric 
99e81d9d49SDimitry Andric // Static Functions
100f3fbd1c0SDimitry Andric 
CreateInstance(lldb::LanguageType language)10114f1b3e8SDimitry Andric Language *CPlusPlusLanguage::CreateInstance(lldb::LanguageType language) {
102cfca06d7SDimitry Andric   // Use plugin for C++ but not for Objective-C++ (which has its own plugin).
103cfca06d7SDimitry Andric   if (Language::LanguageIsCPlusPlus(language) &&
104cfca06d7SDimitry Andric       language != eLanguageTypeObjC_plus_plus)
105e81d9d49SDimitry Andric     return new CPlusPlusLanguage();
106e81d9d49SDimitry Andric   return nullptr;
107e81d9d49SDimitry Andric }
108e81d9d49SDimitry Andric 
Clear()10914f1b3e8SDimitry Andric void CPlusPlusLanguage::MethodName::Clear() {
110e81d9d49SDimitry Andric   m_full.Clear();
111e81d9d49SDimitry Andric   m_basename = llvm::StringRef();
112e81d9d49SDimitry Andric   m_context = llvm::StringRef();
113e81d9d49SDimitry Andric   m_arguments = llvm::StringRef();
114e81d9d49SDimitry Andric   m_qualifiers = llvm::StringRef();
115e3b55780SDimitry Andric   m_return_type = llvm::StringRef();
116e81d9d49SDimitry Andric   m_parsed = false;
117e81d9d49SDimitry Andric   m_parse_error = false;
118e81d9d49SDimitry Andric }
119e81d9d49SDimitry Andric 
ReverseFindMatchingChars(const llvm::StringRef & s,const llvm::StringRef & left_right_chars,size_t & left_pos,size_t & right_pos,size_t pos=llvm::StringRef::npos)12074a628f7SDimitry Andric static bool ReverseFindMatchingChars(const llvm::StringRef &s,
121e81d9d49SDimitry Andric                                      const llvm::StringRef &left_right_chars,
12214f1b3e8SDimitry Andric                                      size_t &left_pos, size_t &right_pos,
12314f1b3e8SDimitry Andric                                      size_t pos = llvm::StringRef::npos) {
124e81d9d49SDimitry Andric   assert(left_right_chars.size() == 2);
125e81d9d49SDimitry Andric   left_pos = llvm::StringRef::npos;
126e81d9d49SDimitry Andric   const char left_char = left_right_chars[0];
127e81d9d49SDimitry Andric   const char right_char = left_right_chars[1];
128e81d9d49SDimitry Andric   pos = s.find_last_of(left_right_chars, pos);
129e81d9d49SDimitry Andric   if (pos == llvm::StringRef::npos || s[pos] == left_char)
130e81d9d49SDimitry Andric     return false;
131e81d9d49SDimitry Andric   right_pos = pos;
132e81d9d49SDimitry Andric   uint32_t depth = 1;
13314f1b3e8SDimitry Andric   while (pos > 0 && depth > 0) {
134e81d9d49SDimitry Andric     pos = s.find_last_of(left_right_chars, pos);
135e81d9d49SDimitry Andric     if (pos == llvm::StringRef::npos)
136e81d9d49SDimitry Andric       return false;
13714f1b3e8SDimitry Andric     if (s[pos] == left_char) {
13814f1b3e8SDimitry Andric       if (--depth == 0) {
139e81d9d49SDimitry Andric         left_pos = pos;
140e81d9d49SDimitry Andric         return left_pos < right_pos;
141e81d9d49SDimitry Andric       }
14214f1b3e8SDimitry Andric     } else if (s[pos] == right_char) {
143e81d9d49SDimitry Andric       ++depth;
144e81d9d49SDimitry Andric     }
145e81d9d49SDimitry Andric   }
146e81d9d49SDimitry Andric   return false;
147e81d9d49SDimitry Andric }
148e81d9d49SDimitry Andric 
IsTrivialBasename(const llvm::StringRef & basename)14974a628f7SDimitry Andric static bool IsTrivialBasename(const llvm::StringRef &basename) {
15074a628f7SDimitry Andric   // Check that the basename matches with the following regular expression
151f73363f1SDimitry Andric   // "^~?([A-Za-z_][A-Za-z_0-9]*)$" We are using a hand written implementation
152f73363f1SDimitry Andric   // because it is significantly more efficient then using the general purpose
153f73363f1SDimitry Andric   // regular expression library.
154e81d9d49SDimitry Andric   size_t idx = 0;
155ac9a064cSDimitry Andric   if (basename.starts_with('~'))
156e81d9d49SDimitry Andric     idx = 1;
157e81d9d49SDimitry Andric 
158e81d9d49SDimitry Andric   if (basename.size() <= idx)
159e81d9d49SDimitry Andric     return false; // Empty string or "~"
160e81d9d49SDimitry Andric 
161e81d9d49SDimitry Andric   if (!std::isalpha(basename[idx]) && basename[idx] != '_')
162cfca06d7SDimitry Andric     return false; // First character (after removing the possible '~'') isn't in
16314f1b3e8SDimitry Andric                   // [A-Za-z_]
164e81d9d49SDimitry Andric 
165e81d9d49SDimitry Andric   // Read all characters matching [A-Za-z_0-9]
166e81d9d49SDimitry Andric   ++idx;
16714f1b3e8SDimitry Andric   while (idx < basename.size()) {
168e81d9d49SDimitry Andric     if (!std::isalnum(basename[idx]) && basename[idx] != '_')
169e81d9d49SDimitry Andric       break;
170e81d9d49SDimitry Andric     ++idx;
171e81d9d49SDimitry Andric   }
172e81d9d49SDimitry Andric 
173e81d9d49SDimitry Andric   // We processed all characters. It is a vaild basename.
17494994d37SDimitry Andric   return idx == basename.size();
175e81d9d49SDimitry Andric }
176e81d9d49SDimitry Andric 
177e3b55780SDimitry Andric /// Writes out the function name in 'full_name' to 'out_stream'
178e3b55780SDimitry Andric /// but replaces each argument type with the variable name
179e3b55780SDimitry Andric /// and the corresponding pretty-printed value
PrettyPrintFunctionNameWithArgs(Stream & out_stream,char const * full_name,ExecutionContextScope * exe_scope,VariableList const & args)180e3b55780SDimitry Andric static bool PrettyPrintFunctionNameWithArgs(Stream &out_stream,
181e3b55780SDimitry Andric                                             char const *full_name,
182e3b55780SDimitry Andric                                             ExecutionContextScope *exe_scope,
183e3b55780SDimitry Andric                                             VariableList const &args) {
184e3b55780SDimitry Andric   CPlusPlusLanguage::MethodName cpp_method{ConstString(full_name)};
185e3b55780SDimitry Andric 
186e3b55780SDimitry Andric   if (!cpp_method.IsValid())
187e3b55780SDimitry Andric     return false;
188e3b55780SDimitry Andric 
189e3b55780SDimitry Andric   llvm::StringRef return_type = cpp_method.GetReturnType();
190e3b55780SDimitry Andric   if (!return_type.empty()) {
191e3b55780SDimitry Andric     out_stream.PutCString(return_type);
192e3b55780SDimitry Andric     out_stream.PutChar(' ');
193e3b55780SDimitry Andric   }
194e3b55780SDimitry Andric 
195e3b55780SDimitry Andric   out_stream.PutCString(cpp_method.GetScopeQualifiedName());
196e3b55780SDimitry Andric   out_stream.PutChar('(');
197e3b55780SDimitry Andric 
198e3b55780SDimitry Andric   FormatEntity::PrettyPrintFunctionArguments(out_stream, args, exe_scope);
199e3b55780SDimitry Andric 
200e3b55780SDimitry Andric   out_stream.PutChar(')');
201e3b55780SDimitry Andric 
202e3b55780SDimitry Andric   llvm::StringRef qualifiers = cpp_method.GetQualifiers();
203e3b55780SDimitry Andric   if (!qualifiers.empty()) {
204e3b55780SDimitry Andric     out_stream.PutChar(' ');
205e3b55780SDimitry Andric     out_stream.PutCString(qualifiers);
206e3b55780SDimitry Andric   }
207e3b55780SDimitry Andric 
208e3b55780SDimitry Andric   return true;
209e3b55780SDimitry Andric }
210e3b55780SDimitry Andric 
TrySimplifiedParse()21174a628f7SDimitry Andric bool CPlusPlusLanguage::MethodName::TrySimplifiedParse() {
212f73363f1SDimitry Andric   // This method tries to parse simple method definitions which are presumably
213f73363f1SDimitry Andric   // most comman in user programs. Definitions that can be parsed by this
214f73363f1SDimitry Andric   // function don't have return types and templates in the name.
21574a628f7SDimitry Andric   // A::B::C::fun(std::vector<T> &) const
216e81d9d49SDimitry Andric   size_t arg_start, arg_end;
21774a628f7SDimitry Andric   llvm::StringRef full(m_full.GetCString());
218e81d9d49SDimitry Andric   llvm::StringRef parens("()", 2);
21914f1b3e8SDimitry Andric   if (ReverseFindMatchingChars(full, parens, arg_start, arg_end)) {
220e81d9d49SDimitry Andric     m_arguments = full.substr(arg_start, arg_end - arg_start + 1);
221e81d9d49SDimitry Andric     if (arg_end + 1 < full.size())
22274a628f7SDimitry Andric       m_qualifiers = full.substr(arg_end + 1).ltrim();
22374a628f7SDimitry Andric 
22474a628f7SDimitry Andric     if (arg_start == 0)
22574a628f7SDimitry Andric       return false;
226e81d9d49SDimitry Andric     size_t basename_end = arg_start;
227e81d9d49SDimitry Andric     size_t context_start = 0;
22874a628f7SDimitry Andric     size_t context_end = full.rfind(':', basename_end);
229e81d9d49SDimitry Andric     if (context_end == llvm::StringRef::npos)
230e81d9d49SDimitry Andric       m_basename = full.substr(0, basename_end);
23114f1b3e8SDimitry Andric     else {
232e81d9d49SDimitry Andric       if (context_start < context_end)
23374a628f7SDimitry Andric         m_context = full.substr(context_start, context_end - 1 - context_start);
234e81d9d49SDimitry Andric       const size_t basename_begin = context_end + 1;
23574a628f7SDimitry Andric       m_basename = full.substr(basename_begin, basename_end - basename_begin);
236e81d9d49SDimitry Andric     }
237e81d9d49SDimitry Andric 
23874a628f7SDimitry Andric     if (IsTrivialBasename(m_basename)) {
23974a628f7SDimitry Andric       return true;
24074a628f7SDimitry Andric     } else {
241e81d9d49SDimitry Andric       // The C++ basename doesn't match our regular expressions so this can't
242e81d9d49SDimitry Andric       // be a valid C++ method, clear everything out and indicate an error
243e81d9d49SDimitry Andric       m_context = llvm::StringRef();
244e81d9d49SDimitry Andric       m_basename = llvm::StringRef();
245e81d9d49SDimitry Andric       m_arguments = llvm::StringRef();
246e81d9d49SDimitry Andric       m_qualifiers = llvm::StringRef();
247e3b55780SDimitry Andric       m_return_type = llvm::StringRef();
24874a628f7SDimitry Andric       return false;
249e81d9d49SDimitry Andric     }
25074a628f7SDimitry Andric   }
25174a628f7SDimitry Andric   return false;
25274a628f7SDimitry Andric }
25374a628f7SDimitry Andric 
Parse()25474a628f7SDimitry Andric void CPlusPlusLanguage::MethodName::Parse() {
25574a628f7SDimitry Andric   if (!m_parsed && m_full) {
25674a628f7SDimitry Andric     if (TrySimplifiedParse()) {
25774a628f7SDimitry Andric       m_parse_error = false;
25874a628f7SDimitry Andric     } else {
25974a628f7SDimitry Andric       CPlusPlusNameParser parser(m_full.GetStringRef());
26074a628f7SDimitry Andric       if (auto function = parser.ParseAsFunctionDefinition()) {
261e3b55780SDimitry Andric         m_basename = function->name.basename;
262e3b55780SDimitry Andric         m_context = function->name.context;
263e3b55780SDimitry Andric         m_arguments = function->arguments;
264e3b55780SDimitry Andric         m_qualifiers = function->qualifiers;
265e3b55780SDimitry Andric         m_return_type = function->return_type;
26674a628f7SDimitry Andric         m_parse_error = false;
26714f1b3e8SDimitry Andric       } else {
268e81d9d49SDimitry Andric         m_parse_error = true;
269e81d9d49SDimitry Andric       }
270e81d9d49SDimitry Andric     }
27174a628f7SDimitry Andric     m_parsed = true;
27274a628f7SDimitry Andric   }
273e81d9d49SDimitry Andric }
274e81d9d49SDimitry Andric 
GetBasename()27514f1b3e8SDimitry Andric llvm::StringRef CPlusPlusLanguage::MethodName::GetBasename() {
276e81d9d49SDimitry Andric   if (!m_parsed)
277e81d9d49SDimitry Andric     Parse();
278e81d9d49SDimitry Andric   return m_basename;
279e81d9d49SDimitry Andric }
280e81d9d49SDimitry Andric 
GetContext()28114f1b3e8SDimitry Andric llvm::StringRef CPlusPlusLanguage::MethodName::GetContext() {
282e81d9d49SDimitry Andric   if (!m_parsed)
283e81d9d49SDimitry Andric     Parse();
284e81d9d49SDimitry Andric   return m_context;
285e81d9d49SDimitry Andric }
286e81d9d49SDimitry Andric 
GetArguments()28714f1b3e8SDimitry Andric llvm::StringRef CPlusPlusLanguage::MethodName::GetArguments() {
288e81d9d49SDimitry Andric   if (!m_parsed)
289e81d9d49SDimitry Andric     Parse();
290e81d9d49SDimitry Andric   return m_arguments;
291e81d9d49SDimitry Andric }
292e81d9d49SDimitry Andric 
GetQualifiers()29314f1b3e8SDimitry Andric llvm::StringRef CPlusPlusLanguage::MethodName::GetQualifiers() {
294e81d9d49SDimitry Andric   if (!m_parsed)
295e81d9d49SDimitry Andric     Parse();
296e81d9d49SDimitry Andric   return m_qualifiers;
297e81d9d49SDimitry Andric }
298e81d9d49SDimitry Andric 
GetReturnType()299e3b55780SDimitry Andric llvm::StringRef CPlusPlusLanguage::MethodName::GetReturnType() {
300e3b55780SDimitry Andric   if (!m_parsed)
301e3b55780SDimitry Andric     Parse();
302e3b55780SDimitry Andric   return m_return_type;
303e3b55780SDimitry Andric }
304e3b55780SDimitry Andric 
GetScopeQualifiedName()30514f1b3e8SDimitry Andric std::string CPlusPlusLanguage::MethodName::GetScopeQualifiedName() {
3067fed546dSDimitry Andric   if (!m_parsed)
3077fed546dSDimitry Andric     Parse();
30874a628f7SDimitry Andric   if (m_context.empty())
309cfca06d7SDimitry Andric     return std::string(m_basename);
3107fed546dSDimitry Andric 
3117fed546dSDimitry Andric   std::string res;
3127fed546dSDimitry Andric   res += m_context;
3137fed546dSDimitry Andric   res += "::";
3147fed546dSDimitry Andric   res += m_basename;
3157fed546dSDimitry Andric   return res;
3167fed546dSDimitry Andric }
3177fed546dSDimitry Andric 
318e3b55780SDimitry Andric llvm::StringRef
GetBasenameNoTemplateParameters()319e3b55780SDimitry Andric CPlusPlusLanguage::MethodName::GetBasenameNoTemplateParameters() {
320e3b55780SDimitry Andric   llvm::StringRef basename = GetBasename();
321e3b55780SDimitry Andric   size_t arg_start, arg_end;
322e3b55780SDimitry Andric   llvm::StringRef parens("<>", 2);
323e3b55780SDimitry Andric   if (ReverseFindMatchingChars(basename, parens, arg_start, arg_end))
324e3b55780SDimitry Andric     return basename.substr(0, arg_start);
325e3b55780SDimitry Andric 
326e3b55780SDimitry Andric   return basename;
327e3b55780SDimitry Andric }
328e3b55780SDimitry Andric 
ContainsPath(llvm::StringRef path)329145449b1SDimitry Andric bool CPlusPlusLanguage::MethodName::ContainsPath(llvm::StringRef path) {
330145449b1SDimitry Andric   if (!m_parsed)
331145449b1SDimitry Andric     Parse();
332e3b55780SDimitry Andric 
333145449b1SDimitry Andric   // If we can't parse the incoming name, then just check that it contains path.
334145449b1SDimitry Andric   if (m_parse_error)
335145449b1SDimitry Andric     return m_full.GetStringRef().contains(path);
336145449b1SDimitry Andric 
337145449b1SDimitry Andric   llvm::StringRef identifier;
338145449b1SDimitry Andric   llvm::StringRef context;
339145449b1SDimitry Andric   std::string path_str = path.str();
340b1c73532SDimitry Andric   bool success = CPlusPlusLanguage::ExtractContextAndIdentifier(
341b1c73532SDimitry Andric       path_str.c_str(), context, identifier);
342145449b1SDimitry Andric   if (!success)
343145449b1SDimitry Andric     return m_full.GetStringRef().contains(path);
344145449b1SDimitry Andric 
345e3b55780SDimitry Andric   // Basename may include template arguments.
346e3b55780SDimitry Andric   // E.g.,
347e3b55780SDimitry Andric   // GetBaseName(): func<int>
348e3b55780SDimitry Andric   // identifier   : func
349e3b55780SDimitry Andric   //
350e3b55780SDimitry Andric   // ...but we still want to account for identifiers with template parameter
351e3b55780SDimitry Andric   // lists, e.g., when users set breakpoints on template specializations.
352e3b55780SDimitry Andric   //
353e3b55780SDimitry Andric   // E.g.,
354e3b55780SDimitry Andric   // GetBaseName(): func<uint32_t>
355e3b55780SDimitry Andric   // identifier   : func<int32_t*>
356e3b55780SDimitry Andric   //
357e3b55780SDimitry Andric   // Try to match the basename with or without template parameters.
358e3b55780SDimitry Andric   if (GetBasename() != identifier &&
359e3b55780SDimitry Andric       GetBasenameNoTemplateParameters() != identifier)
360145449b1SDimitry Andric     return false;
361e3b55780SDimitry Andric 
362145449b1SDimitry Andric   // Incoming path only had an identifier, so we match.
363145449b1SDimitry Andric   if (context.empty())
364145449b1SDimitry Andric     return true;
365145449b1SDimitry Andric   // Incoming path has context but this method does not, no match.
366145449b1SDimitry Andric   if (m_context.empty())
367145449b1SDimitry Andric     return false;
368145449b1SDimitry Andric 
369145449b1SDimitry Andric   llvm::StringRef haystack = m_context;
370145449b1SDimitry Andric   if (!haystack.consume_back(context))
371145449b1SDimitry Andric     return false;
372145449b1SDimitry Andric   if (haystack.empty() || !isalnum(haystack.back()))
373145449b1SDimitry Andric     return true;
374145449b1SDimitry Andric 
375145449b1SDimitry Andric   return false;
376145449b1SDimitry Andric }
377145449b1SDimitry Andric 
IsCPPMangledName(llvm::StringRef name)378706b4fc4SDimitry Andric bool CPlusPlusLanguage::IsCPPMangledName(llvm::StringRef name) {
379f73363f1SDimitry Andric   // FIXME!! we should really run through all the known C++ Language plugins
380f73363f1SDimitry Andric   // and ask each one if this is a C++ mangled name
381e81d9d49SDimitry Andric 
382706b4fc4SDimitry Andric   Mangled::ManglingScheme scheme = Mangled::GetManglingScheme(name);
383706b4fc4SDimitry Andric 
384706b4fc4SDimitry Andric   if (scheme == Mangled::eManglingSchemeNone)
385f73363f1SDimitry Andric     return false;
386f73363f1SDimitry Andric 
387f73363f1SDimitry Andric   return true;
388e81d9d49SDimitry Andric }
389e81d9d49SDimitry Andric 
DemangledNameContainsPath(llvm::StringRef path,ConstString demangled) const390145449b1SDimitry Andric bool CPlusPlusLanguage::DemangledNameContainsPath(llvm::StringRef path,
391145449b1SDimitry Andric                                                   ConstString demangled) const {
392145449b1SDimitry Andric   MethodName demangled_name(demangled);
393145449b1SDimitry Andric   return demangled_name.ContainsPath(path);
394145449b1SDimitry Andric }
395145449b1SDimitry Andric 
ExtractContextAndIdentifier(const char * name,llvm::StringRef & context,llvm::StringRef & identifier)39614f1b3e8SDimitry Andric bool CPlusPlusLanguage::ExtractContextAndIdentifier(
39714f1b3e8SDimitry Andric     const char *name, llvm::StringRef &context, llvm::StringRef &identifier) {
39894994d37SDimitry Andric   if (MSVCUndecoratedNameParser::IsMSVCUndecoratedName(name))
39994994d37SDimitry Andric     return MSVCUndecoratedNameParser::ExtractContextAndIdentifier(name, context,
40094994d37SDimitry Andric                                                                   identifier);
40194994d37SDimitry Andric 
40274a628f7SDimitry Andric   CPlusPlusNameParser parser(name);
40374a628f7SDimitry Andric   if (auto full_name = parser.ParseAsFullName()) {
404e3b55780SDimitry Andric     identifier = full_name->basename;
405e3b55780SDimitry Andric     context = full_name->context;
406e81d9d49SDimitry Andric     return true;
407e81d9d49SDimitry Andric   }
408e81d9d49SDimitry Andric   return false;
409e81d9d49SDimitry Andric }
410e81d9d49SDimitry Andric 
41194994d37SDimitry Andric namespace {
41294994d37SDimitry Andric class NodeAllocator {
41394994d37SDimitry Andric   llvm::BumpPtrAllocator Alloc;
41414f1b3e8SDimitry Andric 
41594994d37SDimitry Andric public:
reset()41694994d37SDimitry Andric   void reset() { Alloc.Reset(); }
41714f1b3e8SDimitry Andric 
makeNode(Args &&...args)41894994d37SDimitry Andric   template <typename T, typename... Args> T *makeNode(Args &&... args) {
41994994d37SDimitry Andric     return new (Alloc.Allocate(sizeof(T), alignof(T)))
42094994d37SDimitry Andric         T(std::forward<Args>(args)...);
42194994d37SDimitry Andric   }
42214f1b3e8SDimitry Andric 
allocateNodeArray(size_t sz)42394994d37SDimitry Andric   void *allocateNodeArray(size_t sz) {
42494994d37SDimitry Andric     return Alloc.Allocate(sizeof(llvm::itanium_demangle::Node *) * sz,
42594994d37SDimitry Andric                           alignof(llvm::itanium_demangle::Node *));
42614f1b3e8SDimitry Andric   }
42714f1b3e8SDimitry Andric };
42814f1b3e8SDimitry Andric 
429706b4fc4SDimitry Andric template <typename Derived>
430706b4fc4SDimitry Andric class ManglingSubstitutor
431706b4fc4SDimitry Andric     : public llvm::itanium_demangle::AbstractManglingParser<Derived,
43294994d37SDimitry Andric                                                             NodeAllocator> {
433706b4fc4SDimitry Andric   using Base =
434706b4fc4SDimitry Andric       llvm::itanium_demangle::AbstractManglingParser<Derived, NodeAllocator>;
43514f1b3e8SDimitry Andric 
436706b4fc4SDimitry Andric public:
ManglingSubstitutor()437706b4fc4SDimitry Andric   ManglingSubstitutor() : Base(nullptr, nullptr) {}
43814f1b3e8SDimitry Andric 
439706b4fc4SDimitry Andric   template <typename... Ts>
substitute(llvm::StringRef Mangled,Ts &&...Vals)440706b4fc4SDimitry Andric   ConstString substitute(llvm::StringRef Mangled, Ts &&... Vals) {
441706b4fc4SDimitry Andric     this->getDerived().reset(Mangled, std::forward<Ts>(Vals)...);
442706b4fc4SDimitry Andric     return substituteImpl(Mangled);
443706b4fc4SDimitry Andric   }
44494994d37SDimitry Andric 
445706b4fc4SDimitry Andric protected:
reset(llvm::StringRef Mangled)446706b4fc4SDimitry Andric   void reset(llvm::StringRef Mangled) {
447706b4fc4SDimitry Andric     Base::reset(Mangled.begin(), Mangled.end());
44894994d37SDimitry Andric     Written = Mangled.begin();
44994994d37SDimitry Andric     Result.clear();
45094994d37SDimitry Andric     Substituted = false;
45194994d37SDimitry Andric   }
45294994d37SDimitry Andric 
substituteImpl(llvm::StringRef Mangled)453706b4fc4SDimitry Andric   ConstString substituteImpl(llvm::StringRef Mangled) {
454145449b1SDimitry Andric     Log *log = GetLog(LLDBLog::Language);
455706b4fc4SDimitry Andric     if (this->parse() == nullptr) {
45694994d37SDimitry Andric       LLDB_LOG(log, "Failed to substitute mangling in {0}", Mangled);
45794994d37SDimitry Andric       return ConstString();
45894994d37SDimitry Andric     }
45994994d37SDimitry Andric     if (!Substituted)
46094994d37SDimitry Andric       return ConstString();
46194994d37SDimitry Andric 
46294994d37SDimitry Andric     // Append any trailing unmodified input.
46394994d37SDimitry Andric     appendUnchangedInput();
46494994d37SDimitry Andric     LLDB_LOG(log, "Substituted mangling {0} -> {1}", Mangled, Result);
46594994d37SDimitry Andric     return ConstString(Result);
46694994d37SDimitry Andric   }
46794994d37SDimitry Andric 
trySubstitute(llvm::StringRef From,llvm::StringRef To)468706b4fc4SDimitry Andric   void trySubstitute(llvm::StringRef From, llvm::StringRef To) {
469312c0ed1SDimitry Andric     if (!llvm::StringRef(currentParserPos(), this->numLeft()).starts_with(From))
470706b4fc4SDimitry Andric       return;
471706b4fc4SDimitry Andric 
47294994d37SDimitry Andric     // We found a match. Append unmodified input up to this point.
47394994d37SDimitry Andric     appendUnchangedInput();
47494994d37SDimitry Andric 
47594994d37SDimitry Andric     // And then perform the replacement.
476706b4fc4SDimitry Andric     Result += To;
477706b4fc4SDimitry Andric     Written += From.size();
47894994d37SDimitry Andric     Substituted = true;
47994994d37SDimitry Andric   }
480706b4fc4SDimitry Andric 
481706b4fc4SDimitry Andric private:
482706b4fc4SDimitry Andric   /// Input character until which we have constructed the respective output
483706b4fc4SDimitry Andric   /// already.
4844b4fe385SDimitry Andric   const char *Written = "";
485706b4fc4SDimitry Andric 
486706b4fc4SDimitry Andric   llvm::SmallString<128> Result;
487706b4fc4SDimitry Andric 
488706b4fc4SDimitry Andric   /// Whether we have performed any substitutions.
4894b4fe385SDimitry Andric   bool Substituted = false;
490706b4fc4SDimitry Andric 
currentParserPos() const491706b4fc4SDimitry Andric   const char *currentParserPos() const { return this->First; }
492706b4fc4SDimitry Andric 
appendUnchangedInput()493706b4fc4SDimitry Andric   void appendUnchangedInput() {
494706b4fc4SDimitry Andric     Result +=
495706b4fc4SDimitry Andric         llvm::StringRef(Written, std::distance(Written, currentParserPos()));
496706b4fc4SDimitry Andric     Written = currentParserPos();
497706b4fc4SDimitry Andric   }
498706b4fc4SDimitry Andric };
499706b4fc4SDimitry Andric 
500706b4fc4SDimitry Andric /// Given a mangled function `Mangled`, replace all the primitive function type
501706b4fc4SDimitry Andric /// arguments of `Search` with type `Replace`.
502706b4fc4SDimitry Andric class TypeSubstitutor : public ManglingSubstitutor<TypeSubstitutor> {
503706b4fc4SDimitry Andric   llvm::StringRef Search;
504706b4fc4SDimitry Andric   llvm::StringRef Replace;
505706b4fc4SDimitry Andric 
506706b4fc4SDimitry Andric public:
reset(llvm::StringRef Mangled,llvm::StringRef Search,llvm::StringRef Replace)507706b4fc4SDimitry Andric   void reset(llvm::StringRef Mangled, llvm::StringRef Search,
508706b4fc4SDimitry Andric              llvm::StringRef Replace) {
509706b4fc4SDimitry Andric     ManglingSubstitutor::reset(Mangled);
510706b4fc4SDimitry Andric     this->Search = Search;
511706b4fc4SDimitry Andric     this->Replace = Replace;
512706b4fc4SDimitry Andric   }
513706b4fc4SDimitry Andric 
parseType()514706b4fc4SDimitry Andric   llvm::itanium_demangle::Node *parseType() {
515706b4fc4SDimitry Andric     trySubstitute(Search, Replace);
516706b4fc4SDimitry Andric     return ManglingSubstitutor::parseType();
51794994d37SDimitry Andric   }
51894994d37SDimitry Andric };
519706b4fc4SDimitry Andric 
520706b4fc4SDimitry Andric class CtorDtorSubstitutor : public ManglingSubstitutor<CtorDtorSubstitutor> {
521706b4fc4SDimitry Andric public:
522706b4fc4SDimitry Andric   llvm::itanium_demangle::Node *
parseCtorDtorName(llvm::itanium_demangle::Node * & SoFar,NameState * State)523706b4fc4SDimitry Andric   parseCtorDtorName(llvm::itanium_demangle::Node *&SoFar, NameState *State) {
524706b4fc4SDimitry Andric     trySubstitute("C1", "C2");
525706b4fc4SDimitry Andric     trySubstitute("D1", "D2");
526706b4fc4SDimitry Andric     return ManglingSubstitutor::parseCtorDtorName(SoFar, State);
52714f1b3e8SDimitry Andric   }
528706b4fc4SDimitry Andric };
529706b4fc4SDimitry Andric } // namespace
53014f1b3e8SDimitry Andric 
GenerateAlternateFunctionManglings(const ConstString mangled_name) const531c0981da4SDimitry Andric std::vector<ConstString> CPlusPlusLanguage::GenerateAlternateFunctionManglings(
532c0981da4SDimitry Andric     const ConstString mangled_name) const {
533c0981da4SDimitry Andric   std::vector<ConstString> alternates;
534c0981da4SDimitry Andric 
53514f1b3e8SDimitry Andric   /// Get a basic set of alternative manglings for the given symbol `name`, by
53614f1b3e8SDimitry Andric   /// making a few basic possible substitutions on basic types, storage duration
53714f1b3e8SDimitry Andric   /// and `const`ness for the given symbol. The output parameter `alternates`
53814f1b3e8SDimitry Andric   /// is filled with a best-guess, non-exhaustive set of different manglings
53914f1b3e8SDimitry Andric   /// for the given name.
54014f1b3e8SDimitry Andric 
54114f1b3e8SDimitry Andric   // Maybe we're looking for a const symbol but the debug info told us it was
54214f1b3e8SDimitry Andric   // non-const...
54314f1b3e8SDimitry Andric   if (!strncmp(mangled_name.GetCString(), "_ZN", 3) &&
54414f1b3e8SDimitry Andric       strncmp(mangled_name.GetCString(), "_ZNK", 4)) {
54514f1b3e8SDimitry Andric     std::string fixed_scratch("_ZNK");
54614f1b3e8SDimitry Andric     fixed_scratch.append(mangled_name.GetCString() + 3);
547c0981da4SDimitry Andric     alternates.push_back(ConstString(fixed_scratch));
54814f1b3e8SDimitry Andric   }
54914f1b3e8SDimitry Andric 
55014f1b3e8SDimitry Andric   // Maybe we're looking for a static symbol but we thought it was global...
55114f1b3e8SDimitry Andric   if (!strncmp(mangled_name.GetCString(), "_Z", 2) &&
55214f1b3e8SDimitry Andric       strncmp(mangled_name.GetCString(), "_ZL", 3)) {
55314f1b3e8SDimitry Andric     std::string fixed_scratch("_ZL");
55414f1b3e8SDimitry Andric     fixed_scratch.append(mangled_name.GetCString() + 2);
555c0981da4SDimitry Andric     alternates.push_back(ConstString(fixed_scratch));
55614f1b3e8SDimitry Andric   }
55714f1b3e8SDimitry Andric 
55894994d37SDimitry Andric   TypeSubstitutor TS;
55914f1b3e8SDimitry Andric   // `char` is implementation defined as either `signed` or `unsigned`.  As a
56014f1b3e8SDimitry Andric   // result a char parameter has 3 possible manglings: 'c'-char, 'a'-signed
56114f1b3e8SDimitry Andric   // char, 'h'-unsigned char.  If we're looking for symbols with a signed char
56214f1b3e8SDimitry Andric   // parameter, try finding matches which have the general case 'c'.
56314f1b3e8SDimitry Andric   if (ConstString char_fixup =
56494994d37SDimitry Andric           TS.substitute(mangled_name.GetStringRef(), "a", "c"))
565c0981da4SDimitry Andric     alternates.push_back(char_fixup);
56614f1b3e8SDimitry Andric 
56714f1b3e8SDimitry Andric   // long long parameter mangling 'x', may actually just be a long 'l' argument
56814f1b3e8SDimitry Andric   if (ConstString long_fixup =
56994994d37SDimitry Andric           TS.substitute(mangled_name.GetStringRef(), "x", "l"))
570c0981da4SDimitry Andric     alternates.push_back(long_fixup);
57114f1b3e8SDimitry Andric 
57214f1b3e8SDimitry Andric   // unsigned long long parameter mangling 'y', may actually just be unsigned
57314f1b3e8SDimitry Andric   // long 'm' argument
57414f1b3e8SDimitry Andric   if (ConstString ulong_fixup =
57594994d37SDimitry Andric           TS.substitute(mangled_name.GetStringRef(), "y", "m"))
576c0981da4SDimitry Andric     alternates.push_back(ulong_fixup);
57714f1b3e8SDimitry Andric 
578706b4fc4SDimitry Andric   if (ConstString ctor_fixup =
579706b4fc4SDimitry Andric           CtorDtorSubstitutor().substitute(mangled_name.GetStringRef()))
580c0981da4SDimitry Andric     alternates.push_back(ctor_fixup);
581706b4fc4SDimitry Andric 
582c0981da4SDimitry Andric   return alternates;
583c0981da4SDimitry Andric }
584c0981da4SDimitry Andric 
FindBestAlternateFunctionMangledName(const Mangled mangled,const SymbolContext & sym_ctx) const585c0981da4SDimitry Andric ConstString CPlusPlusLanguage::FindBestAlternateFunctionMangledName(
586c0981da4SDimitry Andric     const Mangled mangled, const SymbolContext &sym_ctx) const {
587c0981da4SDimitry Andric   ConstString demangled = mangled.GetDemangledName();
588c0981da4SDimitry Andric   if (!demangled)
589c0981da4SDimitry Andric     return ConstString();
590c0981da4SDimitry Andric 
591c0981da4SDimitry Andric   CPlusPlusLanguage::MethodName cpp_name(demangled);
592c0981da4SDimitry Andric   std::string scope_qualified_name = cpp_name.GetScopeQualifiedName();
593c0981da4SDimitry Andric 
594c0981da4SDimitry Andric   if (!scope_qualified_name.size())
595c0981da4SDimitry Andric     return ConstString();
596c0981da4SDimitry Andric 
597c0981da4SDimitry Andric   if (!sym_ctx.module_sp)
598c0981da4SDimitry Andric     return ConstString();
599c0981da4SDimitry Andric 
600c0981da4SDimitry Andric   lldb_private::SymbolFile *sym_file = sym_ctx.module_sp->GetSymbolFile();
601c0981da4SDimitry Andric   if (!sym_file)
602c0981da4SDimitry Andric     return ConstString();
603c0981da4SDimitry Andric 
604c0981da4SDimitry Andric   std::vector<ConstString> alternates;
605c0981da4SDimitry Andric   sym_file->GetMangledNamesForFunction(scope_qualified_name, alternates);
606c0981da4SDimitry Andric 
607c0981da4SDimitry Andric   std::vector<ConstString> param_and_qual_matches;
608c0981da4SDimitry Andric   std::vector<ConstString> param_matches;
609c0981da4SDimitry Andric   for (size_t i = 0; i < alternates.size(); i++) {
610c0981da4SDimitry Andric     ConstString alternate_mangled_name = alternates[i];
611c0981da4SDimitry Andric     Mangled mangled(alternate_mangled_name);
612c0981da4SDimitry Andric     ConstString demangled = mangled.GetDemangledName();
613c0981da4SDimitry Andric 
614c0981da4SDimitry Andric     CPlusPlusLanguage::MethodName alternate_cpp_name(demangled);
615c0981da4SDimitry Andric     if (!cpp_name.IsValid())
616c0981da4SDimitry Andric       continue;
617c0981da4SDimitry Andric 
618c0981da4SDimitry Andric     if (alternate_cpp_name.GetArguments() == cpp_name.GetArguments()) {
619c0981da4SDimitry Andric       if (alternate_cpp_name.GetQualifiers() == cpp_name.GetQualifiers())
620c0981da4SDimitry Andric         param_and_qual_matches.push_back(alternate_mangled_name);
621c0981da4SDimitry Andric       else
622c0981da4SDimitry Andric         param_matches.push_back(alternate_mangled_name);
623c0981da4SDimitry Andric     }
624c0981da4SDimitry Andric   }
625c0981da4SDimitry Andric 
626c0981da4SDimitry Andric   if (param_and_qual_matches.size())
627c0981da4SDimitry Andric     return param_and_qual_matches[0]; // It is assumed that there will be only
628c0981da4SDimitry Andric                                       // one!
629c0981da4SDimitry Andric   else if (param_matches.size())
630c0981da4SDimitry Andric     return param_matches[0]; // Return one of them as a best match
631c0981da4SDimitry Andric   else
632c0981da4SDimitry Andric     return ConstString();
63314f1b3e8SDimitry Andric }
63414f1b3e8SDimitry Andric 
LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp)63514f1b3e8SDimitry Andric static void LoadLibCxxFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
636e81d9d49SDimitry Andric   if (!cpp_category_sp)
637e81d9d49SDimitry Andric     return;
638e81d9d49SDimitry Andric 
639e81d9d49SDimitry Andric   TypeSummaryImpl::Flags stl_summary_flags;
640e81d9d49SDimitry Andric   stl_summary_flags.SetCascades(true)
641e81d9d49SDimitry Andric       .SetSkipPointers(false)
642e81d9d49SDimitry Andric       .SetSkipReferences(false)
643e81d9d49SDimitry Andric       .SetDontShowChildren(true)
644e81d9d49SDimitry Andric       .SetDontShowValue(true)
645e81d9d49SDimitry Andric       .SetShowMembersOneLiner(false)
646e81d9d49SDimitry Andric       .SetHideItemNames(false);
647e81d9d49SDimitry Andric 
6485f29bb8aSDimitry Andric   AddCXXSummary(cpp_category_sp,
64994994d37SDimitry Andric                 lldb_private::formatters::LibcxxStringSummaryProviderASCII,
6507fa27ce4SDimitry Andric                 "std::string summary provider", "^std::__[[:alnum:]]+::string$",
6515f29bb8aSDimitry Andric                 stl_summary_flags, true);
652706b4fc4SDimitry Andric   AddCXXSummary(cpp_category_sp,
653706b4fc4SDimitry Andric                 lldb_private::formatters::LibcxxStringSummaryProviderASCII,
654706b4fc4SDimitry Andric                 "std::string summary provider",
6557fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string<char, "
6567fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<char>, "
6577fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::allocator<char> >$",
6587fa27ce4SDimitry Andric                 stl_summary_flags, true);
6597fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
6607fa27ce4SDimitry Andric                 lldb_private::formatters::LibcxxStringSummaryProviderASCII,
6617fa27ce4SDimitry Andric                 "std::string summary provider",
6627fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string<unsigned char, "
663706b4fc4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<unsigned char>, "
6647fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::allocator<unsigned char> >$",
665706b4fc4SDimitry Andric                 stl_summary_flags, true);
6665f29bb8aSDimitry Andric 
6675f29bb8aSDimitry Andric   AddCXXSummary(cpp_category_sp,
66894994d37SDimitry Andric                 lldb_private::formatters::LibcxxStringSummaryProviderUTF16,
6695f29bb8aSDimitry Andric                 "std::u16string summary provider",
6707fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string<char16_t, "
6715f29bb8aSDimitry Andric                 "std::__[[:alnum:]]+::char_traits<char16_t>, "
6727fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::allocator<char16_t> >$",
6735f29bb8aSDimitry Andric                 stl_summary_flags, true);
6745f29bb8aSDimitry Andric 
6755f29bb8aSDimitry Andric   AddCXXSummary(cpp_category_sp,
67694994d37SDimitry Andric                 lldb_private::formatters::LibcxxStringSummaryProviderUTF32,
6775f29bb8aSDimitry Andric                 "std::u32string summary provider",
6787fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string<char32_t, "
6795f29bb8aSDimitry Andric                 "std::__[[:alnum:]]+::char_traits<char32_t>, "
6807fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::allocator<char32_t> >$",
6815f29bb8aSDimitry Andric                 stl_summary_flags, true);
682e81d9d49SDimitry Andric 
6835f29bb8aSDimitry Andric   AddCXXSummary(cpp_category_sp,
6845f29bb8aSDimitry Andric                 lldb_private::formatters::LibcxxWStringSummaryProvider,
6855f29bb8aSDimitry Andric                 "std::wstring summary provider",
6867fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::wstring$", stl_summary_flags, true);
6877fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
6887fa27ce4SDimitry Andric                 lldb_private::formatters::LibcxxWStringSummaryProvider,
6897fa27ce4SDimitry Andric                 "std::wstring summary provider",
6907fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string<wchar_t, "
6915f29bb8aSDimitry Andric                 "std::__[[:alnum:]]+::char_traits<wchar_t>, "
6927fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::allocator<wchar_t> >$",
6935f29bb8aSDimitry Andric                 stl_summary_flags, true);
694e81d9d49SDimitry Andric 
6956f8fc217SDimitry Andric   AddCXXSummary(cpp_category_sp,
6966f8fc217SDimitry Andric                 lldb_private::formatters::LibcxxStringViewSummaryProviderASCII,
6976f8fc217SDimitry Andric                 "std::string_view summary provider",
6987fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::string_view$", stl_summary_flags, true);
6997fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
7007fa27ce4SDimitry Andric                 lldb_private::formatters::LibcxxStringViewSummaryProviderASCII,
7017fa27ce4SDimitry Andric                 "std::string_view summary provider",
7027fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string_view<char, "
7037fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<char> >$",
7046f8fc217SDimitry Andric                 stl_summary_flags, true);
7056f8fc217SDimitry Andric   AddCXXSummary(cpp_category_sp,
7066f8fc217SDimitry Andric                 lldb_private::formatters::LibcxxStringViewSummaryProviderASCII,
7076f8fc217SDimitry Andric                 "std::string_view summary provider",
7087fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string_view<unsigned char, "
7097fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<unsigned char> >$",
7106f8fc217SDimitry Andric                 stl_summary_flags, true);
7116f8fc217SDimitry Andric 
7126f8fc217SDimitry Andric   AddCXXSummary(cpp_category_sp,
7136f8fc217SDimitry Andric                 lldb_private::formatters::LibcxxStringViewSummaryProviderUTF16,
7146f8fc217SDimitry Andric                 "std::u16string_view summary provider",
7157fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string_view<char16_t, "
7167fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<char16_t> >$",
7176f8fc217SDimitry Andric                 stl_summary_flags, true);
7186f8fc217SDimitry Andric 
7196f8fc217SDimitry Andric   AddCXXSummary(cpp_category_sp,
7206f8fc217SDimitry Andric                 lldb_private::formatters::LibcxxStringViewSummaryProviderUTF32,
7216f8fc217SDimitry Andric                 "std::u32string_view summary provider",
7227fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string_view<char32_t, "
7237fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<char32_t> >$",
7246f8fc217SDimitry Andric                 stl_summary_flags, true);
7256f8fc217SDimitry Andric 
7266f8fc217SDimitry Andric   AddCXXSummary(cpp_category_sp,
7276f8fc217SDimitry Andric                 lldb_private::formatters::LibcxxWStringViewSummaryProvider,
7286f8fc217SDimitry Andric                 "std::wstring_view summary provider",
7297fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::wstring_view$", stl_summary_flags, true);
7306f8fc217SDimitry Andric   AddCXXSummary(cpp_category_sp,
7316f8fc217SDimitry Andric                 lldb_private::formatters::LibcxxWStringViewSummaryProvider,
7326f8fc217SDimitry Andric                 "std::wstring_view summary provider",
7337fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::basic_string_view<wchar_t, "
7347fa27ce4SDimitry Andric                 "std::__[[:alnum:]]+::char_traits<wchar_t> >$",
7356f8fc217SDimitry Andric                 stl_summary_flags, true);
7366f8fc217SDimitry Andric 
737e81d9d49SDimitry Andric   SyntheticChildren::Flags stl_synth_flags;
73814f1b3e8SDimitry Andric   stl_synth_flags.SetCascades(true).SetSkipPointers(false).SetSkipReferences(
73914f1b3e8SDimitry Andric       false);
740f73363f1SDimitry Andric   SyntheticChildren::Flags stl_deref_flags = stl_synth_flags;
741f73363f1SDimitry Andric   stl_deref_flags.SetFrontEndWantsDereference();
742e81d9d49SDimitry Andric 
74314f1b3e8SDimitry Andric   AddCXXSynthetic(
74414f1b3e8SDimitry Andric       cpp_category_sp,
745ef5d0b5eSDimitry Andric       lldb_private::formatters::LibcxxBitsetSyntheticFrontEndCreator,
746ef5d0b5eSDimitry Andric       "libc++ std::bitset synthetic children",
747ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::bitset<.+>$", stl_deref_flags, true);
748ef5d0b5eSDimitry Andric   AddCXXSynthetic(
749ef5d0b5eSDimitry Andric       cpp_category_sp,
75014f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdVectorSyntheticFrontEndCreator,
75114f1b3e8SDimitry Andric       "libc++ std::vector synthetic children",
752ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::vector<.+>$", stl_deref_flags, true);
753ac9a064cSDimitry Andric   AddCXXSynthetic(
754ac9a064cSDimitry Andric       cpp_category_sp,
755ac9a064cSDimitry Andric       lldb_private::formatters::LibcxxStdValarraySyntheticFrontEndCreator,
756ac9a064cSDimitry Andric       "libc++ std::valarray synthetic children",
757ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::valarray<.+>$", stl_deref_flags, true);
758ac9a064cSDimitry Andric   AddCXXSynthetic(
759ac9a064cSDimitry Andric       cpp_category_sp,
760ac9a064cSDimitry Andric       lldb_private::formatters::LibcxxStdSliceArraySyntheticFrontEndCreator,
761ac9a064cSDimitry Andric       "libc++ std::slice_array synthetic children",
762ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::slice_array<.+>$", stl_deref_flags, true);
763ac9a064cSDimitry Andric   AddCXXSynthetic(
764ac9a064cSDimitry Andric       cpp_category_sp,
765ac9a064cSDimitry Andric       lldb_private::formatters::LibcxxStdProxyArraySyntheticFrontEndCreator,
766ac9a064cSDimitry Andric       "libc++ synthetic children for the valarray proxy arrays",
767ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::(gslice|mask|indirect)_array<.+>$",
768ac9a064cSDimitry Andric       stl_deref_flags, true);
76914f1b3e8SDimitry Andric   AddCXXSynthetic(
77014f1b3e8SDimitry Andric       cpp_category_sp,
771ef5d0b5eSDimitry Andric       lldb_private::formatters::LibcxxStdForwardListSyntheticFrontEndCreator,
772ef5d0b5eSDimitry Andric       "libc++ std::forward_list synthetic children",
773ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::forward_list<.+>$", stl_synth_flags, true);
774ef5d0b5eSDimitry Andric   AddCXXSynthetic(
775ef5d0b5eSDimitry Andric       cpp_category_sp,
77614f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdListSyntheticFrontEndCreator,
77714f1b3e8SDimitry Andric       "libc++ std::list synthetic children",
778ac9a064cSDimitry Andric       // A POSIX variant of: "^std::__(?!cxx11:)[[:alnum:]]+::list<.+>$"
779ac9a064cSDimitry Andric       // so that it does not clash with: "^std::(__cxx11::)?list<.+>$"
7807fa27ce4SDimitry Andric       "^std::__([A-Zabd-z0-9]|cx?[A-Za-wyz0-9]|cxx1?[A-Za-z02-9]|"
781ac9a064cSDimitry Andric       "cxx11[[:alnum:]])[[:alnum:]]*::list<.+>$",
782ead24645SDimitry Andric       stl_deref_flags, true);
78314f1b3e8SDimitry Andric   AddCXXSynthetic(
78414f1b3e8SDimitry Andric       cpp_category_sp,
78514f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator,
786ac9a064cSDimitry Andric       "libc++ std::map synthetic children", "^std::__[[:alnum:]]+::map<.+> >$",
787ac9a064cSDimitry Andric       stl_synth_flags, true);
78814f1b3e8SDimitry Andric   AddCXXSynthetic(
78914f1b3e8SDimitry Andric       cpp_category_sp,
79014f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator,
791ac9a064cSDimitry Andric       "libc++ std::set synthetic children", "^std::__[[:alnum:]]+::set<.+> >$",
792ac9a064cSDimitry Andric       stl_deref_flags, true);
79314f1b3e8SDimitry Andric   AddCXXSynthetic(
79414f1b3e8SDimitry Andric       cpp_category_sp,
79514f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator,
79614f1b3e8SDimitry Andric       "libc++ std::multiset synthetic children",
797ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::multiset<.+> >$", stl_deref_flags, true);
79814f1b3e8SDimitry Andric   AddCXXSynthetic(
79914f1b3e8SDimitry Andric       cpp_category_sp,
80014f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdMapSyntheticFrontEndCreator,
80114f1b3e8SDimitry Andric       "libc++ std::multimap synthetic children",
802ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::multimap<.+> >$", stl_synth_flags, true);
80314f1b3e8SDimitry Andric   AddCXXSynthetic(
80414f1b3e8SDimitry Andric       cpp_category_sp,
80514f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEndCreator,
80614f1b3e8SDimitry Andric       "libc++ std::unordered containers synthetic children",
807ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::unordered_(multi)?(map|set)<.+> >$",
80814f1b3e8SDimitry Andric       stl_synth_flags, true);
80914f1b3e8SDimitry Andric   AddCXXSynthetic(
81014f1b3e8SDimitry Andric       cpp_category_sp,
81114f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxInitializerListSyntheticFrontEndCreator,
81214f1b3e8SDimitry Andric       "libc++ std::initializer_list synthetic children",
813ac9a064cSDimitry Andric       "^std::initializer_list<.+>$", stl_synth_flags, true);
814ef5d0b5eSDimitry Andric   AddCXXSynthetic(cpp_category_sp, LibcxxQueueFrontEndCreator,
815ef5d0b5eSDimitry Andric                   "libc++ std::queue synthetic children",
816ac9a064cSDimitry Andric                   "^std::__[[:alnum:]]+::queue<.+>$", stl_synth_flags, true);
817ef5d0b5eSDimitry Andric   AddCXXSynthetic(cpp_category_sp, LibcxxTupleFrontEndCreator,
818ef5d0b5eSDimitry Andric                   "libc++ std::tuple synthetic children",
819ac9a064cSDimitry Andric                   "^std::__[[:alnum:]]+::tuple<.*>$", stl_synth_flags, true);
82077fc4c14SDimitry Andric   AddCXXSynthetic(cpp_category_sp, LibcxxOptionalSyntheticFrontEndCreator,
82194994d37SDimitry Andric                   "libc++ std::optional synthetic children",
822ac9a064cSDimitry Andric                   "^std::__[[:alnum:]]+::optional<.+>$", stl_synth_flags, true);
82394994d37SDimitry Andric   AddCXXSynthetic(cpp_category_sp, LibcxxVariantFrontEndCreator,
82494994d37SDimitry Andric                   "libc++ std::variant synthetic children",
825ac9a064cSDimitry Andric                   "^std::__[[:alnum:]]+::variant<.+>$", stl_synth_flags, true);
82614f1b3e8SDimitry Andric   AddCXXSynthetic(
82714f1b3e8SDimitry Andric       cpp_category_sp,
82814f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxAtomicSyntheticFrontEndCreator,
82914f1b3e8SDimitry Andric       "libc++ std::atomic synthetic children",
8307fa27ce4SDimitry Andric       "^std::__[[:alnum:]]+::atomic<.+>$", stl_synth_flags, true);
831145449b1SDimitry Andric   AddCXXSynthetic(
832145449b1SDimitry Andric       cpp_category_sp,
833145449b1SDimitry Andric       lldb_private::formatters::LibcxxStdSpanSyntheticFrontEndCreator,
834ac9a064cSDimitry Andric       "libc++ std::span synthetic children", "^std::__[[:alnum:]]+::span<.+>$",
835ac9a064cSDimitry Andric       stl_deref_flags, true);
836e3b55780SDimitry Andric   AddCXXSynthetic(
837e3b55780SDimitry Andric       cpp_category_sp,
838e3b55780SDimitry Andric       lldb_private::formatters::LibcxxStdRangesRefViewSyntheticFrontEndCreator,
839e3b55780SDimitry Andric       "libc++ std::ranges::ref_view synthetic children",
840ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::ranges::ref_view<.+>$", stl_deref_flags, true);
841e81d9d49SDimitry Andric 
842e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
843ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::deque<.+>$", eFormatterMatchRegex,
84414f1b3e8SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
84514f1b3e8SDimitry Andric           stl_synth_flags,
846e81d9d49SDimitry Andric           "lldb.formatters.cpp.libcxx.stddeque_SynthProvider")));
847e81d9d49SDimitry Andric 
84814f1b3e8SDimitry Andric   AddCXXSynthetic(
84914f1b3e8SDimitry Andric       cpp_category_sp,
85014f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEndCreator,
851ac9a064cSDimitry Andric       "shared_ptr synthetic children", "^std::__[[:alnum:]]+::shared_ptr<.+>$",
852ac9a064cSDimitry Andric       stl_synth_flags, true);
853cfca06d7SDimitry Andric 
8547fa27ce4SDimitry Andric   static constexpr const char *const libcxx_std_unique_ptr_regex =
855ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::unique_ptr<.+>$";
856cfca06d7SDimitry Andric   AddCXXSynthetic(
857cfca06d7SDimitry Andric       cpp_category_sp,
858cfca06d7SDimitry Andric       lldb_private::formatters::LibcxxUniquePtrSyntheticFrontEndCreator,
859cfca06d7SDimitry Andric       "unique_ptr synthetic children", libcxx_std_unique_ptr_regex,
860cfca06d7SDimitry Andric       stl_synth_flags, true);
861cfca06d7SDimitry Andric 
86214f1b3e8SDimitry Andric   AddCXXSynthetic(
86314f1b3e8SDimitry Andric       cpp_category_sp,
86414f1b3e8SDimitry Andric       lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEndCreator,
865ac9a064cSDimitry Andric       "weak_ptr synthetic children", "^std::__[[:alnum:]]+::weak_ptr<.+>$",
866ac9a064cSDimitry Andric       stl_synth_flags, true);
867706b4fc4SDimitry Andric   AddCXXSummary(cpp_category_sp,
868706b4fc4SDimitry Andric                 lldb_private::formatters::LibcxxFunctionSummaryProvider,
869706b4fc4SDimitry Andric                 "libc++ std::function summary provider",
8707fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::function<.+>$", stl_summary_flags, true);
871e81d9d49SDimitry Andric 
8727fa27ce4SDimitry Andric   static constexpr const char *const libcxx_std_coroutine_handle_regex =
873ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::coroutine_handle<.+>$";
874e3b55780SDimitry Andric   AddCXXSynthetic(
875e3b55780SDimitry Andric       cpp_category_sp,
876e3b55780SDimitry Andric       lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEndCreator,
877e3b55780SDimitry Andric       "coroutine_handle synthetic children", libcxx_std_coroutine_handle_regex,
878e3b55780SDimitry Andric       stl_deref_flags, true);
879e3b55780SDimitry Andric 
88014f1b3e8SDimitry Andric   stl_summary_flags.SetDontShowChildren(false);
88114f1b3e8SDimitry Andric   stl_summary_flags.SetSkipPointers(false);
88214f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
88314f1b3e8SDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
884ac9a064cSDimitry Andric                 "libc++ std::bitset summary provider",
885ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::bitset<.+>$", stl_summary_flags, true);
886ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
887ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
888ac9a064cSDimitry Andric                 "libc++ std::vector summary provider",
889ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::vector<.+>$", stl_summary_flags, true);
890ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
891ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
892ac9a064cSDimitry Andric                 "libc++ std::valarray summary provider",
893ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::valarray<.+>$", stl_summary_flags, true);
894ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
895ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxStdSliceArraySummaryProvider,
896ac9a064cSDimitry Andric                 "libc++ std::slice_array summary provider",
897ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::slice_array<.+>$", stl_summary_flags,
898ac9a064cSDimitry Andric                 true);
899ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
900ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
901ac9a064cSDimitry Andric                 "libc++ summary provider for the valarray proxy arrays",
902ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::(gslice|mask|indirect)_array<.+>$",
903ef5d0b5eSDimitry Andric                 stl_summary_flags, true);
904ead24645SDimitry Andric   AddCXXSummary(
905ead24645SDimitry Andric       cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider,
906ef5d0b5eSDimitry Andric       "libc++ std::list summary provider",
907ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::forward_list<.+>$", stl_summary_flags, true);
908ac9a064cSDimitry Andric   AddCXXSummary(
909ac9a064cSDimitry Andric       cpp_category_sp, lldb_private::formatters::LibcxxContainerSummaryProvider,
910ac9a064cSDimitry Andric       "libc++ std::list summary provider",
911ac9a064cSDimitry Andric       // A POSIX variant of: "^std::__(?!cxx11:)[[:alnum:]]+::list<.+>$"
912ac9a064cSDimitry Andric       // so that it does not clash with: "^std::(__cxx11::)?list<.+>$"
9137fa27ce4SDimitry Andric       "^std::__([A-Zabd-z0-9]|cx?[A-Za-wyz0-9]|cxx1?[A-Za-z02-9]|"
914ac9a064cSDimitry Andric       "cxx11[[:alnum:]])[[:alnum:]]*::list<.+>$",
91514f1b3e8SDimitry Andric       stl_summary_flags, true);
916ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
917ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
9187fa27ce4SDimitry Andric                 "libc++ std::map summary provider",
919ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::map<.+>$", stl_summary_flags, true);
920ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
921ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
9227fa27ce4SDimitry Andric                 "libc++ std::deque summary provider",
923ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::deque<.+>$", stl_summary_flags, true);
924ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
925ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
9267fa27ce4SDimitry Andric                 "libc++ std::queue summary provider",
927ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::queue<.+>$", stl_summary_flags, true);
928ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
929ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
9307fa27ce4SDimitry Andric                 "libc++ std::set summary provider",
931ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::set<.+>$", stl_summary_flags, true);
932ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
933ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
9347fa27ce4SDimitry Andric                 "libc++ std::multiset summary provider",
935ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::multiset<.+>$", stl_summary_flags, true);
936ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
937ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
9387fa27ce4SDimitry Andric                 "libc++ std::multimap summary provider",
939ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::multimap<.+>$", stl_summary_flags, true);
9407fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
9417fa27ce4SDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
94214f1b3e8SDimitry Andric                 "libc++ std::unordered containers summary provider",
943ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::unordered_(multi)?(map|set)<.+> >$",
94414f1b3e8SDimitry Andric                 stl_summary_flags, true);
945ef5d0b5eSDimitry Andric   AddCXXSummary(cpp_category_sp, LibcxxContainerSummaryProvider,
946ef5d0b5eSDimitry Andric                 "libc++ std::tuple summary provider",
947ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::tuple<.*>$", stl_summary_flags, true);
948c0981da4SDimitry Andric   AddCXXSummary(cpp_category_sp,
949c0981da4SDimitry Andric                 lldb_private::formatters::LibCxxAtomicSummaryProvider,
95014f1b3e8SDimitry Andric                 "libc++ std::atomic summary provider",
9517fa27ce4SDimitry Andric                 "^std::__[[:alnum:]]+::atomic<.+>$", stl_summary_flags, true);
952ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
953ac9a064cSDimitry Andric                 lldb_private::formatters::GenericOptionalSummaryProvider,
95494994d37SDimitry Andric                 "libc++ std::optional summary provider",
955ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::optional<.+>$", stl_summary_flags, true);
956ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
957ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxVariantSummaryProvider,
95894994d37SDimitry Andric                 "libc++ std::variant summary provider",
959ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::variant<.+>$", stl_summary_flags, true);
960ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
961ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxContainerSummaryProvider,
962145449b1SDimitry Andric                 "libc++ std::span summary provider",
963ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::span<.+>$", stl_summary_flags, true);
964e81d9d49SDimitry Andric 
965e81d9d49SDimitry Andric   stl_summary_flags.SetSkipPointers(true);
966e81d9d49SDimitry Andric 
96714f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
96814f1b3e8SDimitry Andric                 lldb_private::formatters::LibcxxSmartPointerSummaryProvider,
96914f1b3e8SDimitry Andric                 "libc++ std::shared_ptr summary provider",
970ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::shared_ptr<.+>$", stl_summary_flags,
971ac9a064cSDimitry Andric                 true);
97214f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
97314f1b3e8SDimitry Andric                 lldb_private::formatters::LibcxxSmartPointerSummaryProvider,
97414f1b3e8SDimitry Andric                 "libc++ std::weak_ptr summary provider",
975ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::weak_ptr<.+>$", stl_summary_flags, true);
976cfca06d7SDimitry Andric   AddCXXSummary(cpp_category_sp,
977cfca06d7SDimitry Andric                 lldb_private::formatters::LibcxxUniquePointerSummaryProvider,
978cfca06d7SDimitry Andric                 "libc++ std::unique_ptr summary provider",
979cfca06d7SDimitry Andric                 libcxx_std_unique_ptr_regex, stl_summary_flags, true);
980e81d9d49SDimitry Andric 
981e3b55780SDimitry Andric   AddCXXSummary(cpp_category_sp,
982e3b55780SDimitry Andric                 lldb_private::formatters::StdlibCoroutineHandleSummaryProvider,
983e3b55780SDimitry Andric                 "libc++ std::coroutine_handle summary provider",
984e3b55780SDimitry Andric                 libcxx_std_coroutine_handle_regex, stl_summary_flags, true);
985e3b55780SDimitry Andric 
98614f1b3e8SDimitry Andric   AddCXXSynthetic(
98714f1b3e8SDimitry Andric       cpp_category_sp,
98814f1b3e8SDimitry Andric       lldb_private::formatters::LibCxxVectorIteratorSyntheticFrontEndCreator,
98914f1b3e8SDimitry Andric       "std::vector iterator synthetic children",
9907fa27ce4SDimitry Andric       "^std::__[[:alnum:]]+::__wrap_iter<.+>$", stl_synth_flags, true);
991e81d9d49SDimitry Andric 
99214f1b3e8SDimitry Andric   AddCXXSynthetic(
99314f1b3e8SDimitry Andric       cpp_category_sp,
99414f1b3e8SDimitry Andric       lldb_private::formatters::LibCxxMapIteratorSyntheticFrontEndCreator,
99514f1b3e8SDimitry Andric       "std::map iterator synthetic children",
9967fa27ce4SDimitry Andric       "^std::__[[:alnum:]]+::__map_(const_)?iterator<.+>$", stl_synth_flags,
99714f1b3e8SDimitry Andric       true);
9981f917f69SDimitry Andric 
9997fa27ce4SDimitry Andric   AddCXXSynthetic(cpp_category_sp,
10001f917f69SDimitry Andric                   lldb_private::formatters::
10011f917f69SDimitry Andric                       LibCxxUnorderedMapIteratorSyntheticFrontEndCreator,
10021f917f69SDimitry Andric                   "std::unordered_map iterator synthetic children",
10037fa27ce4SDimitry Andric                   "^std::__[[:alnum:]]+::__hash_map_(const_)?iterator<.+>$",
10041f917f69SDimitry Andric                   stl_synth_flags, true);
1005b1c73532SDimitry Andric   // Chrono duration typedefs
1006b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1007b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::nanoseconds", eFormatterMatchRegex,
1008b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1009b1c73532SDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ns")));
1010b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1011b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::microseconds", eFormatterMatchRegex,
1012b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1013b1c73532SDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} µs")));
1014b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1015b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::milliseconds", eFormatterMatchRegex,
1016b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1017b1c73532SDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} ms")));
1018b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1019b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
1020b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1021b1c73532SDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
1022b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1023b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::minutes", eFormatterMatchRegex,
1024b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1025b1c73532SDimitry Andric                                                     eTypeOptionHideValue,
1026b1c73532SDimitry Andric                                                 "${var.__rep_} min")));
1027b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1028b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::hours", eFormatterMatchRegex,
1029b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1030b1c73532SDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} h")));
1031b1c73532SDimitry Andric 
1032b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1033b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::days", eFormatterMatchRegex,
1034b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1035b1c73532SDimitry Andric                                                     eTypeOptionHideValue,
1036b1c73532SDimitry Andric                                                 "${var.__rep_} days")));
1037b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1038b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::weeks", eFormatterMatchRegex,
1039b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1040b1c73532SDimitry Andric                                                     eTypeOptionHideValue,
1041b1c73532SDimitry Andric                                                 "${var.__rep_} weeks")));
1042b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1043b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::months", eFormatterMatchRegex,
1044b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1045b1c73532SDimitry Andric                                                     eTypeOptionHideValue,
1046b1c73532SDimitry Andric                                                 "${var.__rep_} months")));
1047b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1048b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::years", eFormatterMatchRegex,
1049b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1050b1c73532SDimitry Andric                                                     eTypeOptionHideValue,
1051b1c73532SDimitry Andric                                                 "${var.__rep_} years")));
1052b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1053b1c73532SDimitry Andric       "^std::__[[:alnum:]]+::chrono::seconds", eFormatterMatchRegex,
1054b1c73532SDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1055b1c73532SDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "${var.__rep_} s")));
1056950076cdSDimitry Andric 
10574df029ccSDimitry Andric   // Chrono time point types
10584df029ccSDimitry Andric 
10594df029ccSDimitry Andric   AddCXXSummary(cpp_category_sp,
10604df029ccSDimitry Andric                 lldb_private::formatters::LibcxxChronoSysSecondsSummaryProvider,
10614df029ccSDimitry Andric                 "libc++ std::chrono::sys_seconds summary provider",
10624df029ccSDimitry Andric                 "^std::__[[:alnum:]]+::chrono::time_point<"
10634df029ccSDimitry Andric                 "std::__[[:alnum:]]+::chrono::system_clock, "
1064ac9a064cSDimitry Andric                 "std::__[[:alnum:]]+::chrono::duration<.*, "
10654df029ccSDimitry Andric                 "std::__[[:alnum:]]+::ratio<1, 1> "
10664df029ccSDimitry Andric                 "> >$",
10674df029ccSDimitry Andric                 eTypeOptionHideChildren | eTypeOptionHideValue |
10684df029ccSDimitry Andric                     eTypeOptionCascade,
10694df029ccSDimitry Andric                 true);
10704df029ccSDimitry Andric   AddCXXSummary(cpp_category_sp,
10714df029ccSDimitry Andric                 lldb_private::formatters::LibcxxChronoSysDaysSummaryProvider,
10724df029ccSDimitry Andric                 "libc++ std::chrono::sys_seconds summary provider",
10734df029ccSDimitry Andric                 "^std::__[[:alnum:]]+::chrono::time_point<"
10744df029ccSDimitry Andric                 "std::__[[:alnum:]]+::chrono::system_clock, "
10754df029ccSDimitry Andric                 "std::__[[:alnum:]]+::chrono::duration<int, "
10764df029ccSDimitry Andric                 "std::__[[:alnum:]]+::ratio<86400, 1> "
10774df029ccSDimitry Andric                 "> >$",
10784df029ccSDimitry Andric                 eTypeOptionHideChildren | eTypeOptionHideValue |
10794df029ccSDimitry Andric                     eTypeOptionCascade,
10804df029ccSDimitry Andric                 true);
10814df029ccSDimitry Andric 
1082ac9a064cSDimitry Andric   AddCXXSummary(
1083ac9a064cSDimitry Andric       cpp_category_sp,
1084ac9a064cSDimitry Andric       lldb_private::formatters::LibcxxChronoLocalSecondsSummaryProvider,
1085ac9a064cSDimitry Andric       "libc++ std::chrono::local_seconds summary provider",
1086ac9a064cSDimitry Andric       "^std::__[[:alnum:]]+::chrono::time_point<"
1087ac9a064cSDimitry Andric       "std::__[[:alnum:]]+::chrono::local_t, "
1088ac9a064cSDimitry Andric       "std::__[[:alnum:]]+::chrono::duration<.*, "
1089ac9a064cSDimitry Andric       "std::__[[:alnum:]]+::ratio<1, 1> "
1090ac9a064cSDimitry Andric       "> >$",
1091ac9a064cSDimitry Andric       eTypeOptionHideChildren | eTypeOptionHideValue | eTypeOptionCascade,
1092ac9a064cSDimitry Andric       true);
1093ac9a064cSDimitry Andric   AddCXXSummary(cpp_category_sp,
1094ac9a064cSDimitry Andric                 lldb_private::formatters::LibcxxChronoLocalDaysSummaryProvider,
1095ac9a064cSDimitry Andric                 "libc++ std::chrono::local_seconds summary provider",
1096ac9a064cSDimitry Andric                 "^std::__[[:alnum:]]+::chrono::time_point<"
1097ac9a064cSDimitry Andric                 "std::__[[:alnum:]]+::chrono::local_t, "
1098ac9a064cSDimitry Andric                 "std::__[[:alnum:]]+::chrono::duration<int, "
1099ac9a064cSDimitry Andric                 "std::__[[:alnum:]]+::ratio<86400, 1> "
1100ac9a064cSDimitry Andric                 "> >$",
1101ac9a064cSDimitry Andric                 eTypeOptionHideChildren | eTypeOptionHideValue |
1102ac9a064cSDimitry Andric                     eTypeOptionCascade,
1103ac9a064cSDimitry Andric                 true);
1104ac9a064cSDimitry Andric 
1105950076cdSDimitry Andric   // Chrono calendar types
1106950076cdSDimitry Andric 
1107950076cdSDimitry Andric   cpp_category_sp->AddTypeSummary(
1108950076cdSDimitry Andric       "^std::__[[:alnum:]]+::chrono::day$", eFormatterMatchRegex,
1109950076cdSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1110950076cdSDimitry Andric                                                     eTypeOptionHideValue,
1111950076cdSDimitry Andric                                                 "day=${var.__d_%u}")));
11124df029ccSDimitry Andric 
1113950076cdSDimitry Andric   AddCXXSummary(cpp_category_sp,
1114950076cdSDimitry Andric                 lldb_private::formatters::LibcxxChronoMonthSummaryProvider,
1115950076cdSDimitry Andric                 "libc++ std::chrono::month summary provider",
1116950076cdSDimitry Andric                 "^std::__[[:alnum:]]+::chrono::month$",
1117950076cdSDimitry Andric                 eTypeOptionHideChildren | eTypeOptionHideValue, true);
1118950076cdSDimitry Andric 
1119950076cdSDimitry Andric   cpp_category_sp->AddTypeSummary(
1120950076cdSDimitry Andric       "^std::__[[:alnum:]]+::chrono::year$", eFormatterMatchRegex,
1121950076cdSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
1122950076cdSDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue, "year=${var.__y_}")));
1123950076cdSDimitry Andric 
11244df029ccSDimitry Andric   AddCXXSummary(cpp_category_sp,
11254df029ccSDimitry Andric                 lldb_private::formatters::LibcxxChronoWeekdaySummaryProvider,
11264df029ccSDimitry Andric                 "libc++ std::chrono::weekday summary provider",
11274df029ccSDimitry Andric                 "^std::__[[:alnum:]]+::chrono::weekday$",
11284df029ccSDimitry Andric                 eTypeOptionHideChildren | eTypeOptionHideValue, true);
11294df029ccSDimitry Andric 
11304df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11314df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::weekday_indexed$", eFormatterMatchRegex,
11324df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
11334df029ccSDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue,
11344df029ccSDimitry Andric           "${var.__wd_} index=${var.__idx_%u}")));
11354df029ccSDimitry Andric 
11364df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11374df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::weekday_last$", eFormatterMatchRegex,
11384df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
11394df029ccSDimitry Andric                                                     eTypeOptionHideValue,
11404df029ccSDimitry Andric                                                 "${var.__wd_} index=last")));
1141950076cdSDimitry Andric   cpp_category_sp->AddTypeSummary(
1142950076cdSDimitry Andric       "^std::__[[:alnum:]]+::chrono::month_day$", eFormatterMatchRegex,
1143950076cdSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1144950076cdSDimitry Andric                                                     eTypeOptionHideValue,
1145950076cdSDimitry Andric                                                 "${var.__m_} ${var.__d_}")));
1146950076cdSDimitry Andric   cpp_category_sp->AddTypeSummary(
1147950076cdSDimitry Andric       "^std::__[[:alnum:]]+::chrono::month_day_last$", eFormatterMatchRegex,
1148950076cdSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
1149950076cdSDimitry Andric                                                     eTypeOptionHideValue,
1150950076cdSDimitry Andric                                                 "${var.__m_} day=last")));
11514df029ccSDimitry Andric 
11524df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11534df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::month_weekday$", eFormatterMatchRegex,
11544df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
11554df029ccSDimitry Andric                                                     eTypeOptionHideValue,
11564df029ccSDimitry Andric                                                 "${var.__m_} ${var.__wdi_}")));
11574df029ccSDimitry Andric 
11584df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11594df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::month_weekday_last$", eFormatterMatchRegex,
11604df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
11614df029ccSDimitry Andric                                                     eTypeOptionHideValue,
11624df029ccSDimitry Andric                                                 "${var.__m_} ${var.__wdl_}")));
11634df029ccSDimitry Andric 
11644df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11654df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::year_month$", eFormatterMatchRegex,
11664df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
11674df029ccSDimitry Andric                                                     eTypeOptionHideValue,
11684df029ccSDimitry Andric                                                 "${var.__y_} ${var.__m_}")));
11694df029ccSDimitry Andric 
1170950076cdSDimitry Andric   AddCXXSummary(
1171950076cdSDimitry Andric       cpp_category_sp,
1172950076cdSDimitry Andric       lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider,
1173950076cdSDimitry Andric       "libc++ std::chrono::year_month_day summary provider",
1174950076cdSDimitry Andric       "^std::__[[:alnum:]]+::chrono::year_month_day$",
1175950076cdSDimitry Andric       eTypeOptionHideChildren | eTypeOptionHideValue, true);
11764df029ccSDimitry Andric 
11774df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11784df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::year_month_day_last$",
11794df029ccSDimitry Andric       eFormatterMatchRegex,
11804df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(eTypeOptionHideChildren |
11814df029ccSDimitry Andric                                                     eTypeOptionHideValue,
11824df029ccSDimitry Andric                                                 "${var.__y_} ${var.__mdl_}")));
11834df029ccSDimitry Andric 
11844df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11854df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::year_month_weekday$", eFormatterMatchRegex,
11864df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
11874df029ccSDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue,
11884df029ccSDimitry Andric           "${var.__y_} ${var.__m_} ${var.__wdi_}")));
11894df029ccSDimitry Andric 
11904df029ccSDimitry Andric   cpp_category_sp->AddTypeSummary(
11914df029ccSDimitry Andric       "^std::__[[:alnum:]]+::chrono::year_month_weekday_last$",
11924df029ccSDimitry Andric       eFormatterMatchRegex,
11934df029ccSDimitry Andric       TypeSummaryImplSP(new StringSummaryFormat(
11944df029ccSDimitry Andric           eTypeOptionHideChildren | eTypeOptionHideValue,
11954df029ccSDimitry Andric           "${var.__y_} ${var.__m_} ${var.__wdl_}")));
1196e81d9d49SDimitry Andric }
1197e81d9d49SDimitry Andric 
LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp)119814f1b3e8SDimitry Andric static void LoadLibStdcppFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1199e81d9d49SDimitry Andric   if (!cpp_category_sp)
1200e81d9d49SDimitry Andric     return;
1201e81d9d49SDimitry Andric 
1202e81d9d49SDimitry Andric   TypeSummaryImpl::Flags stl_summary_flags;
1203e81d9d49SDimitry Andric   stl_summary_flags.SetCascades(true)
1204e81d9d49SDimitry Andric       .SetSkipPointers(false)
1205e81d9d49SDimitry Andric       .SetSkipReferences(false)
1206e81d9d49SDimitry Andric       .SetDontShowChildren(true)
1207e81d9d49SDimitry Andric       .SetDontShowValue(true)
1208e81d9d49SDimitry Andric       .SetShowMembersOneLiner(false)
1209e81d9d49SDimitry Andric       .SetHideItemNames(false);
1210e81d9d49SDimitry Andric 
121114f1b3e8SDimitry Andric   lldb::TypeSummaryImplSP std_string_summary_sp(
121214f1b3e8SDimitry Andric       new StringSummaryFormat(stl_summary_flags, "${var._M_dataplus._M_p}"));
1213e81d9d49SDimitry Andric 
121414f1b3e8SDimitry Andric   lldb::TypeSummaryImplSP cxx11_string_summary_sp(new CXXFunctionSummaryFormat(
121514f1b3e8SDimitry Andric       stl_summary_flags, LibStdcppStringSummaryProvider,
1216e81d9d49SDimitry Andric       "libstdc++ c++11 std::string summary provider"));
121714f1b3e8SDimitry Andric   lldb::TypeSummaryImplSP cxx11_wstring_summary_sp(new CXXFunctionSummaryFormat(
121814f1b3e8SDimitry Andric       stl_summary_flags, LibStdcppWStringSummaryProvider,
1219e81d9d49SDimitry Andric       "libstdc++ c++11 std::wstring summary provider"));
1220e81d9d49SDimitry Andric 
1221e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::string", eFormatterMatchExact,
1222e81d9d49SDimitry Andric                                   std_string_summary_sp);
1223e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::basic_string<char>",
1224b1c73532SDimitry Andric                                   eFormatterMatchExact, std_string_summary_sp);
1225e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary(
1226e3b55780SDimitry Andric       "std::basic_string<char,std::char_traits<char>,std::allocator<char> >",
1227e3b55780SDimitry Andric       eFormatterMatchExact, std_string_summary_sp);
1228e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary(
1229e3b55780SDimitry Andric       "std::basic_string<char, std::char_traits<char>, std::allocator<char> >",
1230e3b55780SDimitry Andric       eFormatterMatchExact, std_string_summary_sp);
1231e81d9d49SDimitry Andric 
1232e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::__cxx11::string", eFormatterMatchExact,
1233e81d9d49SDimitry Andric                                   cxx11_string_summary_sp);
1234e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary(
1235e3b55780SDimitry Andric       "std::__cxx11::basic_string<char, std::char_traits<char>, "
1236e3b55780SDimitry Andric       "std::allocator<char> >",
1237e3b55780SDimitry Andric       eFormatterMatchExact, cxx11_string_summary_sp);
1238e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::__cxx11::basic_string<unsigned char, "
1239c0981da4SDimitry Andric                                   "std::char_traits<unsigned char>, "
1240e3b55780SDimitry Andric                                   "std::allocator<unsigned char> >",
1241e3b55780SDimitry Andric                                   eFormatterMatchExact,
1242706b4fc4SDimitry Andric                                   cxx11_string_summary_sp);
1243e81d9d49SDimitry Andric 
124414f1b3e8SDimitry Andric   // making sure we force-pick the summary for printing wstring (_M_p is a
124514f1b3e8SDimitry Andric   // wchar_t*)
124614f1b3e8SDimitry Andric   lldb::TypeSummaryImplSP std_wstring_summary_sp(
124714f1b3e8SDimitry Andric       new StringSummaryFormat(stl_summary_flags, "${var._M_dataplus._M_p%S}"));
1248e81d9d49SDimitry Andric 
1249e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::wstring", eFormatterMatchExact,
1250e81d9d49SDimitry Andric                                   std_wstring_summary_sp);
1251e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::basic_string<wchar_t>",
1252e3b55780SDimitry Andric                                   eFormatterMatchExact, std_wstring_summary_sp);
1253e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::basic_string<wchar_t,std::char_traits<"
1254e3b55780SDimitry Andric                                   "wchar_t>,std::allocator<wchar_t> >",
1255e3b55780SDimitry Andric                                   eFormatterMatchExact, std_wstring_summary_sp);
1256e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary(
1257e3b55780SDimitry Andric       "std::basic_string<wchar_t, std::char_traits<wchar_t>, "
1258e3b55780SDimitry Andric       "std::allocator<wchar_t> >",
1259e3b55780SDimitry Andric       eFormatterMatchExact, std_wstring_summary_sp);
1260e81d9d49SDimitry Andric 
1261e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("std::__cxx11::wstring", eFormatterMatchExact,
1262e81d9d49SDimitry Andric                                   cxx11_wstring_summary_sp);
1263e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary(
1264e3b55780SDimitry Andric       "std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, "
1265e3b55780SDimitry Andric       "std::allocator<wchar_t> >",
1266e3b55780SDimitry Andric       eFormatterMatchExact, cxx11_wstring_summary_sp);
1267e81d9d49SDimitry Andric 
1268e81d9d49SDimitry Andric   SyntheticChildren::Flags stl_synth_flags;
126914f1b3e8SDimitry Andric   stl_synth_flags.SetCascades(true).SetSkipPointers(false).SetSkipReferences(
127014f1b3e8SDimitry Andric       false);
1271c0981da4SDimitry Andric   SyntheticChildren::Flags stl_deref_flags = stl_synth_flags;
1272c0981da4SDimitry Andric   stl_deref_flags.SetFrontEndWantsDereference();
1273e81d9d49SDimitry Andric 
1274e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1275e3b55780SDimitry Andric       "^std::vector<.+>(( )?&)?$", eFormatterMatchRegex,
127614f1b3e8SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
127714f1b3e8SDimitry Andric           stl_synth_flags,
1278e81d9d49SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdVectorSynthProvider")));
1279e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1280e3b55780SDimitry Andric       "^std::map<.+> >(( )?&)?$", eFormatterMatchRegex,
128114f1b3e8SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
128214f1b3e8SDimitry Andric           stl_synth_flags,
1283c0981da4SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
1284e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1285e3b55780SDimitry Andric       "^std::deque<.+>(( )?&)?$", eFormatterMatchRegex,
128677fc4c14SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
128777fc4c14SDimitry Andric           stl_deref_flags,
128877fc4c14SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdDequeSynthProvider")));
1289e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1290e3b55780SDimitry Andric       "^std::set<.+> >(( )?&)?$", eFormatterMatchRegex,
1291c0981da4SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
1292c0981da4SDimitry Andric           stl_deref_flags,
1293c0981da4SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
1294e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1295e3b55780SDimitry Andric       "^std::multimap<.+> >(( )?&)?$", eFormatterMatchRegex,
1296c0981da4SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
1297c0981da4SDimitry Andric           stl_deref_flags,
1298c0981da4SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
1299e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1300e3b55780SDimitry Andric       "^std::multiset<.+> >(( )?&)?$", eFormatterMatchRegex,
1301c0981da4SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
1302c0981da4SDimitry Andric           stl_deref_flags,
1303c0981da4SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdMapLikeSynthProvider")));
1304e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1305e3b55780SDimitry Andric       "^std::unordered_(multi)?(map|set)<.+> >$", eFormatterMatchRegex,
1306f65dcba8SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
1307f65dcba8SDimitry Andric           stl_deref_flags,
1308f65dcba8SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdUnorderedMapSynthProvider")));
1309e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1310e3b55780SDimitry Andric       "^std::(__cxx11::)?list<.+>(( )?&)?$", eFormatterMatchRegex,
131114f1b3e8SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
131277fc4c14SDimitry Andric           stl_deref_flags,
1313e81d9d49SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdListSynthProvider")));
1314e3b55780SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1315e3b55780SDimitry Andric       "^std::(__cxx11::)?forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
1316c0981da4SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
1317c0981da4SDimitry Andric           stl_synth_flags,
1318c0981da4SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.StdForwardListSynthProvider")));
1319b1c73532SDimitry Andric   cpp_category_sp->AddTypeSynthetic(
1320b1c73532SDimitry Andric       "^std::variant<.+>$", eFormatterMatchRegex,
1321b1c73532SDimitry Andric       SyntheticChildrenSP(new ScriptedSyntheticChildren(
1322b1c73532SDimitry Andric           stl_synth_flags,
1323b1c73532SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.VariantSynthProvider")));
1324f65dcba8SDimitry Andric 
132514f1b3e8SDimitry Andric   stl_summary_flags.SetDontShowChildren(false);
1326c0981da4SDimitry Andric   stl_summary_flags.SetSkipPointers(false);
1327e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::bitset<.+>(( )?&)?$",
1328e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1329e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1330e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1331e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::vector<.+>(( )?&)?$",
1332e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1333e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1334e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1335e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::map<.+> >(( )?&)?$",
1336e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1337e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1338e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1339e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::set<.+> >(( )?&)?$",
1340e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1341e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1342e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1343e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::deque<.+>(( )?&)?$",
1344e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1345e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1346e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1347e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::multimap<.+> >(( )?&)?$",
1348e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1349e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1350e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1351e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::multiset<.+> >(( )?&)?$",
1352e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1353e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1354e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1355e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::unordered_(multi)?(map|set)<.+> >$",
1356e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1357e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1358e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1359e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary("^std::(__cxx11::)?list<.+>(( )?&)?$",
1360e3b55780SDimitry Andric                                   eFormatterMatchRegex,
1361e3b55780SDimitry Andric                                   TypeSummaryImplSP(new StringSummaryFormat(
1362e3b55780SDimitry Andric                                       stl_summary_flags, "size=${svar%#}")));
1363e3b55780SDimitry Andric   cpp_category_sp->AddTypeSummary(
1364e3b55780SDimitry Andric       "^std::(__cxx11::)?forward_list<.+>(( )?&)?$", eFormatterMatchRegex,
1365e3b55780SDimitry Andric       TypeSummaryImplSP(new ScriptSummaryFormat(
1366e3b55780SDimitry Andric           stl_summary_flags,
1367e3b55780SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.ForwardListSummaryProvider")));
1368b1c73532SDimitry Andric   cpp_category_sp->AddTypeSummary(
1369b1c73532SDimitry Andric       "^std::variant<.+>$", eFormatterMatchRegex,
1370b1c73532SDimitry Andric       TypeSummaryImplSP(new ScriptSummaryFormat(
1371b1c73532SDimitry Andric           stl_summary_flags,
1372b1c73532SDimitry Andric           "lldb.formatters.cpp.gnu_libstdcpp.VariantSummaryProvider")));
1373e81d9d49SDimitry Andric 
137414f1b3e8SDimitry Andric   AddCXXSynthetic(
137514f1b3e8SDimitry Andric       cpp_category_sp,
137614f1b3e8SDimitry Andric       lldb_private::formatters::LibStdcppVectorIteratorSyntheticFrontEndCreator,
137714f1b3e8SDimitry Andric       "std::vector iterator synthetic children",
13787fa27ce4SDimitry Andric       "^__gnu_cxx::__normal_iterator<.+>$", stl_synth_flags, true);
1379e81d9d49SDimitry Andric 
138014f1b3e8SDimitry Andric   AddCXXSynthetic(
138114f1b3e8SDimitry Andric       cpp_category_sp,
138214f1b3e8SDimitry Andric       lldb_private::formatters::LibstdcppMapIteratorSyntheticFrontEndCreator,
13837fa27ce4SDimitry Andric       "std::map iterator synthetic children", "^std::_Rb_tree_iterator<.+>$",
13847fa27ce4SDimitry Andric       stl_synth_flags, true);
1385f3fbd1c0SDimitry Andric 
138614f1b3e8SDimitry Andric   AddCXXSynthetic(
138714f1b3e8SDimitry Andric       cpp_category_sp,
138814f1b3e8SDimitry Andric       lldb_private::formatters::LibStdcppUniquePtrSyntheticFrontEndCreator,
13897fa27ce4SDimitry Andric       "std::unique_ptr synthetic children", "^std::unique_ptr<.+>(( )?&)?$",
13907fa27ce4SDimitry Andric       stl_synth_flags, true);
139114f1b3e8SDimitry Andric   AddCXXSynthetic(
139214f1b3e8SDimitry Andric       cpp_category_sp,
139314f1b3e8SDimitry Andric       lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator,
13947fa27ce4SDimitry Andric       "std::shared_ptr synthetic children", "^std::shared_ptr<.+>(( )?&)?$",
13957fa27ce4SDimitry Andric       stl_synth_flags, true);
139614f1b3e8SDimitry Andric   AddCXXSynthetic(
139714f1b3e8SDimitry Andric       cpp_category_sp,
139814f1b3e8SDimitry Andric       lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator,
13997fa27ce4SDimitry Andric       "std::weak_ptr synthetic children", "^std::weak_ptr<.+>(( )?&)?$",
14007fa27ce4SDimitry Andric       stl_synth_flags, true);
140114f1b3e8SDimitry Andric   AddCXXSynthetic(
140214f1b3e8SDimitry Andric       cpp_category_sp,
140314f1b3e8SDimitry Andric       lldb_private::formatters::LibStdcppTupleSyntheticFrontEndCreator,
14047fa27ce4SDimitry Andric       "std::tuple synthetic children", "^std::tuple<.+>(( )?&)?$",
140514f1b3e8SDimitry Andric       stl_synth_flags, true);
140614f1b3e8SDimitry Andric 
14077fa27ce4SDimitry Andric   static constexpr const char *const libstdcpp_std_coroutine_handle_regex =
14087fa27ce4SDimitry Andric       "^std::coroutine_handle<.+>(( )?&)?$";
1409e3b55780SDimitry Andric   AddCXXSynthetic(
1410e3b55780SDimitry Andric       cpp_category_sp,
1411e3b55780SDimitry Andric       lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEndCreator,
1412e3b55780SDimitry Andric       "std::coroutine_handle synthetic children",
1413e3b55780SDimitry Andric       libstdcpp_std_coroutine_handle_regex, stl_deref_flags, true);
1414e3b55780SDimitry Andric 
1415c0981da4SDimitry Andric   AddCXXSynthetic(
1416c0981da4SDimitry Andric       cpp_category_sp,
1417c0981da4SDimitry Andric       lldb_private::formatters::LibStdcppBitsetSyntheticFrontEndCreator,
14187fa27ce4SDimitry Andric       "std::bitset synthetic child", "^std::bitset<.+>(( )?&)?$",
1419c0981da4SDimitry Andric       stl_deref_flags, true);
1420c0981da4SDimitry Andric 
142177fc4c14SDimitry Andric   AddCXXSynthetic(
142277fc4c14SDimitry Andric       cpp_category_sp,
142377fc4c14SDimitry Andric       lldb_private::formatters::LibStdcppOptionalSyntheticFrontEndCreator,
14247fa27ce4SDimitry Andric       "std::optional synthetic child", "^std::optional<.+>(( )?&)?$",
14257fa27ce4SDimitry Andric       stl_deref_flags, true);
142677fc4c14SDimitry Andric 
142714f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
142814f1b3e8SDimitry Andric                 lldb_private::formatters::LibStdcppUniquePointerSummaryProvider,
142914f1b3e8SDimitry Andric                 "libstdc++ std::unique_ptr summary provider",
14307fa27ce4SDimitry Andric                 "^std::unique_ptr<.+>(( )?&)?$", stl_summary_flags, true);
143114f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
143214f1b3e8SDimitry Andric                 lldb_private::formatters::LibStdcppSmartPointerSummaryProvider,
143314f1b3e8SDimitry Andric                 "libstdc++ std::shared_ptr summary provider",
14347fa27ce4SDimitry Andric                 "^std::shared_ptr<.+>(( )?&)?$", stl_summary_flags, true);
143514f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
143614f1b3e8SDimitry Andric                 lldb_private::formatters::LibStdcppSmartPointerSummaryProvider,
143714f1b3e8SDimitry Andric                 "libstdc++ std::weak_ptr summary provider",
14387fa27ce4SDimitry Andric                 "^std::weak_ptr<.+>(( )?&)?$", stl_summary_flags, true);
1439e3b55780SDimitry Andric   AddCXXSummary(cpp_category_sp,
1440e3b55780SDimitry Andric                 lldb_private::formatters::StdlibCoroutineHandleSummaryProvider,
1441e3b55780SDimitry Andric                 "libstdc++ std::coroutine_handle summary provider",
1442e3b55780SDimitry Andric                 libstdcpp_std_coroutine_handle_regex, stl_summary_flags, true);
14437fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
14447fa27ce4SDimitry Andric                 lldb_private::formatters::GenericOptionalSummaryProvider,
144577fc4c14SDimitry Andric                 "libstd++ std::optional summary provider",
14467fa27ce4SDimitry Andric                 "^std::optional<.+>(( )?&)?$", stl_summary_flags, true);
1447e81d9d49SDimitry Andric }
1448e81d9d49SDimitry Andric 
LoadSystemFormatters(lldb::TypeCategoryImplSP cpp_category_sp)144914f1b3e8SDimitry Andric static void LoadSystemFormatters(lldb::TypeCategoryImplSP cpp_category_sp) {
1450e81d9d49SDimitry Andric   if (!cpp_category_sp)
1451e81d9d49SDimitry Andric     return;
1452e81d9d49SDimitry Andric 
1453e81d9d49SDimitry Andric   TypeSummaryImpl::Flags string_flags;
1454e81d9d49SDimitry Andric   string_flags.SetCascades(true)
1455e81d9d49SDimitry Andric       .SetSkipPointers(true)
1456e81d9d49SDimitry Andric       .SetSkipReferences(false)
1457e81d9d49SDimitry Andric       .SetDontShowChildren(true)
1458e81d9d49SDimitry Andric       .SetDontShowValue(false)
1459e81d9d49SDimitry Andric       .SetShowMembersOneLiner(false)
1460e81d9d49SDimitry Andric       .SetHideItemNames(false);
1461e81d9d49SDimitry Andric 
1462e81d9d49SDimitry Andric   TypeSummaryImpl::Flags string_array_flags;
1463e81d9d49SDimitry Andric   string_array_flags.SetCascades(true)
1464e81d9d49SDimitry Andric       .SetSkipPointers(true)
1465e81d9d49SDimitry Andric       .SetSkipReferences(false)
1466e81d9d49SDimitry Andric       .SetDontShowChildren(true)
1467e81d9d49SDimitry Andric       .SetDontShowValue(true)
1468e81d9d49SDimitry Andric       .SetShowMembersOneLiner(false)
1469e81d9d49SDimitry Andric       .SetHideItemNames(false);
1470e81d9d49SDimitry Andric 
1471ead24645SDimitry Andric   AddCXXSummary(cpp_category_sp,
1472ead24645SDimitry Andric                 lldb_private::formatters::Char8StringSummaryProvider,
14737fa27ce4SDimitry Andric                 "char8_t * summary provider", "char8_t *", string_flags);
14747fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
14757fa27ce4SDimitry Andric                 lldb_private::formatters::Char8StringSummaryProvider,
14767fa27ce4SDimitry Andric                 "char8_t [] summary provider", "char8_t ?\\[[0-9]+\\]",
14777fa27ce4SDimitry Andric                 string_array_flags, true);
1478ead24645SDimitry Andric 
1479e81d9d49SDimitry Andric   AddCXXSummary(cpp_category_sp,
1480e81d9d49SDimitry Andric                 lldb_private::formatters::Char16StringSummaryProvider,
14817fa27ce4SDimitry Andric                 "char16_t * summary provider", "char16_t *", string_flags);
14827fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
14837fa27ce4SDimitry Andric                 lldb_private::formatters::Char16StringSummaryProvider,
14847fa27ce4SDimitry Andric                 "char16_t [] summary provider", "char16_t ?\\[[0-9]+\\]",
14857fa27ce4SDimitry Andric                 string_array_flags, true);
1486e81d9d49SDimitry Andric 
1487e81d9d49SDimitry Andric   AddCXXSummary(cpp_category_sp,
1488e81d9d49SDimitry Andric                 lldb_private::formatters::Char32StringSummaryProvider,
14897fa27ce4SDimitry Andric                 "char32_t * summary provider", "char32_t *", string_flags);
14907fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
14917fa27ce4SDimitry Andric                 lldb_private::formatters::Char32StringSummaryProvider,
14927fa27ce4SDimitry Andric                 "char32_t [] summary provider", "char32_t ?\\[[0-9]+\\]",
14937fa27ce4SDimitry Andric                 string_array_flags, true);
1494e81d9d49SDimitry Andric 
149514f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp,
149614f1b3e8SDimitry Andric                 lldb_private::formatters::WCharStringSummaryProvider,
14977fa27ce4SDimitry Andric                 "wchar_t * summary provider", "wchar_t *", string_flags);
14987fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
14997fa27ce4SDimitry Andric                 lldb_private::formatters::WCharStringSummaryProvider,
15007fa27ce4SDimitry Andric                 "wchar_t * summary provider", "wchar_t ?\\[[0-9]+\\]",
15017fa27ce4SDimitry Andric                 string_array_flags, true);
1502e81d9d49SDimitry Andric 
15037fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
15047fa27ce4SDimitry Andric                 lldb_private::formatters::Char16StringSummaryProvider,
15057fa27ce4SDimitry Andric                 "unichar * summary provider", "unichar *", string_flags);
1506e81d9d49SDimitry Andric 
1507e81d9d49SDimitry Andric   TypeSummaryImpl::Flags widechar_flags;
1508e81d9d49SDimitry Andric   widechar_flags.SetDontShowValue(true)
1509e81d9d49SDimitry Andric       .SetSkipPointers(true)
1510e81d9d49SDimitry Andric       .SetSkipReferences(false)
1511e81d9d49SDimitry Andric       .SetCascades(true)
1512e81d9d49SDimitry Andric       .SetDontShowChildren(true)
1513e81d9d49SDimitry Andric       .SetHideItemNames(true)
1514e81d9d49SDimitry Andric       .SetShowMembersOneLiner(false);
1515e81d9d49SDimitry Andric 
1516ead24645SDimitry Andric   AddCXXSummary(cpp_category_sp, lldb_private::formatters::Char8SummaryProvider,
15177fa27ce4SDimitry Andric                 "char8_t summary provider", "char8_t", widechar_flags);
15187fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
15197fa27ce4SDimitry Andric                 lldb_private::formatters::Char16SummaryProvider,
15207fa27ce4SDimitry Andric                 "char16_t summary provider", "char16_t", widechar_flags);
15217fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
15227fa27ce4SDimitry Andric                 lldb_private::formatters::Char32SummaryProvider,
15237fa27ce4SDimitry Andric                 "char32_t summary provider", "char32_t", widechar_flags);
152414f1b3e8SDimitry Andric   AddCXXSummary(cpp_category_sp, lldb_private::formatters::WCharSummaryProvider,
15257fa27ce4SDimitry Andric                 "wchar_t summary provider", "wchar_t", widechar_flags);
1526e81d9d49SDimitry Andric 
15277fa27ce4SDimitry Andric   AddCXXSummary(cpp_category_sp,
15287fa27ce4SDimitry Andric                 lldb_private::formatters::Char16SummaryProvider,
15297fa27ce4SDimitry Andric                 "unichar summary provider", "unichar", widechar_flags);
1530e81d9d49SDimitry Andric }
1531e81d9d49SDimitry Andric 
GetTypeScavenger()153214f1b3e8SDimitry Andric std::unique_ptr<Language::TypeScavenger> CPlusPlusLanguage::GetTypeScavenger() {
153314f1b3e8SDimitry Andric   class CPlusPlusTypeScavenger : public Language::ImageListTypeScavenger {
153414f1b3e8SDimitry Andric   public:
15355f29bb8aSDimitry Andric     CompilerType AdjustForInclusion(CompilerType &candidate) override {
153614f1b3e8SDimitry Andric       LanguageType lang_type(candidate.GetMinimumLanguage());
153714f1b3e8SDimitry Andric       if (!Language::LanguageIsC(lang_type) &&
153814f1b3e8SDimitry Andric           !Language::LanguageIsCPlusPlus(lang_type))
153914f1b3e8SDimitry Andric         return CompilerType();
154014f1b3e8SDimitry Andric       if (candidate.IsTypedefType())
154114f1b3e8SDimitry Andric         return candidate.GetTypedefedType();
154214f1b3e8SDimitry Andric       return candidate;
154314f1b3e8SDimitry Andric     }
154414f1b3e8SDimitry Andric   };
154514f1b3e8SDimitry Andric 
154614f1b3e8SDimitry Andric   return std::unique_ptr<TypeScavenger>(new CPlusPlusTypeScavenger());
154714f1b3e8SDimitry Andric }
154814f1b3e8SDimitry Andric 
GetFormatters()154914f1b3e8SDimitry Andric lldb::TypeCategoryImplSP CPlusPlusLanguage::GetFormatters() {
155074a628f7SDimitry Andric   static llvm::once_flag g_initialize;
1551e81d9d49SDimitry Andric   static TypeCategoryImplSP g_category;
1552e81d9d49SDimitry Andric 
155374a628f7SDimitry Andric   llvm::call_once(g_initialize, [this]() -> void {
1554c0981da4SDimitry Andric     DataVisualization::Categories::GetCategory(ConstString(GetPluginName()),
1555c0981da4SDimitry Andric                                                g_category);
155614f1b3e8SDimitry Andric     if (g_category) {
1557e81d9d49SDimitry Andric       LoadLibStdcppFormatters(g_category);
15585f29bb8aSDimitry Andric       LoadLibCxxFormatters(g_category);
1559e81d9d49SDimitry Andric       LoadSystemFormatters(g_category);
1560e81d9d49SDimitry Andric     }
1561e81d9d49SDimitry Andric   });
1562e81d9d49SDimitry Andric   return g_category;
1563e81d9d49SDimitry Andric }
1564e81d9d49SDimitry Andric 
1565e81d9d49SDimitry Andric HardcodedFormatters::HardcodedSummaryFinder
GetHardcodedSummaries()156614f1b3e8SDimitry Andric CPlusPlusLanguage::GetHardcodedSummaries() {
156774a628f7SDimitry Andric   static llvm::once_flag g_initialize;
1568e81d9d49SDimitry Andric   static ConstString g_vectortypes("VectorTypes");
1569e81d9d49SDimitry Andric   static HardcodedFormatters::HardcodedSummaryFinder g_formatters;
1570e81d9d49SDimitry Andric 
157174a628f7SDimitry Andric   llvm::call_once(g_initialize, []() -> void {
1572e81d9d49SDimitry Andric     g_formatters.push_back(
157314f1b3e8SDimitry Andric         [](lldb_private::ValueObject &valobj, lldb::DynamicValueType,
1574e81d9d49SDimitry Andric            FormatManager &) -> TypeSummaryImpl::SharedPointer {
157514f1b3e8SDimitry Andric           static CXXFunctionSummaryFormat::SharedPointer formatter_sp(
157614f1b3e8SDimitry Andric               new CXXFunctionSummaryFormat(
157714f1b3e8SDimitry Andric                   TypeSummaryImpl::Flags(),
157814f1b3e8SDimitry Andric                   lldb_private::formatters::CXXFunctionPointerSummaryProvider,
157914f1b3e8SDimitry Andric                   "Function pointer summary provider"));
15807fa27ce4SDimitry Andric           if (CompilerType CT = valobj.GetCompilerType();
1581b1c73532SDimitry Andric               CT.IsFunctionPointerType() || CT.IsMemberFunctionPointerType() ||
1582b1c73532SDimitry Andric               valobj.GetValueType() == lldb::eValueTypeVTableEntry) {
1583e81d9d49SDimitry Andric             return formatter_sp;
1584e81d9d49SDimitry Andric           }
1585e81d9d49SDimitry Andric           return nullptr;
1586e81d9d49SDimitry Andric         });
1587e81d9d49SDimitry Andric     g_formatters.push_back(
158814f1b3e8SDimitry Andric         [](lldb_private::ValueObject &valobj, lldb::DynamicValueType,
1589e81d9d49SDimitry Andric            FormatManager &fmt_mgr) -> TypeSummaryImpl::SharedPointer {
159014f1b3e8SDimitry Andric           static CXXFunctionSummaryFormat::SharedPointer formatter_sp(
159114f1b3e8SDimitry Andric               new CXXFunctionSummaryFormat(
159214f1b3e8SDimitry Andric                   TypeSummaryImpl::Flags()
1593e81d9d49SDimitry Andric                       .SetCascades(true)
1594e81d9d49SDimitry Andric                       .SetDontShowChildren(true)
1595e81d9d49SDimitry Andric                       .SetHideItemNames(true)
1596e81d9d49SDimitry Andric                       .SetShowMembersOneLiner(true)
1597e81d9d49SDimitry Andric                       .SetSkipPointers(true)
1598e81d9d49SDimitry Andric                       .SetSkipReferences(false),
1599e81d9d49SDimitry Andric                   lldb_private::formatters::VectorTypeSummaryProvider,
1600e81d9d49SDimitry Andric                   "vector_type pointer summary provider"));
1601344a3780SDimitry Andric           if (valobj.GetCompilerType().IsVectorType()) {
1602e81d9d49SDimitry Andric             if (fmt_mgr.GetCategory(g_vectortypes)->IsEnabled())
1603e81d9d49SDimitry Andric               return formatter_sp;
1604e81d9d49SDimitry Andric           }
1605e81d9d49SDimitry Andric           return nullptr;
1606e81d9d49SDimitry Andric         });
1607f3fbd1c0SDimitry Andric     g_formatters.push_back(
160814f1b3e8SDimitry Andric         [](lldb_private::ValueObject &valobj, lldb::DynamicValueType,
1609f3fbd1c0SDimitry Andric            FormatManager &fmt_mgr) -> TypeSummaryImpl::SharedPointer {
161014f1b3e8SDimitry Andric           static CXXFunctionSummaryFormat::SharedPointer formatter_sp(
161114f1b3e8SDimitry Andric               new CXXFunctionSummaryFormat(
161214f1b3e8SDimitry Andric                   TypeSummaryImpl::Flags()
1613f3fbd1c0SDimitry Andric                       .SetCascades(true)
1614f3fbd1c0SDimitry Andric                       .SetDontShowChildren(true)
1615f3fbd1c0SDimitry Andric                       .SetHideItemNames(true)
1616f3fbd1c0SDimitry Andric                       .SetShowMembersOneLiner(true)
1617f3fbd1c0SDimitry Andric                       .SetSkipPointers(true)
1618f3fbd1c0SDimitry Andric                       .SetSkipReferences(false),
1619f3fbd1c0SDimitry Andric                   lldb_private::formatters::BlockPointerSummaryProvider,
1620f3fbd1c0SDimitry Andric                   "block pointer summary provider"));
1621344a3780SDimitry Andric           if (valobj.GetCompilerType().IsBlockPointerType()) {
1622f3fbd1c0SDimitry Andric             return formatter_sp;
1623f3fbd1c0SDimitry Andric           }
1624f3fbd1c0SDimitry Andric           return nullptr;
1625f3fbd1c0SDimitry Andric         });
1626e81d9d49SDimitry Andric   });
1627e81d9d49SDimitry Andric 
1628e81d9d49SDimitry Andric   return g_formatters;
1629e81d9d49SDimitry Andric }
1630e81d9d49SDimitry Andric 
1631e81d9d49SDimitry Andric HardcodedFormatters::HardcodedSyntheticFinder
GetHardcodedSynthetics()163214f1b3e8SDimitry Andric CPlusPlusLanguage::GetHardcodedSynthetics() {
163374a628f7SDimitry Andric   static llvm::once_flag g_initialize;
1634e81d9d49SDimitry Andric   static ConstString g_vectortypes("VectorTypes");
1635e81d9d49SDimitry Andric   static HardcodedFormatters::HardcodedSyntheticFinder g_formatters;
1636e81d9d49SDimitry Andric 
163774a628f7SDimitry Andric   llvm::call_once(g_initialize, []() -> void {
163814f1b3e8SDimitry Andric     g_formatters.push_back([](lldb_private::ValueObject &valobj,
1639c0981da4SDimitry Andric                               lldb::DynamicValueType, FormatManager &fmt_mgr)
1640c0981da4SDimitry Andric                                -> SyntheticChildren::SharedPointer {
164114f1b3e8SDimitry Andric       static CXXSyntheticChildren::SharedPointer formatter_sp(
164214f1b3e8SDimitry Andric           new CXXSyntheticChildren(
164314f1b3e8SDimitry Andric               SyntheticChildren::Flags()
164414f1b3e8SDimitry Andric                   .SetCascades(true)
164514f1b3e8SDimitry Andric                   .SetSkipPointers(true)
164614f1b3e8SDimitry Andric                   .SetSkipReferences(true)
164714f1b3e8SDimitry Andric                   .SetNonCacheable(true),
1648e81d9d49SDimitry Andric               "vector_type synthetic children",
1649e81d9d49SDimitry Andric               lldb_private::formatters::VectorTypeSyntheticFrontEndCreator));
1650344a3780SDimitry Andric       if (valobj.GetCompilerType().IsVectorType()) {
1651e81d9d49SDimitry Andric         if (fmt_mgr.GetCategory(g_vectortypes)->IsEnabled())
1652e81d9d49SDimitry Andric           return formatter_sp;
1653e81d9d49SDimitry Andric       }
1654e81d9d49SDimitry Andric       return nullptr;
1655e81d9d49SDimitry Andric     });
165614f1b3e8SDimitry Andric     g_formatters.push_back([](lldb_private::ValueObject &valobj,
1657c0981da4SDimitry Andric                               lldb::DynamicValueType, FormatManager &fmt_mgr)
1658c0981da4SDimitry Andric                                -> SyntheticChildren::SharedPointer {
165914f1b3e8SDimitry Andric       static CXXSyntheticChildren::SharedPointer formatter_sp(
166014f1b3e8SDimitry Andric           new CXXSyntheticChildren(
166114f1b3e8SDimitry Andric               SyntheticChildren::Flags()
166214f1b3e8SDimitry Andric                   .SetCascades(true)
166314f1b3e8SDimitry Andric                   .SetSkipPointers(true)
166414f1b3e8SDimitry Andric                   .SetSkipReferences(true)
166514f1b3e8SDimitry Andric                   .SetNonCacheable(true),
1666f3fbd1c0SDimitry Andric               "block pointer synthetic children",
1667f3fbd1c0SDimitry Andric               lldb_private::formatters::BlockPointerSyntheticFrontEndCreator));
1668344a3780SDimitry Andric       if (valobj.GetCompilerType().IsBlockPointerType()) {
1669f3fbd1c0SDimitry Andric         return formatter_sp;
1670f3fbd1c0SDimitry Andric       }
1671f3fbd1c0SDimitry Andric       return nullptr;
1672f3fbd1c0SDimitry Andric     });
1673e81d9d49SDimitry Andric   });
1674e81d9d49SDimitry Andric 
1675e81d9d49SDimitry Andric   return g_formatters;
1676e81d9d49SDimitry Andric }
167794994d37SDimitry Andric 
IsNilReference(ValueObject & valobj)1678b60736ecSDimitry Andric bool CPlusPlusLanguage::IsNilReference(ValueObject &valobj) {
1679b60736ecSDimitry Andric   if (!Language::LanguageIsCPlusPlus(valobj.GetObjectRuntimeLanguage()) ||
1680b60736ecSDimitry Andric       !valobj.IsPointerType())
1681b60736ecSDimitry Andric     return false;
1682b60736ecSDimitry Andric   bool canReadValue = true;
1683b60736ecSDimitry Andric   bool isZero = valobj.GetValueAsUnsigned(0, &canReadValue) == 0;
1684b60736ecSDimitry Andric   return canReadValue && isZero;
1685b60736ecSDimitry Andric }
1686b60736ecSDimitry Andric 
IsSourceFile(llvm::StringRef file_path) const168794994d37SDimitry Andric bool CPlusPlusLanguage::IsSourceFile(llvm::StringRef file_path) const {
168894994d37SDimitry Andric   const auto suffixes = {".cpp", ".cxx", ".c++", ".cc",  ".c",
168994994d37SDimitry Andric                          ".h",   ".hh",  ".hpp", ".hxx", ".h++"};
169094994d37SDimitry Andric   for (auto suffix : suffixes) {
16917fa27ce4SDimitry Andric     if (file_path.ends_with_insensitive(suffix))
169294994d37SDimitry Andric       return true;
169394994d37SDimitry Andric   }
169494994d37SDimitry Andric 
169594994d37SDimitry Andric   // Check if we're in a STL path (where the files usually have no extension
169694994d37SDimitry Andric   // that we could check for.
169794994d37SDimitry Andric   return file_path.contains("/usr/include/c++/");
169894994d37SDimitry Andric }
1699e3b55780SDimitry Andric 
GetFunctionDisplayName(const SymbolContext * sc,const ExecutionContext * exe_ctx,FunctionNameRepresentation representation,Stream & s)1700e3b55780SDimitry Andric bool CPlusPlusLanguage::GetFunctionDisplayName(
1701e3b55780SDimitry Andric     const SymbolContext *sc, const ExecutionContext *exe_ctx,
1702e3b55780SDimitry Andric     FunctionNameRepresentation representation, Stream &s) {
1703e3b55780SDimitry Andric   switch (representation) {
1704e3b55780SDimitry Andric   case FunctionNameRepresentation::eNameWithArgs: {
1705e3b55780SDimitry Andric     // Print the function name with arguments in it
1706e3b55780SDimitry Andric     if (sc->function) {
1707e3b55780SDimitry Andric       ExecutionContextScope *exe_scope =
1708e3b55780SDimitry Andric           exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr;
1709e3b55780SDimitry Andric       const char *cstr = sc->function->GetName().AsCString(nullptr);
1710e3b55780SDimitry Andric       if (cstr) {
1711e3b55780SDimitry Andric         const InlineFunctionInfo *inline_info = nullptr;
1712e3b55780SDimitry Andric         VariableListSP variable_list_sp;
1713e3b55780SDimitry Andric         bool get_function_vars = true;
1714e3b55780SDimitry Andric         if (sc->block) {
1715e3b55780SDimitry Andric           Block *inline_block = sc->block->GetContainingInlinedBlock();
1716e3b55780SDimitry Andric 
1717e3b55780SDimitry Andric           if (inline_block) {
1718e3b55780SDimitry Andric             get_function_vars = false;
17194df029ccSDimitry Andric             inline_info = inline_block->GetInlinedFunctionInfo();
1720e3b55780SDimitry Andric             if (inline_info)
1721e3b55780SDimitry Andric               variable_list_sp = inline_block->GetBlockVariableList(true);
1722e3b55780SDimitry Andric           }
1723e3b55780SDimitry Andric         }
1724e3b55780SDimitry Andric 
1725e3b55780SDimitry Andric         if (get_function_vars) {
1726e3b55780SDimitry Andric           variable_list_sp =
1727e3b55780SDimitry Andric               sc->function->GetBlock(true).GetBlockVariableList(true);
1728e3b55780SDimitry Andric         }
1729e3b55780SDimitry Andric 
1730e3b55780SDimitry Andric         if (inline_info) {
1731e3b55780SDimitry Andric           s.PutCString(cstr);
1732e3b55780SDimitry Andric           s.PutCString(" [inlined] ");
1733e3b55780SDimitry Andric           cstr = inline_info->GetName().GetCString();
1734e3b55780SDimitry Andric         }
1735e3b55780SDimitry Andric 
1736e3b55780SDimitry Andric         VariableList args;
1737e3b55780SDimitry Andric         if (variable_list_sp)
1738e3b55780SDimitry Andric           variable_list_sp->AppendVariablesWithScope(eValueTypeVariableArgument,
1739e3b55780SDimitry Andric                                                      args);
1740e3b55780SDimitry Andric         if (args.GetSize() > 0) {
1741e3b55780SDimitry Andric           if (!PrettyPrintFunctionNameWithArgs(s, cstr, exe_scope, args))
1742e3b55780SDimitry Andric             return false;
1743e3b55780SDimitry Andric         } else {
1744e3b55780SDimitry Andric           s.PutCString(cstr);
1745e3b55780SDimitry Andric         }
1746e3b55780SDimitry Andric         return true;
1747e3b55780SDimitry Andric       }
1748e3b55780SDimitry Andric     } else if (sc->symbol) {
1749e3b55780SDimitry Andric       const char *cstr = sc->symbol->GetName().AsCString(nullptr);
1750e3b55780SDimitry Andric       if (cstr) {
1751e3b55780SDimitry Andric         s.PutCString(cstr);
1752e3b55780SDimitry Andric         return true;
1753e3b55780SDimitry Andric       }
1754e3b55780SDimitry Andric     }
1755e3b55780SDimitry Andric   } break;
1756e3b55780SDimitry Andric   default:
1757e3b55780SDimitry Andric     return false;
1758e3b55780SDimitry Andric   }
1759e3b55780SDimitry Andric 
1760e3b55780SDimitry Andric   return false;
1761e3b55780SDimitry Andric }
1762