Lldb: Unable to bind generic parameters in context with weakly captured self

Hello,

I have opened an issue regarding LLDB, see lldb: Unable to bind generic parameters in context with weakly captured self · Issue #9194 · swiftlang/llvm-project · GitHub .

TL;DR:
If you capture weakly a generic class, lldb is not able to bind generic variables, for example:

final class Bridge<T> {
    var current: T
    init(c: T) { current = c }
    func foo() {
        Task { [weak self] in
            print(self?.current) // HERE!
        }
    } 
}

Do you happen to know about any workaround, or whether the issue was already fixed? I have tested the issue on Xcode 15.4.

Hi Mikoláš,

Thanks for opening the issue! This seems to be fixed in OSS LLDB:

(lldb) expr T.self
(Int.Type) $R4 = Int
(lldb) expr self
(q.Bridge<Int>?) $R5 = 0x000060000018c080 {
  current = 1
}

You can use p or, if that doesn't work, v, to print on older LLDBs (in general I default to p over expr, as that is usually more efficient).

// On older lldb
(lldb) expr self
error: <EXPR>:2:43: error: cannot find type '$__lldb_context' in scope
extension Swift.Optional where Wrapped == $__lldb_context {
                                          ^~~~~~~~~~~~~~~

error: <EXPR>:19:27: error: instance method '$__lldb_user_expr_1' requires the types 'Bridge<Int>' and '<<error type>>' be equivalent
    $__lldb_injected_self.$__lldb_user_expr_1(
                          ^

<EXPR>:4:17: note: where 'Wrapped' = 'Bridge<Int>'
  mutating func $__lldb_user_expr_1(_ $__lldb_arg : UnsafeMutablePointer<Any>) {
                ^

(lldb) p self
(q.Bridge<Int>?) 0x0000600001750140 {
  current = 1
}
2 Likes