符号化的正确姿势

符号化的正确姿势_第1张图片

GUI方式

将 .ips crash report 文件拖放到 Xcode > Window > Devices and Simulators > View Device Logs中, 然后导出 .crash 符号化文件.

使用条件: crash report 对应的 Archive 包是在本机构建的

symbolicatecrash

symbolicatecrash 是一个 exec (可执行文件), Xcode自带, iOS 15 之前的系统产生的 crash report, 可以直接被整个符号化, 文件路径可以通过 find 来查找1 , 结果是:

/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash

使用方式参考如下示例:

// 若执行路径与文件路径不同, 需要补充完整的URI绝对路径
$ symbolicatecrash xxx.ips xxx.dSYM > symbolicated.crash

常见问题

1. Error: “DEVELOPER_DIR” is not defined at /Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash line 69.

DEVELOPER_DIR是执行所依赖的环境变量, 解决办法如下:

```shell
$ export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
```
2. Error: No crash report version in xxx.ips at /Applications/Xcode.app/…/symbolicatecrash line 1365.

iOS 15 及之后的版本产生的 crash report, 格式有变, 已经无法使用 symbolicatecrash 符号化

> **Xcode 13 Release Notes > Instruments > New Features**
> To support the new JSON-format crash logs generated in macOS Monterey and iOS 15, Instruments includes a new CrashSymbolicator.py script. This Python 3 script replaces the symbolicatecrash utility for JSON-format logs and supports inlined frames with its default options. For more information, see: CrashSymbolicator.py --help. CrashSymbolicator.py is located in the Contents/SharedFrameworks/CoreSymbolicationDT.framework/Resources/ subdirectory within Xcode 13. (78891800)
3. UUID2 不匹配
// 查看dSYM文件的UUID
$ dwarfdump --uuid <dSYM path>

atos命令

The atos command converts numeric (数字的) addresses to their symbolic (符号的) equivalents (复数, 等同物, 对应物). If full debug symbol information is available, for example in a .app.dSYM sitting beside a .app, then the output of atos will include file name and source line number information.

常用参数 (参数顺序没有要求)

  1. -o |

    The path to a binary image file or dSYM in which to look up symbols.

  2. -l

    The load address of the binary image. This value is always assumed to be in hex, even without a “0x” prefix. The input addresses are assumed to be in a binary image
    with that load address. Load addresses for binary images can be found in the Binary Images: section at the bottom of crash, sample, leaks, and malloc_history reports.

  3. -arch architecture

    The particular architecure of a binary image file in which to look up symbols.

使用方式

// atos -arch 指令集 -0 dsym -l 调用地址 符号模块地址
// load adress:可执行指令部分相对镜像文件中的起始加载地址 address to symbolicate:调用函数的地址
atos -arch <Binary Architecture> -o <Path to dSYM file>/Contents/Resources/DWARF/<binary image name> -l <load address> <address to symbolicate>

示例

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libswiftCore.dylib              0x00000001cb264b00 specialized _fatalErrorMessage+ 2112256 (_:_:file:line:flags:) + 296
1   libswiftCore.dylib              0x00000001cb264b00 specialized _fatalErrorMessage+ 2112256 (_:_:file:line:flags:) + 296
2   libswiftCore.dylib              0x00000001cb070524 _ArrayBuffer._checkInoutAndNativeTypeCheckedBounds+ 62756 (_:wasNativeTypeChecked:) + 232
3   libswiftCore.dylib              0x00000001cb073510 Array.subscript.getter + 84
4   appName                             0x00000001005feba0 0x1004f0000 + 1108896
5   appName                             0x00000001005fcc88 0x1004f0000 + 1100936
6   appName                             0x00000001005fce84 0x1004f0000 + 1101444
7   UIKitCore                       0x00000001c9f180f0 -[UIApplication 

借助xcrun实现交互式

// 执行如下命令
$ xcrun atos -o appName.dSYM/Contents/Resources/DWARF/appName -l 0x1004f0000 -arch arm64
// 然后在换行处输入
0x00000001005feba0
// 终端输出
AppDelegate.updateRootViewController() (in ) (AppDelegate.swift:104)

直接使用 atos

// 解析整个
atos -o xxx.app.dSYM/Contents/Resources/DWARF/xxx -l 0x00000001c4fe7000 -arch arm64
// 解析单行
atos -arch arm64 -o xxx.app.dSYM/Contents/Resources/DWARF/xxx -l 0x00000001c4fe7000 0x00000001a2d6e29c

CrashSymbolicator.py

  • 脚本所在位置:

/Applications/Xcode.app/Contents/SharedFrameworks/CoreSymbolicationDT.framework/Versions/A/Resources/CrashSymbolicator.py

  • 怎样使用
// -d: dSYM符号表文件, -o: 输出符号化的文件, -p: iOS系统生成的crashReport
$ python3 CrashSymbolicator.py -d <dSYM> -o <symbolicated.crash> -p <xxx.ips>

思考

  1. 怎么查看 crash report 的 UUID ?

  1. 怎样使用find快速查找文件路径 ; ↩︎

  2. 什么是UUID ? ; ↩︎

你可能感兴趣的:(iOS开发,ios,crash,symbolicator,ips)