Skip to content

Commit 76e0c40

Browse files
Merge pull request #8742 from apple/dl/lldb-Fix-unsafe-pointer-type-determination-logic
[lldb] Fix unsafe pointer type determination logic
2 parents a765952 + 3767fd1 commit 76e0c40

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lldb/source/Plugins/Language/Swift/SwiftUnsafeTypes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,11 @@ std::unique_ptr<SwiftUnsafeType> SwiftUnsafeType::Create(ValueObject &valobj) {
383383
}
384384

385385
llvm::StringRef valobj_type_name(type.GetTypeName().GetCString());
386-
bool is_raw = valobj_type_name.contains("Raw");
387-
bool is_buffer_ptr = valobj_type_name.contains("BufferPointer");
386+
valobj_type_name.consume_front("Swift.");
387+
valobj_type_name.consume_front("Unsafe");
388+
valobj_type_name.consume_front("Mutable");
389+
bool is_raw = valobj_type_name.consume_front("Raw");
390+
bool is_buffer_ptr = valobj_type_name.consume_front("Buffer");
388391
UnsafePointerKind kind =
389392
static_cast<UnsafePointerKind>(is_buffer_ptr << 1 | is_raw);
390393

lldb/test/API/functionalities/data-formatter/swift-unsafe/main.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ class Number<T:Numeric> {
3535
}
3636
}
3737

38+
// Put "Raw" in the name to test that the data formatter is not confused into
39+
// choosing a one of the Unsafe*Raw types.
40+
struct NotRaw {
41+
var x: Int
42+
}
43+
3844
func main() {
3945
// UnsafeBufferPointer
4046
let structArray = [ IntPair(1), IntPair(-2), IntPair(3) ]
@@ -204,6 +210,17 @@ func main() {
204210
//% substrs=['(UInt8) [0] = 1'])
205211
}
206212

213+
let cooked: [NotRaw] = [.init(x: 1), .init(x: 2), .init(x: 4)]
214+
cooked.withUnsafeBufferPointer { buffer in
215+
print("break")
216+
//% self.expect("frame variable buffer",
217+
//% patterns=[
218+
//% '\(UnsafeBufferPointer<a.NotRaw>\) buffer = 3 values \(0[xX][0-9a-fA-F]+\) {',
219+
//% '\[0\] = \(x = 1\)',
220+
//% '\[1\] = \(x = 2\)',
221+
//% '\[2\] = \(x = 4\)',
222+
//% ])
223+
}
207224
}
208225

209226
main()

0 commit comments

Comments
 (0)