FormatManager.h revision 263363
194742Sobrien//===-- FormatManager.h -------------------------------------------*- C++ -*-===// 294742Sobrien// 394742Sobrien// The LLVM Compiler Infrastructure 495253Sru// 594742Sobrien// This file is distributed under the University of Illinois Open Source 694772Simp// License. See LICENSE.TXT for details. 794772Simp// 8107358Sobrien//===----------------------------------------------------------------------===// 9107358Sobrien 10107358Sobrien#ifndef lldb_FormatManager_h_ 11107358Sobrien#define lldb_FormatManager_h_ 12107358Sobrien 1396991Srwatson// C Includes 1496991Srwatson// C++ Includes 1596991Srwatson 16102773Srwatson// Other libraries and framework includes 17102773Srwatson// Project includes 1894854Ssos#include "lldb/lldb-public.h" 1994917Simp#include "lldb/lldb-enumerations.h" 2094917Simp 2194917Simp#include "lldb/DataFormatters/FormatCache.h" 2294917Simp#include "lldb/DataFormatters/FormatNavigator.h" 2394845Smarkm#include "lldb/DataFormatters/TypeCategory.h" 2494845Smarkm#include "lldb/DataFormatters/TypeCategoryMap.h" 2594845Smarkm 2695382Srnordier#include <atomic> 2794847Sjhb 2894847Sjhbnamespace lldb_private { 2994847Sjhb 3094849Sphk// this file (and its. cpp) contain the low-level implementation of LLDB Data Visualization 3194849Sphk// class DataVisualization is the high-level front-end of this feature 3294849Sphk// clients should refer to that class as the entry-point into the data formatters 3394849Sphk// unless they have a good reason to bypass it and prefer to use this file's objects directly 3494849Sphk 3594849Sphkclass FormatManager : public IFormatChangeListener 3694849Sphk{ 3794855Sscottl typedef FormatMap<ConstString, TypeSummaryImpl> NamedSummariesMap; 3894855Sscottl typedef TypeCategoryMap::MapType::iterator CategoryMapIterator; 3994902Sbennopublic: 4094915Sken 4199607Smjacob typedef TypeCategoryMap::CallbackType CategoryCallback; 4294915Sken 4394915Sken FormatManager (); 4494915Sken 4594915Sken NamedSummariesMap& 4694915Sken GetNamedSummaryNavigator () 47105411Snjl { 4894915Sken return m_named_summaries_map; 4994915Sken } 5094915Sken 5199607Smjacob void 52106734Smjacob EnableCategory (const ConstString& category_name, 5397611Sbillf TypeCategoryMap::Position pos = TypeCategoryMap::Default) 5494918Sgshapiro { 5594918Sgshapiro m_categories_map.Enable(category_name, 5694918Sgshapiro pos); 5794918Sgshapiro } 5894918Sgshapiro 5994955Smurray void 6094955Smurray DisableCategory (const ConstString& category_name) 6195054Snectar { 62106187Sdes m_categories_map.Disable(category_name); 63106187Sdes } 6495455Sdes 6598750Sdes void 6699606Sdes EnableCategory (const lldb::TypeCategoryImplSP& category, 6799606Sdes TypeCategoryMap::Position pos = TypeCategoryMap::Default) 6899606Sdes { 6996268Sgad m_categories_map.Enable(category, 7096268Sgad pos); 7196268Sgad } 7296301Sgrog 7396332Speter void 7496332Speter DisableCategory (const lldb::TypeCategoryImplSP& category) 7596332Speter { 7696332Speter m_categories_map.Disable(category); 7796332Speter } 78100314Sru 79100314Sru bool 8096451Sru DeleteCategory (const ConstString& category_name) 8197611Sbillf { 8298208Simp return m_categories_map.Delete(category_name); 8398333Sanholt } 8499193Sjmallett 8598475Sjmallett void 8698986Sjmallett ClearCategories () 8799193Sjmallett { 8899193Sjmallett return m_categories_map.Clear(); 8999611Sgordon } 9099732Sjoerg 9199732Sjoerg 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