-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[LLDB] Add formatters for MSVC STL std::shared_ptr #147575
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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8894b65
[LLDB] Add formatters for MSVC STL std::shared_ptr
Nerixyz 083687d
fix: comment regarding missing debug info
Nerixyz 51b5615
fix: move callbacks to Generic.cpp
Nerixyz 91fd149
fix: simplify type detection
Nerixyz 3784e17
fix: remove empty build options
Nerixyz 9b88cec
fix: move functions and check for STL there
Nerixyz d5367f2
fix: remove check for _Ptr
Nerixyz 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
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
168 changes: 168 additions & 0 deletions
168
lldb/source/Plugins/Language/CPlusPlus/MsvcStlSmartPointer.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,168 @@ | ||
| //===-- MsvcStlSmartPointer.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 "Generic.h" | ||
| #include "MsvcStl.h" | ||
|
|
||
| #include "lldb/DataFormatters/FormattersHelpers.h" | ||
| #include "lldb/DataFormatters/TypeSynthetic.h" | ||
|
|
||
| using namespace lldb; | ||
|
|
||
| bool lldb_private::formatters::IsMsvcStlSmartPointer(ValueObject &valobj) { | ||
| return valobj.GetChildMemberWithName("_Ptr") != nullptr; | ||
| } | ||
|
|
||
| bool lldb_private::formatters::MsvcStlSmartPointerSummaryProvider( | ||
| ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) { | ||
| ValueObjectSP valobj_sp(valobj.GetNonSyntheticValue()); | ||
| if (!valobj_sp) | ||
| return false; | ||
|
|
||
| ValueObjectSP ptr_sp(valobj_sp->GetChildMemberWithName("_Ptr")); | ||
| ValueObjectSP ctrl_sp(valobj_sp->GetChildMemberWithName("_Rep")); | ||
| if (!ctrl_sp || !ptr_sp) | ||
| return false; | ||
|
|
||
| DumpCxxSmartPtrPointerSummary(stream, *ptr_sp, options); | ||
|
|
||
| bool success; | ||
| uint64_t ctrl_addr = ctrl_sp->GetValueAsUnsigned(0, &success); | ||
| // Empty control field (expired) | ||
| if (!success || ctrl_addr == 0) | ||
| return true; | ||
|
|
||
| uint64_t uses = 0; | ||
| if (auto uses_sp = ctrl_sp->GetChildMemberWithName("_Uses")) { | ||
| bool success; | ||
| uses = uses_sp->GetValueAsUnsigned(0, &success); | ||
| if (!success) | ||
| return false; | ||
|
|
||
| stream.Printf(" strong=%" PRIu64, uses); | ||
| } | ||
|
|
||
| // _Weaks is the number of weak references - (_Uses != 0). | ||
| if (auto weak_count_sp = ctrl_sp->GetChildMemberWithName("_Weaks")) { | ||
| bool success; | ||
| uint64_t count = weak_count_sp->GetValueAsUnsigned(0, &success); | ||
| if (!success) | ||
| return false; | ||
|
|
||
| stream.Printf(" weak=%" PRIu64, count - (uses != 0)); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| namespace lldb_private { | ||
| namespace formatters { | ||
|
|
||
| class MsvcStlSmartPointerSyntheticFrontEnd : public SyntheticChildrenFrontEnd { | ||
| public: | ||
| MsvcStlSmartPointerSyntheticFrontEnd(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; | ||
|
|
||
| ~MsvcStlSmartPointerSyntheticFrontEnd() override; | ||
|
|
||
| private: | ||
| ValueObject *m_ptr_obj = nullptr; | ||
| }; | ||
|
|
||
| } // namespace formatters | ||
| } // namespace lldb_private | ||
|
|
||
| lldb_private::formatters::MsvcStlSmartPointerSyntheticFrontEnd:: | ||
| MsvcStlSmartPointerSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp) | ||
| : SyntheticChildrenFrontEnd(*valobj_sp) { | ||
| if (valobj_sp) | ||
| Update(); | ||
| } | ||
|
|
||
| llvm::Expected<uint32_t> lldb_private::formatters:: | ||
| MsvcStlSmartPointerSyntheticFrontEnd::CalculateNumChildren() { | ||
| return (m_ptr_obj ? 1 : 0); | ||
| } | ||
|
|
||
| lldb::ValueObjectSP | ||
| lldb_private::formatters::MsvcStlSmartPointerSyntheticFrontEnd::GetChildAtIndex( | ||
| uint32_t idx) { | ||
| if (!m_ptr_obj) | ||
| return lldb::ValueObjectSP(); | ||
|
|
||
| ValueObjectSP valobj_sp = m_backend.GetSP(); | ||
| if (!valobj_sp) | ||
| return lldb::ValueObjectSP(); | ||
|
|
||
| if (idx == 0) | ||
| return m_ptr_obj->GetSP(); | ||
|
|
||
| if (idx == 1) { | ||
| Status status; | ||
| ValueObjectSP value_sp = m_ptr_obj->Dereference(status); | ||
| if (status.Success()) | ||
| return value_sp; | ||
| } | ||
|
|
||
| return lldb::ValueObjectSP(); | ||
| } | ||
|
|
||
| lldb::ChildCacheState | ||
| lldb_private::formatters::MsvcStlSmartPointerSyntheticFrontEnd::Update() { | ||
| m_ptr_obj = nullptr; | ||
|
|
||
| ValueObjectSP valobj_sp = m_backend.GetSP(); | ||
| if (!valobj_sp) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| auto ptr_obj_sp = valobj_sp->GetChildMemberWithName("_Ptr"); | ||
| if (!ptr_obj_sp) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| auto cast_ptr_sp = GetDesugaredSmartPointerValue(*ptr_obj_sp, *valobj_sp); | ||
| if (!cast_ptr_sp) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| m_ptr_obj = cast_ptr_sp->Clone(ConstString("pointer")).get(); | ||
| return lldb::ChildCacheState::eRefetch; | ||
| } | ||
|
|
||
| llvm::Expected<size_t> | ||
| lldb_private::formatters::MsvcStlSmartPointerSyntheticFrontEnd:: | ||
| GetIndexOfChildWithName(ConstString name) { | ||
| if (name == "_Ptr" || name == "pointer") | ||
Nerixyz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return 0; | ||
|
|
||
| if (name == "object" || name == "$$dereference$$") | ||
| return 1; | ||
|
|
||
| return llvm::createStringError("Type has no child named '%s'", | ||
| name.AsCString()); | ||
| } | ||
|
|
||
| lldb_private::formatters::MsvcStlSmartPointerSyntheticFrontEnd:: | ||
| ~MsvcStlSmartPointerSyntheticFrontEnd() = default; | ||
|
|
||
| lldb_private::SyntheticChildrenFrontEnd * | ||
| lldb_private::formatters::MsvcStlSmartPointerSyntheticFrontEndCreator( | ||
| lldb::ValueObjectSP valobj_sp) { | ||
| if (!valobj_sp) | ||
| return nullptr; | ||
|
|
||
| if (!IsMsvcStlSmartPointer(*valobj_sp)) | ||
| return nullptr; | ||
Nerixyz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return new MsvcStlSmartPointerSyntheticFrontEnd(valobj_sp); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.