如何在 iOS 中调试 webkit 崩溃日志
How to debug webkit crash log in iOS
我们得到了这样的崩溃日志(仅在 iOS 9 上崩溃):
Crashed: com.apple.main-thread
EXC_BAD_ACCESS 0x00000000815fe0fd
和细节
Crashed: com.apple.main-thread
0 WebKit 0x281aa862 std::__1::__function::__func<WebKit::WebsiteDataStore::fetchData(WebKit::WebsiteDataTypes, std::__1::function<void (WTF::Vector<WebKit::WebsiteDataRecord, 0ul, WTF::CrashOnOverflow, 16ul>)>)::$_0, std::__1::allocator<WebKit::WebsiteDataStore::fetchData(WebKit::WebsiteDataTypes, std::__1::function<void (WTF::Vector<WebKit::WebsiteDataRecord, 0ul, WTF::CrashOnOverflow, 16ul>)>)::$_0>, void (WebKit::WebsiteData)>::destroy_deallocate() + 29
1 libobjc.A.dylib 0x20a37e09 object_dispose + 20
2 WebKit 0x2808fbaf std::__1::__function::__func<WebKit::NetworkProcessProxy::fetchWebsiteData(WebCore::SessionID, WebKit::WebsiteDataTypes, std::__1::function<void (WebKit::WebsiteData)>)::$_0, std::__1::allocator<WebKit::NetworkProcessProxy::fetchWebsiteData(WebCore::SessionID, WebKit::WebsiteDataTypes, std::__1::function<void (WebKit::WebsiteData)>)::$_0>, void (WebKit::WebsiteData)>::destroy_deallocate() + 30
3 WebKit 0x280518d5 WTF::HashTable<unsigned long long, WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> > >, WTF::IntHash<unsigned long long>, WTF::HashMap<unsigned long long, std::__1::function<void (WebKit::WebsiteData)>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<std::__1::function<void (WebKit::WebsiteData)> > >::KeyValuePairTraits, WTF::HashTraits<unsigned long long> >::deallocateTable(WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> >*, unsigned int) + 48
4 WebKit 0x2808f449 WebKit::NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch() + 252
5 JavaScriptCore 0x246f7a4f WTF::RunLoop::performWork() + 310
6 JavaScriptCore 0x246f7ebb WTF::RunLoop::performWork(void*) + 22
7 CoreFoundation 0x21255dff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8 CoreFoundation 0x212559ed __CFRunLoopDoSources0 + 452
9 CoreFoundation 0x21253d5b __CFRunLoopRun + 794
10 CoreFoundation 0x211a3229 CFRunLoopRunSpecific + 520
11 CoreFoundation 0x211a3015 CFRunLoopRunInMode + 108
12 GraphicsServices 0x22793ac9 GSEventRunModal + 160
13 UIKit 0x25877189 UIApplicationMain + 144
14 Our App 0x7187e5 main (main.m:20)
15 libdispatch.dylib 0x20e4b873 (Missing)
我们使用WKWebView
来显示一些网页。并使用WKUserContentController
作为桥梁在H5和Native之间做一些调用。
那么,如何调试这种崩溃?
我试图阅读Webkit的源代码,但没有用。崩溃时才发现WebKit网络进程即将退出
我们尝试在WKKit进程崩溃时重新加载webview,崩溃消失了。
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
[_webView reload];
}
我们得到了这样的崩溃日志(仅在 iOS 9 上崩溃):
Crashed: com.apple.main-thread EXC_BAD_ACCESS 0x00000000815fe0fd
和细节
Crashed: com.apple.main-thread
0 WebKit 0x281aa862 std::__1::__function::__func<WebKit::WebsiteDataStore::fetchData(WebKit::WebsiteDataTypes, std::__1::function<void (WTF::Vector<WebKit::WebsiteDataRecord, 0ul, WTF::CrashOnOverflow, 16ul>)>)::$_0, std::__1::allocator<WebKit::WebsiteDataStore::fetchData(WebKit::WebsiteDataTypes, std::__1::function<void (WTF::Vector<WebKit::WebsiteDataRecord, 0ul, WTF::CrashOnOverflow, 16ul>)>)::$_0>, void (WebKit::WebsiteData)>::destroy_deallocate() + 29
1 libobjc.A.dylib 0x20a37e09 object_dispose + 20
2 WebKit 0x2808fbaf std::__1::__function::__func<WebKit::NetworkProcessProxy::fetchWebsiteData(WebCore::SessionID, WebKit::WebsiteDataTypes, std::__1::function<void (WebKit::WebsiteData)>)::$_0, std::__1::allocator<WebKit::NetworkProcessProxy::fetchWebsiteData(WebCore::SessionID, WebKit::WebsiteDataTypes, std::__1::function<void (WebKit::WebsiteData)>)::$_0>, void (WebKit::WebsiteData)>::destroy_deallocate() + 30
3 WebKit 0x280518d5 WTF::HashTable<unsigned long long, WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> > >, WTF::IntHash<unsigned long long>, WTF::HashMap<unsigned long long, std::__1::function<void (WebKit::WebsiteData)>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<std::__1::function<void (WebKit::WebsiteData)> > >::KeyValuePairTraits, WTF::HashTraits<unsigned long long> >::deallocateTable(WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> >*, unsigned int) + 48
4 WebKit 0x2808f449 WebKit::NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch() + 252
5 JavaScriptCore 0x246f7a4f WTF::RunLoop::performWork() + 310
6 JavaScriptCore 0x246f7ebb WTF::RunLoop::performWork(void*) + 22
7 CoreFoundation 0x21255dff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8 CoreFoundation 0x212559ed __CFRunLoopDoSources0 + 452
9 CoreFoundation 0x21253d5b __CFRunLoopRun + 794
10 CoreFoundation 0x211a3229 CFRunLoopRunSpecific + 520
11 CoreFoundation 0x211a3015 CFRunLoopRunInMode + 108
12 GraphicsServices 0x22793ac9 GSEventRunModal + 160
13 UIKit 0x25877189 UIApplicationMain + 144
14 Our App 0x7187e5 main (main.m:20)
15 libdispatch.dylib 0x20e4b873 (Missing)
我们使用WKWebView
来显示一些网页。并使用WKUserContentController
作为桥梁在H5和Native之间做一些调用。
那么,如何调试这种崩溃?
我试图阅读Webkit的源代码,但没有用。崩溃时才发现WebKit网络进程即将退出
我们尝试在WKKit进程崩溃时重新加载webview,崩溃消失了。
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
[_webView reload];
}