为什么有时“自我”而与LLDB调试功能不可用?(Why sometimes 'self

2019-07-21 03:21发布

很多的时候(当它不是每次)我得到了下面的错误,当我尝试在LLDB打印对象。 有一些编译/调试配置改变或这里面LLDB错误?

(lldb) po userLevel
error: warning: Stopped in an Objective-C method, but 'self' isn't available; pretending we are in a generic context
error: use of undeclared identifier 'userLevel'
error: 1 errors parsing expression

我建立与LLVM,不脱衣调试符号。

编辑:这是回溯:

(lldb) bt
* thread #1: tid = 0x1c03, 0x001169c5 FanCake-Beta`-[KWUserLevelController addPoints:](, _cmd=0x0029187b, points=15) + 179 at KWUserLevelController.m:53, stop reason = step over
    frame #0: 0x001169c5 FanCake-Beta`-[KWUserLevelController addPoints:](, _cmd=0x0029187b, points=15) + 179 at KWUserLevelController.m:53
    frame #1: 0x00112172 FanCake-Beta`-[KWEventRealTimeControllergameEngine:hostedGame:didSucceedIn:withScore:](self=0x0b9d7740, _cmd=0x0027a2a7, engine=0x1be5af40, game=0x1be5a850, completionTime=3.59473554800206, score=0) + 421 at KWEventRealTimeController.m:647
    frame #2: 0x0007189a FanCake-Beta`__35-[KMCatchEmGameEngine animateStep6]_block_invoke197(, finished='\x01') + 257 at KMCatchEmGameEngine.m:214
    frame #3: 0x01990df6 UIKit`-[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 223
    frame #4: 0x01983d66 UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 237
    frame #5: 0x01983f04 UIKit`-[UIViewAnimationState animationDidStop:finished:] + 68
    frame #6: 0x017587d8 QuartzCore`CA::Layer::run_animation_callbacks(void*) + 284
    frame #7: 0x03634014 libdispatch.dylib`_dispatch_client_callout + 14
    frame #8: 0x036247d5 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 296
    frame #9: 0x04737af5 CoreFoundation`__CFRunLoopRun + 1925
    frame #10: 0x04736f44 CoreFoundation`CFRunLoopRunSpecific + 276
    frame #11: 0x04736e1b CoreFoundation`CFRunLoopRunInMode + 123
    frame #12: 0x040367e3 GraphicsServices`GSEventRunModal + 88
    frame #13: 0x04036668 GraphicsServices`GSEventRun + 104
    frame #14: 0x01945ffc UIKit`UIApplicationMain + 1211
    frame #15: 0x000039a8 FanCake-Beta`main(argc=1, argv=0xbffff354) + 94 at main.m:13
    frame #16: 0x00002dc5 FanCake-Beta`start + 53

编辑2:当我尝试打印本地变量同样的事情

(lldb) po currentUser
error: variable not available

如果我把一些的NSLog()中的代码,正确的值被打印。 但不与po命令。

Answer 1:

当我有编译器优化开启我通常会出现此错误。 编译器将生成代码,并不一定按照你的代码逻辑流程。

转到您的项目在导航器 - >目标 - >构建设置 - >搜索优化级别 - >扩大优化级别 - >选择调试行 - >更改为无,在你的项目和目标的两列。

希望这可以帮助。



Answer 2:

我是有这个问题,它走了,当我编辑我的方案,并设置运行建立调试。 我已经将它设置为即席测试推送通知和,显然让LLDB不满。



Answer 3:

因为它优化掉。 让我们用一个例子:

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.
}

编译器做了很多事情,使你的代码更快/更小; 忘掉它不再需要的变量是一种很常见的优化。



Answer 4:

作为该其他已经说过的问题 :

在生成设置,设置预编译前缀头,以没有固定的对我来说。



文章来源: Why sometimes 'self' isn't available while debugging with lldb?