<div dir="ltr">Ahh.  Is there any way to change that behavior so that you can add back deleted formatters?   Or make it so that FormatManager itself can be created and then destroyed.  i.e. we could still use it as a singleton / global state in LLDB, but we could create and destroy them with each test in the test suite.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 14, 2015 at 6:48 PM Enrico Granata <<a href="mailto:egranata@apple.com">egranata@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>It’s a hard unit test to write though</div><div><br></div><div>I caught this because I deleted a formatter in a language category and saw it still applied</div><div><br></div><div>Problem is that you can’t add new formatters or add back previously deleted formatters to a language category, and the FormatManager is global state, so a deletion is forever, which worries me as potentially affecting downstream tests</div><div><br></div><div>I’ll keep this in mind though, if I can come up with a good way to cons a test up, I’ll definitely make it happen</div></div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Dec 14, 2015, at 6:45 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:</div><br><div><div dir="ltr">A unit test would be good at catching bugs like this.</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 14, 2015 at 6:23 PM Enrico Granata via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: enrico<br>
Date: Mon Dec 14 20:20:48 2015<br>
New Revision: 255603<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255603&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255603&view=rev</a><br>
Log:<br>
Fix a bug where language categories would hold on to their caches even after changes<br>
<br>
<br>
Modified:<br>
    lldb/trunk/include/lldb/DataFormatters/FormatManager.h<br>
    lldb/trunk/include/lldb/DataFormatters/LanguageCategory.h<br>
    lldb/trunk/source/DataFormatters/FormatManager.cpp<br>
    lldb/trunk/source/DataFormatters/LanguageCategory.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/DataFormatters/FormatManager.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=255603&r1=255602&r2=255603&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/FormatManager.h?rev=255603&r1=255602&r2=255603&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/DataFormatters/FormatManager.h (original)<br>
+++ lldb/trunk/include/lldb/DataFormatters/FormatManager.h Mon Dec 14 20:20:48 2015<br>
@@ -238,11 +238,7 @@ public:<br>
     ShouldPrintAsOneLiner (ValueObject& valobj);<br>
<br>
     void<br>
-    Changed () override<br>
-    {<br>
-        ++m_last_revision;<br>
-        m_format_cache.Clear ();<br>
-    }<br>
+    Changed () override;<br>
<br>
     uint32_t<br>
     GetCurrentRevision () override<br>
@@ -290,13 +286,13 @@ private:<br>
                         bool did_strip_ref,<br>
                         bool did_strip_typedef,<br>
                         bool root_level = false);<br>
-<br>
+<br>
+    std::atomic<uint32_t> m_last_revision;<br>
     FormatCache m_format_cache;<br>
+    Mutex m_language_categories_mutex;<br>
+    LanguageCategories m_language_categories_map;<br>
     NamedSummariesMap m_named_summaries_map;<br>
-    std::atomic<uint32_t> m_last_revision;<br>
     TypeCategoryMap m_categories_map;<br>
-    LanguageCategories m_language_categories_map;<br>
-    Mutex m_language_categories_mutex;<br>
<br>
     ConstString m_default_category_name;<br>
     ConstString m_system_category_name;<br>
<br>
Modified: lldb/trunk/include/lldb/DataFormatters/LanguageCategory.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/LanguageCategory.h?rev=255603&r1=255602&r2=255603&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/LanguageCategory.h?rev=255603&r1=255602&r2=255603&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/DataFormatters/LanguageCategory.h (original)<br>
+++ lldb/trunk/include/lldb/DataFormatters/LanguageCategory.h Mon Dec 14 20:20:48 2015<br>
@@ -69,6 +69,9 @@ public:<br>
     lldb::TypeCategoryImplSP<br>
     GetCategory () const;<br>
<br>
+    FormatCache&<br>
+    GetFormatCache ();<br>
+<br>
     void<br>
     Enable ();<br>
<br>
<br>
Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=255603&r1=255602&r2=255603&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=255603&r1=255602&r2=255603&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)<br>
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Mon Dec 14 20:20:48 2015<br>
@@ -123,6 +123,19 @@ GetFormatFromFormatName (const char *for<br>
     return false;<br>
 }<br>
<br>
+void<br>
+FormatManager::Changed ()<br>
+{<br>
+    ++m_last_revision;<br>
+    m_format_cache.Clear ();<br>
+    Mutex::Locker lang_locker(m_language_categories_mutex);<br>
+    for (auto& iter : m_language_categories_map)<br>
+    {<br>
+        if (iter.second)<br>
+            iter.second->GetFormatCache().Clear();<br>
+    }<br>
+}<br>
+<br>
 bool<br>
 FormatManager::GetFormatFromCString (const char *format_cstr,<br>
                                      bool partial_match_ok,<br>
@@ -1043,12 +1056,12 @@ FormatManager::GetHardcodedValidator (Fo<br>
 }<br>
<br>
 FormatManager::FormatManager() :<br>
+    m_last_revision(0),<br>
     m_format_cache(),<br>
+    m_language_categories_mutex(Mutex::eMutexTypeRecursive),<br>
+    m_language_categories_map(),<br>
     m_named_summaries_map(this),<br>
-    m_last_revision(0),<br>
     m_categories_map(this),<br>
-    m_language_categories_map(),<br>
-    m_language_categories_mutex(Mutex::eMutexTypeRecursive),<br>
     m_default_category_name(ConstString("default")),<br>
     m_system_category_name(ConstString("system")),<br>
     m_vectortypes_category_name(ConstString("VectorTypes"))<br>
@@ -1063,7 +1076,6 @@ FormatManager::FormatManager() :<br>
 void<br>
 FormatManager::LoadSystemFormatters()<br>
 {<br>
-<br>
     TypeSummaryImpl::Flags string_flags;<br>
     string_flags.SetCascades(true)<br>
     .SetSkipPointers(true)<br>
<br>
Modified: lldb/trunk/source/DataFormatters/LanguageCategory.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/LanguageCategory.cpp?rev=255603&r1=255602&r2=255603&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/LanguageCategory.cpp?rev=255603&r1=255602&r2=255603&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/DataFormatters/LanguageCategory.cpp (original)<br>
+++ lldb/trunk/source/DataFormatters/LanguageCategory.cpp Mon Dec 14 20:20:48 2015<br>
@@ -242,6 +242,12 @@ LanguageCategory::GetCategory () const<br>
     return m_category_sp;<br>
 }<br>
<br>
+FormatCache&<br>
+LanguageCategory::GetFormatCache ()<br>
+{<br>
+    return m_format_cache;<br>
+}<br>
+<br>
 void<br>
 LanguageCategory::Enable ()<br>
 {<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>
</div></blockquote></div><br></div><div style="word-wrap:break-word"><div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>Thanks,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><i>- Enrico</i><br>📩 egranata@<font color="#ff2600"></font>.com ☎️ 27683</div>
</div>
<br></div></blockquote></div>