Why sometimes 'self' isn't available while debugging with lldb?

前端 未结 4 1814
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 05:44

A lot of time (when it\'s not every time) I got the following error when I try to print objects on lldb. Is there some build/debug configuration to change or is this an erro

相关标签:
4条回答
  • 2021-01-04 06:28

    As already said in this other question:

    In Build Settings, setting Precompile Prefix Header to NO fixed it for me.

    0 讨论(0)
  • 2021-01-04 06:38

    I was having this problem and it went away when I edited my scheme and set the Run build to Debug. I had set it to AdHoc for testing Push Notifications and that apparently makes LLDB unhappy.

    0 讨论(0)
  • 2021-01-04 06:44

    Because it's optimized away. Let's use an example:

    void f(int self) {
      // Here, "self" is live:Its value is used in the call to NSLog()
      NSLog(@"I am %d",self);
      // Here, "self" is dead: Its value is never used.
      // I could do self=0 or self=self*self and nobody would know.
      // An optimizing compiler will typically optimize it away.
      // It might still be on the stack (in the parameters passed to NSLog())
      // but the compiler shouldn't assume this.
      NSLog(@"Another function call: %d", 1);
      // If "self" was on the stack, it will probably now have been overwritten.
    }
    

    Compilers do a lot of things to make your code faster/smaller; forgetting about variables which are no longer needed is a very common optimization.

    0 讨论(0)
  • 2021-01-04 06:49

    I usually get this error when I have compiler optimization turned on. The compiler will generate code which does not necessarily follow your code logic flow.

    Go to your project in the navigator -> Target -> Build settings -> Search for optimization level -> expand optimization level -> select the debug line -> change to none in both columns of your project and target.

    Hope this helps.

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