文章

符号化 macOS 程序崩溃

有的时候需要手动符号化 macOS 程序的崩溃,跟 iOS 有些区别,简单记录下:

原始崩溃堆栈如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Process:               MyPlayer [10684]
Path:                  /Applications/MyPlayer.app/Contents/MacOS/MyPlayer
Identifier:            com.aa.MyPlayer
Version:               6.24.3 (198574)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           MyPlayer [10684]
User ID:               501

Date/Time:             2026-03-30 10:33:28.318 +0800
OS Version:            Mac OS X 10.14.4 (18E226)
Report Version:        12
Anonymous UUID:        1BE9C11D-3678-9C5F-580C-3E33454BB7C3

Sleep/Wake UUID:       A106C128-4BAF-4758-B2C5-5973C772E5BF

Time Awake Since Boot: 300000 seconds
Time Since Wake:       4700 seconds

System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000018
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [10684]

VM Regions Near 0x18:
--> 
    __TEXT                 00000001051c2000-0000000105ca5000 [ 10.9M] r-x/r-x SM=COW  /Applications/MyPlayer.app/Contents/MacOS/MyPlayer

Application Specific Information:
objc_msgSend() selector name: retain


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib               	0x00007fff7b9ec69d objc_msgSend + 29
1   com.apple.Metal               	0x00007fff5591aeff MTLResourceListAddResource + 397
2   com.apple.driver.AppleIntelHD5000GraphicsMTLDriver	0x00007fff49583a28 -[MTLIGAccelRenderCommandEncoder setEmulationFragmentTextures:withRange:] + 200
3   com.apple.Metal               	0x00007fff5594e1c5 __56-[MTLIOAccelRenderCommandEncoder bindEmulationArguments]_block_invoke_3 + 44
4   com.apple.Metal               	0x00007fff5593830b -[MTLIndirectArgumentBufferEmulationData bindIndirectArgumentsWithFunctions:] + 236
5   com.apple.Metal               	0x00007fff5594e054 -[MTLIOAccelRenderCommandEncoder bindEmulationArguments] + 561
6   com.apple.driver.AppleIntelHD5000GraphicsMTLDriver	0x00007fff495760da -[MTLIGAccelRenderCommandEncoder drawPrimitives:vertexStart:vertexCount:] + 378
7   org.cocoapods.FSPlayer        	0x00000001060a4f59 -[FSMetalRenderer uploadTextureWithEncoder:textures:] + 814
8   org.cocoapods.FSPlayer        	0x00000001060a9bd2 -[FSMetalViewNext encodePicture:renderEncoder:viewport:ratio:hdrPercentage:] + 954
9   org.cocoapods.FSPlayer        	0x00000001060aad79 __41-[FSMetalViewNext _snapshotWithSubtitle:]_block_invoke + 84
10  org.cocoapods.FSPlayer        	0x00000001060a344b -[FSMetalOffscreenRendering snapshot:device:commandBuffer:doUploadPicture:] + 215
11  org.cocoapods.FSPlayer        	0x00000001060aacdd -[FSMetalViewNext _snapshotWithSubtitle:] + 1006
12  com.aa.MRMoviePlayerKit     	0x000000010c4d5c23 -[MRMoviePlayer _saveSnapShotImgWithType:filePath:] + 184
13  com.aa.MyPlayer              	0x0000000105e64971 0x1051c2000 + 108913
14  com.aa.MyPlayer              	0x0000000105e646a6 0x1051c2000 + 108198
15  com.aa.MyPlayer              	0x0000000105e6e233 0x1051c2000 + 148019
16  com.aa.MyPlayer              	0x0000000105e6e7c3 0x1051c2000 + 149443

...

Logical CPU:     4
Error Code:      0x00000004
Trap Number:     14


Binary Images:
       0x1051c2000 -        0x105ca4fdf +com.aa.MyPlayer (6.24.3 - 198574) <5BF20BD5-21AE-3B0F-AF24-50B3FC994853> /Applications/SHPlayer.app/Contents/MacOS/SHPlayer
       0x105f24000 -        0x105f38fff +libusb-1.0.0.dylib (0) <97EF9014-4059-35F7-A4DE-BF2F0CFFE08F> /Applications/SHPlayer.app/Contents/Frameworks/libusb-1.0.0.dylib
    

需要符号化 Thread 0 的第 13-15 行符号,注意崩溃用户的指令集是 x86_64 ,我的指令集是 arm64 的,所以符号化时要明确指定,可以一次性符号化多个符号:

1
2
3
4
5
6
[matt@matt ~]$ atos -arch x86_64 -o /Users/matt/Downloads/dSYMs/MyPlayer.app.dSYM -l 0x1051c2000 0x0000000105e64971 0x0000000105e646a6 0x0000000105e6e233 0x0000000105e6e7c3
-[MyViewController(Player) saveCurrentLocalVideoCoverIfNeed] (in MyPlayer) (MyViewController+Player.m:160)
-[MyViewController(Player) releaseMoviePlayer] (in MyPlayer) (MyViewController+Player.m:142)
-[MyViewController(Player) currentMoviePlayerRebuild:] (in MyPlayer) (MyViewController+Player.m:1633)
-[MyViewController(Player) currentMoviePlayerNeedRebuild:] (in MyPlayer) (MyViewController+Player.m:1686)

DWARF/MyPlayer 为什么跟这个库(也可能是主App)的符号文件?因为崩溃发生在 0x1051c2000 这个 Load Address,然后从崩溃文件的底部 Binary Images 里找到了对应的库是 com.aa.MyPlayer,因此 -o 后面跟这个库对应的 MyPlayer.app.dSYM 路径。

其中 0x0000000105e64971 是要待转换的地址,后面可以跟多个地址,很方便。

也可以一个都不跟直接回车,进入交互式命令后输入一个回车符号化一个也很方便。

本文由作者按照 CC BY 4.0 进行授权

© debugly. 保留部分权利。

本站采用 Jekyll 主题 Chirpy