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
19#include "lldb/lldb-public.h"
20
27
28namespace 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
40public:
41 typedef std::map<lldb::LanguageType, LanguageCategory::UniquePointer>
43
45
46 ~FormatManager() override = default;
47
50 }
51
52 void
55 EnableCategory(category_name, pos, {});
56 }
57
58 void EnableCategory(ConstString category_name,
60 lldb::TypeCategoryImplSP 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
74 m_categories_map.Enable(category, pos);
75 }
76
78 m_categories_map.Disable(category);
79 }
80
82
84
85 bool DeleteCategory(ConstString category_name) {
86 return m_categories_map.Delete(category_name);
87 }
88
90
92
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
107 bool can_create = true);
108
111
114
117
120
122 lldb::DynamicValueType use_dynamic);
123
125 lldb::DynamicValueType use_dynamic);
126
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(candidate_type, items, only_enabled,
137 matching_category, matching_type);
138 }
139
140 static bool GetFormatFromCString(const char *format_cstr,
141 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
157
158 void Changed() override;
159
160 uint32_t GetCurrentRevision() override { return m_last_revision; }
161
164 FormattersMatchVector matches;
165 GetPossibleMatches(valobj, valobj.GetCompilerType(), use_dynamic, matches,
167 return matches;
168 }
169
171
173
174 static std::vector<lldb::LanguageType>
176
177private:
178 static void GetPossibleMatches(ValueObject &valobj,
179 CompilerType compiler_type,
180 lldb::DynamicValueType use_dynamic,
181 FormattersMatchVector &entries,
183 bool root_level = false);
184
185 std::atomic<uint32_t> m_last_revision;
187 std::recursive_mutex m_language_categories_mutex;
191
195
196 template <typename ImplSP>
197 ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
198 template <typename ImplSP> ImplSP GetCached(FormattersMatchData &match_data);
199 template <typename ImplSP> ImplSP GetHardcoded(FormattersMatchData &);
200
202
203 // These functions are meant to initialize formatters that are very low-
204 // level/global in nature and do not naturally belong in any language. The
205 // intent is that most formatters go in language-specific categories.
206 // Eventually, the runtimes should also be allowed to vend their own
207 // formatters, and then one could put formatters that depend on specific
208 // library load events in the language runtimes, on an as-needed basis
210
212
214};
215
216} // namespace lldb_private
217
218#endif // LLDB_DATAFORMATTERS_FORMATMANAGER_H
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
NamedSummariesMap & GetNamedSummaryContainer()
Definition: FormatManager.h:48
ImplSP GetHardcoded(FormattersMatchData &)
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
Definition: FormatManager.h:53
~FormatManager() override=default
lldb::TypeFormatImplSP GetFormatForType(lldb::TypeNameSpecifierImplSP type_sp)
lldb::TypeFormatImplSP GetFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
lldb::TypeFilterImplSP GetFilterForType(lldb::TypeNameSpecifierImplSP type_sp)
std::map< lldb::LanguageType, LanguageCategory::UniquePointer > LanguageCategories
Definition: FormatManager.h:42
std::recursive_mutex m_language_categories_mutex
static ConstString GetTypeForCache(ValueObject &, lldb::DynamicValueType)
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos, lldb::LanguageType lang)
Definition: FormatManager.h:58
TypeCategoryMap & GetCategories()
bool ShouldPrintAsOneLiner(ValueObject &valobj)
void EnableCategory(const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
Definition: FormatManager.h:72
ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static const char * GetFormatAsCString(lldb::Format format)
static bool GetFormatFromCString(const char *format_cstr, lldb::Format &format)
FormattersContainer< TypeSummaryImpl > NamedSummariesMap
Definition: FormatManager.h:37
lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static FormattersMatchVector GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
lldb::TypeCategoryImplSP GetCategory(const char *category_name=nullptr, bool can_create=true)
Definition: FormatManager.h:99
static std::vector< lldb::LanguageType > GetCandidateLanguages(lldb::LanguageType lang_type)
static lldb::Format GetSingleItemFormat(lldb::Format vector_format)
void ForEachCategory(TypeCategoryMap::ForEachCallback callback)
TypeCategoryMap::MapType::iterator CategoryMapIterator
Definition: FormatManager.h:38
NamedSummariesMap m_named_summaries_map
std::atomic< uint32_t > m_last_revision
ImplSP GetCached(FormattersMatchData &match_data)
lldb::ScriptedSyntheticChildrenSP GetSyntheticForType(lldb::TypeNameSpecifierImplSP type_sp)
bool DeleteCategory(ConstString category_name)
Definition: FormatManager.h:85
bool AnyMatches(const FormattersMatchCandidate &candidate_type, TypeCategoryImpl::FormatCategoryItems items=TypeCategoryImpl::ALL_ITEM_TYPES, bool only_enabled=true, const char **matching_category=nullptr, TypeCategoryImpl::FormatCategoryItems *matching_type=nullptr)
TypeCategoryMap m_categories_map
lldb::TypeSummaryImplSP GetSummaryForType(lldb::TypeNameSpecifierImplSP type_sp)
lldb::SyntheticChildrenSP GetSyntheticChildren(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static char GetFormatAsFormatChar(lldb::Format format)
lldb::TypeCategoryImplSP GetCategoryAtIndex(size_t index)
Definition: FormatManager.h:93
uint32_t GetCurrentRevision() override
ConstString m_vectortypes_category_name
void DisableCategory(ConstString category_name)
Definition: FormatManager.h:67
void DisableCategory(const lldb::TypeCategoryImplSP &category)
Definition: FormatManager.h:77
LanguageCategory * GetCategoryForLanguage(lldb::LanguageType lang_type)
LanguageCategories m_language_categories_map
static const uint16_t ALL_ITEM_TYPES
Definition: TypeCategory.h:176
std::function< bool(const lldb::TypeCategoryImplSP &)> ForEachCallback
bool AnyMatches(const FormattersMatchCandidate &candidate_type, TypeCategoryImpl::FormatCategoryItems items=TypeCategoryImpl::ALL_ITEM_TYPES, bool only_enabled=true, const char **matching_category=nullptr, TypeCategoryImpl::FormatCategoryItems *matching_type=nullptr)
bool Enable(KeyType category_name, Position pos=Default)
lldb::TypeCategoryImplSP GetAtIndex(uint32_t)
bool Disable(KeyType category_name)
static const Position Default
bool Get(KeyType name, lldb::TypeCategoryImplSP &entry)
CompilerType GetCompilerType()
Definition: ValueObject.h:352
A class that represents a running process on the host machine.
std::vector< FormattersMatchCandidate > FormattersMatchVector
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:471
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
Definition: lldb-forward.h:468
std::shared_ptr< lldb_private::TypeNameSpecifierImpl > TypeNameSpecifierImplSP
Definition: lldb-forward.h:470
Format
Display format definitions.
LanguageType
Programming language type.
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
Definition: lldb-forward.h:441
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
Definition: lldb-forward.h:459
std::shared_ptr< lldb_private::ScriptedSyntheticChildren > ScriptedSyntheticChildrenSP
Definition: lldb-forward.h:474
std::shared_ptr< lldb_private::TypeFilterImpl > TypeFilterImplSP
Definition: lldb-forward.h:464