Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ lldb_private::formatters::LibcxxStdAtomicSyntheticFrontEnd::
SyntheticChildrenFrontEnd *
lldb_private::formatters::LibcxxAtomicSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
if (valobj_sp)
if (valobj_sp && IsLibCxxAtomic(*valobj_sp))
return new LibcxxStdAtomicSyntheticFrontEnd(valobj_sp);
return nullptr;
}

bool lldb_private::formatters::IsLibCxxAtomic(ValueObject &valobj) {
if (auto valobj_sp = valobj.GetNonSyntheticValue())
return valobj_sp->GetChildMemberWithName("__a_") != nullptr;
return false;
}
2 changes: 2 additions & 0 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxAtomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
namespace lldb_private {
namespace formatters {

bool IsLibCxxAtomic(ValueObject &valobj);

lldb::ValueObjectSP GetLibCxxAtomicValue(ValueObject &valobj);

bool LibCxxAtomicSummaryProvider(ValueObject &valobj, Stream &stream,
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Plugins/Language/CPlusPlus/MsvcStl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ MsvcStlVariantSyntheticFrontEndCreator(CXXSyntheticChildren *,
lldb::ValueObjectSP valobj_sp);

// MSVC STL std::atomic<>
bool IsMsvcStlAtomic(ValueObject &valobj);
bool MsvcStlAtomicSummaryProvider(ValueObject &valobj, Stream &stream,
const TypeSummaryOptions &options);
SyntheticChildrenFrontEnd *
Expand Down
10 changes: 9 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ llvm::Expected<size_t> lldb_private::formatters::
lldb_private::SyntheticChildrenFrontEnd *
lldb_private::formatters::MsvcStlAtomicSyntheticFrontEndCreator(
CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) {
return new MsvcStlAtomicSyntheticFrontEnd(valobj_sp);
if (valobj_sp && IsMsvcStlAtomic(*valobj_sp))
return new MsvcStlAtomicSyntheticFrontEnd(valobj_sp);
return nullptr;
}

bool lldb_private::formatters::MsvcStlAtomicSummaryProvider(
Expand All @@ -100,3 +102,9 @@ bool lldb_private::formatters::MsvcStlAtomicSummaryProvider(
}
return false;
}

bool lldb_private::formatters::IsMsvcStlAtomic(ValueObject &valobj) {
if (auto valobj_sp = valobj.GetNonSyntheticValue())
return valobj_sp->GetChildMemberWithName("_Storage") != nullptr;
return false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CXX_SOURCES := main.cpp

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Test formatting of `std::atomic`s not from any STL
"""

import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class InvalidAtomicDataFormatterTestCase(TestBase):
def test(self):
self.build()
lldbutil.run_to_source_breakpoint(
self, "Set break point at this line.", lldb.SBFileSpec("main.cpp")
)

self.expect_expr(
"a",
result_children=[
ValueCheck(name="foo", value="1"),
ValueCheck(name="bar", value="2"),
],
)
self.expect_expr(
"b",
result_children=[
ValueCheck(name="foo", value="3"),
ValueCheck(name="bar", value="4"),
],
)

self.expect_expr(
"c",
result_children=[
ValueCheck(name="foo", value="5"),
ValueCheck(name="bar", value="6"),
],
)
self.expect_expr(
"d",
result_children=[
ValueCheck(name="foo", value="7"),
ValueCheck(name="bar", value="8"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace std {
Copy link
Member

@Michael137 Michael137 Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

We typically classify these into the "simulator" tests (because they don't rely on the STL). E.g.,:

lldb/test/API/functionalities/data-formatter/data-formatter-stl/libcxx-simulators/invalid-vector

Should we create a msvc-simluators subdirectory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this actually doesn't need to be specific to msvc fwiw. Could have a generic "simulators" directory. And put this test there. Then create another structure here in the std::__1:: namespace to confirm that libc++ also does a sane thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it in a generic simulators directory. libc++ didn't handle this yet, so I added it there as well.

template <typename T> struct atomic {
int foo;
int bar;
};

namespace __1 {
template <typename T> struct atomic {
int foo;
int bar;
};
} // namespace __1
} // namespace std

int main() {
std::atomic<int> a{1, 2};
std::atomic<void> b{3, 4};

std::__1::atomic<int> c{5, 6};
std::__1::atomic<void> d{7, 8};

return 0; // Set break point at this line.
}
Loading