-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[LLDB] Add formatters for MSVC STL std::atomic #149801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
lldb/source/Plugins/Language/CPlusPlus/MsvcStlAtomic.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| //===-- MsvcStlAtomic.cpp -------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "MsvcStl.h" | ||
|
|
||
| #include "lldb/DataFormatters/TypeSynthetic.h" | ||
|
|
||
| using namespace lldb; | ||
|
|
||
| namespace lldb_private { | ||
| namespace formatters { | ||
|
|
||
| class MsvcStlAtomicSyntheticFrontEnd : public SyntheticChildrenFrontEnd { | ||
| public: | ||
| MsvcStlAtomicSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp); | ||
|
|
||
| llvm::Expected<uint32_t> CalculateNumChildren() override; | ||
|
|
||
| lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override; | ||
|
|
||
| lldb::ChildCacheState Update() override; | ||
|
|
||
| llvm::Expected<size_t> GetIndexOfChildWithName(ConstString name) override; | ||
|
|
||
| private: | ||
| ValueObject *m_storage = nullptr; | ||
| CompilerType m_element_type; | ||
| }; | ||
|
|
||
| } // namespace formatters | ||
| } // namespace lldb_private | ||
|
|
||
| lldb_private::formatters::MsvcStlAtomicSyntheticFrontEnd:: | ||
| MsvcStlAtomicSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) | ||
| : SyntheticChildrenFrontEnd(*valobj_sp), m_element_type() { | ||
| if (valobj_sp) | ||
| Update(); | ||
| } | ||
|
|
||
| llvm::Expected<uint32_t> lldb_private::formatters:: | ||
| MsvcStlAtomicSyntheticFrontEnd::CalculateNumChildren() { | ||
| return m_storage ? 1 : 0; | ||
| } | ||
|
|
||
| lldb::ValueObjectSP | ||
| lldb_private::formatters::MsvcStlAtomicSyntheticFrontEnd::GetChildAtIndex( | ||
| uint32_t idx) { | ||
| if (idx == 0) | ||
| return m_storage->Cast(m_element_type)->Clone(ConstString("Value")); | ||
| return nullptr; | ||
| } | ||
|
|
||
| lldb::ChildCacheState | ||
| lldb_private::formatters::MsvcStlAtomicSyntheticFrontEnd::Update() { | ||
| m_storage = nullptr; | ||
| m_element_type.Clear(); | ||
|
|
||
| ValueObjectSP storage_sp = m_backend.GetChildMemberWithName("_Storage"); | ||
| if (!storage_sp) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| m_element_type = m_backend.GetCompilerType().GetTypeTemplateArgument(0); | ||
| if (!m_element_type) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| m_storage = storage_sp.get(); | ||
| return lldb::ChildCacheState::eRefetch; | ||
| } | ||
|
|
||
| llvm::Expected<size_t> lldb_private::formatters:: | ||
| MsvcStlAtomicSyntheticFrontEnd::GetIndexOfChildWithName(ConstString name) { | ||
| if (name == "Value") | ||
| return 0; | ||
| return llvm::createStringError("Type has no child named '%s'", | ||
| name.AsCString()); | ||
| } | ||
|
|
||
| lldb_private::SyntheticChildrenFrontEnd * | ||
| lldb_private::formatters::MsvcStlAtomicSyntheticFrontEndCreator( | ||
| CXXSyntheticChildren *, lldb::ValueObjectSP valobj_sp) { | ||
| return new MsvcStlAtomicSyntheticFrontEnd(valobj_sp); | ||
| } | ||
|
|
||
| bool lldb_private::formatters::MsvcStlAtomicSummaryProvider( | ||
| ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { | ||
| auto synth_sp = valobj.GetSyntheticValue(); | ||
| if (!synth_sp) | ||
| return false; | ||
|
|
||
| auto value_sp = synth_sp->GetChildAtIndex(0); | ||
| std::string summary; | ||
| if (value_sp->GetSummaryAsCString(summary, options) && !summary.empty()) { | ||
| stream << summary; | ||
| return true; | ||
| } | ||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you don't set this? I think we probably do want this to be
true? Would that makestd::atomiclook like:?
(i.e., just not print the synthetic child?)
I know that's not what libc++/libstdc++ does, but we probably should?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be done separately since that's what libc++ and libstdc++ already do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I don't think that's always desired. Atomics can store structs as well (not sure why) and users might want to inspect these. This is also done in the tests here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I wondered if for summaries that can't be formatted without children this would then fall back to showing the children. But yea maybe not. Either way, not something you have to deal with here