应用程序启动时EXC_BAD_ACCESS

时间:2018-10-13 15:14:37

标签: macos cocoa exc-bad-access kern-invalid-address

在我的macOS应用程序中,我遇到了非常罕见的崩溃,无法重现,也无法查明是什么原因造成的。

请在下面查看调用堆栈。

这是我的想法:

这似乎是在应用程序启动时发生的,因为调用堆栈中有NSPersistentUIRestorer

然后,主窗口视图(NSThemeFrame)更改其帧大小并将NSViewGeometryInWindowDidChangeNotification发送给子级。

某些按钮尝试使用_setMouseTrackingForCell设置鼠标跟踪,并在释放某些子视图(或超级视图?)时崩溃。

现在我没主意了,我将不胜感激任何建议或建议。预先谢谢你。

调用堆栈:

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00006080044e6820
Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x7fff50eb4ea9 objc_msgSend + 41
1  AppKit                         0x7fff272c62d5 -[NSView(NSInternal) _uninstallTrackingArea:] + 326
2  AppKit                         0x7fff2726525e -[NSView removeTrackingArea:] + 312
3  AppKit                         0x7fff2729d3c7 -[NSCell(NSPrivate_CellMouseTracking) _setMouseTrackingInRect:ofView:withConfiguration:] + 101
4  AppKit                         0x7fff2729d2fe -[NSCell(NSPrivate_CellMouseTracking) _setMouseTrackingInRect:ofView:] + 90
5  AppKit                         0x7fff2729d1bb -[NSButtonCell _setMouseTrackingInRect:ofView:] + 84
6  AppKit                         0x7fff2729d15c -[NSControl _setMouseTrackingForCell:] + 102
7  AppKit                         0x7fff2729d0af -[NSButton(NSButtonBorder) _setMouseTrackingForCell:] + 47
8  CoreFoundation                 0x7fff29ca5edc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
9  CoreFoundation                 0x7fff29ca5daa _CFXRegistrationPost + 458
10 CoreFoundation                 0x7fff29ca5ae1 ___CFXNotificationPost_block_invoke + 225
11 CoreFoundation                 0x7fff29c63880 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1664
12 CoreFoundation                 0x7fff29c629b7 _CFXNotificationPost + 599
13 Foundation                     0x7fff2bd728c7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
14 AppKit                         0x7fff27ad9859 NSViewHierarchyNoteGeometryInWindowDidChange + 160
15 AppKit                         0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
16 AppKit                         0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
17 AppKit                         0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
18 AppKit                         0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
19 AppKit                         0x7fff27ad9a3a NSViewHierarchyNoteGeometryInWindowDidChange + 641
20 AppKit                         0x7fff2720e9a7 -[NSView _invalidateFocus] + 63
21 AppKit                         0x7fff2724e7dc -[NSView setFrameSize:] + 1902
22 AppKit                         0x7fff27264b1e -[NSView setFrame:] + 371
23 AppKit                         0x7fff2726f49c -[NSThemeFrame _relayoutAuxiliaryViewsOfType:] + 163
24 AppKit                         0x7fff2726f3e6 -[NSThemeFrame relayoutAuxiliaryViewsOfType:] + 27
25 AppKit                         0x7fff2726ec33 -[NSTitlebarViewController insertChildViewController:atIndex:] + 386
26 AppKit                         0x7fff27a88caa -[NSWindowStackController _makeTabBarForWindow:visible:] + 221
27 AppKit                         0x7fff27a8bc77 -[NSWindowStackController _addSyncedTabBarItemForWindow:atIndex:] + 625
28 AppKit                         0x7fff27a89b96 -[NSWindowStackController insertWindow:atIndex:] + 628
29 AppKit                         0x7fff27a8990b -[NSWindowStackController addWindow:] + 437
30 AppKit                         0x7fff276180ff -[NSWindow(NSWindowTabbing) _restoreTabbedWindowStateWithCoder:] + 299
31 AppKit                         0x7fff27533c82 -[NSWindow restoreStateWithCoder:] + 96
32 AppKit                         0x7fff274fcf17 restorePersistentStateWithWindowRestoration + 1004
33 AppKit                         0x7fff27533be2 -[NSPersistentUIRestorer invokeRestoration:] + 572
34 AppKit                         0x7fff27533947 __79-[NSPersistentUIRestorer finishedRestoringWindowsWithZOrder:completionHandler:]_block_invoke + 194
35 AppKit                         0x7fff27533723 +[NSWindow _batchMinimizeWindowsWithBlock:] + 86
36 AppKit                         0x7fff274fd475 -[NSPersistentUIRestorer finishedRestoringWindowsWithZOrder:completionHandler:] + 705
37 AppKit                         0x7fff27532a79 __82-[NSPersistentUIRestorer restoreStateFromRecords:usingDelegate:completionHandler:]_block_invoke_3 + 168
38 AppKit                         0x7fff2753298e __99-[NSApplication(NSPersistentUIRestorationSupport) _restoreWindowWithRestoration:completionHandler:]_block_invoke + 365
39 AppKit                         0x7fff27cb94e3 -[NSDocument(NSPersistentUISupport) restoreDocumentWindowWithIdentifier:state:completionHandler:] + 497
40 AppKit                         0x7fff2777d3c4 -[NSDocumentControllerPersistentRestoration loadedDocument:forAutoID:] + 176
41 AppKit                         0x7fff27782221 __89-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_2 + 185
42 AppKit                         0x7fff27790f70 ___NSMainRunLoopPerformBlock_block_invoke + 25
43 CoreFoundation                 0x7fff29cae87c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
44 CoreFoundation                 0x7fff29c91253 __CFRunLoopDoBlocks + 275
45 CoreFoundation                 0x7fff29c91018 __CFRunLoopRun + 3128
46 CoreFoundation                 0x7fff29c90153 CFRunLoopRunSpecific + 483
47 HIToolbox                      0x7fff28f7ad96 RunCurrentEventLoopInMode + 286
48 HIToolbox                      0x7fff28f7ab06 ReceiveNextEventCommon + 613
49 HIToolbox                      0x7fff28f7a884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
50 AppKit                         0x7fff2722ba73 _DPSNextEvent + 2085
51 AppKit                         0x7fff279c1e34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
52 AppKit                         0x7fff27220885 -[NSApplication run] + 764
53 AppKit                         0x7fff271efa72 NSApplicationMain + 804
54 MyApp                          0x106be1479 main (AppDelegate.swift:17)
55 libdyld.dylib                  0x7fff51adc015 start + 1

更新1:

正在运行的具有僵尸程序的应用程序在输出中显示以下警告

objc[67272]: Class _NSZombie_CFReadStream is implemented in both ?? (0x6040000bb290) and ?? (0x6040000b8150). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSMachPort is implemented in both ?? (0x604000151990) and ?? (0x6040001532d0). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_CFMachPort is implemented in both ?? (0x604000157110) and ?? (0x60400015c0d0). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSConcreteTask is implemented in both ?? (0x604000157250) and ?? (0x604000153a50). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSConcreteFileHandle is implemented in both ?? (0x60400016f450) and ?? (0x604000170c90). One of the two will be used. Which one is undefined.
objc[67272]: Class _NSZombie_NSConcreteFileHandle is implemented in both ?? (0x60400016f450) and ?? (0x6040001724d0). One of the two will be used. Which one is undefined.

更新2: 我设法使用符号断点重现了准确的调用堆栈(但仍然从未见过实际的崩溃)。

然后使用LLDB,我请求了有关按钮的信息,并发现它只是一个凹陷样式的常规按钮。不确定为什么有时会导致崩溃。可能只是视图层次结构树中的第一片叶子。

对于好奇的人,这是我获得信息的方式:

(lldb) expr -l Swift -- import Cocoa
(lldb) po $arg1
<NSButton: 0x60f0000ebdb0>
(lldb) expr -l Swift -- let $btn = unsafeBitCast(0x60f0000f7660, to: NSButton.self)
(lldb) expr -l Swift -- print($btn.title)

0 个答案:

没有答案