ios Xcode 异常断点不打印抛出异常的详细信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17238673/
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 exception breakpoint doesn't print details of the exception being thrown
提问by nirvana
SUMMARY
概括
When I set an exception breakpoint, I don't get the exception message. How do I get the exception message? I already know how to get the stack trace, but that doesn't include the exception message.
当我设置异常断点时,我没有收到异常消息。如何获取异常消息?我已经知道如何获取堆栈跟踪,但这不包括异常消息。
DETAILS
细节
In the past I developed iOS Apps with Xcode and when there was a problem, I'd get an error/exception. The exception would often have a message like "can't dereference null" or whatever.
过去我使用 Xcode 开发 iOS 应用程序,当出现问题时,我会收到错误/异常。异常通常会出现“不能取消引用 null”之类的消息。
Now, using Xcode 4.6.x for the past several weeks I've never gotten an exception message. I'll often get a SIGABRT. I put in the break on exception breakpoint and it will break there, but it's off in some assembly within the iOS SDK and I never get a message.
现在,过去几周使用 Xcode 4.6.x,我从未收到过异常消息。我经常会收到 SIGABRT。我在异常断点处设置了中断,它会在那里中断,但它在 iOS SDK 中的某些程序集中关闭,我从未收到消息。
In fact, I can't remember the last time I saw anything show up in the debugger console.
事实上,我不记得上次在调试器控制台中看到任何东西是什么时候了。
Did exception info dissappear with the migration to LLVM?
迁移到 LLVM 时异常信息是否消失了?
It's very frustrating to have my app just crash in the SDK without knowing why. I check the last function to make sure things are set up correctly (objects allocated, etc) and they are which means I'm left with no clues.
让我的应用程序在不知道原因的情况下在 SDK 中崩溃是非常令人沮丧的。我检查最后一个函数以确保设置正确(分配的对象等),这意味着我没有任何线索。
Is it possibly a build setting held over from the past is somehow turning off exception messages?
是否可能是过去保留的构建设置以某种方式关闭了异常消息?
Please reopen question. It now has an answer!
请重新提问。现在有了答案!
In the comments an excellent answer has been given. This should be promoted to full answer, and so I can mark the question answered and others who have this common issue can find it. In order for that to happen, the question needs to be reopened! (I'll delete this plea after that happens.)
在评论中已经给出了很好的答案。这应该提升为完整答案,这样我就可以标记已回答的问题,并且其他有此常见问题的人可以找到它。为了做到这一点,需要重新打开这个问题!(在那之后我会删除这个请求。)
回答by ucangetit
I will update Jeff's answer here:
我将在这里更新杰夫的回答:
To have both the line causing the exception highlighted(and not UIApplicationMain() in main.m) AND to see the reason for the exception(e.g., "error: A fetch request must have an entity."), do this:
- In the Breakpoint navigator:
- Add (+), Add Exception Breakpoint
- Select the new breakpoint, Control-Click, Edit Breakpoint
- Add Action
- Enter: po $arg1
The relevant part of the stack trace will be in the nagivator area.
要同时突出显示导致异常的行(而不是 main.m 中的 UIApplicationMain())并查看异常的原因(例如,“错误:获取请求必须有一个实体。”),请执行以下操作:
- 在断点导航器中:
- 添加(+),添加异常断点
- 选择新断点,按住 Control 键单击,编辑断点
- 添加操作
- 输入:po $arg1
堆栈跟踪的相关部分将在导航器区域中。
This seems to still work in Xcode 9
这似乎在 Xcode 9 中仍然有效
Here is my addition for use with Xcode 6 and below.
这是我添加的用于 Xcode 6 及以下版本的内容。
- Enter: po (NSException*) $eax
- 输入:po (NSException*) $eax
In Xcode 6 you must explicitly provide the object type because it is no longer inferred.
在 Xcode 6 中,您必须明确提供对象类型,因为它不再被推断。
回答by jcady
For Xcode 7-9 (based off Jeff's answer):
对于 Xcode 7-9(基于 Jeff 的回答):
In the Breakpoint navigator:
在断点导航器中:
- Add (+), Add Exception Breakpoint
- Select the new breakpoint, Control-Click, Edit Breakpoint
- Add Action
- Enter:
po $arg1
- 添加(+),添加异常断点
- 选择新断点,按住 Control 键单击,编辑断点
- 添加操作
- 进入:
po $arg1
回答by Jeff
To have both the line causing the exception highlighted(and not UIApplicationMain() in main.m) AND to see the reason for the exception(e.g., "error: A fetch request must have an entity."), do this:
要同时突出显示导致异常的行(而不是 main.m 中的 UIApplicationMain())并查看异常的原因(例如,“错误:获取请求必须有一个实体。”),请执行以下操作:
- In the Breakpoint navigator:
- Add (+), Add Exception Breakpoint
- Select the new breakpoint, Contorl-Click, Edit Breakpoint
- Add Action
- Enter: po $eax
- 在断点导航器中:
- 添加(+),添加异常断点
- 选择新断点,Contorl-Click,Edit Breakpoint
- 添加操作
- 输入:po $eax
The relevant part of the stack trace will be in the nagivator area.
堆栈跟踪的相关部分将在导航器区域中。
回答by Roma
Yes xcode is not so friendly for debugging. I like this article which helps me to understand crash logs a bit clearly)) Demystifying iOS Application Crash Logs
是的 xcode 对调试不太友好。我喜欢这篇文章,它可以帮助我更清楚地理解崩溃日志)) 揭秘 iOS 应用程序崩溃日志
Also do this if you see error "message sent to deallocated instance"
如果您看到错误“消息发送到已释放的实例”,也请执行此操作
'Products -> Edit Scheme -> Enable Zombie Objects'
'产品 -> 编辑方案 -> 启用僵尸对象'
this will enable zombie objects and when you do profile to your project choose "zombie", cause error and you will be able to see which objects was deallocated e.g NSArray *myArray
这将启用僵尸对象,当你对你的项目进行配置时选择“僵尸”,导致错误,你将能够看到哪些对象被释放,例如 NSArray *myArray
回答by bcause
The information I get from po $eax
or po (NSException *)$eax
seems to be different from what Xcode would print if no exception breakpoints are set. So I do the following,
如果没有设置异常断点,我从Xcode获得的信息po $eax
或po (NSException *)$eax
似乎与 Xcode 打印的信息不同。所以我做以下,
- Add an exception breakpoint
- Exception occurs, breakpoint was hit -> I know the location
- Temporarily disable breakpoints (second button on the left in Debug area)
- Continue program execution (third button on the left in Debug area)
- Details are printed -> I know the cause
- 添加异常断点
- 发生异常,断点被击中 ->我知道位置
- 暂时禁用断点(调试区域左侧的第二个按钮)
- 继续程序执行(Debug区左侧第三个按钮)
- 打印详细信息 ->我知道原因
Obviously not very elegant and flexible, but at least I two big questions are answered (where and why).
显然不是很优雅和灵活,但至少我回答了两个大问题(在哪里和为什么)。
回答by yoAlex5
You can use bt
or thread backtrace
command to print error trace
您可以使用bt
或thread backtrace
命令打印错误跟踪
Show the stack backtrace for the current thread.
显示当前线程的堆栈回溯。
The same stack trace you can find in crash reports
您可以在崩溃报告中找到的相同堆栈跟踪
Information about current thread use currentThread
有关当前线程使用的信息 currentThread
//Objective-C
po [NSThread currentThread]
//Swift
po Thread.currentThread