File indexing completed on 2026-05-10 08:42:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_DATAFORMATTERS_FORMATMANAGER_H
0010 #define LLDB_DATAFORMATTERS_FORMATMANAGER_H
0011
0012 #include <atomic>
0013 #include <initializer_list>
0014 #include <map>
0015 #include <mutex>
0016 #include <vector>
0017
0018 #include "lldb/lldb-enumerations.h"
0019 #include "lldb/lldb-public.h"
0020
0021 #include "lldb/DataFormatters/FormatCache.h"
0022 #include "lldb/DataFormatters/FormatClasses.h"
0023 #include "lldb/DataFormatters/FormattersContainer.h"
0024 #include "lldb/DataFormatters/LanguageCategory.h"
0025 #include "lldb/DataFormatters/TypeCategory.h"
0026 #include "lldb/DataFormatters/TypeCategoryMap.h"
0027
0028 namespace lldb_private {
0029
0030
0031
0032
0033
0034
0035
0036 class FormatManager : public IFormatChangeListener {
0037 typedef FormattersContainer<TypeSummaryImpl> NamedSummariesMap;
0038 typedef TypeCategoryMap::MapType::iterator CategoryMapIterator;
0039
0040 public:
0041 typedef std::map<lldb::LanguageType, LanguageCategory::UniquePointer>
0042 LanguageCategories;
0043
0044 FormatManager();
0045
0046 ~FormatManager() override = default;
0047
0048 NamedSummariesMap &GetNamedSummaryContainer() {
0049 return m_named_summaries_map;
0050 }
0051
0052 void
0053 EnableCategory(ConstString category_name,
0054 TypeCategoryMap::Position pos = TypeCategoryMap::Default) {
0055 EnableCategory(category_name, pos, {});
0056 }
0057
0058 void EnableCategory(ConstString category_name,
0059 TypeCategoryMap::Position pos, lldb::LanguageType lang) {
0060 lldb::TypeCategoryImplSP category_sp;
0061 if (m_categories_map.Get(category_name, category_sp) && category_sp) {
0062 m_categories_map.Enable(category_sp, pos);
0063 category_sp->AddLanguage(lang);
0064 }
0065 }
0066
0067 void DisableCategory(ConstString category_name) {
0068 m_categories_map.Disable(category_name);
0069 }
0070
0071 void
0072 EnableCategory(const lldb::TypeCategoryImplSP &category,
0073 TypeCategoryMap::Position pos = TypeCategoryMap::Default) {
0074 m_categories_map.Enable(category, pos);
0075 }
0076
0077 void DisableCategory(const lldb::TypeCategoryImplSP &category) {
0078 m_categories_map.Disable(category);
0079 }
0080
0081 void EnableAllCategories();
0082
0083 void DisableAllCategories();
0084
0085 bool DeleteCategory(ConstString category_name) {
0086 return m_categories_map.Delete(category_name);
0087 }
0088
0089 void ClearCategories() { return m_categories_map.Clear(); }
0090
0091 uint32_t GetCategoriesCount() { return m_categories_map.GetCount(); }
0092
0093 lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index) {
0094 return m_categories_map.GetAtIndex(index);
0095 }
0096
0097 void ForEachCategory(TypeCategoryMap::ForEachCallback callback);
0098
0099 lldb::TypeCategoryImplSP GetCategory(const char *category_name = nullptr,
0100 bool can_create = true) {
0101 if (!category_name)
0102 return GetCategory(m_default_category_name);
0103 return GetCategory(ConstString(category_name));
0104 }
0105
0106 lldb::TypeCategoryImplSP GetCategory(ConstString category_name,
0107 bool can_create = true);
0108
0109 lldb::TypeFormatImplSP
0110 GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp);
0111
0112 lldb::TypeSummaryImplSP
0113 GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp);
0114
0115 lldb::TypeFilterImplSP
0116 GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp);
0117
0118 lldb::ScriptedSyntheticChildrenSP
0119 GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp);
0120
0121 lldb::TypeFormatImplSP GetFormat(ValueObject &valobj,
0122 lldb::DynamicValueType use_dynamic);
0123
0124 lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj,
0125 lldb::DynamicValueType use_dynamic);
0126
0127 lldb::SyntheticChildrenSP
0128 GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
0129
0130 bool
0131 AnyMatches(const FormattersMatchCandidate &candidate_type,
0132 TypeCategoryImpl::FormatCategoryItems items =
0133 TypeCategoryImpl::ALL_ITEM_TYPES,
0134 bool only_enabled = true, const char **matching_category = nullptr,
0135 TypeCategoryImpl::FormatCategoryItems *matching_type = nullptr) {
0136 return m_categories_map.AnyMatches(candidate_type, items, only_enabled,
0137 matching_category, matching_type);
0138 }
0139
0140 static bool GetFormatFromCString(const char *format_cstr,
0141 lldb::Format &format);
0142
0143 static char GetFormatAsFormatChar(lldb::Format format);
0144
0145 static const char *GetFormatAsCString(lldb::Format format);
0146
0147
0148
0149
0150 static lldb::Format GetSingleItemFormat(lldb::Format vector_format);
0151
0152
0153
0154
0155
0156 bool ShouldPrintAsOneLiner(ValueObject &valobj);
0157
0158 void Changed() override;
0159
0160 uint32_t GetCurrentRevision() override { return m_last_revision; }
0161
0162 static FormattersMatchVector
0163 GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic) {
0164 FormattersMatchVector matches;
0165 GetPossibleMatches(valobj, valobj.GetCompilerType(), use_dynamic, matches,
0166 FormattersMatchCandidate::Flags(), true);
0167 return matches;
0168 }
0169
0170 static ConstString GetTypeForCache(ValueObject &, lldb::DynamicValueType);
0171
0172 LanguageCategory *GetCategoryForLanguage(lldb::LanguageType lang_type);
0173
0174 static std::vector<lldb::LanguageType>
0175 GetCandidateLanguages(lldb::LanguageType lang_type);
0176
0177 private:
0178 static void GetPossibleMatches(ValueObject &valobj,
0179 CompilerType compiler_type,
0180 lldb::DynamicValueType use_dynamic,
0181 FormattersMatchVector &entries,
0182 FormattersMatchCandidate::Flags current_flags,
0183 bool root_level = false);
0184
0185 std::atomic<uint32_t> m_last_revision;
0186 FormatCache m_format_cache;
0187 std::recursive_mutex m_language_categories_mutex;
0188 LanguageCategories m_language_categories_map;
0189 NamedSummariesMap m_named_summaries_map;
0190 TypeCategoryMap m_categories_map;
0191
0192 ConstString m_default_category_name;
0193 ConstString m_system_category_name;
0194 ConstString m_vectortypes_category_name;
0195
0196 template <typename ImplSP>
0197 ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
0198 template <typename ImplSP> ImplSP GetCached(FormattersMatchData &match_data);
0199 template <typename ImplSP> ImplSP GetHardcoded(FormattersMatchData &);
0200
0201 TypeCategoryMap &GetCategories() { return m_categories_map; }
0202
0203
0204
0205
0206
0207
0208
0209 void LoadSystemFormatters();
0210
0211 void LoadVectorFormatters();
0212
0213 friend class FormattersMatchData;
0214 };
0215
0216 }
0217
0218 #endif