FormatCache.cpp revision 263363
1//===-- FormatCache.cpp ------------------------------------------*- 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#include "lldb/lldb-python.h" 11 12// C Includes 13 14// C++ Includes 15 16// Other libraries and framework includes 17 18// Project includes 19#include "lldb/DataFormatters/FormatCache.h" 20 21using namespace lldb; 22using namespace lldb_private; 23 24FormatCache::Entry::Entry () : 25m_format_cached(false), 26m_summary_cached(false), 27m_synthetic_cached(false), 28m_format_sp(), 29m_summary_sp(), 30m_synthetic_sp() 31{} 32 33FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) : 34m_summary_cached(false), 35m_synthetic_cached(false), 36m_summary_sp(), 37m_synthetic_sp() 38{ 39 SetFormat (format_sp); 40} 41 42FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : 43m_format_cached(false), 44m_synthetic_cached(false), 45m_format_sp(), 46m_synthetic_sp() 47{ 48 SetSummary (summary_sp); 49} 50 51FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : 52m_format_cached(false), 53m_summary_cached(false), 54m_format_sp(), 55m_summary_sp() 56{ 57 SetSynthetic (synthetic_sp); 58} 59 60FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp) 61{ 62 SetFormat (format_sp); 63 SetSummary (summary_sp); 64 SetSynthetic (synthetic_sp); 65} 66 67bool 68FormatCache::Entry::IsFormatCached () 69{ 70 return m_format_cached; 71} 72 73bool 74FormatCache::Entry::IsSummaryCached () 75{ 76 return m_summary_cached; 77} 78 79bool 80FormatCache::Entry::IsSyntheticCached () 81{ 82 return m_synthetic_cached; 83} 84 85lldb::TypeFormatImplSP 86FormatCache::Entry::GetFormat () 87{ 88 return m_format_sp; 89} 90 91lldb::TypeSummaryImplSP 92FormatCache::Entry::GetSummary () 93{ 94 return m_summary_sp; 95} 96 97lldb::SyntheticChildrenSP 98FormatCache::Entry::GetSynthetic () 99{ 100 return m_synthetic_sp; 101} 102 103void 104FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp) 105{ 106 m_format_cached = true; 107 m_format_sp = format_sp; 108} 109 110void 111FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp) 112{ 113 m_summary_cached = true; 114 m_summary_sp = summary_sp; 115} 116 117void 118FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp) 119{ 120 m_synthetic_cached = true; 121 m_synthetic_sp = synthetic_sp; 122} 123 124FormatCache::FormatCache () : 125m_map(), 126m_mutex (Mutex::eMutexTypeRecursive) 127#ifdef LLDB_CONFIGURATION_DEBUG 128,m_cache_hits(0),m_cache_misses(0) 129#endif 130{ 131} 132 133FormatCache::Entry& 134FormatCache::GetEntry (const ConstString& type) 135{ 136 auto i = m_map.find(type), 137 e = m_map.end(); 138 if (i != e) 139 return i->second; 140 m_map[type] = FormatCache::Entry(); 141 return m_map[type]; 142} 143 144bool 145FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) 146{ 147 Mutex::Locker lock(m_mutex); 148 auto entry = GetEntry(type); 149 if (entry.IsSummaryCached()) 150 { 151#ifdef LLDB_CONFIGURATION_DEBUG 152 m_cache_hits++; 153#endif 154 format_sp = entry.GetFormat(); 155 return true; 156 } 157#ifdef LLDB_CONFIGURATION_DEBUG 158 m_cache_misses++; 159#endif 160 format_sp.reset(); 161 return false; 162} 163 164bool 165FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) 166{ 167 Mutex::Locker lock(m_mutex); 168 auto entry = GetEntry(type); 169 if (entry.IsSummaryCached()) 170 { 171#ifdef LLDB_CONFIGURATION_DEBUG 172 m_cache_hits++; 173#endif 174 summary_sp = entry.GetSummary(); 175 return true; 176 } 177#ifdef LLDB_CONFIGURATION_DEBUG 178 m_cache_misses++; 179#endif 180 summary_sp.reset(); 181 return false; 182} 183 184bool 185FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) 186{ 187 Mutex::Locker lock(m_mutex); 188 auto entry = GetEntry(type); 189 if (entry.IsSyntheticCached()) 190 { 191#ifdef LLDB_CONFIGURATION_DEBUG 192 m_cache_hits++; 193#endif 194 synthetic_sp = entry.GetSynthetic(); 195 return true; 196 } 197#ifdef LLDB_CONFIGURATION_DEBUG 198 m_cache_misses++; 199#endif 200 synthetic_sp.reset(); 201 return false; 202} 203 204void 205FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp) 206{ 207 Mutex::Locker lock(m_mutex); 208 GetEntry(type).SetFormat(format_sp); 209} 210 211void 212FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) 213{ 214 Mutex::Locker lock(m_mutex); 215 GetEntry(type).SetSummary(summary_sp); 216} 217 218void 219FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) 220{ 221 Mutex::Locker lock(m_mutex); 222 GetEntry(type).SetSynthetic(synthetic_sp); 223} 224 225void 226FormatCache::Clear () 227{ 228 Mutex::Locker lock(m_mutex); 229 m_map.clear(); 230} 231 232