Xcode lldb error: can't print out Swift variable - get “$__lldb_injected_self.$__lldb_wrapped_expr_x” instead

前端 未结 2 928
花落未央
花落未央 2020-12-14 11:14

Sometimes, when trying to print out a variable in the debugger, the following error message is displayed:

error: warning: :12:9: warning: initial         


        
相关标签:
2条回答
  • 2020-12-14 11:33

    As a workaround you can print it in the lldb debugger using:

    frame variable variablename
    

    Also possible using shortened syntax for quicker typing

    fr v variablename
    

    Since XCode 10.2 an ever simpler lldb syntax is supported:

    v variable
    

    Update - new workarounds:

    Print stack addresses:

    v -L variablename
    

    po like on stack frame variable.property

     v -o variablename.property
    

    Swift like p

    e unsafeBitCast(address, to: ClassName.self)
    

    Update2 - new workaround applicable for Swift classes being wrappers of objc classes.

    Example:

    v response
    (HTTPURLResponse) response = 0x0000000283ba7640 {
    

    if v works^:

    e -l objc -- (int)[0x0000000283ba7640 statusCode]
    (int) $2 = 404
    

    I'd appreciate reports what is actually helpful and works. Thanks.

    More information on this kind of capabilities can be found here: https://developer.apple.com/library/content/documentation/General/Conceptual/lldb-guide/chapters/C5-Examining-The-Call-Stack.html

    0 讨论(0)
  • 2020-12-14 11:45

    Cleaning the project and deleting derived data solved it for me.

    0 讨论(0)
提交回复
热议问题