简体   繁体   English

跟踪iPhone上的出站访问

[英]Track down out-of-bounds access on iPhone

I work on an average (~ 20k lines of code, Objective-C mixed with C++), and I am figthing to hunt down an EXC_BAD_ACCESS error. 我平均工作(大约2万行代码,Objective-C与C ++混合使用),并且我想找出一个EXC_BAD_ACCESS错误。

I have tried all the common techniques (like enabling NSZombie, guard edges,etc.) So far, I have ruled out the possibility to access a released object, and the double-free error. 到目前为止,我已经尝试了所有常用技术(例如启用NSZombie,保护边缘等),但排除了访问已释放对象的可能性和双重释放错误。

It seems that something writes on a memory space where it shouldn't. 似乎有些东西不应该写在内存空间上。 But, as many memory errors, it's not happening all the time, and it's not crashing always in the same place. 但是,由于有许多内存错误,这种错误并非一直发生,并且不会总是在同一位置崩溃。 (Sometimes I receive the "object was modified after being freed" message). (有时,我收到“对象被释放后被修改”的消息)。

Sometimes, the overwritten memory belongs to the allocator , and it crashes on malloc, or on free(). 有时,被覆盖的内存属于allocator ,它在malloc或free()上崩溃。

And, of course, some changes in the app may influence the bug's behaviour - if I try to comment out parts of the code, the error appears less often, so it's more difficult to find it. 而且,当然,应用程序中的某些更改可能会影响Bug的行为-如果我尝试注释掉部分代码,则错误的出现频率会降低,因此更难找到它。

Finally, I have been looking into using valgrind , but it seems that all those who used it worked on the simulator. 最后,我一直在研究使用valgrind ,但是似乎所有使用它的人都可以在模拟器上工作。 but my code must run on the actual device (some code is ARM -specific) 但我的代码必须在实际设备上运行(某些代码是ARM特定的)

Are there any general tips on how to debug such errors? 是否有关于如何调试这样的错误任何大会的提示?

Note: The app involves video processing , so the amount of memory used is fairly large. 注意:该应用程序涉及视频处理 ,因此使用的内存量非常大。

There are some special tools available on the XCode. XCode上有一些特殊的工具。 You could try to use them in order to analyse your code. 您可以尝试使用它们来分析您的代码。 http://developer.apple.com/library/mac/#featuredarticles/StaticAnalysis/index.html It will produce some warning in case of invalid objects usage so it could help you to find a problem. http://developer.apple.com/library/mac/#featuredarticles/StaticAnalysis/index.html如果对象使用无效,它将产生一些警告,因此可以帮助您发现问题。

If you feel that the C++ code is causing the issue you could copy the C++ out of your iPhone project and create a Mac project. 如果您认为C ++代码引起了问题,则可以将C ++复制出iPhone项目并创建Mac项目。 With this you could set up various stress tests. 这样,您可以设置各种压力测试。 And, you should be able to use valgrind as well. 并且,您也应该能够使用valgrind。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM