Skip to content

Conversation

da-viper
Copy link
Contributor

This causes a crash because lldb-dap will check the first child to see if it is array like to lazy load the children.

This causes a crash because lldb-dap will check the first child to see if it is array like to lazy load the children.
@llvmbot
Copy link
Member

llvmbot commented Oct 12, 2025

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

Changes

This causes a crash because lldb-dap will check the first child to see if it is array like to lazy load the children.


Full diff: https://github.com/llvm/llvm-project/pull/163077.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp (+1-1)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp
index 3ec324577ac76..372b6c7afdd78 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp
@@ -50,7 +50,7 @@ llvm::Expected<uint32_t> lldb_private::formatters::
 lldb::ValueObjectSP
 lldb_private::formatters::MsvcStlAtomicSyntheticFrontEnd::GetChildAtIndex(
     uint32_t idx) {
-  if (idx == 0)
+  if (idx == 0 && m_storage && m_element_type.IsValid())
     return m_storage->Cast(m_element_type)->Clone(ConstString("Value"));
   return nullptr;
 }

@da-viper da-viper requested a review from Nerixyz October 12, 2025 15:15
@da-viper
Copy link
Contributor Author

Not sure the best way to test this, As it only happens because MSVC std::atomic formatter is loaded on linux because of the matching regex ^std::atomic<+*>

AddCXXSynthetic(cpp_category_sp, MsvcStlAtomicSyntheticFrontEndCreator,
"MSVC STL std::atomic synthetic children",
"^std::atomic<.+>$", stl_synth_flags, true);
.

maybe on MSVC the std::atomic is a typedef to an underlying type and match against that ?

@Nerixyz
Copy link
Contributor

Nerixyz commented Oct 12, 2025

The changes to the atomic synthetic children look good to me.

Not sure the best way to test this

You could create a mock atomic like

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

@Michael137
Copy link
Member

Michael137 commented Oct 13, 2025

Not sure the best way to test this, As it only happens because MSVC std::atomic formatter is loaded on linux because of the matching regex ^std::atomic<+*>

AddCXXSynthetic(cpp_category_sp, MsvcStlAtomicSyntheticFrontEndCreator,
"MSVC STL std::atomic synthetic children",
"^std::atomic<.+>$", stl_synth_flags, true);

.
maybe on MSVC the std::atomic is a typedef to an underlying type and match against that ?

By "loaded" do you mean it's actually trying to use it? That seems wrong. I thought the formatters have a callback to check that we are on MSVC vs. Linux. Maybe that check isn't working?

@Michael137
Copy link
Member

Ah we don't have such a callback because libstdc++ doesn't have a std::atomic formatter

@Michael137
Copy link
Member

Michael137 commented Oct 13, 2025

Maybe the MSVC formatters (even ones that don't have a libstdc++ counterpart) should be check if the type is an actually valid MSVC type. Like we do for the common STL formatters. @Nerixyz ?

@Nerixyz
Copy link
Contributor

Nerixyz commented Oct 13, 2025

Maybe the MSVC formatters (even ones that don't have a libstdc++ counterpart) should be check if the type is an actually valid MSVC type. Like we do for the common STL formatters. @Nerixyz ?

They should. This patch is still good to avoid crashes with other STLs and potential changes to MS' one. Should the MSVC check happen in this PR or in another one?

@Michael137
Copy link
Member

Maybe the MSVC formatters (even ones that don't have a libstdc++ counterpart) should be check if the type is an actually valid MSVC type. Like we do for the common STL formatters. @Nerixyz ?

They should. This patch is still good to avoid crashes with other STLs and potential changes to MS' one. Should the MSVC check happen in this PR or in another one?

Separate PR would make sense!

Nerixyz added a commit that referenced this pull request Oct 13, 2025
…163176)

From
#163077 (comment):
Currently, `std::atomic<T>` will always use the MSVC STL synthetic
children and summary. When inspecting types from other STLs, the output
would not show any children.

This PR adds a check that `std::atomic` contains `_Storage` to be
classified as coming from MSVC's STL.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Oct 13, 2025
…children (#163176)

From
llvm/llvm-project#163077 (comment):
Currently, `std::atomic<T>` will always use the MSVC STL synthetic
children and summary. When inspecting types from other STLs, the output
would not show any children.

This PR adds a check that `std::atomic` contains `_Storage` to be
classified as coming from MSVC's STL.
@da-viper
Copy link
Contributor Author

It seems #163176 covers the test case.

akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
…lvm#163176)

From
llvm#163077 (comment):
Currently, `std::atomic<T>` will always use the MSVC STL synthetic
children and summary. When inspecting types from other STLs, the output
would not show any children.

This PR adds a check that `std::atomic` contains `_Storage` to be
classified as coming from MSVC's STL.
@da-viper da-viper merged commit 17e06aa into llvm:main Oct 15, 2025
12 checks passed
@da-viper da-viper deleted the fix-msvc-stl-atomic branch October 15, 2025 10:57
@Michael137
Copy link
Member

Michael137 commented Oct 15, 2025

It seems #163176 covers the test case.

Technically it doesnt. This patch adds a null check for the case where we picked the MSVC formatter but the layout wasnt the one that the MSVC formatter expected. A test-case for this would look like the simulator test that @Nerixyz added in the patch you linked. But we would need a dummy atomic type that has a _Storage field (so the msvc formatter is picked) but had an invalid type template argument (e.g., an integral non-type template parameter).

Not saying such a test is all that interesting since MSVC STL is unlikely to change in that way and the null check is good to have anyway. But it would've been good to wait for another round of reviews/approvals before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants