Index: lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp =================================================================== --- lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp +++ lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "LibCxxAtomic.h" +#include "lldb/DataFormatters/FormattersHelpers.h" using namespace lldb; using namespace lldb_private; @@ -100,8 +101,6 @@ size_t GetIndexOfChildWithName(ConstString name) override; - lldb::ValueObjectSP GetSyntheticValue() override; - private: ValueObject *m_real_child; }; @@ -127,26 +126,20 @@ size_t lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd:: CalculateNumChildren() { - return m_real_child ? m_real_child->GetNumChildren() : 0; + return m_real_child ? 1 : 0; } lldb::ValueObjectSP lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::GetChildAtIndex( size_t idx) { - return m_real_child ? m_real_child->GetChildAtIndex(idx, true) : nullptr; + if (idx == 0) + return m_real_child->GetSP()->Clone(ConstString("Value")); + return nullptr; } size_t lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd:: GetIndexOfChildWithName(ConstString name) { - return m_real_child ? m_real_child->GetIndexOfChildWithName(name) - : UINT32_MAX; -} - -lldb::ValueObjectSP lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd:: - GetSyntheticValue() { - if (m_real_child && m_real_child->CanProvideValue()) - return m_real_child->GetSP(); - return nullptr; + return formatters::ExtractIndexFromString(name.GetCString()); } SyntheticChildrenFrontEnd * Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py =================================================================== --- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py +++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/TestLibCxxAtomic.py @@ -42,13 +42,19 @@ substrs=['stopped', 'stop reason = breakpoint']) - s = self.get_variable('s') - i = self.get_variable('i') + s_atomic = self.get_variable('s') + i_atomic = self.get_variable('i') if self.TraceOn(): - print(s) + print(s_atomic) if self.TraceOn(): - print(i) + print(i_atomic) + + # Extract the content of the std::atomic wrappers. + self.assertEqual(s_atomic.GetNumChildren(), 1) + s = s_atomic.GetChildAtIndex(0) + self.assertEqual(i_atomic.GetNumChildren(), 1) + i = i_atomic.GetChildAtIndex(0) self.assertTrue(i.GetValueAsUnsigned(0) == 5, "i == 5") self.assertTrue(s.GetNumChildren() == 2, "s has two children") @@ -58,3 +64,9 @@ self.assertTrue( s.GetChildAtIndex(1).GetValueAsUnsigned(0) == 2, "s.y == 2") + + # Try printing the child that points to its own parent object. + # This should just treat the atomic pointer as a normal pointer. + self.expect("frame var p.child", substrs=["Value = 0x"]) + self.expect("frame var p", substrs=["parent = {", "Value = 0x", "}"]) + self.expect("frame var p.child.parent", substrs=["p.child.parent = {\n Value = 0x"]) Index: lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/main.cpp =================================================================== --- lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/main.cpp +++ lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx/atomic/main.cpp @@ -8,6 +8,18 @@ #include +// Define a Parent and Child struct that can point to each other. +class Parent; +struct Child { + // This should point to the parent which in turn owns this + // child instance. This cycle should not cause LLDB to infinite loop + // during printing. + std::atomic parent{nullptr}; +}; +struct Parent { + Child child; +}; + struct S { int x = 1; int y = 2; @@ -19,7 +31,11 @@ s.store(S()); std::atomic i; i.store(5); - + + Parent p; + // Let the child node know what its parent is. + p.child.parent = &p; + return 0; // Set break point at this line. }