关闭

printStackTrace

161人阅读 评论(0) 收藏 举报
分类:
- (void)printStackTrace:(NSException *)e//要写入log文件的信息
{
    NSString *stack = [[e userInfo] objectForKey:NSStackTraceKey];
    NSMutableArray *args = [NSMutableArray arrayWithCapacity:20];
    if (stack) {
        NSTask *ls = [[NSTask alloc] init];
        NSString *pid = [[NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]] stringValue];
        [args addObject:@"-p"];//-p
        [args addObject:pid];
        [args addObjectsFromArray:[stack componentsSeparatedByString:@"  "]];
        // Note: function addresses are separated by double spaces, not a single space.
        [ls setLaunchPath:@"/usr/bin/atos"];//xcrun atos
        [ls setArguments:args];
       // [ls launch];
        NSPipe *pipe;
        pipe = [NSPipe pipe];
        [ls setStandardOutput: pipe];
        NSFileHandle *file;
        file = [pipe fileHandleForReading];
        [ls launch];
        NSData *data;
        data = [file readDataToEndOfFile];
        NSString *string;
        string = [[NSString alloc] initWithData: data
                                       encoding: NSUTF8StringEncoding];
        NSString *strFormat = [NSString stringWithFormat:@"\n\n*************************exception begin\nexception time: %@\n%@\n*************************exception end\n\n",[NSDate date] ,string];
        DDLogCError(strFormat);

    } else {
        DDLogCError(@"No stack trace available.");
    }
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:125536次
    • 积分:2713
    • 等级:
    • 排名:第13956名
    • 原创:112篇
    • 转载:251篇
    • 译文:0篇
    • 评论:1条
    最新评论