From 48ca8b8fe2b47597a33c62fac1e83c18432307df Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Sat, 7 Jan 2012 20:58:07 +0000 Subject: [PATCH] Recursive calls to ValueObject::GetSummaryAsCString() are causing crashes. The previous approach to controlling the recursion was doing it from outside the function which is not reliable. Now it is being done inside the function. This might not solve all of the crashes that we were seeing since there are other functions that clear the bit that indicates that the summary is in the process of being generated, but it might solve some. llvm-svn: 147741 --- lldb/include/lldb/Core/ValueObject.h | 6 ++--- lldb/source/Core/ValueObject.cpp | 43 +++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index d119a65..2a93f4b 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -951,7 +951,7 @@ public: m_forced_summary_format = format; m_user_id_of_forced_summary = m_update_point.GetModID(); m_summary_str.clear(); - m_trying_summary_already = false; + m_is_getting_summary = false; } lldb::SummaryFormatSP @@ -987,7 +987,7 @@ public: { m_last_summary_format = format; m_summary_str.clear(); - m_trying_summary_already = false; + m_is_getting_summary = false; } void @@ -1109,7 +1109,7 @@ protected: m_is_bitfield_for_scalar:1, m_is_expression_path_child:1, m_is_child_at_offset:1, - m_trying_summary_already:1; // used to prevent endless recursion in printing summaries + m_is_getting_summary:1; friend class ClangExpressionDeclMap; // For GetValue friend class ClangExpressionVariable; // For SetName diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 23d22d1..549b40b 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -95,7 +95,7 @@ ValueObject::ValueObject (ValueObject &parent) : m_is_bitfield_for_scalar(false), m_is_expression_path_child(false), m_is_child_at_offset(false), - m_trying_summary_already(false) + m_is_getting_summary(false) { m_manager->ManageObject(this); } @@ -141,7 +141,7 @@ ValueObject::ValueObject (ExecutionContextScope *exe_scope, m_is_bitfield_for_scalar(false), m_is_expression_path_child(false), m_is_child_at_offset(false), - m_trying_summary_already(false) + m_is_getting_summary(false) { m_manager = new ValueObjectManager(); m_manager->ManageObject (this); @@ -564,6 +564,13 @@ ValueObject::CreateChildAtIndex (uint32_t idx, bool synthetic_array_member, int3 const char * ValueObject::GetSummaryAsCString () { + // Watch for recursion which can happen with summary strings and other + // variable formatting options. + if (m_is_getting_summary) + return NULL; + + m_is_getting_summary = true; + if (UpdateValueIfNeeded (true)) { if (m_summary_str.empty()) @@ -635,6 +642,7 @@ ValueObject::GetSummaryAsCString () } } } + m_is_getting_summary = false; if (m_summary_str.empty()) return NULL; return m_summary_str.c_str(); @@ -1129,33 +1137,32 @@ ValueObject::GetPrintableRepresentation(Stream& s, case eDisplayValue: return_value = GetValueAsCString(); break; + case eDisplaySummary: - if (m_trying_summary_already) - return_value = NULL; - else - { - m_trying_summary_already = true; - return_value = GetSummaryAsCString(); - m_trying_summary_already = false; - break; - } + return_value = GetSummaryAsCString(); + break; + case eDisplayLanguageSpecific: return_value = GetObjectDescription(); break; + case eDisplayLocation: return_value = GetLocationAsCString(); break; + case eDisplayChildrenCount: - { - alloc_mem.resize(512); - return_value = &alloc_mem[0]; - int count = GetNumChildren(); - snprintf((char*)return_value, 512, "%d", count); + { + alloc_mem.resize(512); + return_value = &alloc_mem[0]; + int count = GetNumChildren(); + snprintf((char*)return_value, 512, "%d", count); + } break; - } + case eDisplayType: return_value = GetTypeName().AsCString(); break; + default: break; } @@ -3742,7 +3749,7 @@ ValueObject::ClearUserVisibleData() m_value_str.clear(); m_summary_str.clear(); m_object_desc_str.clear(); - m_trying_summary_already = false; + m_is_getting_summary = false; } SymbolContextScope * -- 2.7.4