且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS EXC_BAD_ACCESS:如何调试?

更新时间:2023-02-03 10:00:30

我会做的是在绿色箭头上方找到一个断点,显示EXC_BAD_ACCESS错误。然后再次运行您的代码并重现步骤来生成崩溃。



当您进入断点时,您可以使用右键单击和打印描述来检查对象是否为有效对象在Xcode的控制台左侧,或在XCode的控制台部分输入命令'po'。这就是我通常检测错误的方式。



有用的是在调试器停止后跟踪堆栈。它在左侧面板中显示了断点之前的方法的线索和链接。



希望这有助于我,并希望我对如何跟踪的方法的描述错误有帮助。


I am getting an EXC_BAD_ACCESS. I know what this usually means: Trying to access an object that doesn't exist (anymore) is the most likely cause.

So, where do I find that?

I have read numerous posts on the internet, and they all say:

"Enable NSZombie" in the scheme.

Now when I run the debugger, for what should I look? I can not see any difference...

Note: This is not about a perticular error in my code, but generally how to use the debugger with NSZombie enabled

What I would do it will be to locate a breakpoint just one line above the green arrow showing the EXC_BAD_ACCESS error. Then run again your code and reproduce the steps to generate the crash.

When you get to your breakpoint you can check that your objects are valid objects using right click and print description in the left side of your console within Xcode or typing the command 'po' within the console section in XCode. That's how I usually detect the errors.

Something useful is to trace the stack once the debugger stopped. It show in the left panel the threads and chain of invocations of the methods before the break point.

Hope this helps and hope my description of the alternative in how to track the error helps.