如何调试“枚举时集合被突变”?错误之类的,当Xcode无法为我提供足够的信息时? [英] How to debug "Collection was mutated while being enumerated" errors and like, when Xcode does not provide me with enough information?

查看:81
本文介绍了如何调试“枚举时集合被突变”?错误之类的,当Xcode无法为我提供足够的信息时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我看到一个重复出现的错误:

Currently, I see a recurring error:

2013-04-18 02:35:51.583 aaah[1713:1110f] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x1fc00dc0> was mutated while being enumerated.'

在失败的后台队列中(我看到我的队列此刻处于状态通过按Command + 5导致崩溃),我看到:

In the failing background queue (I see my queues state upon the moment of a crash by pressing Command + 5) I see:

0 _pthread_kill
1 pthread_kill

我看到我完全不理解的汇编输出。

And I see assembly output which I completely don't understand.

我知道如何解决这种数组枚举错误-我只是不明白应该在哪里/如何寻找导致我的应用崩溃的代码。

I know how to resolve this kind of array enumeration errors - I just can't understand where/how I should seek for the piece of code causing my app to crash.

我有很多使用AFNetworking和Core Data的多线程代码,所以我不只记得关键部分可能在哪里。

I have much multi-threaded code using AFNetworking and Core Data, so I can't just remember where the crucial section might be.

此外,此错误并不总是发生,但有时会很难仅使用隔离方法来隔离越来越少的代码段,以最终确定错误的代码段。

Also, this error occurs not always, but from time to time, so it is difficult just to use "isolation approach", isolating smaller and smaller pieces of code, to finally identify the buggy piece of code.

所以问题是:

如何从此输出中提取一些更有用的信息,或Xcode可以为我提供更多详细程度,因此我知道如何解决这段令人讨厌的代码。

推荐答案

您是否尝试过设置异常断点?有时调试器会在块内部进行异常处理,但可能会有所帮助。

Have you tried setting an exception breakpoint? Sometimes the debugger struggles with exception handling inside blocks but it might help.

在断点导航器(窗口左侧的选项卡之一)中,单击加号按钮在窗口底部,然后选择添加异常断点。然后击中完成。

In the breakpoints navigator (one of the tabs on the left side of the window) click the plus button at the bottom of the window and select add an exception breakpoint. Then hit done.

现在,当您崩溃时,调试器应该希望将您放到引发异常的那一刻。

Now when you crash, the debugger should hopefully put you right before the instant the exception was raised.

请参见 http://developer.apple.com/library/mac/#recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html 了解更多信息。

编辑:

根据评论中提供的反馈,这里还有一些分析:

Based on the feedback provided in the comments, here's some more analysis:

您的应用程序引发的异常意味着您试图更改枚举块内的集合类型(在本例中为 NSMutableOrderedSet ) for循环)。似乎您要删除循环中的对象: [NSMutableOrderedSet removeObjectsInRange:inOrderedSet:]

The exception your application is raising means that you attempted to change a collection type (in this case, an NSMutableOrderedSet) inside of an enumeration block (in your case, most likely a for-loop). It looks like you're trying to remove objects in a set that you are looping over: [NSMutableOrderedSet removeObjectsInRange:inOrderedSet:]

要解决此问题,应存储要删除的范围,然后在不再遍历集合时进行实际删除。依我所知,这仍然很困难,因为您没有深入到Objective-C代码。您应该查看左侧面板中正在运行的线程,并查看它们当前使用的方法。这可能会提示您代码在哪里错误。

To resolve this you should store the ranges you wish to remove and then do the actual removing once you're no longer iterating over the set. It's still going to be difficult since, as I understand it, you're not breaking inside of Objective-C code. You should look at the running threads in the panel on the left and look at what method they're currently in. That might give you a hint as to where your code is wrong.

这篇关于如何调试“枚举时集合被突变”?错误之类的,当Xcode无法为我提供足够的信息时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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