2013-03-07 80 views
14

很多时间(当它不是每次)我尝试在lldb上打印对象时出现以下错误。是否有一些构建/调试配置更改或这是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:当我如果我把一些的NSLog()中的代码打印本地变量

(lldb) po currentUser 
error: variable not available 

,正确的同样的事情值正在打印。但与po命令不同。

+0

查看围绕断点的代码可能很有用,特别是如果您在C函数内,“self”实际上不存在。 – 2013-03-07 08:00:56

+3

在调试器控制台中键入'bt'并发布输出。这将让我们看到你在哪里。 – trojanfoe 2013-03-07 08:01:09

+0

@Benoit我只使用ObjC,我在addPoints:方法里面没有什么时髦的东西。 – 2013-03-07 08:07:35

回答

24

我打开编译器优化时通常会出现此错误。编译器将生成不一定跟随您的代码逻辑流程的代码。

转到导航器中的项目 - >目标 - >生成设置 - >搜索优化级别 - >展开优化级别 - >选择调试行 - >在项目和目标的两列中更改为无。

希望这会有所帮助。

+0

问题解决了,谢谢!这是拯救生命! – 2013-03-08 09:06:41

+0

没问题。请记住,该应用运行速度较慢,无优化(因为它没有优化),所以如果您正在运行计算密集型或AV密集型应用,则必须来回切换以正确测试您的应用。 – Spectravideo328 2013-03-08 11:42:04

+0

宾果!谢谢 – iOSDevil 2013-05-11 08:44:43

5

我有这个问题,当我编辑我的方案并将运行构建设置为调试时,它就消失了。我将它设置为AdHoc来测试推送通知,这显然使LLDB不高兴。

5

因为它被优化了。我们举一个例子:

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

编译器会做很多事情来使您的代码更快/更小;忘记不再需要的变量是非常普遍的优化。

+0

好吧,我明白了!感谢您的解释。 – 2013-03-08 09:05:31

0

正如已经在这等question说:

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

相关问题