编程技术记录

世界你好!

日志格式

先说日志格式,常见的日志格式: 日志头 + 线程堆栈 + 映像加载信息

日志头(截取我们需要的部分)

# 软硬件信息
Hardware Model:      iPhone9,1
Code Type:           ARM-64 (Native)
OS Version:          iPhone OS 13.3.1 (17D50)

# 崩溃原因
Exception Type:  EXC_GUARD
Exception Subtype: GUARD_TYPE_FD
Exception Message: CLOSE on file descriptor 66 (guarded with 0x534b434869d9c32f)
Exception Note:  SIMULATED (this is NOT a crash)

# 崩溃线程
Triggered by Thread:  44

崩溃线程信息(截取我们需要的部分)

Thread 44 name:  MHD-worker
Thread 44 Crashed:

# 调用堆栈
# 栈号  模块名   方法地址   加载地址  偏移量
0   libsystem_kernel.dylib          0x00000001aa54ae8c close + 8
1   iQiYiPhoneVideo                 0x0000000100cceda0 0x1005e0000 + 7269792
2   iQiYiPhoneVideo                 0x0000000100ccbde4 0x1005e0000 + 7257572
3   iQiYiPhoneVideo                 0x0000000100ccc83c 0x1005e0000 + 7260220
4   iQiYiPhoneVideo                 0x0000000100ccdc00 0x1005e0000 + 7265280
5   libsystem_pthread.dylib         0x00000001aa46dd8c _pthread_start + 156
6   libsystem_pthread.dylib         0x00000001aa47176c thread_start + 8

Thread 44 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000001   x1: 0x0000000000000000   x2: 0x0000000171516bdc   x3: 0x0000000171516e00
    x4: 0x0000000000000000   x5: 0x0000000000000400   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0000000000000005   x9: 0x0000000000000006  x10: 0x0000000000000001  x11: 0x0000000000000000
   x12: 0x0000000000000001  x13: 0x0000000000000002  x14: 0x0000000000000000  x15: 0x0000000000006dc2
   x16: 0x0000000000000006  x17: 0x0000000055800000  x18: 0x0000000000000000  x19: 0x0000000109d900e0
   x20: 0x0000000000000042  x21: 0x0000000171516e80  x22: 0x0000000171516f00  x23: 0x0000000000000000
   x24: 0x0000000000000000  x25: 0x0000000000000000  x26: 0x0000000000000000  x27: 0x0000000000000000
   x28: 0x0000000000000000   fp: 0x0000000171516c20   lr: 0x0000000100cceda0
    sp: 0x0000000171516c00   pc: 0x00000001aa54ae8c cpsr: 0x60000000
   esr: 0x00000000  Address size fault

二进制映像加载信息(截取我们需要的部分)

Binary Images:
# 模块的地址范围  模块UUID  指令集架构  模块路径
0x1005e0000 - 0x1070abfff iQiYiPhoneVideo arm64  <f26ad8c2b7083876944b1f6602d11caa> /var/containers/Bundle/Application/A9DAE6D8-A1D0-4EF1-AE5A-6F6795EDCD58/iQiYiPhoneVideo.app/iQiYiPhoneVideo

崩溃所在模块的UUID

1、崩溃日志中App的UUID
2、Xcode打包时dSYM的UUID

1和2要匹配上才能对崩溃日志符号话

崩溃日志中App的UUID需要从二进制映像加载信息中获取,在尖括号内,本文为f26ad8c2b7083876944b1f6602d11caa

# 模块的地址范围  模块UUID  指令集架构  模块路径
0x1005e0000 - 0x1070abfff iQiYiPhoneVideo arm64  <f26ad8c2b7083876944b1f6602d11caa> /var/containers/Bundle/Application/A9DAE6D8-A1D0-4EF1-AE5A-6F6795EDCD58/iQiYiPhoneVideo.app/iQiYiPhoneVideo

Xcode打包时dSYM的UUID,使用命令dwarfdump获取

dwarfdump --uuid XXX.app.dSYM

符号化

命令为atos, 重要参数为

atos -o 符号表路径  -arch 指令集架构  -l 模块加载地址  方法地址A 方法地址B 方法地址C ....
  • 符号表文件,在dSYM里面Contents/Resources/DWARF/xxx
  • 指令集架构,在崩溃日志的信息头,或者二进制映像加载信息中都可以获取,本文为arm64
  • 模块加载地址,也叫模块基地址,从二进制映像加载信息中的地址范围获取,本文为0x1005e0000
  • 方法地址,在崩溃堆栈信息中获取

例如

atos -o xxx.app.dSYM/Contents/Resources/DWARF/xxx  -arch arm64 -l 0x1005e0000 0x0000000100cceda0

模块地址

有时候,自定义的崩溃日志只有崩溃堆栈信息,那么模块的加载地址如何获取呢?

例如一些堆栈

1   iQiYiPhoneVideo                 0x0000000100cceda0  xxxxx + 7269792

按照
方法地址 = 模块地址 + 偏移量
那么
模块地址 = 0x0000000100cceda0 – 7269792 = 0x1005e0000

© Beli. All Rights Reserved.