iOS信号处理程序与SIGSEGV卡在一起
我想在崩溃发生后记录崩溃(在我的例子中,我想记录SIGSEGV崩溃),并在iOS上的下一次启动时向我的服务器报告 我引用这篇文章 我这样做:iOS信号处理程序与SIGSEGV卡在一起,ios,iphone,crash,signals,handler,Ios,Iphone,Crash,Signals,Handler,我想在崩溃发生后记录崩溃(在我的例子中,我想记录SIGSEGV崩溃),并在iOS上的下一次启动时向我的服务器报告 我引用这篇文章 我这样做: 发射后 使用以下代码触发崩溃: 它确实运行在mysighandler中。但它在崩溃发生后卡住了(在没有Xcode调试的情况下单击主屏幕中的应用程序图标) 在mysighandler中,我可以避免此代码的卡滞问题 void mysighandler(int signalCode) { // record the crash... signal(S
mysighandler
中。但它在崩溃发生后卡住了(在没有Xcode调试的情况下单击主屏幕中的应用程序图标)
在mysighandler
中,我可以避免此代码的卡滞问题
void mysighandler(int signalCode)
{
// record the crash...
signal(SIGSEGV, SIG_DFL);
}
或
我的问题是处理SIGSEGV碰撞(信号)的正确方法是什么?
这是完整的演示代码。可以复制到AppDelegate
,然后再试一次
@interface AppDelegate ()
@end
@implementation AppDelegate
void mysighandler(int signalCode)
{
// // This code can avoid the stuck issue.
// signal(SIGSEGV, SIG_DFL);
//
// // This code can also avoid the stuck issue.
// abort();
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// handle the SIGSEGV signal.
signal(SIGSEGV, mysighandler);
// trigger the SIGSEGV crash
__unsafe_unretained NSObject *aaa;
@autoreleasepool {
NSObject *obj = [[NSObject alloc] init];
aaa = obj;
}
[aaa respondsToSelector:@selector(init)];
return YES;
}
@end
void mysighandler(int signalCode)
{
// record the crash...
signal(SIGSEGV, SIG_DFL);
}
void mysighandler(int signalCode)
{
// record the crash...
abort();
}
@interface AppDelegate ()
@end
@implementation AppDelegate
void mysighandler(int signalCode)
{
// // This code can avoid the stuck issue.
// signal(SIGSEGV, SIG_DFL);
//
// // This code can also avoid the stuck issue.
// abort();
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// handle the SIGSEGV signal.
signal(SIGSEGV, mysighandler);
// trigger the SIGSEGV crash
__unsafe_unretained NSObject *aaa;
@autoreleasepool {
NSObject *obj = [[NSObject alloc] init];
aaa = obj;
}
[aaa respondsToSelector:@selector(init)];
return YES;
}
@end