-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb][Formatters] Consistently unwrap pointer element_type in std::shared_ptr formatters #147340
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
Michael137
merged 3 commits into
llvm:main
from
Michael137:lldb/shared_ptr-consistent-deref-format
Jul 8, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===-- Generic.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" | ||
|
|
||
| lldb::ValueObjectSP lldb_private::formatters::GetCxxSmartPtrElementPointerType( | ||
| ValueObject &ptr, ValueObject &container) { | ||
| auto container_type = container.GetCompilerType().GetNonReferenceType(); | ||
| if (!container_type) | ||
| return nullptr; | ||
|
|
||
| auto arg = container_type.GetTypeTemplateArgument(0); | ||
| if (!arg) | ||
| return nullptr; | ||
|
|
||
| return ptr.Cast(arg.GetPointerType()); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| #include "lldb/ValueObject/ValueObjectConstResult.h" | ||
|
|
||
| #include "Plugins/Language/CPlusPlus/CxxStringTypes.h" | ||
| #include "Plugins/Language/CPlusPlus/Generic.h" | ||
| #include "Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.h" | ||
| #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" | ||
| #include "lldb/lldb-enumerations.h" | ||
|
|
@@ -264,11 +265,7 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::GetChildAtIndex( | |
|
|
||
| if (idx == 1) { | ||
| Status status; | ||
| auto value_type_sp = valobj_sp->GetCompilerType() | ||
| .GetTypeTemplateArgument(0) | ||
| .GetPointerType(); | ||
| ValueObjectSP cast_ptr_sp = m_ptr_obj->Cast(value_type_sp); | ||
| ValueObjectSP value_sp = cast_ptr_sp->Dereference(status); | ||
| ValueObjectSP value_sp = m_ptr_obj->Dereference(status); | ||
| if (status.Success()) | ||
| return value_sp; | ||
| } | ||
|
|
@@ -293,7 +290,11 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::Update() { | |
| if (!ptr_obj_sp) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| m_ptr_obj = ptr_obj_sp->Clone(ConstString("pointer")).get(); | ||
| auto cast_ptr_sp = GetCxxSmartPtrElementPointerType(*ptr_obj_sp, *valobj_sp); | ||
| if (!cast_ptr_sp) | ||
| return lldb::ChildCacheState::eRefetch; | ||
|
|
||
| m_ptr_obj = cast_ptr_sp->Clone(ConstString("pointer")).get(); | ||
|
|
||
| lldb::ValueObjectSP cntrl_sp(valobj_sp->GetChildMemberWithName("__cntrl_")); | ||
|
|
||
|
|
@@ -305,7 +306,7 @@ lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd::Update() { | |
| llvm::Expected<size_t> | ||
| lldb_private::formatters::LibcxxSharedPtrSyntheticFrontEnd:: | ||
| GetIndexOfChildWithName(ConstString name) { | ||
| if (name == "__ptr_" || name == "pointer") | ||
| if (name == "pointer") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| return 0; | ||
|
|
||
| if (name == "object" || name == "$$dereference$$") | ||
|
|
||
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
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.
GetDesugaredSmartPointerValue?