The problem is that there isn't a natural way to give registers a type in the swift TypeSystem, so the register-name variables aren't available in swift expressions. You can, however, use register read to get the value of the register, and use that value in the po expression.
If you want to actually print the contents of a swift class object that you only have the address of, you will indeed need to cast it to the appropriate type. Because pointers aren't a first class entity in swift, that's a bit more tedious than it is in C based languages.
But one of the special behaviors of the po command - that is: "print object description" - is that if the expression you pass it resolves to an Int literal, lldb will treat that as an Any, and call debugDescription on that. This only works for swift classes, however, not for structs.
So for instance, if you have:
class Foo : CustomDebugStringConvertible {
var a = 100
var debugDescription: String {
return "a: \(a)"
}
}
func doSomething() -> Int {
let myFoo = Foo()
return myFoo.a
}
print(doSomething())
You can at least get the object description from just the object's location, for instance:
(lldb) b s -p return
Breakpoint 1: 2 locations.
(lldb) run
Process 80234 launched: '/tmp/has_addr' (arm64)
Process 80234 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2
frame #0: 0x0000000100000a64 has_addr`has_addr.doSomething() -> Swift.Int at has_addr.swift:10
7
8 func doSomething() -> Int {
9 let myFoo = Foo()
-> 10 return myFoo.a
^
11 }
12
13 print(doSomething())
Target 0: (has_addr) stopped.
(lldb) v -L
scalar: (has_addr.Foo) myFoo = 0x0000000ae2c012c0 {
0x0000000ae2c012d0: a = 100
}
(lldb) po 0x0000000ae2c012c0
a: 100
po selfpo selfis only going to work if you have debug information for the frame in which you are stopped. There are situations where you'd really like to know what self is when stopped in code you don't have debug information for - e.g. you are crashing in a system library.