]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormatManager.h
Upgrade Unbound to 1.6.8. More to follow.
[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-enumerations.h"
24 #include "lldb/lldb-public.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
36 // Visualization
37 // class DataVisualization is the high-level front-end of this feature
38 // clients should refer to that class as the entry-point into the data
39 // formatters
40 // unless they have a good reason to bypass it and prefer to use this file's
41 // objects directly
42
43 class FormatManager : public IFormatChangeListener {
44   typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap;
45   typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
46
47 public:
48   typedef std::map<lldb::LanguageType, LanguageCategory::UniquePointer>
49       LanguageCategories;
50
51   FormatManager();
52
53   ~FormatManager() override = default;
54
55   NamedSummariesMap &GetNamedSummaryContainer() {
56     return m_named_summaries_map;
57   }
58
59   void
60   EnableCategory(const ConstString &category_name,
61                  TypeCategoryMap::Position pos = TypeCategoryMap::Default) {
62     EnableCategory(category_name, pos,
63                    std::initializer_list<lldb::LanguageType>());
64   }
65
66   void EnableCategory(const ConstString &category_name,
67                       TypeCategoryMap::Position pos, lldb::LanguageType lang) {
68     std::initializer_list<lldb::LanguageType> langs = {lang};
69     EnableCategory(category_name, pos, langs);
70   }
71
72   void EnableCategory(const ConstString &category_name,
73                       TypeCategoryMap::Position pos = TypeCategoryMap::Default,
74                       std::initializer_list<lldb::LanguageType> langs = {}) {
75     TypeCategoryMap::ValueSP category_sp;
76     if (m_categories_map.Get(category_name, category_sp) && category_sp) {
77       m_categories_map.Enable(category_sp, pos);
78       for (const lldb::LanguageType lang : langs)
79         category_sp->AddLanguage(lang);
80     }
81   }
82
83   void DisableCategory(const ConstString &category_name) {
84     m_categories_map.Disable(category_name);
85   }
86
87   void
88   EnableCategory(const lldb::TypeCategoryImplSP &category,
89                  TypeCategoryMap::Position pos = TypeCategoryMap::Default) {
90     m_categories_map.Enable(category, pos);
91   }
92
93   void DisableCategory(const lldb::TypeCategoryImplSP &category) {
94     m_categories_map.Disable(category);
95   }
96
97   void EnableAllCategories();
98
99   void DisableAllCategories();
100
101   bool DeleteCategory(const ConstString &category_name) {
102     return m_categories_map.Delete(category_name);
103   }
104
105   void ClearCategories() { return m_categories_map.Clear(); }
106
107   uint32_t GetCategoriesCount() { return m_categories_map.GetCount(); }
108
109   lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index) {
110     return m_categories_map.GetAtIndex(index);
111   }
112
113   void ForEachCategory(TypeCategoryMap::ForEachCallback callback);
114
115   lldb::TypeCategoryImplSP GetCategory(const char *category_name = nullptr,
116                                        bool can_create = true) {
117     if (!category_name)
118       return GetCategory(m_default_category_name);
119     return GetCategory(ConstString(category_name));
120   }
121
122   lldb::TypeCategoryImplSP GetCategory(const ConstString &category_name,
123                                        bool can_create = true);
124
125   lldb::TypeFormatImplSP
126   GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp);
127
128   lldb::TypeSummaryImplSP
129   GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp);
130
131   lldb::TypeFilterImplSP
132   GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp);
133
134 #ifndef LLDB_DISABLE_PYTHON
135   lldb::ScriptedSyntheticChildrenSP
136   GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp);
137 #endif
138
139 #ifndef LLDB_DISABLE_PYTHON
140   lldb::SyntheticChildrenSP
141   GetSyntheticChildrenForType(lldb::TypeNameSpecifierImplSP type_sp);
142 #endif
143
144   lldb::TypeValidatorImplSP
145   GetValidatorForType(lldb::TypeNameSpecifierImplSP type_sp);
146
147   lldb::TypeFormatImplSP GetFormat(ValueObject &valobj,
148                                    lldb::DynamicValueType use_dynamic);
149
150   lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj,
151                                            lldb::DynamicValueType use_dynamic);
152
153 #ifndef LLDB_DISABLE_PYTHON
154   lldb::SyntheticChildrenSP
155   GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
156 #endif
157
158   lldb::TypeValidatorImplSP GetValidator(ValueObject &valobj,
159                                          lldb::DynamicValueType use_dynamic);
160
161   bool
162   AnyMatches(ConstString type_name,
163              TypeCategoryImpl::FormatCategoryItems items =
164                  TypeCategoryImpl::ALL_ITEM_TYPES,
165              bool only_enabled = true, const char **matching_category = nullptr,
166              TypeCategoryImpl::FormatCategoryItems *matching_type = nullptr) {
167     return m_categories_map.AnyMatches(type_name, items, only_enabled,
168                                        matching_category, matching_type);
169   }
170
171   static bool GetFormatFromCString(const char *format_cstr,
172                                    bool partial_match_ok, lldb::Format &format);
173
174   static char GetFormatAsFormatChar(lldb::Format format);
175
176   static const char *GetFormatAsCString(lldb::Format format);
177
178   // if the user tries to add formatters for, say, "struct Foo"
179   // those will not match any type because of the way we strip qualifiers from
180   // typenames
181   // this method looks for the case where the user is adding a
182   // "class","struct","enum" or "union" Foo
183   // and strips the unnecessary qualifier
184   static ConstString GetValidTypeName(const ConstString &type);
185
186   // when DataExtractor dumps a vectorOfT, it uses a predefined format for each
187   // item
188   // this method returns it, or eFormatInvalid if vector_format is not a
189   // vectorOf
190   static lldb::Format GetSingleItemFormat(lldb::Format vector_format);
191
192   // this returns true if the ValueObjectPrinter is *highly encouraged*
193   // to actually represent this ValueObject in one-liner format
194   // If this object has a summary formatter, however, we should not
195   // try and do one-lining, just let the summary do the right thing
196   bool ShouldPrintAsOneLiner(ValueObject &valobj);
197
198   void Changed() override;
199
200   uint32_t GetCurrentRevision() override { return m_last_revision; }
201
202   static FormattersMatchVector
203   GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) {
204     FormattersMatchVector matches;
205     GetPossibleMatches(valobj, valobj.GetCompilerType(),
206                        lldb_private::eFormatterChoiceCriterionDirectChoice,
207                        use_dynamic, matches, false, false, false, true);
208     return matches;
209   }
210
211   static ConstString GetTypeForCache(ValueObject &, lldb::DynamicValueType);
212
213   LanguageCategory *GetCategoryForLanguage(lldb::LanguageType lang_type);
214
215   static std::vector<lldb::LanguageType>
216   GetCandidateLanguages(lldb::LanguageType lang_type);
217
218 private:
219   static std::vector<lldb::LanguageType>
220   GetCandidateLanguages(ValueObject &valobj);
221
222   static void GetPossibleMatches(ValueObject &valobj,
223                                  CompilerType compiler_type, uint32_t reason,
224                                  lldb::DynamicValueType use_dynamic,
225                                  FormattersMatchVector &entries,
226                                  bool did_strip_ptr, bool did_strip_ref,
227                                  bool did_strip_typedef,
228                                  bool root_level = false);
229
230   std::atomic<uint32_t> m_last_revision;
231   FormatCache m_format_cache;
232   std::recursive_mutex m_language_categories_mutex;
233   LanguageCategories m_language_categories_map;
234   NamedSummariesMap m_named_summaries_map;
235   TypeCategoryMap m_categories_map;
236
237   ConstString m_default_category_name;
238   ConstString m_system_category_name;
239   ConstString m_vectortypes_category_name;
240
241   lldb::TypeFormatImplSP GetHardcodedFormat(FormattersMatchData &);
242
243   lldb::TypeSummaryImplSP GetHardcodedSummaryFormat(FormattersMatchData &);
244
245   lldb::SyntheticChildrenSP
246   GetHardcodedSyntheticChildren(FormattersMatchData &);
247
248   lldb::TypeValidatorImplSP GetHardcodedValidator(FormattersMatchData &);
249
250   TypeCategoryMap &GetCategories() { return m_categories_map; }
251
252   // These functions are meant to initialize formatters that are very
253   // low-level/global in nature
254   // and do not naturally belong in any language. The intent is that most
255   // formatters go in
256   // language-specific categories. Eventually, the runtimes should also be
257   // allowed to vend their
258   // own formatters, and then one could put formatters that depend on specific
259   // library load events
260   // in the language runtimes, on an as-needed basis
261   void LoadSystemFormatters();
262
263   void LoadVectorFormatters();
264
265   friend class FormattersMatchData;
266 };
267
268 } // namespace lldb_private
269
270 #endif // lldb_FormatManager_h_