LLDB mainline
FormatCache.cpp
Go to the documentation of this file.
1//===-- FormatCache.cpp ---------------------------------------------------===//
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
10
11
13
14using namespace lldb;
15using namespace lldb_private;
16
18 : m_format_cached(false), m_summary_cached(false),
19 m_synthetic_cached(false) {}
20
21bool FormatCache::Entry::IsFormatCached() { return m_format_cached; }
22
23bool FormatCache::Entry::IsSummaryCached() { return m_summary_cached; }
24
25bool FormatCache::Entry::IsSyntheticCached() { return m_synthetic_cached; }
26
27void FormatCache::Entry::Get(lldb::TypeFormatImplSP &retval) {
28 retval = m_format_sp;
29}
30
31void FormatCache::Entry::Get(lldb::TypeSummaryImplSP &retval) {
32 retval = m_summary_sp;
33}
34
35void FormatCache::Entry::Get(lldb::SyntheticChildrenSP &retval) {
36 retval = m_synthetic_sp;
37}
38
39void FormatCache::Entry::Set(lldb::TypeFormatImplSP format_sp) {
40 m_format_cached = true;
41 m_format_sp = format_sp;
42}
43
44void FormatCache::Entry::Set(lldb::TypeSummaryImplSP summary_sp) {
45 m_summary_cached = true;
46 m_summary_sp = summary_sp;
47}
48
49void FormatCache::Entry::Set(lldb::SyntheticChildrenSP synthetic_sp) {
50 m_synthetic_cached = true;
51 m_synthetic_sp = synthetic_sp;
52}
53
54namespace lldb_private {
55
56template<> bool FormatCache::Entry::IsCached<lldb::TypeFormatImplSP>() {
57 return IsFormatCached();
58}
59template<> bool FormatCache::Entry::IsCached<lldb::TypeSummaryImplSP> () {
60 return IsSummaryCached();
61}
62template<> bool FormatCache::Entry::IsCached<lldb::SyntheticChildrenSP>() {
63 return IsSyntheticCached();
64}
65
66} // namespace lldb_private
67
68template <typename ImplSP>
69bool FormatCache::Get(ConstString type, ImplSP &format_impl_sp) {
70 std::lock_guard<std::recursive_mutex> guard(m_mutex);
71 auto entry = m_entries[type];
72 if (entry.IsCached<ImplSP>()) {
74 entry.Get(format_impl_sp);
75 return true;
76 }
78 format_impl_sp.reset();
79 return false;
80}
81
82/// Explicit instantiations for the three types.
83/// \{
84template bool
85FormatCache::Get<lldb::TypeFormatImplSP>(ConstString, lldb::TypeFormatImplSP &);
86template bool
87FormatCache::Get<lldb::TypeSummaryImplSP>(ConstString,
89template bool
90FormatCache::Get<lldb::SyntheticChildrenSP>(ConstString,
92/// \}
93
95 std::lock_guard<std::recursive_mutex> guard(m_mutex);
96 m_entries[type].Set(format_sp);
97}
98
100 std::lock_guard<std::recursive_mutex> guard(m_mutex);
101 m_entries[type].Set(summary_sp);
102}
103
105 lldb::SyntheticChildrenSP &synthetic_sp) {
106 std::lock_guard<std::recursive_mutex> guard(m_mutex);
107 m_entries[type].Set(synthetic_sp);
108}
109
111 std::lock_guard<std::recursive_mutex> guard(m_mutex);
112 m_entries.clear();
113}
A uniqued constant string class.
Definition: ConstString.h:40
std::map< ConstString, Entry > m_entries
Definition: FormatCache.h:48
void Set(ConstString type, lldb::TypeFormatImplSP &format_sp)
Definition: FormatCache.cpp:94
std::recursive_mutex m_mutex
Definition: FormatCache.h:49
bool Get(ConstString type, ImplSP &format_impl_sp)
Definition: FormatCache.cpp:69
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
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::SyntheticChildren > SyntheticChildrenSP
Definition: lldb-forward.h:441
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
Definition: FormatEntity.h:148