LLDB  mainline
FormatManager.h
Go to the documentation of this file.
1 //===-- FormatManager.h -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_DATAFORMATTERS_FORMATMANAGER_H
10 #define LLDB_DATAFORMATTERS_FORMATMANAGER_H
11 
12 #include <atomic>
13 #include <initializer_list>
14 #include <map>
15 #include <mutex>
16 #include <vector>
17 
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-public.h"
20 
27 
28 namespace lldb_private {
29 
30 // this file (and its. cpp) contain the low-level implementation of LLDB Data
31 // Visualization class DataVisualization is the high-level front-end of this
32 // feature clients should refer to that class as the entry-point into the data
33 // formatters unless they have a good reason to bypass it and prefer to use
34 // this file's objects directly
35 
38  typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
39 
40 public:
41  typedef std::map<lldb::LanguageType, LanguageCategory::UniquePointer>
43 
44  FormatManager();
45 
46  ~FormatManager() override = default;
47 
49  return m_named_summaries_map;
50  }
51 
52  void
53  EnableCategory(ConstString category_name,
55  EnableCategory(category_name, pos, {});
56  }
57 
58  void EnableCategory(ConstString category_name,
60  TypeCategoryMap::ValueSP category_sp;
61  if (m_categories_map.Get(category_name, category_sp) && category_sp) {
62  m_categories_map.Enable(category_sp, pos);
63  category_sp->AddLanguage(lang);
64  }
65  }
66 
67  void DisableCategory(ConstString category_name) {
68  m_categories_map.Disable(category_name);
69  }
70 
71  void
72  EnableCategory(const lldb::TypeCategoryImplSP &category,
74  m_categories_map.Enable(category, pos);
75  }
76 
77  void DisableCategory(const lldb::TypeCategoryImplSP &category) {
78  m_categories_map.Disable(category);
79  }
80 
81  void EnableAllCategories();
82 
83  void DisableAllCategories();
84 
85  bool DeleteCategory(ConstString category_name) {
86  return m_categories_map.Delete(category_name);
87  }
88 
89  void ClearCategories() { return m_categories_map.Clear(); }
90 
92 
93  lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index) {
94  return m_categories_map.GetAtIndex(index);
95  }
96 
98 
99  lldb::TypeCategoryImplSP GetCategory(const char *category_name = nullptr,
100  bool can_create = true) {
101  if (!category_name)
103  return GetCategory(ConstString(category_name));
104  }
105 
106  lldb::TypeCategoryImplSP GetCategory(ConstString category_name,
107  bool can_create = true);
108 
109  lldb::TypeFormatImplSP
110  GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp);
111 
112  lldb::TypeSummaryImplSP
113  GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp);
114 
115  lldb::TypeFilterImplSP
116  GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp);
117 
118  lldb::ScriptedSyntheticChildrenSP
119  GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp);
120 
121  lldb::TypeFormatImplSP GetFormat(ValueObject &valobj,
122  lldb::DynamicValueType use_dynamic);
123 
124  lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj,
125  lldb::DynamicValueType use_dynamic);
126 
127  lldb::SyntheticChildrenSP
129 
130  bool
134  bool only_enabled = true, const char **matching_category = nullptr,
135  TypeCategoryImpl::FormatCategoryItems *matching_type = nullptr) {
136  return m_categories_map.AnyMatches(type_name, items, only_enabled,
137  matching_category, matching_type);
138  }
139 
140  static bool GetFormatFromCString(const char *format_cstr,
141  bool partial_match_ok, lldb::Format &format);
142 
143  static char GetFormatAsFormatChar(lldb::Format format);
144 
145  static const char *GetFormatAsCString(lldb::Format format);
146 
147  // when DataExtractor dumps a vectorOfT, it uses a predefined format for each
148  // item this method returns it, or eFormatInvalid if vector_format is not a
149  // vectorOf
150  static lldb::Format GetSingleItemFormat(lldb::Format vector_format);
151 
152  // this returns true if the ValueObjectPrinter is *highly encouraged* to
153  // actually represent this ValueObject in one-liner format If this object has
154  // a summary formatter, however, we should not try and do one-lining, just
155  // let the summary do the right thing
156  bool ShouldPrintAsOneLiner(ValueObject &valobj);
157 
158  void Changed() override;
159 
161 
162  static FormattersMatchVector
164  FormattersMatchVector matches;
165  GetPossibleMatches(valobj, valobj.GetCompilerType(),
166  use_dynamic, matches, false, false, false, true);
167  return matches;
168  }
169 
171 
173 
174  static std::vector<lldb::LanguageType>
176 
177 private:
178  static void GetPossibleMatches(ValueObject &valobj,
179  CompilerType compiler_type,
180  lldb::DynamicValueType use_dynamic,
181  FormattersMatchVector &entries,
182  bool did_strip_ptr, bool did_strip_ref,
183  bool did_strip_typedef,
184  bool root_level = false);
185 
186  std::atomic<uint32_t> m_last_revision;
188  std::recursive_mutex m_language_categories_mutex;
192 
196 
197  template <typename ImplSP>
198  ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
199  template <typename ImplSP> ImplSP GetCached(FormattersMatchData &match_data);
200  template <typename ImplSP> ImplSP GetHardcoded(FormattersMatchData &);
201 
203 
204  // These functions are meant to initialize formatters that are very low-
205  // level/global in nature and do not naturally belong in any language. The
206  // intent is that most formatters go in language-specific categories.
207  // Eventually, the runtimes should also be allowed to vend their own
208  // formatters, and then one could put formatters that depend on specific
209  // library load events in the language runtimes, on an as-needed basis
210  void LoadSystemFormatters();
211 
212  void LoadVectorFormatters();
213 
214  friend class FormattersMatchData;
215 };
216 
217 } // namespace lldb_private
218 
219 #endif // LLDB_DATAFORMATTERS_FORMATMANAGER_H
lldb_private::FormattersMatchData
Definition: FormatClasses.h:84
lldb_private::FormatManager::~FormatManager
~FormatManager() override=default
lldb_private::FormatManager::GetPossibleMatches
static FormattersMatchVector GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
Definition: FormatManager.h:163
lldb-public.h
lldb_private::FormatManager::m_language_categories_mutex
std::recursive_mutex m_language_categories_mutex
Definition: FormatManager.h:188
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::FormatManager
Definition: FormatManager.h:36
lldb_private::FormatManager::AnyMatches
bool AnyMatches(ConstString type_name, TypeCategoryImpl::FormatCategoryItems items=TypeCategoryImpl::ALL_ITEM_TYPES, bool only_enabled=true, const char **matching_category=nullptr, TypeCategoryImpl::FormatCategoryItems *matching_type=nullptr)
Definition: FormatManager.h:131
lldb_private::FormatManager::GetFormat
lldb::TypeFormatImplSP GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
Definition: FormatManager.cpp:670
FormatClasses.h
lldb_private::FormatManager::GetNamedSummaryContainer
NamedSummariesMap & GetNamedSummaryContainer()
Definition: FormatManager.h:48
lldb_private::FormatManager::GetFormatAsFormatChar
static char GetFormatAsFormatChar(lldb::Format format)
Definition: FormatManager.cpp:144
lldb_private::FormatManager::GetCandidateLanguages
static std::vector< lldb::LanguageType > GetCandidateLanguages(lldb::LanguageType lang_type)
Definition: FormatManager.cpp:568
lldb_private::FormatManager::GetCached
ImplSP GetCached(FormattersMatchData &match_data)
Definition: FormatManager.cpp:638
lldb_private::FormatManager::GetCurrentRevision
uint32_t GetCurrentRevision() override
Definition: FormatManager.h:160
lldb_private::TypeCategoryMap::Enable
bool Enable(KeyType category_name, Position pos=Default)
Definition: TypeCategoryMap.cpp:46
lldb_private::FormatManager::DeleteCategory
bool DeleteCategory(ConstString category_name)
Definition: FormatManager.h:85
lldb_private::FormatCache
Definition: FormatCache.h:20
TypeCategoryMap.h
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::TypeCategoryImpl::ALL_ITEM_TYPES
static const uint16_t ALL_ITEM_TYPES
Definition: TypeCategory.h:72
lldb_private::FormatManager::GetCategory
lldb::TypeCategoryImplSP GetCategory(const char *category_name=nullptr, bool can_create=true)
Definition: FormatManager.h:99
lldb_private::FormattersContainer< TypeSummaryImpl >
lldb_private::TypeCategoryMap::AnyMatches
bool AnyMatches(ConstString type_name, TypeCategoryImpl::FormatCategoryItems items=TypeCategoryImpl::ALL_ITEM_TYPES, bool only_enabled=true, const char **matching_category=nullptr, TypeCategoryImpl::FormatCategoryItems *matching_type=nullptr)
Definition: TypeCategoryMap.cpp:156
lldb_private::FormatManager::EnableAllCategories
void EnableAllCategories()
Definition: FormatManager.cpp:158
lldb_private::FormatManager::m_last_revision
std::atomic< uint32_t > m_last_revision
Definition: FormatManager.h:186
lldb_private::FormatManager::GetFormatFromCString
static bool GetFormatFromCString(const char *format_cstr, bool partial_match_ok, lldb::Format &format)
Definition: FormatManager.cpp:126
lldb_private::FormatManager::DisableCategory
void DisableCategory(const lldb::TypeCategoryImplSP &category)
Definition: FormatManager.h:77
lldb_private::FormatManager::m_format_cache
FormatCache m_format_cache
Definition: FormatManager.h:187
lldb_private::TypeCategoryMap::GetAtIndex
lldb::TypeCategoryImplSP GetAtIndex(uint32_t)
Definition: TypeCategoryMap.cpp:247
lldb_private::FormatManager::Get
ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
Definition: FormatManager.cpp:611
lldb_private::FormatManager::m_vectortypes_category_name
ConstString m_vectortypes_category_name
Definition: FormatManager.h:195
lldb_private::TypeCategoryMap
Definition: TypeCategoryMap.h:24
lldb_private::TypeCategoryMap::ForEachCallback
std::function< bool(const ValueSP &)> ForEachCallback
Definition: TypeCategoryMap.h:35
lldb_private::FormatManager::GetSummaryForType
lldb::TypeSummaryImplSP GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
Definition: FormatManager.cpp:330
lldb_private::FormatManager::ShouldPrintAsOneLiner
bool ShouldPrintAsOneLiner(ValueObject &valobj)
Definition: FormatManager.cpp:458
lldb_private::FormatManager::m_categories_map
TypeCategoryMap m_categories_map
Definition: FormatManager.h:191
lldb_private::FormatManager::GetFormatAsCString
static const char * GetFormatAsCString(lldb::Format format)
Definition: FormatManager.cpp:152
lldb_private::FormatManager::m_named_summaries_map
NamedSummariesMap m_named_summaries_map
Definition: FormatManager.h:190
lldb_private::FormattersMatchVector
std::vector< FormattersMatchCandidate > FormattersMatchVector
Definition: FormatClasses.h:81
lldb_private::FormatManager::FormatManager
FormatManager()
Definition: FormatManager.cpp:687
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::FormatManager::LoadVectorFormatters
void LoadVectorFormatters()
lldb_private::TypeCategoryMap::Default
static const Position Default
Definition: TypeCategoryMap.h:40
lldb_private::FormatManager::GetCategoryAtIndex
lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index)
Definition: FormatManager.h:93
lldb-enumerations.h
lldb_private::TypeCategoryMap::ValueSP
ValueType::SharedPointer ValueSP
Definition: TypeCategoryMap.h:28
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:494
lldb_private::FormatManager::LanguageCategories
std::map< lldb::LanguageType, LanguageCategory::UniquePointer > LanguageCategories
Definition: FormatManager.h:42
lldb_private::FormatManager::DisableAllCategories
void DisableAllCategories()
Definition: FormatManager.cpp:167
lldb_private::LanguageCategory
Definition: LanguageCategory.h:21
lldb_private::TypeCategoryMap::Delete
bool Delete(KeyType name)
Definition: TypeCategoryMap.cpp:34
lldb_private::FormatManager::m_language_categories_map
LanguageCategories m_language_categories_map
Definition: FormatManager.h:189
lldb_private::FormatManager::NamedSummariesMap
FormattersContainer< TypeSummaryImpl > NamedSummariesMap
Definition: FormatManager.h:37
lldb_private::FormatManager::m_default_category_name
ConstString m_default_category_name
Definition: FormatManager.h:193
lldb_private::FormatManager::ClearCategories
void ClearCategories()
Definition: FormatManager.h:89
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
FormatCache.h
LanguageCategory.h
lldb_private::FormatManager::EnableCategory
void EnableCategory(const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
Definition: FormatManager.h:72
uint32_t
lldb_private::TypeCategoryMap::Disable
bool Disable(KeyType category_name)
Definition: TypeCategoryMap.cpp:54
lldb_private::FormatManager::LoadSystemFormatters
void LoadSystemFormatters()
Definition: FormatManager.cpp:702
lldb_private::FormatManager::GetFilterForType
lldb::TypeFilterImplSP GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)
Definition: FormatManager.cpp:354
lldb_private::FormatManager::GetCategoriesCount
uint32_t GetCategoriesCount()
Definition: FormatManager.h:91
lldb_private::FormatManager::DisableCategory
void DisableCategory(ConstString category_name)
Definition: FormatManager.h:67
lldb_private::ValueObject::GetCompilerType
CompilerType GetCompilerType()
Definition: ValueObject.h:352
lldb_private::FormatManager::GetHardcoded
ImplSP GetHardcoded(FormattersMatchData &)
Definition: FormatManager.cpp:599
uint16_t
lldb_private::FormatManager::GetFormatForType
lldb::TypeFormatImplSP GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)
Definition: FormatManager.cpp:306
lldb_private::FormatManager::GetSyntheticChildren
lldb::SyntheticChildrenSP GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
Definition: FormatManager.cpp:682
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::FormatManager::m_system_category_name
ConstString m_system_category_name
Definition: FormatManager.h:194
lldb_private::FormatManager::GetCategories
TypeCategoryMap & GetCategories()
Definition: FormatManager.h:202
TypeCategory.h
lldb_private::FormatManager::CategoryMapIterator
TypeCategoryMap::MapType::iterator CategoryMapIterator
Definition: FormatManager.h:38
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::FormatManager::Changed
void Changed() override
Definition: FormatManager.cpp:116
lldb_private::TypeCategoryMap::Get
bool Get(KeyType name, ValueSP &entry)
Definition: TypeCategoryMap.cpp:133
lldb_private::TypeCategoryMap::Clear
void Clear()
Definition: TypeCategoryMap.cpp:125
lldb_private::FormatManager::GetTypeForCache
static ConstString GetTypeForCache(ValueObject &, lldb::DynamicValueType)
Definition: FormatManager.cpp:556
lldb_private::FormatManager::EnableCategory
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos, lldb::LanguageType lang)
Definition: FormatManager.h:58
lldb_private::FormatManager::ForEachCategory
void ForEachCategory(TypeCategoryMap::ForEachCallback callback)
Definition: FormatManager.cpp:402
lldb_private::FormatManager::GetCategoryForLanguage
LanguageCategory * GetCategoryForLanguage(lldb::LanguageType lang_type)
Definition: FormatManager.cpp:586
lldb_private::TypeCategoryMap::GetCount
uint32_t GetCount()
Definition: TypeCategoryMap.h:78
FormattersContainer.h
lldb_private::FormatManager::GetSummaryFormat
lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
Definition: FormatManager.cpp:676
lldb_private::FormatManager::GetSyntheticForType
lldb::ScriptedSyntheticChildrenSP GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)
Definition: FormatManager.cpp:378
lldb_private::FormatManager::EnableCategory
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
Definition: FormatManager.h:53
lldb_private::FormatManager::GetSingleItemFormat
static lldb::Format GetSingleItemFormat(lldb::Format vector_format)
Definition: FormatManager.cpp:430
lldb_private::IFormatChangeListener
Definition: FormattersContainer.h:31