]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormatManager.h
Slightly reduce diffs against upstream lldb, and comment out PDB support.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / FormatManager.h
1 //===-- FormatManager.h -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_FormatManager_h_
11 #define lldb_FormatManager_h_
12
13 // C Includes
14 // C++ Includes
15 #include <atomic>
16 #include <initializer_list>
17 #include <map>
18 #include <mutex>
19 #include <vector>
20
21 // Other libraries and framework includes
22 // Project includes
23 #include "lldb/lldb-public.h"
24 #include "lldb/lldb-enumerations.h"
25
26 #include "lldb/DataFormatters/FormatCache.h"
27 #include "lldb/DataFormatters/FormatClasses.h"
28 #include "lldb/DataFormatters/FormattersContainer.h"
29 #include "lldb/DataFormatters/LanguageCategory.h"
30 #include "lldb/DataFormatters/TypeCategory.h"
31 #include "lldb/DataFormatters/TypeCategoryMap.h"
32
33 namespace lldb_private {
34     
35 // this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization
36 // class DataVisualization is the high-level front-end of this feature
37 // clients should refer to that class as the entry-point into the data formatters
38 // unless they have a good reason to bypass it and prefer to use this file's objects directly
39
40 class FormatManager : public IFormatChangeListener
41 {
42     typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap;
43     typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
44 public:
45     typedef std::map<lldb::LanguageType, LanguageCategory::UniquePointer> LanguageCategories;
46     
47     FormatManager();
48     
49     ~FormatManager() override = default;
50
51     NamedSummariesMap&
52     GetNamedSummaryContainer ()
53     {
54         return m_named_summaries_map;
55     }
56     
57     void
58     EnableCategory (const ConstString& category_name,
59                     TypeCategoryMap::Position pos = TypeCategoryMap::Default)
60     {
61         EnableCategory(category_name,
62                        pos,
63                        std::initializer_list<lldb::LanguageType>());
64     }
65
66     void
67     EnableCategory (const ConstString& category_name,
68                     TypeCategoryMap::Position pos,
69                     lldb::LanguageType lang)
70     {
71         std::initializer_list<lldb::LanguageType> langs = {lang};
72         EnableCategory(category_name,
73                        pos,
74                        langs);
75     }
76     
77     void
78     EnableCategory (const ConstString& category_name,
79                     TypeCategoryMap::Position pos = TypeCategoryMap::Default,
80                     std::initializer_list<lldb::LanguageType> langs = {})
81     {
82         TypeCategoryMap::ValueSP category_sp;
83         if (m_categories_map.Get(category_name, category_sp) && category_sp)
84         {
85             m_categories_map.Enable(category_sp, pos);
86             for (const lldb::LanguageType lang : langs)
87                 category_sp->AddLanguage(lang);
88         }
89     }
90     
91     void
92     DisableCategory (const ConstString& category_name)
93     {
94         m_categories_map.Disable(category_name);
95     }
96     
97     void
98     EnableCategory (const lldb::TypeCategoryImplSP& category,
99                     TypeCategoryMap::Position pos = TypeCategoryMap::Default)
100     {
101         m_categories_map.Enable(category,
102                                 pos);
103     }
104     
105     void
106     DisableCategory (const lldb::TypeCategoryImplSP& category)
107     {
108         m_categories_map.Disable(category);
109     }
110     
111     void
112     EnableAllCategories ();
113     
114     void
115     DisableAllCategories ();
116     
117     bool
118     DeleteCategory (const ConstString& category_name)
119     {
120         return m_categories_map.Delete(category_name);
121     }
122     
123     void
124     ClearCategories ()
125     {
126         return m_categories_map.Clear();
127     }
128     
129     uint32_t
130     GetCategoriesCount ()
131     {
132         return m_categories_map.GetCount();
133     }
134     
135     lldb::TypeCategoryImplSP
136     GetCategoryAtIndex (size_t index)
137     {
138         return m_categories_map.GetAtIndex(index);
139     }
140     
141     void
142     ForEachCategory (TypeCategoryMap::ForEachCallback callback);
143     
144     lldb::TypeCategoryImplSP
145     GetCategory(const char* category_name = nullptr,
146                 bool can_create = true)
147     {
148         if (!category_name)
149             return GetCategory(m_default_category_name);
150         return GetCategory(ConstString(category_name));
151     }
152     
153     lldb::TypeCategoryImplSP
154     GetCategory (const ConstString& category_name,
155                  bool can_create = true);
156
157     lldb::TypeFormatImplSP
158     GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp);
159     
160     lldb::TypeSummaryImplSP
161     GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp);
162
163     lldb::TypeFilterImplSP
164     GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp);
165
166 #ifndef LLDB_DISABLE_PYTHON
167     lldb::ScriptedSyntheticChildrenSP
168     GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp);
169 #endif
170     
171 #ifndef LLDB_DISABLE_PYTHON
172     lldb::SyntheticChildrenSP
173     GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp);
174 #endif
175     
176     lldb::TypeValidatorImplSP
177     GetValidatorForType (lldb::TypeNameSpecifierImplSP type_sp);
178     
179     lldb::TypeFormatImplSP
180     GetFormat (ValueObject& valobj,
181                lldb::DynamicValueType use_dynamic);
182     
183     lldb::TypeSummaryImplSP
184     GetSummaryFormat (ValueObject& valobj,
185                       lldb::DynamicValueType use_dynamic);
186
187 #ifndef LLDB_DISABLE_PYTHON
188     lldb::SyntheticChildrenSP
189     GetSyntheticChildren (ValueObject& valobj,
190                           lldb::DynamicValueType use_dynamic);
191 #endif
192     
193     lldb::TypeValidatorImplSP
194     GetValidator (ValueObject& valobj,
195                   lldb::DynamicValueType use_dynamic);
196     
197     bool
198     AnyMatches(ConstString type_name,
199                TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
200                bool only_enabled = true,
201                const char** matching_category = nullptr,
202                TypeCategoryImpl::FormatCategoryItems* matching_type = nullptr)
203     {
204         return m_categories_map.AnyMatches(type_name,
205                                            items,
206                                            only_enabled,
207                                            matching_category,
208                                            matching_type);
209     }
210
211     static bool
212     GetFormatFromCString (const char *format_cstr,
213                           bool partial_match_ok,
214                           lldb::Format &format);
215
216     static char
217     GetFormatAsFormatChar (lldb::Format format);
218
219     static const char *
220     GetFormatAsCString (lldb::Format format);
221     
222     // if the user tries to add formatters for, say, "struct Foo"
223     // those will not match any type because of the way we strip qualifiers from typenames
224     // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo
225     // and strips the unnecessary qualifier
226     static ConstString
227     GetValidTypeName (const ConstString& type);
228     
229     // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item
230     // this method returns it, or eFormatInvalid if vector_format is not a vectorOf
231     static lldb::Format
232     GetSingleItemFormat (lldb::Format vector_format);
233     
234     // this returns true if the ValueObjectPrinter is *highly encouraged*
235     // to actually represent this ValueObject in one-liner format
236     // If this object has a summary formatter, however, we should not
237     // try and do one-lining, just let the summary do the right thing
238     bool
239     ShouldPrintAsOneLiner (ValueObject& valobj);
240     
241     void
242     Changed () override;
243     
244     uint32_t
245     GetCurrentRevision () override
246     {
247         return m_last_revision;
248     }
249
250     static FormattersMatchVector
251     GetPossibleMatches (ValueObject& valobj,
252                         lldb::DynamicValueType use_dynamic)
253     {
254         FormattersMatchVector matches;
255         GetPossibleMatches (valobj,
256                             valobj.GetCompilerType(),
257                             lldb_private::eFormatterChoiceCriterionDirectChoice,
258                             use_dynamic,
259                             matches,
260                             false,
261                             false,
262                             false,
263                             true);
264         return matches;
265     }
266     
267     static ConstString
268     GetTypeForCache (ValueObject&, lldb::DynamicValueType);
269     
270     LanguageCategory*
271     GetCategoryForLanguage (lldb::LanguageType lang_type);
272
273     static std::vector<lldb::LanguageType>
274     GetCandidateLanguages (lldb::LanguageType lang_type);
275
276 private:
277     static std::vector<lldb::LanguageType>
278     GetCandidateLanguages (ValueObject& valobj);
279     
280     static void
281     GetPossibleMatches (ValueObject& valobj,
282                         CompilerType compiler_type,
283                         uint32_t reason,
284                         lldb::DynamicValueType use_dynamic,
285                         FormattersMatchVector& entries,
286                         bool did_strip_ptr,
287                         bool did_strip_ref,
288                         bool did_strip_typedef,
289                         bool root_level = false);
290
291     std::atomic<uint32_t> m_last_revision;
292     FormatCache m_format_cache;
293     std::recursive_mutex m_language_categories_mutex;
294     LanguageCategories m_language_categories_map;
295     NamedSummariesMap m_named_summaries_map;
296     TypeCategoryMap m_categories_map;
297     
298     ConstString m_default_category_name;
299     ConstString m_system_category_name;
300     ConstString m_vectortypes_category_name;
301     
302     lldb::TypeFormatImplSP
303     GetHardcodedFormat (FormattersMatchData&);
304     
305     lldb::TypeSummaryImplSP
306     GetHardcodedSummaryFormat (FormattersMatchData&);
307
308     lldb::SyntheticChildrenSP
309     GetHardcodedSyntheticChildren (FormattersMatchData&);
310     
311     lldb::TypeValidatorImplSP
312     GetHardcodedValidator (FormattersMatchData&);
313     
314     TypeCategoryMap&
315     GetCategories ()
316     {
317         return m_categories_map;
318     }
319     
320     // These functions are meant to initialize formatters that are very low-level/global in nature
321     // and do not naturally belong in any language. The intent is that most formatters go in
322     // language-specific categories. Eventually, the runtimes should also be allowed to vend their
323     // own formatters, and then one could put formatters that depend on specific library load events
324     // in the language runtimes, on an as-needed basis
325     void
326     LoadSystemFormatters ();
327     
328     void
329     LoadVectorFormatters ();
330     
331     friend class FormattersMatchData;
332 };
333     
334 } // namespace lldb_private
335     
336 #endif // lldb_FormatManager_h_