[英]Why sometimes 'self' isn't available while debugging with 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:當我嘗試打印本地變量時也是如此
(lldb) po currentUser
error: variable not available
如果我在代碼中放入一些NSLog(),則打印正確的值。 但不是po
命令。
打開編譯器優化時,我通常會收到此錯誤。 編譯器將生成不一定遵循代碼邏輯流程的代碼。
轉到導航器中的項目 - >目標 - >構建設置 - >搜索優化級別 - >擴展優化級別 - >選擇調試行 - >在項目和目標的兩列中更改為無。
希望這可以幫助。
我遇到了這個問題,當我編輯我的方案並將Run build設置為Debug時它就消失了。 我已將其設置為AdHoc以測試推送通知,這顯然使LLDB不滿意。
因為它被優化了。 我們來舉個例子:
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.
}
編譯器做了很多事情來使你的代碼更快/更小; 忘記不再需要的變量是一種非常常見的優化。
正如在另一個問題中所說:
在構建設置中,將預編譯前綴標題設置為NO為我修復它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.