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。在过去的几个星期里,我从来没有收到过一个例外的消息。我经常会得到一个SIGABRT。我在异常断点上添加了break,它会在那里中断,但是它在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.)
在评论中给出了一个很好的答案。这应该被推广到完整的答案,这样我就可以标记所回答的问题,而其他有这个共同问题的人也可以找到它。为了实现这个目标,这个问题需要重新打开!(在那之后我会删除这个请求。)
5 个解决方案
#1
48
I will update Jeff's answer here:
我将更新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())),并查看异常的原因(例如,“error: fetch请求必须有一个实体”),请这样做:
- In the Breakpoint navigator:
- Add (+), Add Exception Breakpoint
- 添加(+),添加异常断点。
- Select the new breakpoint, Control-Click, Edit Breakpoint
- 选择新的断点,控件单击,编辑断点
- Add Action
- 添加操作
- Enter: po $arg1
- 输入:阿宝__arg1美元
- 在断点导航器:Add(+)中,添加异常断点,选择新的断点,单击控件,编辑断点添加操作Enter: po $arg1
The relevant part of the stack trace will be in the nagivator area.
堆栈跟踪的相关部分将位于nagivator区域。
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中,必须显式地提供对象类型,因为不再推断对象类型。
#2
44
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
- 输入:阿宝__arg1美元
#3
11
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())),并查看异常的原因(例如,“error: fetch请求必须有一个实体”),请这样做:
- In the Breakpoint navigator:
- Add (+), Add Exception Breakpoint
- 添加(+),添加异常断点。
- Select the new breakpoint, Contorl-Click, Edit Breakpoint
- 选择新的断点,点击,编辑断点
- Add Action
- 添加操作
- Enter: po $eax
- 输入:阿宝eax美元
- 在断点导航器:Add(+)中,添加异常断点,选择新的断点,单击,编辑断点添加操作Enter: po $eax
The relevant part of the stack trace will be in the nagivator area.
堆栈跟踪的相关部分将位于nagivator区域。
#4
4
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对调试不太友好。我喜欢这篇帮助我更清楚地理解崩溃日志的文章)
Also do this if you see error "message sent to deallocated instance"
如果看到错误“发送到deallocate实例的消息”,也要这样做
'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
这将启用僵尸对象,当您对项目进行配置时,请选择“zombie”,这会导致错误,您将能够看到哪个对象被释放。g NSArray * myArray
#5
3
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,
我从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
- 细节已经打印出来了——我知道原因
Obviously not very elegant and flexible, but at least I two big questions are answered (where and why).
显然不是很优雅和灵活,但我至少回答了两个大问题(在哪里和为什么)。
#1
48
I will update Jeff's answer here:
我将更新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())),并查看异常的原因(例如,“error: fetch请求必须有一个实体”),请这样做:
- In the Breakpoint navigator:
- Add (+), Add Exception Breakpoint
- 添加(+),添加异常断点。
- Select the new breakpoint, Control-Click, Edit Breakpoint
- 选择新的断点,控件单击,编辑断点
- Add Action
- 添加操作
- Enter: po $arg1
- 输入:阿宝__arg1美元
- 在断点导航器:Add(+)中,添加异常断点,选择新的断点,单击控件,编辑断点添加操作Enter: po $arg1
The relevant part of the stack trace will be in the nagivator area.
堆栈跟踪的相关部分将位于nagivator区域。
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中,必须显式地提供对象类型,因为不再推断对象类型。
#2
44
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
- 输入:阿宝__arg1美元
#3
11
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())),并查看异常的原因(例如,“error: fetch请求必须有一个实体”),请这样做:
- In the Breakpoint navigator:
- Add (+), Add Exception Breakpoint
- 添加(+),添加异常断点。
- Select the new breakpoint, Contorl-Click, Edit Breakpoint
- 选择新的断点,点击,编辑断点
- Add Action
- 添加操作
- Enter: po $eax
- 输入:阿宝eax美元
- 在断点导航器:Add(+)中,添加异常断点,选择新的断点,单击,编辑断点添加操作Enter: po $eax
The relevant part of the stack trace will be in the nagivator area.
堆栈跟踪的相关部分将位于nagivator区域。
#4
4
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对调试不太友好。我喜欢这篇帮助我更清楚地理解崩溃日志的文章)
Also do this if you see error "message sent to deallocated instance"
如果看到错误“发送到deallocate实例的消息”,也要这样做
'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
这将启用僵尸对象,当您对项目进行配置时,请选择“zombie”,这会导致错误,您将能够看到哪个对象被释放。g NSArray * myArray
#5
3
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,
我从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
- 细节已经打印出来了——我知道原因
Obviously not very elegant and flexible, but at least I two big questions are answered (where and why).
显然不是很优雅和灵活,但我至少回答了两个大问题(在哪里和为什么)。