无法跟踪[NSData getBytes:length:] crash [英] Cannot track down [NSData getBytes:length:] crash

查看:2567
本文介绍了无法跟踪[NSData getBytes:length:] crash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Foundation的 - [NSData(NSData)getBytes:length:] 方法中有一个奇怪的 EXC_BAD_ACCESS 它经常发生,但我不能从堆栈跟踪中获得任何有意义的信息。除了开源库( SDWebImage 中有一个),我的代码中没有调用 getBytes:length:一个在 SocketRocket ),但它似乎并不像他们导致崩溃。



唯一的提示是,在 com.apple.CFNetwork.addPersistCacheToStorageDaemon 线程中发生崩溃,但我不知道这是关于什么的。有人可以帮忙吗?



Stacktrace来自Crashlytics:

  :com.apple.CFNetwork.addPersistCacheToStorageDaemon 
0 libsystem_platform.dylib 0x3044a208 _platform_memmove $ VARIANT $ CortexA9 + 160
1基础0x22df9167 - [NSData(NSData)getBytes:length:] + 118
2 0x22df9167 - [NSData(NSData)getBytes:length:] + 118
基础0x22e21a1b - [NSData(NSData)replacementObjectForCoder:] + 134
4基础0x22dc2aff - [NSXPCEncoder _replaceObject:] + 90
基础0x22e240dd - [NSXPCEncoder _encodeArrayOfObjects:forKey:] + 192
6基础0x22e212ff - [NSDictionary(NSDictionary)encodeWithCoder:] + 922
7基础0x22dc32c9 - [NSXPCEncoder _encodeObject:] + 604
8基金会0x22dc379d encodeInvocationArguments + 460
9基金会0x22dc3455 - [NSXPCEncoder encodeInvocation:] + 360
10基金会0x22dc32c9 - [NSXPCEncoder _encodeObject:] + 604
11基金会0x22dc2335 - [NSXPCConnection _sendInvocation:proxyNumber :remoteInterface:withErrorHandler:timeout:userInfo:] + 1860
12基础0x22dd2823 - [NSXPCConnection _sendInvocation:proxyNumber:remoteInterface:withErrorHandler:] + 58
13基础0x22dd27db - [_ NSXPCDistantObjectWithError forwardInvocation:] + 114
14的CoreFoundation 0x2217e831 ___forwarding___ + 352
15的CoreFoundation 0x220afb88 _CF_forwarding_prep_0 + 24
16 CFNetwork的0x21c52ac9 - [NSURLStorage_CacheClient addCachedResponseWithDictionary:关键:] + 120
17 CFNetwork的0x21c21e29 ___ZN12__CFURLCache23CreateAndStoreCacheNodeEP16__CFURLCacheNodePK20_CFCachedURLResponsePK10__CFStringPK13_CFURLRequestPKvbRb_block_invoke + 1576
18 libdispatch.dylib 0x302cf423 _dispatch_call_block_and_release + 10
19 libdispatch.dylib 0x302d95d9 _dispatch_queue_drain $ VARIANT $ MP + 948
20 libdispatch.dylib 0x302d90a9 _dispatch_queue_invoke $ VARIANT $ MP + 84
21 libdispatch.dylib 0x302db0d3 _dispatch_root_queue_drain + 330
22 libdispatch.dylib 0x302dc1fb _dispatch_worker_thread3 + 106
23 libsystem_pthread.dylib 0x3044ce25 _pthread_wqthread + 668

另一个(不常发生):

 线程:崩溃:com.apple.CFNetwork.addPersistCacheToStorageDaemon 
0 libsystem_platform.dylib 0x000000019344d300 _platform_memmove + 176
1基础0x0000000182dfce18 - [NSData(NSData)getBytes:length:] + 172
2基础0x0000000182dfce18 - [NSData(NSData)getBytes:length:] + 172
3基础0x0000000182e2ae3c - [NSData(NSData)replacementObjectForCoder:] + 160
4基础0x0000000182dbd320 - [NSXPCEncoder _replaceObject:] + 120
5基础0x0000000182e2dac8 - [NSXPCEncoder _encodeArrayOfObjects forKey:] + 256
6基金会0x0000000182e2a544 - [NSDictionary中(的NSDictionary)encodeWithCoder:] + 1016
7基金会0x0000000182dbdd10 - [NSXPCEncoder _encodeObject:] + 716
8基金会0x0000000182dbe2e8 encodeInvocationArguments + 508
9基金会0x0000000182dbdee4 - [NSXPCEncoder encodeInvocation:] + 412
10基础0x0000000182dbdd10 - [NSXPCEncoder _encodeObject:] + 716
11基础0x0000000182dbcb0c - [NSXPCConnection _sendInvocation:proxyNumber:remoteInterface:withErrorHandler:timeout:userInfo:] + 2196
12的CoreFoundation 0x0000000181fde230 ___forwarding___ + 440
13的CoreFoundation 0x0000000181ee2b6c _CF_forwarding_prep_0 + 92
14 CFNetwork的0x000000018199c908 ___ZN12__CFURLCache23CreateAndStoreCacheNodeEP16__CFURLCacheNodePK20_CFCachedURLResponsePK10__CFStringPK13_CFURLRequestPKvbRb_block_invoke + 1976
15 libdispatch.dylib 0x00000001932793ac _dispatch_call_block_and_release + 24
16 libdispatch.dylib 0x000000019327936c _dispatch_client_callout + 16
17 libdispatch.dylib 0x00000001932834c0 _dispatch_queue_drain + 1216
18 libdispatch.dylib 0x000000019327c474 _dispatch_queue_invoke + 132
19 libdispatch.dylib 0x0000000193285224 _dispatch_root_queue_drain + 664
20 libdispatch.dylib 0x000000019328675c _dispatch_worker_thread3 + 108
21 libsystem_pthread.dylib 0x00000001934552e4 _pthread_wqthread + 816


解决方案



像MIT Mobile这样的应用程序,Mile point也受到影响



这里是 MIT & MilePoint



com.apple.CFNetwork.addPersistCacheToStorageDaemon



CFNetwork是较低级别的C API









$ b b

EXC_BAD_ACCESS



这意味着消息被发送到没有类的实例的内存地址执行它。因此会导致错误访问



何时会发生?


  1. 未初始化对象

  2. 已释放对象

  3. 不太可能发生的其他事情

我们如何解决这个问题?




  • 您可以通过在xcode中启用 NSZombie 来捕获一些错误(数字2)。



启用NSZombie:



启用此功能时,每个已释放物件的位置都会保留一个虚拟物件(僵尸)允许调试已经发布的对象。非常易于启用:


  1. 在XCode的可执行文件中双击您的可执行文件

  2. 参数选项卡在要在环境中设置的变量(这是底部列表,请小心您编辑的变量)

  3. 单击+按钮,变量输入NSZombieEnabled和值YES



现在不想知道发生了什么,你会看到确切的类是麻烦制造者,你会调试它很快。



注意:
不要离开僵尸启用,当您将应用程序提交到App Store。




  • 如果您使用第三方库,请更新它至最新的



注意:



我的建议是从不使用第三方框架除非它不可避免,因为库本身将有错误有时是开发人员控制,有时图书馆将更新到当前SDK.You可以找到更多关于它这里



希望这有助于


I got a strange EXC_BAD_ACCESS crash inside Foundation's -[NSData(NSData) getBytes:length:] method. It happens quite often, but I cannot get any meaningful information out of stack trace. There are no calls to getBytes:length: inside my code, except for open-source libraries (one in SDWebImage and one in SocketRocket), but it doesn't seem like they're causing the crash.

The only hint is that crash happens inside com.apple.CFNetwork.addPersistCacheToStorageDaemon thread, but I have no idea what is it about. Can someone help?

Stacktrace from Crashlytics:

Thread : Crashed: com.apple.CFNetwork.addPersistCacheToStorageDaemon
0  libsystem_platform.dylib       0x3044a208 _platform_memmove$VARIANT$CortexA9 + 160
1  Foundation                     0x22df9167 -[NSData(NSData) getBytes:length:] + 118
2  Foundation                     0x22df9167 -[NSData(NSData) getBytes:length:] + 118
3  Foundation                     0x22e21a1b -[NSData(NSData) replacementObjectForCoder:] + 134
4  Foundation                     0x22dc2aff -[NSXPCEncoder _replaceObject:] + 90
5  Foundation                     0x22e240dd -[NSXPCEncoder _encodeArrayOfObjects:forKey:] + 192
6  Foundation                     0x22e212ff -[NSDictionary(NSDictionary) encodeWithCoder:] + 922
7  Foundation                     0x22dc32c9 -[NSXPCEncoder _encodeObject:] + 604
8  Foundation                     0x22dc379d encodeInvocationArguments + 460
9  Foundation                     0x22dc3455 -[NSXPCEncoder encodeInvocation:] + 360
10 Foundation                     0x22dc32c9 -[NSXPCEncoder _encodeObject:] + 604
11 Foundation                     0x22dc2335 -[NSXPCConnection _sendInvocation:proxyNumber:remoteInterface:withErrorHandler:timeout:userInfo:] + 1860
12 Foundation                     0x22dd2823 -[NSXPCConnection _sendInvocation:proxyNumber:remoteInterface:withErrorHandler:] + 58
13 Foundation                     0x22dd27db -[_NSXPCDistantObjectWithError forwardInvocation:] + 114
14 CoreFoundation                 0x2217e831 ___forwarding___ + 352
15 CoreFoundation                 0x220afb88 _CF_forwarding_prep_0 + 24
16 CFNetwork                      0x21c52ac9 -[NSURLStorage_CacheClient addCachedResponseWithDictionary:key:] + 120
17 CFNetwork                      0x21c21e29 ___ZN12__CFURLCache23CreateAndStoreCacheNodeEP16__CFURLCacheNodePK20_CFCachedURLResponsePK10__CFStringPK13_CFURLRequestPKvbRb_block_invoke + 1576
18 libdispatch.dylib              0x302cf423 _dispatch_call_block_and_release + 10
19 libdispatch.dylib              0x302d95d9 _dispatch_queue_drain$VARIANT$mp + 948
20 libdispatch.dylib              0x302d90a9 _dispatch_queue_invoke$VARIANT$mp + 84
21 libdispatch.dylib              0x302db0d3 _dispatch_root_queue_drain + 330
22 libdispatch.dylib              0x302dc1fb _dispatch_worker_thread3 + 106
23 libsystem_pthread.dylib        0x3044ce25 _pthread_wqthread + 668

And another one (happens less often):

Thread : Crashed: com.apple.CFNetwork.addPersistCacheToStorageDaemon
0  libsystem_platform.dylib       0x000000019344d300 _platform_memmove + 176
1  Foundation                     0x0000000182dfce18 -[NSData(NSData) getBytes:length:] + 172
2  Foundation                     0x0000000182dfce18 -[NSData(NSData) getBytes:length:] + 172
3  Foundation                     0x0000000182e2ae3c -[NSData(NSData) replacementObjectForCoder:] + 160
4  Foundation                     0x0000000182dbd320 -[NSXPCEncoder _replaceObject:] + 120
5  Foundation                     0x0000000182e2dac8 -[NSXPCEncoder _encodeArrayOfObjects:forKey:] + 256
6  Foundation                     0x0000000182e2a544 -[NSDictionary(NSDictionary) encodeWithCoder:] + 1016
7  Foundation                     0x0000000182dbdd10 -[NSXPCEncoder _encodeObject:] + 716
8  Foundation                     0x0000000182dbe2e8 encodeInvocationArguments + 508
9  Foundation                     0x0000000182dbdee4 -[NSXPCEncoder encodeInvocation:] + 412
10 Foundation                     0x0000000182dbdd10 -[NSXPCEncoder _encodeObject:] + 716
11 Foundation                     0x0000000182dbcb0c -[NSXPCConnection _sendInvocation:proxyNumber:remoteInterface:withErrorHandler:timeout:userInfo:] + 2196
12 CoreFoundation                 0x0000000181fde230 ___forwarding___ + 440
13 CoreFoundation                 0x0000000181ee2b6c _CF_forwarding_prep_0 + 92
14 CFNetwork                      0x000000018199c908 ___ZN12__CFURLCache23CreateAndStoreCacheNodeEP16__CFURLCacheNodePK20_CFCachedURLResponsePK10__CFStringPK13_CFURLRequestPKvbRb_block_invoke + 1976
15 libdispatch.dylib              0x00000001932793ac _dispatch_call_block_and_release + 24
16 libdispatch.dylib              0x000000019327936c _dispatch_client_callout + 16
17 libdispatch.dylib              0x00000001932834c0 _dispatch_queue_drain + 1216
18 libdispatch.dylib              0x000000019327c474 _dispatch_queue_invoke + 132
19 libdispatch.dylib              0x0000000193285224 _dispatch_root_queue_drain + 664
20 libdispatch.dylib              0x000000019328675c _dispatch_worker_thread3 + 108
21 libsystem_pthread.dylib        0x00000001934552e4 _pthread_wqthread + 816

解决方案

With the introduction of iOS 8 there are some unexpected bug occurrance also happening we've to keep that in mind as well.

Apps like MIT Mobile,Mile point also suffers from the issue like yours,this is not wide spread though as of now.

Here are the bug links for MIT & MilePoint.

com.apple.CFNetwork.addPersistCacheToStorageDaemon

CFNetwork is lower level C API and it is wrapped by higher level class like NSURLConnection.

so the crash occurs during a network operation

EXC_BAD_ACCESS

It means that message was sent to an memory address where there’s no instance of a class to execute it. Thus results "bad access"

When will it happen?

  1. An object is not initialized
  2. An object is already released
  3. Something else that is not very likely to happen

How can we solve this problem ?

  • You can catch some of the bugs(number 2) by Enabling NSZombie in xcode

Enabling NSZombie:

When this feature is enabled, a dummy object (a zombie) is kept on the place of every released object, thus allowing to debug objects which were released already. Very easy to enable:

  1. Double click your executable in the "Executables" in XCode
  2. Open "Arguments" tab In "Variables to be set in the environment" (that’s the list at the bottom, be careful which one you edit)
  3. click the "+" button and for name of the variable enter "NSZombieEnabled" and for value "YES"

Now instead of wondering what’s going on and which exact object produced the problem, you’ll see exactly which class is the trouble maker, and you’ll debug it quite fast.

Note: Do not leave the zombies enabled, when you submit your app to the App store. Also, it’s a good practice to disable them if you don’t really need them.

  • If you are using third party libraries kindly update it to the latest

Note:

My suggestion is never use third party framework unless its unavoidable because the library itself will have bugs sometimes which is out of developer control and sometimes library would be updated late to current SDK.You can find more about it here

Hope this helps

这篇关于无法跟踪[NSData getBytes:length:] crash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆