在没有 NSZombie 的情况下追踪 EXC_BAD_ACCESS?

发布于 2024-09-07 01:53:35 字数 1023 浏览 1 评论 0原文

我已经研究了两天了,仍然找不到崩溃的原因。

我知道这与尝试访问已释放的对象有关,但我不知道哪个访问或哪个对象。

每当我在谷歌上尝试找到 EXC_BAD_ACCESS 的来源时,人们都会建议使用 NSZombies。问题是当我启用僵尸时(通过环境变量在 xcode 中或通过 ObjectAlloc 属性在仪器中),程序不会像通常那样崩溃,并且僵尸不会报告任何内容(日志中没有显示任何内容,并且在日志中没有标记任何内容)仪器)。我对 NSZombie 缺少什么吗?

我尝试利用来自 xcode 调试器和仪器中的 ObjectAlloc 的一些信息,但所有信息都非常神秘,并不能真正帮助我。

我已将调试器设置为在出现 Objective-C 异常时停止。当它执行时,这是显示的调用堆栈:

0 objc_msgSend
1 ??
2 -[UITableViewCell removeFromSuperView]
3 -[UIView dealloc]
... etc ...

首先,“1 ??”是怎么回事? ?问号是什么意思?其次,我如何知道它在我的代码中被调用的位置?所陈述的所有操作都过于通用(例如 UIView dealloc,但是哪个 UIView?以及在哪里?)。

此外,当异常发生时,它指向汇编代码,这对我没有任何好处,除非我花几个小时试图弄清楚代码的作用。我知道一些汇编,但必须有更好的方法......对吧?

有什么方法可以获取有意义的信息,了解异常发生之前代码中运行的最后一行是什么?

我尝试过在周围撒一些 NSLogs 和断点,但这对我没有多大帮助,因为崩溃发生在我从导航控制器弹出视图控制器之后。在我放置断点的任何地方,断点都能很好地达到(崩溃后我找不到中断点)。只有当我在调试器中“继续”时才会发生异常。就好像崩溃发生在我的代码之外,所以我不知道在哪里可以处理它。

我检查了我的代码并仔细检查了我是否遵守所有内存管理规则(至少据我所知)。我确信这是非常微妙的东西,但我似乎找不到它。

如果有人有任何想法如何在没有 NSZombie 的情况下找到此类错误,请分享。

谢谢。

I've spent two days on this and I still can't find the cause of the crash.

I know it has something to do with trying to access an object that has been freed but I don't know which access or which object.

Whenever I google trying to find the source of EXC_BAD_ACCESS people suggest using NSZombies. The problem is when I enable zombies (either in xcode via environment variable or in instruments via ObjectAlloc properties) the program doesn't crash where it usually does and the zombies don't report anything (nothing shows up in logs and nothing is flagged in instruments). Is there something I'm missing with NSZombie?

I've tried utilizing some information from xcode's debugger and from ObjectAlloc in instruments but all the information is very cryptic and doesn't really help me.

I've set the debugger to stop on objective-c exceptions. When it does it this is the call stack shown:

0 objc_msgSend
1 ??
2 -[UITableViewCell removeFromSuperView]
3 -[UIView dealloc]
... etc ...

First of all, what's the deal with '1 ??' ? What do the question marks mean? Second of all how can I know where this was called in my code? All the operations stated are too generic (eg UIView dealloc, but which UIView? And where?).

Also when the exception occurs it points to assembly code which again, doesn't do me any good unless I was to spend hours trying to figure out what the code does. I know some assembly but there has to be a better way... right?

Is there any way I can get meaningful information as to what was the last line that ran in my code before the exception occurred?

I've tried sprinkling some NSLogs and breakpoints around but it doesn't help me much because the crash happens after I pop a view controller from a navigation controller. Everywhere I place breakpoints the breakpoints are reached fine (I can't find a point to break after the crash). It's only when I 'continue' in the debugger that the exception occurs. It's as if the crash happens outside of my code so I have no idea where to get a handle on it.

I've looked through my code and double checked that I adhere to all the memory management rules (at least to the best of my knowledge). I'm sure it's something very subtle but I can't seem to find it.

If anyone has any ideas how to find such bugs without NSZombie please share.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女 2024-09-14 01:53:35

好吧,我发现了问题。我有一个自定义表格单元格类,其中我首先在 dealloc 方法中调用 [super dealloc] (而不是最后一个)。我想我写这门课很匆忙,并没有真正考虑过。我猜父母释放了孩子需要释放的东西?

所以我对自己的问题没有真正的答案,但基本上我结合使用临时代码跟踪和各种调试技术(断点、NSLog、尝试解密神秘的堆栈跟踪等)发现了问题。

实际上,帮助我的主要策略是一点一点地注释掉代码,直到我将问题区域简化为尽可能简单,同时仍然保持崩溃完好无损。这让我意识到问题并不在我想象的地方,而是在一个更微妙的区域(例如,在本例中是在辅助类的 dealloc 方法中)。

我希望这可以帮助某人。我将暂时不回答这个问题,以防有人有更彻底的调试策略而不依赖 NSZombies。另外,如果有人可以澄清这两个问号在堆栈跟踪中的含义,那将会很有帮助。

Well I found the problem. I had a custom table cell class in which I called [super dealloc] first in the dealloc method (rather than last). I guess I wrote this class in a hurry and didn't really think about it. I'm guessing something got released in the parent that the child needed for releasing?

So I don't have a real answer to my own question but basically I found the problem using a combination of ad-hoc code tracing and various debugging techniques (breakpoints, NSLogs, trying to decypher cryptic stack trace,etc).

Actually the main strategy that helped me was commenting out code bit by bit until I stripped down the problem area into as simple as it gets while still keeping the crash intact. This let me realize the problem wasn't where I thought it would be but in a more subtle area (eg in the dealloc method of a secondary class in this case).

I hope this can sort of help someone out. I'll leave this question unanswered for a bit incase someone has a more thorough debugging strategy without relying on NSZombies. Also if someone can clarify what those two question marks mean in the stack trace that would be helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文