我在我的應用程序(SymSteam)中發現了一個特別困難的問題。似乎每當我的應用程序作爲登錄項啓動時,它都會成功啓動,但幾秒鐘後就會崩潰。如果應用程序由用戶啓動(即通過Finder),它運行正常並且不會崩潰。可可應用程序在登錄時崩潰
在登錄後立即檢查控制檯,我看到以下內容:
04/08/2012 18:51:47.437 SymSteam[187]: SteamApps exists & SteamAppsSymb exists, suggesting everything is A-OK.
04/08/2012 18:51:47.451 SymSteam[187]: Succesfully started observing everything I need to
04/08/2012 18:51:52.623 com.apple.launchd.peruser.501[124]: ([0x0-0x16016].com.simplecode.SymSteam[187]) Job appears to have crashed: Segmentation fault: 11
前兩行表明我的應用程序開始了罰款,並能爲它NSWorkspace的通知中心所需的註冊通知。雖然之後我無法弄清楚是什麼導致了分段錯誤。
也有一個崩潰報告。下面是它的一個摘錄:
OS Version: Mac OS X 10.8 (12A269)
Report Version: 10
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff80902278 _cache_getImp + 4
1 libobjc.A.dylib 0x00007fff80903f51 lookUpMethod + 41
2 libobjc.A.dylib 0x00007fff80905d5e class_respondsToSelector + 31
3 com.apple.CoreFoundation 0x00007fff82adb7ab objectIsKindOfClass + 43
4 com.apple.CoreFoundation 0x00007fff82adb812 __exceptionMatch + 18
5 libobjc.A.dylib 0x00007fff8090d1d4 _objc_exception_do_catch(objc_typeinfo*, objc_typeinfo*, void**, unsigned int) + 144
6 libc++abi.dylib 0x00007fff81621807 get_adjusted_ptr(std::type_info const*, std::type_info const*, void**) + 71
7 libc++abi.dylib 0x00007fff81621439 __gxx_personality_v0 + 889
8 libunwind.dylib 0x00007fff8b678c22 _Unwind_RaiseException + 158
9 libc++abi.dylib 0x00007fff81621baa __cxa_rethrow + 72
10 libobjc.A.dylib 0x00007fff8090d5f5 objc_exception_rethrow + 40
11 com.apple.CoreFoundation 0x00007fff82a7ce36 CFRunLoopRunSpecific + 390
12 com.apple.HIToolbox 0x00007fff8c855774 RunCurrentEventLoopInMode + 209
13 com.apple.HIToolbox 0x00007fff8c855512 ReceiveNextEventCommon + 356
14 com.apple.HIToolbox 0x00007fff8c8553a3 BlockUntilNextEventMatchingListInMode + 62
15 com.apple.AppKit 0x00007fff87afefa3 _DPSNextEvent + 685
16 com.apple.AppKit 0x00007fff87afe862 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
17 com.apple.AppKit 0x00007fff87af5c03 -[NSApplication run] + 517
18 com.apple.AppKit 0x00007fff87a9a656 NSApplicationMain + 869
19 com.simplecode.SymSteam 0x0000000108df4d54 start + 52
Thread 1:
0 libsystem_kernel.dylib 0x00007fff82dad6d6 __workq_kernreturn + 10
1 libsystem_c.dylib 0x00007fff84c27f2c _pthread_workq_return + 25
2 libsystem_c.dylib 0x00007fff84c27cf3 _pthread_wqthread + 412
3 libsystem_c.dylib 0x00007fff84c121b1 start_wqthread + 13
Thread 2:: Dispatch queue: com.apple.libdispatch-manager
0 libsystem_kernel.dylib 0x00007fff82dadd16 kevent + 10
1 libdispatch.dylib 0x00007fff81bafe26 _dispatch_mgr_invoke + 883
2 libdispatch.dylib 0x00007fff81bafa2a _dispatch_mgr_thread + 54
Thread 3:
0 libsystem_kernel.dylib 0x00007fff82dad6d6 __workq_kernreturn + 10
1 libsystem_c.dylib 0x00007fff84c27f2c _pthread_workq_return + 25
2 libsystem_c.dylib 0x00007fff84c27cf3 _pthread_wqthread + 412
3 libsystem_c.dylib 0x00007fff84c121b1 start_wqthread + 13
Thread 4:
0 libsystem_kernel.dylib 0x00007fff82dad6d6 __workq_kernreturn + 10
1 libsystem_c.dylib 0x00007fff84c27f2c _pthread_workq_return + 25
2 libsystem_c.dylib 0x00007fff84c27cf3 _pthread_wqthread + 412
3 libsystem_c.dylib 0x00007fff84c121b1 start_wqthread + 13
Thread 0 crashed with X86 Thread State (64-bit):
rax: 0x1000000000000000 rbx: 0x00007fff70bf5810 rcx: 0x0000000000000001 rdx: 0x0000000000000000
rdi: 0x1000000000000000 rsi: 0x00007fff88323f93 rbp: 0x00007fff56e0b910 rsp: 0x00007fff56e0b8d0
r8: 0x0000000000000000 r9: 0x0000000000000000 r10: 0x00000000510558d1 r11: 0x1000000000000000
r12: 0x0000000000000000 r13: 0x0000000000000000 r14: 0x1000000000000000 r15: 0x00007fff88323f93
rip: 0x00007fff80902278 rfl: 0x0000000000010202 cr2: 0x00007fff88424000
Logical CPU: 0
我感到困惑,什麼是造成問題的原因,因爲當在登錄時沒有啓動,即使在登錄時啓動,它啓動應用程序不會崩潰,但隨後崩潰了幾秒鐘後來。我不知道如何去調試這個bug,因爲我不能在程序中設置斷點或者使用Instruments,因爲這個bug只發生在登錄時。
任何有關如何去調試這個建議非常感謝!
對於它的價值,我的應用程序是一個後臺應用程序(所以它沒有一個常駐圖標或主窗口),它採用了Growl & Sparkle框架,當它推出了它註冊從NSWorkspace通知。
更新:
這裏的時候,我的應用程序啓動多數民衆贊成執行的代碼(在applicationDidFinishLaunching:
方法一些無關痛癢的代碼已被省略)。正如我上面所說,這一切都在崩潰之前得到執行。
的applicationDidFinishLaunching方法:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
[self.appController performInitialDriveScan];
[self.appController startWatchingDrives];
}
performInitialDriveScan:
只是使用的NSFileManager幾次,看看某些目錄存在。我不會在這裏發佈它,因爲它很長。我是漂亮確信它不是墜機的來源。
startWatchingDrives
:
- (void)startWatchingDrives{
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self.saController selector:@selector(didMountDrive:) name:NSWorkspaceDidMountNotification object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self.saController selector:@selector(didUnMountDrive:) name:NSWorkspaceDidUnmountNotification object:nil];
NSLog(@"Succesfully started observing everything I need to");
}
這只是增加了一個觀察員到手錶正在裝載/卸載驅動器NSWorkspace的通知中心。
這就是應用程序啓動過程中執行的所有內容。在調用startWatchingDrives
方法之後發生崩潰,並且如上所述,僅在應用程序在登錄時啓動時纔會發生。這發生在我的應用程序沒有真正做任何事情時。
也許有些代碼會有所幫助。 – Mundi 2012-08-04 20:14:01
嗯,這是問題的一半,我不知道要發佈什麼代碼,因爲我找不到崩潰的來源。我將添加在啓動應用程序時執行的代碼,但我不確定它是否會有很大的幫助。 – alexjohnj 2012-08-04 20:22:14
嘗試使用NSZombies,併發布你得到的。 – sridvijay 2012-08-04 20:47:54