• 处理minidump文件用到的“工具”的分享


    前言

    最近崩溃平台有BUG,native的崩溃堆栈解析不出来,只能自己线下人肉解堆栈了。本着能善用工具提高工作效果的习惯,最终收获了如下的zshe脚本(方法)用于后续的工作,借此笔记跟大家分享与交流,供大家参考之

    分享产物

    // xxx.so是我关注出现崩溃的so

    stackwalk=/Applications/Android\ Studio.app/Contents/plugins/android-ndk/resources/lldb/bin/minidump_stackwalk
    
    # for minidump
    stackwalk=/Applications/Android\ Studio.app/Contents/plugins/android-ndk/resources/lldb/bin/minidump_stackwalk
    
    # for minidump
    function dumpaddr() {
       ${stackwalk} -s $1 | grep libxxx.so | head -n $2
    }
    
    function adumpaddr() {
       ${stackwalk} -s $1 | grep libxxx.so | head -n $2 | awk -F"+" '{print $2}' | xargs -I {} llvm-addr2line -p -f -C -e $3 {}
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    具体说明

    首先我们回顾一下地址解析命令,即add2line。我的环境下配置的是这样的

    $ type llvm-addr2line
    llvm-addr2line is /Users/luo/Library/Android/sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-addr2line
    
    • 1
    • 2

    add2line的输入是带有调试符号信息的so文件,还有我们想解析的崩溃堆栈地址,如下示例

    $ llvm-addr2line -p -f -C -e xxx.so文件路径 0x3f80f 0x122c26 0xd1e 0x79a 0xd22 0xd22 0xd1e 0xd22 0xd1e 0x79a 0xd1e 0x3ffe5 0x746e5 0x11b4e2 0x3ffe5 0x11b4e2 0x8437b 0x7a7df 0x7e53f 0x79a 0x3ffe5 0x40417 0x11b4e2 0xdeefe
    
    • 1

    so文件可以下载到,然后我们需要利用minidump_stackwalk命令从dump文件读取崩溃堆栈信息,获取我们需要的那些崩溃地址(如下图红圈圈住的地址)
    在这里插入图片描述
    所以dumpaddr方法是过滤想要用的一批地址,需要调整第二个参数

    $ /Applications/Android\ Studio.app/Contents/plugins/android-ndk/resources/lldb/bin/minidump_stackwalk -s d0c25ac8-c49b-4655-95573dbc-7af2c98d.dmp | grep libxxx.so | head -n 30
     2  libxxx.so + 0x3f80f
     3  libxxx.so + 0x122c26
     4  libxxx.so + 0xd1e
     7  libxxx.so + 0x79a
     8  libxxx.so + 0xd22
     9  libxxx.so + 0xd22
    10  libxxx.so + 0xd1e
    11  libxxx.so + 0xd22
    12  libxxx.so + 0xd1e
    15  libxxx.so + 0x79a
    16  libxxx.so + 0xd1e
    18  libxxx.so + 0x3ffe5
    19  libxxx.so + 0x746e5
    21  libxxx.so + 0x11b4e2
    23  libxxx.so + 0x3ffe5
    25  libxxx.so + 0x11b4e2
    26  libxxx.so + 0x8437b
    27  libxxx.so + 0x7a7df
    30  libxxx.so + 0x7e53f
    32  libxxx.so + 0x79a
    33  libxxx.so + 0x3ffe5
    34  libxxx.so + 0x40417
    36  libxxx.so + 0x11b4e2
    37  libxxx.so + 0xdeefe
    39  libxxx.so + 0x87d17
    40  libxxx.so + 0x3f80f
     2  libxxx.so + 0xa6bbd
     4  libxxx.so + 0xa6393
     5  libxxx.so + 0x10fc12
     6  libxxx.so + 0x10fba1
    
    # 换方法调用
    $ dumpaddr d0c25ac8-c49b-4655-95573dbc-7af2c98d.dmp 30
     2  libxxx.so + 0x3f80f
     3  libxxx.so + 0x122c26
     4  libxxx.so + 0xd1e
     7  libxxx.so + 0x79a
     8  libxxx.so + 0xd22
     9  libxxx.so + 0xd22
    10  libxxx.so + 0xd1e
    11  libxxx.so + 0xd22
    12  libxxx.so + 0xd1e
    15  libxxx.so + 0x79a
    16  libxxx.so + 0xd1e
    18  libxxx.so + 0x3ffe5
    19  libxxx.so + 0x746e5
    21  libxxx.so + 0x11b4e2
    23  libxxx.so + 0x3ffe5
    25  libxxx.so + 0x11b4e2
    26  libxxx.so + 0x8437b
    27  libxxx.so + 0x7a7df
    30  libxxx.so + 0x7e53f
    32  libxxx.so + 0x79a
    33  libxxx.so + 0x3ffe5
    34  libxxx.so + 0x40417
    36  libxxx.so + 0x11b4e2
    37  libxxx.so + 0xdeefe
    39  libxxx.so + 0x87d17
    40  libxxx.so + 0x3f80f
     2  libxxx.so + 0xa6bbd // 这里是其它线程的调用堆,所以我们调过调整 方法的第二个参数来示作过滤
     4  libxxx.so + 0xa6393
     5  libxxx.so + 0x10fc12
     6  libxxx.so + 0x10fba1
    
    • 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

    再加上 head -n $2 | awk -F"+" '{print $2}
    就是截出地址,然后通过xargs命令把地址参数交给add2line解析出对应函数行数信息

    具体的使用就是CD到dump文件目录
    先dumpaddr然后ctrl + a ,输按a 再ctrl + e ,再输入so的路径

    # luo@ ericluodeMacBook-Pro-2 in ~/Downloads/d0c25ac8-c49b-4655-95573dbc-7af2c98d_2 [15:56:51]
    $ dumpaddr d0c25ac8-c49b-4655-95573dbc-7af2c98d.dmp 26
     2  libxxx.so + 0x3f80f
     3  libxxx.so + 0x122c26
     4  libxxx.so + 0xd1e
     7  libxxx.so + 0x79a
     8  libxxx.so + 0xd22
     9  libxxx.so + 0xd22
    10  libxxx.so + 0xd1e
    11  libxxx.so + 0xd22
    12  libxxx.so + 0xd1e
    15  libxxx.so + 0x79a
    16  libxxx.so + 0xd1e
    18  libxxx.so + 0x3ffe5
    19  libxxx.so + 0x746e5
    21  libxxx.so + 0x11b4e2
    23  libxxx.so + 0x3ffe5
    25  libxxx.so + 0x11b4e2
    26  libxxx.so + 0x8437b
    27  libxxx.so + 0x7a7df
    30  libxxx.so + 0x7e53f
    32  libxxx.so + 0x79a
    33  libxxx.so + 0x3ffe5
    34  libxxx.so + 0x40417
    36  libxxx.so + 0x11b4e2
    37  libxxx.so + 0xdeefe
    39  libxxx.so + 0x87d17
    40  libxxx.so + 0x3f80f
    
    # luo@ ericluodeMacBook-Pro-2 in ~/Downloads/d0c25ac8-c49b-4655-95573dbc-7af2c98d_2 [15:56:55]
    $ adumpaddr d0c25ac8-c49b-4655-95573dbc-7af2c98d.dmp 26 libxxx.so的具体路径
    后面的崩溃栈函数信息没有贴出来
    
    • 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

    说明:

    # 这个逻辑可以得到一串地址,xargs把前面的一列地址转成了一行,可以copy这一行内容,然后手动输入add2line so地址 paste的也是可以的
    ${stackwalk} -s $1 | grep libxxx.so | head -n $2 | awk -F"+" '{print $2}' | xargs
    
    • 1
    • 2

    相关文章

  • 相关阅读:
    微软宣布 S2C2F 已被 OpenSSF 采用
    node连接mongoose数据库流程
    19--Django-项目实战-博客开发-开放对外访问接口、文章详情页以及下方点赞功能实现
    java实现命令模式
    程序员搞副业一些会用到的工具
    客户分析中变量分类
    java_函数式接口
    [python][原创]模拟实现yolov5训练时候终端的训练进度显示
    selenium 知网爬虫之根据【关键词】获取文献信息
    一位苦逼程序员的找工作经历
  • 原文地址:https://blog.csdn.net/SCHOLAR_II/article/details/126663820