Skip to content

[lldb] Name UnsafePointer's single child 'pointee' #3264

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class SwiftUnsafeType {
addr_t GetStartAddress() const { return m_start_addr; }
CompilerType GetElementType() const { return m_elem_type; }
UnsafePointerKind GetKind() const { return m_kind; }
bool HasPointee() const {
return m_count == 1 && m_kind == UnsafePointerKind::eSwiftUnsafePointer;
}
virtual bool Update() = 0;

virtual ~SwiftUnsafeType() = default;
Expand Down Expand Up @@ -525,6 +528,14 @@ bool lldb_private::formatters::swift::UnsafeTypeSyntheticFrontEnd::Update() {
DataExtractor buffer_data(m_buffer_sp->GetBytes(),
m_buffer_sp->GetByteSize(), m_order, m_ptr_size);

// UnsafePointer/UnsafeMutablePointer have a `pointee` property.
if (m_unsafe_ptr->HasPointee()) {
DataExtractor data(buffer_data, 0, m_element_stride);
m_children.push_back(CreateValueObjectFromData(
"pointee", data, m_exe_ctx_ref, element_type));
return true;
}

for (size_t i = 0; i < num_children; i++) {
StreamString idx_name;
idx_name.Printf("[%zu]", i);
Expand All @@ -544,6 +555,8 @@ bool lldb_private::formatters::swift::UnsafeTypeSyntheticFrontEnd::

size_t lldb_private::formatters::swift::UnsafeTypeSyntheticFrontEnd::
GetIndexOfChildWithName(ConstString name) {
if (m_unsafe_ptr->HasPointee() && name == "pointee")
return 0;
return UINT32_MAX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,24 @@ func main() {
//% self.expect("frame variable -d run-target unsafe_ptr",
//% patterns=[
//% '\(UnsafePointer<(.*)\.ColorCode>\) unsafe_ptr = 0[xX][0-9a-fA-F]+ {',
//% '\[0\] = RGB {',
//% 'pointee = RGB {',
//% 'RGB = \(0 = 155, 1 = 219, 2 = 255\)'
//% ])
//% self.expect("frame variable -d run-target unsafe_ptr.pointee",
//% patterns=[
//% 'pointee = RGB {',
//% 'RGB = \(0 = 155, 1 = 219, 2 = 255\)'
//% ])

var unsafe_mutable_ptr = UnsafeMutablePointer(&colors[1])
//% self.expect("frame variable -d run-target unsafe_mutable_ptr",
//% patterns=[
//% '\(UnsafeMutablePointer<(.*)\.ColorCode>\) unsafe_mutable_ptr = 0[xX][0-9a-fA-F]+ {',
//% '\[0\] = Hex \(Hex = 4539903\)'
//% 'pointee = Hex \(Hex = 4539903\)'
//% ])
//% self.expect("frame variable -d run-target unsafe_mutable_ptr.pointee",
//% patterns=[
//% 'pointee = Hex \(Hex = 4539903\)'
//% ])

let unsafe_raw_ptr = UnsafeRawPointer(&colors[0])
Expand Down