出现错误时,在远程服务器上记录callstack

时间:2015-12-03 09:25:37

标签: ios objective-c iphone xcode

当用户设备上出现错误时,应用会在远程服务器上记录错误说明和callstack

// Build the error string
NSString *error = [@"some error happened\n" stringByAppendingString:[NSThread callStackSymbols]];

// Log the error
NSLog(@"%@", error);

// Set up the web service address with param containing the error string
NSURL *url = [NSURL URLWithString:"https://myServer.com/myLoggerWebService?_error=error"];

// Send request to the server
id response = [NSString stringWithContentOfURL:url encoding:NSUTF8StringEncoding error:nil];
  • 因此,当我查看XCode中的日志时,我会在发生错误之前调用包含所有方法(具有可理解名称)的经典callstack:

    0   MyAppName                           0x00000001014a1b3b -[GlobalFunctions prepareQuery:withStatement:] + 315
    1   MyAppName                           0x00000001014a3b7e -[GlobalFunctions insertIntoWithQuery:] + 78
    2   MyAppName                           0x00000001014a3ab9 -[GlobalFunctions insertInto:fields:values:] + 1417
    3   MyAppName                           0x0000000101488f67 -[Evenement save] + 3287
    4   MyAppName                           0x00000001014055c1 -[SyncElement saveOrUpdateWithPK:tableName:] + 241
    5   MyAppName                           0x0000000101485073 +[Evenement syncDownload:] + 1251
    6   MyAppName                           0x0000000101403228 +[SyncElement sync:] + 40
    7   MyAppName                           0x000000010141150b __61+[Sync syncClassesWithIndex:check:syncType:doBlockOnSuccess:]_block_invoke + 123
    8   MyAppName                           0x00000001014e8af8 __77+[MBProgressHUD(utils) initWithText:detailTxt:doBlock:onFinish:hideOnFinish:]_block_invoke + 56
    9   MyAppName                           0x000000010152bf88 __40+[BlockHelper doBlock:onQueue:onFinish:]_block_invoke + 56
    10  libdispatch.dylib                   0x0000000106ddde5d _dispatch_call_block_and_release + 12
    11  libdispatch.dylib                   0x0000000106dfe49b _dispatch_client_callout + 8
    12  libdispatch.dylib                   0x0000000106de6bef _dispatch_root_queue_drain + 1829
    13  libdispatch.dylib                   0x0000000106de64c5 _dispatch_worker_thread3 + 111
    14  libsystem_pthread.dylib             0x000000010712f4f2 _pthread_wqthread + 1129
    15  libsystem_pthread.dylib             0x000000010712d375 start_wqthread + 13
    
  • 但是当我查看远程服务器上的日志时,我得到了这个无用的callstack,没有方法名称

    0   MyAppName                           0x00000001001612bc MyAppName + 479932
    1   MyAppName                           0x0000000100162e28 MyAppName + 486952
    2   MyAppName                           0x0000000100162b7c MyAppName + 486268
    3   MyAppName                           0x000000010015a854 MyAppName + 452692
    4   MyAppName                           0x000000010015a4dc MyAppName + 451804
    5   MyAppName                           0x000000010015a3cc MyAppName + 451532
    6   MyAppName                           0x000000010015a2cc MyAppName + 451276
    7   MyAppName                           0x0000000100103a40 MyAppName + 96832
    8   MyAppName                           0x000000010010ceb8 MyAppName + 134840
    9   MyAppName                           0x0000000100103d88 MyAppName + 97672
    10  MyAppName                           0x00000001001b395c MyAppName + 817500
    11  MyAppName                           0x00000001001b30dc MyAppName + 815324
    12  libdispatch.dylib                   0x00000001952e1994 <redacted> + 24
    13  libdispatch.dylib                   0x00000001952e1954 <redacted> + 16
    14  libdispatch.dylib                   0x00000001952ec0a4 <redacted> + 1448
    15  libdispatch.dylib                   0x00000001952e4a5c <redacted> + 132
    16  libdispatch.dylib                   0x00000001952ee318 <redacted> + 720
    17  libdispatch.dylib                   0x00000001952efc4c <redacted> + 108
    18  libsystem_pthread.dylib             0x00000001954c121c _pthread_wqthread + 816
    19  libsystem_pthread.dylib             0x00000001954c0ee0 start_wqthread + 4
    

有人知道为什么吗?如果是这样,有没有办法在远程服务器上记录可读的callstack(即第一个)?

1 个答案:

答案 0 :(得分:0)

解决方案是使用atos手动对堆栈跟踪的每一行进行符号化。这个主题帮助了我:iOS crash reports: atos not working as expected

这里有关于符号化和崩溃日志的一些文档: