Skip to content

Conversation

@MrBoboGet
Copy link

lldb-dap crashes when requesting variables if the scope includes a std::shared_ptr, as it assumes that m_ptr_obj is not null after Update. This is however only true if Update doesn't fail for any reason, and the problem is that LibStdcppSharedPtrSyntheticFrontEnd is used even when running on windows and not using libstdcpp. As _M_ptr is not present in the class, so is m_ptr_obj always null, which results in a crash when calling GetChildAtIndex with idx= 0.

This commit only fixes the crash by adding a null check, whether or not it's a bug that LibStdcppSharedPtrSyntheticFrontEnd is used on windows at all is difficult for me to decide, and there doesn't seem to be any support for microsoft STL regardless.

A minimal example showcasing the bug is easy to provide:

#include <iostream>
#include <memory>
int main(int arg, char** argv)
{
    std::shared_ptr<int> broken = std::make_shared<int>();
    std::cout<<"Hello world!"<<std::endl;   
}

Compiling the above with clang++ and setting a breakpoint before printing hello world and debugging should produce the crash on all DAP clients running on windows.

@MrBoboGet MrBoboGet requested a review from JDevlieghere as a code owner May 24, 2025 15:05
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the lldb label May 24, 2025
@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-lldb

Author: Emanuel Berggren (MrBoboGet)

Changes

lldb-dap crashes when requesting variables if the scope includes a std::shared_ptr, as it assumes that m_ptr_obj is not null after Update. This is however only true if Update doesn't fail for any reason, and the problem is that LibStdcppSharedPtrSyntheticFrontEnd is used even when running on windows and not using libstdcpp. As _M_ptr is not present in the class, so is m_ptr_obj always null, which results in a crash when calling GetChildAtIndex with idx= 0.

This commit only fixes the crash by adding a null check, whether or not it's a bug that LibStdcppSharedPtrSyntheticFrontEnd is used on windows at all is difficult for me to decide, and there doesn't seem to be any support for microsoft STL regardless.

A minimal example showcasing the bug is easy to provide:

#include &lt;iostream&gt;
#include &lt;memory&gt;
int main(int arg, char** argv)
{
    std::shared_ptr&lt;int&gt; broken = std::make_shared&lt;int&gt;();
    std::cout&lt;&lt;"Hello world!"&lt;&lt;std::endl;   
}

Compiling the above with clang++ and setting a breakpoint before printing hello world and debugging should produce the crash on all DAP clients running on windows.


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

1 Files Affected:

  • (modified) lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp (+1-1)
diff --git a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
index 02113baf64b8c..54158d9a0d85a 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp
@@ -379,7 +379,7 @@ LibStdcppSharedPtrSyntheticFrontEnd::CalculateNumChildren() {
 
 lldb::ValueObjectSP
 LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(uint32_t idx) {
-  if (idx == 0)
+  if (idx == 0 && m_ptr_obj)
     return m_ptr_obj->GetSP();
   if (idx == 1) {
     if (m_ptr_obj && !m_obj_obj) {

@Michael137
Copy link
Member

Thanks for the patch

I believe #140761 addresses this issue (and another). There's some discussion around testing too

@MrBoboGet
Copy link
Author

Ah, it does, didn't think about double checking if it had been solved outside of main. Then this pull request is completely redundant

@MrBoboGet MrBoboGet closed this May 24, 2025
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.

3 participants