使用 iPhone 应用程序的 Xcode 调试缓慢且滞后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3226311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode debug with iPhone app is slow and laggy
提问by rano
I am debugging an iPhone app I'm writing in Xcode, but sometimes now the debugger (which is GDB) slows a lot (doing a step-by-step debugging) and becomes unresponsive sometimes (the icons for stepping-in, stepping-over, stepping-out are not clickable), after sometimes it gets back to normal and continues and other times it stay like that forever or a message appears in console: "Timed out" (or something similar) and I can see my CPU from activity monitor going up to 90%. As a workaround I used to put a brekpoint after the line of code I was interested in and simply went with 'Continue' to 'Continue' (doing so it run perfectly fine and fast). Can this be code dependent? Is there a way I can debug the debugger (behaviour) ?
我正在调试我在 Xcode 中编写的 iPhone 应用程序,但有时现在调试器(即 GDB)会减慢很多(进行逐步调试)并且有时会变得无响应(用于步进、步进的图标-结束,退出不可点击),有时它会恢复正常并继续,有时它会永远保持这种状态或控制台中出现一条消息:“超时”(或类似的东西),我可以看到我的 CPU 从活动监视器高达 90%。作为一种解决方法,我曾经在我感兴趣的代码行之后放置一个断点,然后简单地将“继续”转到“继续”(这样做它运行得非常好且快速)。这可以依赖于代码吗?有没有办法调试调试器(行为)?
UPDATE: The complete message is
更新:完整的消息是
Timed out fetching data. Variable display may be inaccurate.
Googling for it i discovered that it happens when Xcode gdb is trying to look inside data formatters. Someone suggested to disable Run>Variable View>Use Data Formatter (in xcode 3.2, previous i guess it is Debug->Variables View->Enable Data Formatters) and it seems to work for me too (till now) So now I am asking: why? : D
谷歌搜索我发现它发生在 Xcode gdb 试图查看数据格式化程序内部时。有人建议禁用 Run>Variable View>Use Data Formatter(在 xcode 3.2 中,以前我猜它是 Debug->Variables View->Enable Data Formatters)并且它似乎对我也有用(直到现在)所以现在我问: 为什么?:D
UPDATE2:
This solved the debugger from stopping on a specific part of the code but it stil hangs (with the same message) in another calling. It seems to me that this involves some CoreData API like (NSEntityDescription*)entityForName: inManagedObjectContext:
UPDATE2:这解决了调试器在代码的特定部分停止的问题,但它仍然在另一个调用中挂起(带有相同的消息)。在我看来,这涉及一些 CoreData API,例如(NSEntityDescription*)entityForName: inManagedObjectContext:
UPDATE3: Would it be best to cache the NSEntityDescription instead of creating always a new one?
UPDATE3:最好缓存 NSEntityDescription 而不是总是创建一个新的?
回答by deepwinter
I have observed very slow debugging when 'Queue Debugging' is enabled in the scheme. If you don't need queue debugging, consider disabling it.
在方案中启用“队列调试”时,我观察到调试速度非常慢。如果您不需要队列调试,请考虑禁用它。
回答by Prcela
I had the same issue and found some related answer on apple's discussion:
我有同样的问题,并在苹果的讨论中找到了一些相关的答案:
One common cause of problems is trying to run the data formatters on uninitialized objects. We don't actually have any way to tell for sure when an object is good or not. We have some heuristics, but stack objects sometimes point to the leftovers of another stack object that are "almost good enough" and fool us. One trick that will help out with this is when you are breaking in a function, break after the objects are initialized, not at the very beginning of the function.
问题的一个常见原因是尝试在未初始化的对象上运行数据格式化程序。我们实际上没有任何方法可以确定一个物体何时好坏。我们有一些启发式方法,但是堆栈对象有时会指向另一个“几乎足够好”的堆栈对象的剩余部分并愚弄我们。对此有帮助的一个技巧是,当您在函数中中断时,在对象初始化后中断,而不是在函数的最开始时中断。
回答by Neal L
Try running your code in Instruments. This could be a memory issue, so watch your utilization in Instruments as the code runs. When you get to the part where it becomes less and less responsive, you should see the memory usage go up and be able to trace back from there in Instruments.
尝试在 Instruments 中运行您的代码。这可能是内存问题,因此请在代码运行时注意您在 Instruments 中的使用情况。当您到达响应越来越慢的部分时,您应该看到内存使用量上升,并且能够在 Instruments 中从那里追溯。
Hope this helps!
希望这可以帮助!
回答by ERiDeM
I had a same problem and I solved it disablingthe option "Run" - "Enable/Disable Guard Alloc" in xCode. Now it works so fast! Check if you have this option enabled and disable it.
我有一个同样的问题,我解决它禁用选项“运行” - “启用/禁用保护的Alloc”在Xcode中。现在它工作得如此之快!检查您是否启用了此选项并将其禁用。
Hope it helps! :D
希望能帮助到你!:D
回答by Aditya
I have also faced same problem as soon as i migrated to xCode 3.2. i have been using xcode 3.0 and 2.0 , i never faced this problem in those SDKs. So i think this is an issue with the new SDK.
迁移到 xCode 3.2 后,我也遇到了同样的问题。我一直在使用 xcode 3.0 和 2.0,我从未在这些 SDK 中遇到过这个问题。所以我认为这是新 SDK 的问题。
回答by cregox
I'm very new to Xcode debugging, but while doing my research I stumbled upon this questionwhich may be helpful to your issue.
我对 Xcode 调试非常陌生,但是在进行研究时,我偶然发现了这个问题,这可能对您的问题有所帮助。
Basically there are two people in there who had many issues with xcode debugging and the OP solved his issue through a clean install. Quoting LucasTizma's 4th edit:
基本上有两个人在 xcode 调试方面有很多问题,OP 通过全新安装解决了他的问题。引用LucasTizma的第四次编辑:
FINALLY got device debugging to work. I have a feeling that something low-level on my device was causing issues...nothing I did worked on my system. However, I installed Xcode on another system and device debugging on the same device (with the same cable) worked flawlessly. Directly after that, device debugging began working on my original machine, leading me to believe that some strange hardware flag was screwed up and somehow "reset" on the second machine. In any case, it works now.
终于让设备调试工作了。我有一种感觉,我的设备上的一些低级别的东西导致了问题......我在我的系统上没有做任何工作。但是,我在另一个系统上安装了 Xcode,并且在同一台设备(使用同一根电缆)上的设备调试工作完美无缺。紧接着,设备调试开始在我原来的机器上工作,让我相信一些奇怪的硬件标志被搞砸了,并以某种方式在第二台机器上“重置”了。无论如何,它现在可以工作了。