FormatManager.h revision 258054
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 16// Other libraries and framework includes 17// Project includes 18#include "lldb/lldb-public.h" 19#include "lldb/lldb-enumerations.h" 20 21#include "lldb/DataFormatters/FormatCache.h" 22#include "lldb/DataFormatters/FormatNavigator.h" 23#include "lldb/DataFormatters/TypeCategory.h" 24#include "lldb/DataFormatters/TypeCategoryMap.h" 25 26#include <atomic> 27 28namespace lldb_private { 29 30// this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization 31// class DataVisualization is the high-level front-end of this feature 32// clients should refer to that class as the entry-point into the data formatters 33// unless they have a good reason to bypass it and prefer to use this file's objects directly 34 35class FormatManager : public IFormatChangeListener 36{ 37 typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap; 38 typedef TypeCategoryMap::MapType::iterator CategoryMapIterator; 39public: 40 41 typedef TypeCategoryMap::CallbackType CategoryCallback; 42 43 FormatManager (); 44 45 NamedSummariesMap& 46 GetNamedSummaryNavigator () 47 { 48 return m_named_summaries_map; 49 } 50 51 void 52 EnableCategory (const ConstString& category_name, 53 TypeCategoryMap::Position pos = TypeCategoryMap::Default) 54 { 55 m_categories_map.Enable(category_name, 56 pos); 57 } 58 59 void 60 DisableCategory (const ConstString& category_name) 61 { 62 m_categories_map.Disable(category_name); 63 } 64 65 void 66 EnableCategory (const lldb::TypeCategoryImplSP& category, 67 TypeCategoryMap::Position pos = TypeCategoryMap::Default) 68 { 69 m_categories_map.Enable(category, 70 pos); 71 } 72 73 void 74 DisableCategory (const lldb::TypeCategoryImplSP& category) 75 { 76 m_categories_map.Disable(category); 77 } 78 79 bool 80 DeleteCategory (const ConstString& category_name) 81 { 82 return m_categories_map.Delete(category_name); 83 } 84 85 void 86 ClearCategories () 87 { 88 return m_categories_map.Clear(); 89 } 90 91 uint32_t 92 GetCategoriesCount () 93 { 94 return m_categories_map.GetCount(); 95 } 96 97 lldb::TypeCategoryImplSP 98 GetCategoryAtIndex (size_t index) 99 { 100 return m_categories_map.GetAtIndex(index); 101 } 102 103 void 104 LoopThroughCategories (CategoryCallback callback, void* param) 105 { 106 m_categories_map.LoopThrough(callback, param); 107 } 108 109 lldb::TypeCategoryImplSP 110 GetCategory (const char* category_name = NULL, 111 bool can_create = true) 112 { 113 if (!category_name) 114 return GetCategory(m_default_category_name); 115 return GetCategory(ConstString(category_name)); 116 } 117 118 lldb::TypeCategoryImplSP 119 GetCategory (const ConstString& category_name, 120 bool can_create = true); 121 122 lldb::TypeFormatImplSP 123 GetFormatForType (lldb::TypeNameSpecifierImplSP type_sp); 124 125 lldb::TypeSummaryImplSP 126 GetSummaryForType (lldb::TypeNameSpecifierImplSP type_sp); 127 128 lldb::TypeFilterImplSP 129 GetFilterForType (lldb::TypeNameSpecifierImplSP type_sp); 130 131#ifndef LLDB_DISABLE_PYTHON 132 lldb::ScriptedSyntheticChildrenSP 133 GetSyntheticForType (lldb::TypeNameSpecifierImplSP type_sp); 134#endif 135 136#ifndef LLDB_DISABLE_PYTHON 137 lldb::SyntheticChildrenSP 138 GetSyntheticChildrenForType (lldb::TypeNameSpecifierImplSP type_sp); 139#endif 140 141 lldb::TypeFormatImplSP 142 GetFormat (ValueObject& valobj, 143 lldb::DynamicValueType use_dynamic); 144 145 lldb::TypeSummaryImplSP 146 GetSummaryFormat (ValueObject& valobj, 147 lldb::DynamicValueType use_dynamic); 148 149#ifndef LLDB_DISABLE_PYTHON 150 lldb::SyntheticChildrenSP 151 GetSyntheticChildren (ValueObject& valobj, 152 lldb::DynamicValueType use_dynamic); 153#endif 154 155 bool 156 AnyMatches (ConstString type_name, 157 TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES, 158 bool only_enabled = true, 159 const char** matching_category = NULL, 160 TypeCategoryImpl::FormatCategoryItems* matching_type = NULL) 161 { 162 return m_categories_map.AnyMatches(type_name, 163 items, 164 only_enabled, 165 matching_category, 166 matching_type); 167 } 168 169 static bool 170 GetFormatFromCString (const char *format_cstr, 171 bool partial_match_ok, 172 lldb::Format &format); 173 174 static char 175 GetFormatAsFormatChar (lldb::Format format); 176 177 static const char * 178 GetFormatAsCString (lldb::Format format); 179 180 // if the user tries to add formatters for, say, "struct Foo" 181 // those will not match any type because of the way we strip qualifiers from typenames 182 // this method looks for the case where the user is adding a "class","struct","enum" or "union" Foo 183 // and strips the unnecessary qualifier 184 static ConstString 185 GetValidTypeName (const ConstString& type); 186 187 // when DataExtractor dumps a vectorOfT, it uses a predefined format for each item 188 // this method returns it, or eFormatInvalid if vector_format is not a vectorOf 189 static lldb::Format 190 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 197 ShouldPrintAsOneLiner (ValueObject& valobj); 198 199 void 200 Changed () 201 { 202 ++m_last_revision; 203 m_format_cache.Clear (); 204 } 205 206 uint32_t 207 GetCurrentRevision () 208 { 209 return m_last_revision; 210 } 211 212 ~FormatManager () 213 { 214 } 215 216private: 217 FormatCache m_format_cache; 218 NamedSummariesMap m_named_summaries_map; 219 std::atomic<uint32_t> m_last_revision; 220 TypeCategoryMap m_categories_map; 221 222 ConstString m_default_category_name; 223 ConstString m_system_category_name; 224 ConstString m_gnu_cpp_category_name; 225 ConstString m_libcxx_category_name; 226 ConstString m_objc_category_name; 227 ConstString m_corefoundation_category_name; 228 ConstString m_coregraphics_category_name; 229 ConstString m_coreservices_category_name; 230 ConstString m_vectortypes_category_name; 231 ConstString m_appkit_category_name; 232 233 TypeCategoryMap& 234 GetCategories () 235 { 236 return m_categories_map; 237 } 238 239 // WARNING: these are temporary functions that setup formatters 240 // while a few of these actually should be globally available and setup by LLDB itself 241 // most would actually belong to the users' lldbinit file or to some other form of configurable 242 // storage 243 void 244 LoadLibStdcppFormatters (); 245 246 void 247 LoadLibcxxFormatters (); 248 249 void 250 LoadSystemFormatters (); 251 252 void 253 LoadObjCFormatters (); 254}; 255 256} // namespace lldb_private 257 258#endif // lldb_FormatManager_h_ 259