Signal异常处理流程
- Restore the default signal handlers
- 添加signal handler 处理异常
- record the signal information,write a crash report
- Once we’re done, re-raise the signal and let the default handlers deal with it
添加 signal handler
- signal异常
1
2
3
4
5
6
7
8
9定义在 #include <machine/signal.h>
SIGABRT,/* abort() */
SIGBUS,/* bus error */
SIGFPE,/* floating point exception */
SIGILL,/* illegal instruction (not reset when caught) */
SIGPIPE, /* write on a pipe with no one to read it */
SIGSEGV, /* segmentation violation */
SIGSYS,/* bad argument to system call */
SIGTRAP /* trace trap (not reset when caught) */ - 添加handler
关键函数
/**
一、函数原型:sigaction函数的功能是检查或修改与指定信号相关联的> 处理动作(可同时> 两种操作)int sigaction(int signum, const struct sigaction *act,
struct sigaction *oldact);
signum参数指出要捕获的信号类型,act参数指定新的信号处理方式,> > oldact参数输出> 先前信号的处理方式
*/
1 | static bool installSignalHandler() |
处理异常
1 | /** Our custom signal handler. |
调试signal
Xcode Debug模式运行App时,App进程signal被LLDB Debugger调试器捕获;需要使用LLDB调试命令,将指定signal处理抛到用户层处理,方便调试。
查看全部信号传递配置:
// process handle缩写
pro hand
修改指定信号传递配置:
// option:
// -P: PASS
// -S: STOP
// -N: NOTIFY
pro hand -option false 信号名
// 例:SIGABRT信号处理在LLDB不停止,可继续抛到用户层
pro hand -s false SIGABRT