使用
./parseAddress.sh errorPath dSYMPath
Example:
./parseAddress.sh ~/errorInfo.txt ~/CMRead.app.dSYM
errorPath内容
Example:
*** -[__NSCFString rangeOfString:options:range:locale:]: nil argument
(null)
(
0 CoreFoundation 0x000000018fd441d8 <redacted> + 148
1 libobjc.A.dylib 0x000000018e77c55c objc_exception_throw + 56
2 CoreFoundation 0x000000018fd44108 <redacted> + 0
3 Foundation 0x00000001907325ac <redacted> + 352
4 CMRead 0x1001ac228 CMRead + 1753640
5 CMRead 0x100129b6c CMRead + 1219436
6 UIKit 0x0000000195ed03d4 <redacted> + 716
7 UIKit 0x0000000195ed0604 <redacted> + 80
8 UIKit 0x0000000195ebdbac <redacted> + 2304
9 UIKit 0x0000000195ed5668 <redacted> + 116
10 UIKit 0x0000000195c71b14 <redacted> + 176
11 UIKit 0x0000000195b8a54c <redacted> + 1196
12 QuartzCore 0x000000019305240c <redacted> + 148
13 QuartzCore 0x00000001930470e8 <redacted> + 292
14 QuartzCore 0x0000000193046fa8 <redacted> + 32
15 QuartzCore 0x0000000192fc3c64 <redacted> + 252
16 QuartzCore 0x0000000192feb0d0 <redacted> + 512
17 QuartzCore 0x0000000192febaf0 <redacted> + 120
18 CoreFoundation 0x000000018fcf17dc <redacted> + 32
19 CoreFoundation 0x000000018fcef40c <redacted> + 372
20 CoreFoundation 0x000000018fcef89c <redacted> + 1024
21 CoreFoundation 0x000000018fc1e048 CFRunLoopRunSpecific + 444
22 GraphicsServices 0x00000001916a1198 GSEventRunModal + 180
23 UIKit 0x0000000195bf8628 <redacted> + 684
24 UIKit 0x0000000195bf3360 UIApplicationMain + 208
25 CMRead 0x1000d689c CMRead + 878748
26 libdyld.dylib 0x000000018ec005b8 <redacted> + 4
)
dSYM UUID: 098473FA-1928-3623-AFD7-A83E0BA6BC09
CPU Type: arm64
Slide Address: 0x0000000100000000
Binary Image: CMRead
Base Address: 0x0000000100054000
parseAddress.sh
parseAddress.sh文件内容
#!/bin/bash
##author: zhoujie<13456774460@139.com>
##用来把友盟中的错误地址转换为符号
##调试开关
#set -x
progname=${0##*/} ## Get the name of the script without its path
folder=${0%/*}
#cd $folder && echo "cd folder:" $folder
if [[ ${#} < 2 ]]; then
echo "USAGE: $progname errorPath dSYMPath"
fi
##变量定义
error_file=${1:-errorInfo.txt}
dSYMPath=${2:-"/Users/zhoujie/Downloads/CMRead.app.dSYM"}
result_file=${error_file}_parsed.txt
##提取cpu架构
arch=$( grep "CPU Type: arm[0-9]*" ${error_file} | grep -o "arm[v]*[0-9]*" )
echo "CPU Type: " $arch
##提取UUID
uuid_in_error=$( grep "dSYM UUID: " ${error_file} | grep -o -E "[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+" )
echo "uuid_in_error: " $uuid_in_error
uuid_in_dSYM=$(dwarfdump --arch=$arch --uuid $dSYMPath | grep -o -E "[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+" )
echo "uuid_in_dSYM: " $uuid_in_dSYM
##比较UUID
if [[ $uuid_in_error != $uuid_in_dSYM ]]; then
printf "uuid is not match:\n"
printf "\tuuid_in_erro: %s\n" $uuid_in_error
printf "\tuuid_in_dSYM: %s\n" $uuid_in_dSYM
exit 1;
fi
##提取Binary Image
binaryImage=$( grep -o "Binary Image: [0-9a-zA-Z]*" ${error_file} )
binaryImage=${binaryImage##"Binary Image: "}
echo "Binary Image: " $binaryImage
##提取错误地址列表
addresses=$(grep $binaryImage ${error_file} | grep -o "0x[0-9a-f]*")
##清空文件
> $result_file
##错误地址转换为符号
for i in $addresses; do
{
printf "addresses: %s\n" $i
dwarfdump --arch=$arch --lookup $i "$dSYMPath" | grep "AT_name\|Line table file"
if [[ $? -ne 0 ]]; then
atos -o "$dSYMPath"/Contents/Resources/DWARF/$binaryImage -arch $arch $i
fi
printf "\n\n"
} >> $result_file
done
##附上原错误信息
printf "\n\n" >> $result_file
cat $error_file >> $result_file
##打开文件
open $result_file
echo "解析结果:$PWD/$result_file"
网友评论