Skip to content

[lldb] Fix unsafe pointer type determination logic #8963

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
7 changes: 5 additions & 2 deletions lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,11 @@ std::unique_ptr<SwiftUnsafeType> SwiftUnsafeType::Create(ValueObject &valobj) {
}

llvm::StringRef valobj_type_name(type.GetTypeName().GetCString());
bool is_raw = valobj_type_name.contains("Raw");
bool is_buffer_ptr = valobj_type_name.contains("BufferPointer");
valobj_type_name.consume_front("Swift.");
valobj_type_name.consume_front("Unsafe");
valobj_type_name.consume_front("Mutable");
bool is_raw = valobj_type_name.consume_front("Raw");
bool is_buffer_ptr = valobj_type_name.consume_front("Buffer");
UnsafePointerKind kind =
static_cast<UnsafePointerKind>(is_buffer_ptr << 1 | is_raw);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class Number<T:Numeric> {
}
}

// Ensure "Raw" in the name doesn't confuse the data formatters into thinking
// it's a raw value.
struct NotRaw {
var x: Int
}

func main() {
// UnsafeBufferPointer
let structArray = [ IntPair(1), IntPair(-2), IntPair(3) ]
Expand Down Expand Up @@ -204,6 +210,16 @@ func main() {
//% substrs=['(UInt8) [0] = 1'])
}

let cooked: [NotRaw] = [.init(x: 1), .init(x: 2), .init(x: 4)]
cooked.withUnsafeBufferPointer { buffer in
//% self.expect("frame variable buffer",
//% patterns=[
//% '\(UnsafeBufferPointer<a.NotRaw>\) buffer = 3 values \(0[xX][0-9a-fA-F]+\) {',
//% '\[0\] = \(x = 1\)',
//% '\[1\] = \(x = 2\)',
//% '\[2\] = \(x = 4\)',
//% ])
}
}

main()