代码之家  ›  专栏  ›  技术社区  ›  Béatrice Cassistat

Cocoa存档的应用程序崩溃

  •  1
  • Béatrice Cassistat  · 技术社区  · 7 年前

    我是测试/分发存档应用程序的新手。我的MacOS Cocoa应用程序只有在构建为存档时才会崩溃。

    Crashed Thread:        0  Dispatch queue: com.apple.main-thread
    
    Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)
    Exception Codes:       0x0000000000000001, 0x0000000000000000
    Exception Note:        EXC_CORPSE_NOTIFY
    
    Termination Signal:    Illegal instruction: 4
    Termination Reason:    Namespace SIGNAL, Code 0x4
    Terminating Process:   exc handler [0]
    
    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
    0   MY.APP  0x000000010100532a specialized String._CharacterView.index(after:) + 250
    1   MY.APP  0x0000000100f55ef9 specialized static TextCompletionNode.hasCommonPrefix(_:with:beyond:) + 153 (AttributeManager.swift:126)
    2   MY.APP  0x0000000100f571f9 specialized TextCompletionNode.add(entry:for:) + 1161
    3   MY.APP  0x0000000100f584a9 specialized closure #1 in AttributeManager.init(dataSource:loadingHandler:) + 3097
    4   MY.APP  0x0000000100f5439e partial apply for closure #1 in AttributeManager.init(dataSource:loadingHandler:) + 30
    5   MY.APP  0x000000010104d0a3 SearchQueryCommunicator.messageHandler(_:) + 451
    6   MY.APP  0x000000010104d710 protocol witness for MessageHandler.messageHandler(_:) in conformance SearchQueryCommunicator + 16
    7   MY.APP  0x000000010102ede8 Socket.handle(object:) + 456
    8   MY.APP  0x0000000101031928 specialized Socket.readAvailableBytes(from:) + 1096
    9   MY.APP  0x0000000101031c48 specialized Socket.stream(_:handle:) + 104 (Socket.swift:77)
    10  MY.APP  0x000000010102ebff @objc Socket.stream(_:handle:) + 47
    11  com.apple.CoreFoundation        0x00007fff49548dc4 _signalEventSync + 228
    12  com.apple.CoreFoundation        0x00007fff49563736 _cfstream_solo_signalEventSync + 246
    13  com.apple.CoreFoundation        0x00007fff49546ca4 _CFStreamSignalEvent + 484
    14  com.apple.CFNetwork             0x00007fff48448a62 SocketStream::dispatchSignalFromSocketCallbackUnlocked(SocketStreamSignalHolder*) + 58
    15  com.apple.CFNetwork             0x00007fff4844cff9 SocketStream::socketCallback(__CFSocket*, unsigned long, __CFData const*, void const*) + 145
    16  com.apple.CFNetwork             0x00007fff4844cf2e SocketStream::_SocketCallBack_stream(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 70
    17  com.apple.CoreFoundation        0x00007fff49546898 __CFSocketPerformV0 + 1016
    18  com.apple.CoreFoundation        0x00007fff49527a11 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    19  com.apple.CoreFoundation        0x00007fff495e142c __CFRunLoopDoSource0 + 108
    20  com.apple.CoreFoundation        0x00007fff4950a470 __CFRunLoopDoSources0 + 208
    21  com.apple.CoreFoundation        0x00007fff495098ed __CFRunLoopRun + 1293
    22  com.apple.CoreFoundation        0x00007fff49509153 CFRunLoopRunSpecific + 483
    23  com.apple.HIToolbox             0x00007fff487f3d96 RunCurrentEventLoopInMode + 286
    24  com.apple.HIToolbox             0x00007fff487f3b06 ReceiveNextEventCommon + 613
    25  com.apple.HIToolbox             0x00007fff487f3884 _BlockUntilNextEventMatchingListInModeWithFilter + 64
    26  com.apple.AppKit                0x00007fff46aa4a73 _DPSNextEvent + 2085
    27  com.apple.AppKit                0x00007fff4723ae34 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
    28  com.apple.AppKit                0x00007fff46a99885 -[NSApplication run] + 764
    29  com.apple.AppKit                0x00007fff46a68a72 NSApplicationMain + 804
    30  MY.APP  0x0000000100f40949 main + 9 (AppDelegate.swift:12)
    31  libdyld.dylib                   0x00007fff7134a015 start + 1
    

    以下是textcompletionnode函数:

    // we assume firstString and secondString are at least longer than beyond
    private static func hasCommonPrefix(_ firstString:String, with secondString:String, beyond beyondIndex:String.Index) -> String? {
        assert((firstString.endIndex >= beyondIndex) && (secondString.endIndex >= beyondIndex))
        var commonPrefix = String(firstString[..<beyondIndex])
        guard secondString.hasPrefix(commonPrefix) else {
            return nil
        }
        var firstIndex = beyondIndex
        let firstEndIndex = firstString.endIndex
        var previousCommonPrefix: String
        repeat {
            previousCommonPrefix = commonPrefix
            if firstIndex >= firstEndIndex {
                break
            }
            //NSLog("firstString = \"\(firstString)\", firstIndex = \(firstIndex)")
            firstIndex = firstString.index(after: firstIndex) // <-- Crashing?
            commonPrefix = String(firstString[..<firstIndex])
        } while secondString.hasPrefix(commonPrefix)
        return previousCommonPrefix
    }
    

    当从xcode运行应用程序时测试相同的功能时,一切正常。我读到调试信息已从存档的应用程序中删除,因此您无法真正调试它们。我试图添加一个nslog语句来在控制台应用程序中编写一些调试信息,但没有显示任何内容。我还尝试从命令行(myapp.app/contents/macos/myapp)启动应用程序,终端中也没有显示任何内容。

    我想知道更多关于坠机前的情况。我该怎么办?

    编辑 :我试图刷新stderr,甚至根据另一篇文章的回答将stderr重定向到一个文件中: https://stackoverflow.com/a/5938021/301189 什么都没用。简单地替换 NSLog(_:_:) 具有 printf(_:) 帮助我在终端中获得一些输出。不过,我还是不知道为什么在存档的应用程序中无法从stderr获取任何信息。

    另外,在终端中输入一些输出时,不会发生上述崩溃。这么奇怪的虫子…

    0 回复  |  直到 7 年前
    推荐文章