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
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
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
89 void ClearCategories() { return m_categories_map.Clear(); }
90
91 uint32_t GetCategoriesCount() { return m_categories_map.GetCount(); }
92
94 return m_categories_map.GetAtIndex(index);
95 }
96
98
100 bool can_create = true);
101
104
107
110
113
115 lldb::DynamicValueType use_dynamic);
116
118 lldb::DynamicValueType use_dynamic);
119
122
123 static bool GetFormatFromCString(const char *format_cstr,
124 lldb::Format &format);
125
126 static char GetFormatAsFormatChar(lldb::Format format);
127
128 static const char *GetFormatAsCString(lldb::Format format);
129
130 // when DataExtractor dumps a vectorOfT, it uses a predefined format for each
131 // item this method returns it, or eFormatInvalid if vector_format is not a
132 // vectorOf
133 static lldb::Format GetSingleItemFormat(lldb::Format vector_format);
134
135 // this returns true if the ValueObjectPrinter is *highly encouraged* to
136 // actually represent this ValueObject in one-liner format If this object has
137 // a summary formatter, however, we should not try and do one-lining, just
138 // let the summary do the right thing
140
141 void Changed() override;
142
143 uint32_t GetCurrentRevision() override { return m_last_revision; }
144
147 FormattersMatchVector matches;
148 GetPossibleMatches(valobj, valobj.GetCompilerType(), use_dynamic, matches,
150 return matches;
151 }
152
154
156
157 static std::vector<lldb::LanguageType>
159
160private:
161 static void GetPossibleMatches(ValueObject &valobj,
162 CompilerType compiler_type,
163 lldb::DynamicValueType use_dynamic,
164 FormattersMatchVector &entries,
166 bool root_level = false,
167 uint32_t ptr_stripped_depth = 0);
168
169 std::atomic<uint32_t> m_last_revision;
171 std::recursive_mutex m_language_categories_mutex;
175
179
180 template <typename ImplSP>
181 ImplSP Get(ValueObject &valobj, lldb::DynamicValueType use_dynamic);
182 template <typename ImplSP> ImplSP GetCached(FormattersMatchData &match_data);
183 template <typename ImplSP> ImplSP GetHardcoded(FormattersMatchData &);
184
186
187 // These functions are meant to initialize formatters that are very low-
188 // level/global in nature and do not naturally belong in any language. The
189 // intent is that most formatters go in language-specific categories.
190 // Eventually, the runtimes should also be allowed to vend their own
191 // formatters, and then one could put formatters that depend on specific
192 // library load events in the language runtimes, on an as-needed basis
194
196
198};
199
200} // namespace lldb_private
201
202#endif // LLDB_DATAFORMATTERS_FORMATMANAGER_H
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
NamedSummariesMap & GetNamedSummaryContainer()
ImplSP GetHardcoded(FormattersMatchData &)
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
~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
std::recursive_mutex m_language_categories_mutex
static ConstString GetTypeForCache(ValueObject &, lldb::DynamicValueType)
void EnableCategory(ConstString category_name, TypeCategoryMap::Position pos, lldb::LanguageType lang)
TypeCategoryMap & GetCategories()
bool ShouldPrintAsOneLiner(ValueObject &valobj)
void EnableCategory(const lldb::TypeCategoryImplSP &category, TypeCategoryMap::Position pos=TypeCategoryMap::Default)
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
lldb::TypeCategoryImplSP GetCategory(ConstString category_name, bool can_create=true)
lldb::TypeSummaryImplSP GetSummaryFormat(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
static FormattersMatchVector GetPossibleMatches(ValueObject &valobj, lldb::DynamicValueType use_dynamic)
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
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)
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)
uint32_t GetCurrentRevision() override
ConstString m_vectortypes_category_name
void DisableCategory(ConstString category_name)
void DisableCategory(const lldb::TypeCategoryImplSP &category)
LanguageCategory * GetCategoryForLanguage(lldb::LanguageType lang_type)
LanguageCategories m_language_categories_map
std::function< bool(const lldb::TypeCategoryImplSP &)> ForEachCallback
static const Position Default
CompilerType GetCompilerType()
A class that represents a running process on the host machine.
std::vector< FormattersMatchCandidate > FormattersMatchVector
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
std::shared_ptr< lldb_private::TypeFormatImpl > TypeFormatImplSP
std::shared_ptr< lldb_private::TypeNameSpecifierImpl > TypeNameSpecifierImplSP
Format
Display format definitions.
LanguageType
Programming language type.
std::shared_ptr< lldb_private::SyntheticChildren > SyntheticChildrenSP
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
std::shared_ptr< lldb_private::ScriptedSyntheticChildren > ScriptedSyntheticChildrenSP
std::shared_ptr< lldb_private::TypeFilterImpl > TypeFilterImplSP