• breakpad尝试


    何为breakpad:

      如果你的程序是C++程序,crash的时候无所适从,那么你可以考虑使用一下看看

    https://blog.csdn.net/fengyulinde/article/details/81707346


    1
    准备:
    库,代码,编译好


    ./configure && make

    make中要是报错:
    头文件linux_syscall_support.h,该头文件要放在src hird_partylss目录下,其中lss目录要自己建

    make install

    install后下面
    /usr/local/include/
    /usr/local/lib/

    libbreakpad.a
    libbreakpad_client.a

    2.
    库集成到自己的工程:


    头文件:
    #include "client/linux/handler/exception_handler.h"
    #include "third_party/lss/linux_syscall_support.h"
    #include "client/linux/handler/minidump_descriptor.h"

    捕捉函数:
    static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
    void* context,
    bool succeeded)
    {
    std::cout << "Dump path:" << descriptor.path() << std::endl;
    return succeeded;
    }

    程序开始加入捕捉
    int main(int argc, char *argv[])
    {
    google_breakpad::MinidumpDescriptor descriptor("/srv/log");
    google_breakpad::ExceptionHandler eh(descriptor, nullptr, dumpCallback, nullptr, true, -1);

    IgnoreSignals();
    setCorDump();
    ......
    }

    3.
    编译工程会报错:
    "inttypes.h has already been included before this header file, but
    without __STDC_FORMAT_MACROS defined"

    查看源文件:
    breakpadincludegoogle_breakpadcommonreakpad_types.h


    注释掉后,编译成功

    集成完成,出现crash,开发执行分析:

    1. gen sym files:

    dump_syms ./test-server > test-server.sym
    dump_syms /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so > libc-2.31.so.sym


    2. 组织好symbols目录结构,结构必须严格,否则最后读不到符号文件

    $ head -n1 test-server.sym
    MODULE Linux x86_64 1B84C720DE19E3AE62EADD07379DA3F90 test-server


    -symbols(一级目录,别的什么目录下无所谓)
    -----app(二级目录,如:test-server)
       --------id(三级目录,如:1B84C720DE19E3AE62EADD07379DA3F90)
           ------------files:(四级文件:如:test-server.sym )
    -----so1
          xxx

    如:
    symbols
    --test-server
    -------1B84C720DE19E3AE62EADD07379DA3F90
    -----------test-server.sym
    --libc-2.31.so
    --------25929B09B0BC19D0D9D60884BE583EB30
    -----------libc-2.31.so.sym

    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build$ cd symbols/
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols$ ls -l
    total 8
    drwxrwxr-x 3 leehm leehm 4096 Jul 23 09:07 test-server
    drwxrwxr-x 3 leehm leehm 4096 Jul 23 11:46 libc-2.31.so
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols$ cd test-server/
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/test-server$ ls -l
    total 4
    drwxrwxr-x 2 leehm leehm 4096 Jul 23 09:13 1B84C720DE19E3AE62EADD07379DA3F90
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/test-server$ cd 1B84C720DE19E3AE62EADD07379DA3F90/
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/test-server/1B84C720DE19E3AE62EADD07379DA3F90$ ls -l
    total 44888
    -rw-rw-r-- 1 leehm leehm 45964328 Jul 23 08:08 test-server.sym
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/test-server/1B84C720DE19E3AE62EADD07379DA3F90$


    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build$ cd symbols/
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols$ ls -l
    total 8
    drwxrwxr-x 3 leehm leehm 4096 Jul 23 09:07 test-server
    drwxrwxr-x 3 leehm leehm 4096 Jul 23 11:46 libc-2.31.so
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols$ cd libc-2.31.so/
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/libc-2.31.so$ ls -l
    total 4
    drwxrwxr-x 2 leehm leehm 4096 Jul 23 11:46 25929B09B0BC19D0D9D60884BE583EB30
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/libc-2.31.so$ cd 25929B09B0BC19D0D9D60884BE583EB30/
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/libc-2.31.so/25929B09B0BC19D0D9D60884BE583EB30$ ls -l
    total 2652
    -rw-rw-r-- 1 leehm leehm 2714420 Jul 23 11:43 libc-2.31.so.sym
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build/symbols/libc-2.31.so/25929B09B0BC19D0D9D60884BE583EB30$


    3. 生成crash的log
    sudo minidump_stackwalk /srv/log/8b268c24-eb30-4f24-4da6609d-234c1a05.dmp ./symbols > error.1.log


    4. 查看crash生成的log,定位crash的行数

    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build$ cat error.1.log
    Operating system: Linux
    0.0.0 Linux 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64
    CPU: amd64
    family 6 model 158 stepping 9
    1 CPU

    GPU: UNKNOWN

    Crash reason: SIGSEGV /SEGV_MAPERR
    Crash address: 0x0
    Process uptime: not available

    Thread 0 (crashed)
    0 libc-2.31.so!__memmove_avx_unaligned_erms + 0xad
    rax = 0x0000000000000000 rdx = 0x0000000000000002
    rcx = 0x0000000000000031 rbx = 0x000055994f058360
    rsi = 0x0000000000000031 rdi = 0x0000000000000000
    rbp = 0x00007ffeb8e1e150 rsp = 0x00007ffeb8e1d828
    r8 = 0x0000000000000000 r9 = 0x00007ffeb8e1d500
    r10 = 0x00007ffeb8e1d550 r11 = 0x0000000000000000
    r12 = 0x0000000000000000 r13 = 0x0000000000000000
    r14 = 0x000055994eb8d720 r15 = 0x00007ffeb8e1de10
    rip = 0x00007f3114e1e71d
    Found by: given as instruction pointer in context
    1 test-server!main [string_fortified.h : 90 + 0x13]
    rbp = 0x00007ffeb8e1e150 rsp = 0x00007ffeb8e1d830
    rip = 0x000055994d929c1e
    Found by: stack scanning
    2 libc-2.31.so!__libc_start_main [libc-start.c : 308 + 0x1a]
    rbx = 0x000055994e85fe00 rbp = 0x0000000000000000
    rsp = 0x00007ffeb8e1e160 r12 = 0x000055994d931490
    r13 = 0x00007ffeb8e1e240 r14 = 0x0000000000000000
    r15 = 0x0000000000000000 rip = 0x00007f3114cb70b3
    Found by: call frame info
    3 test-server + 0xdca20
    rsp = 0x00007ffeb8e1e180 rip = 0x000055994d929a20
    Found by: stack scanning
    4 test-server + 0x1012e00
    rsp = 0x00007ffeb8e1e188 rip = 0x000055994e85fe00
    Found by: stack scanning
    5 test-server + 0xe4490
    rsp = 0x00007ffeb8e1e198 rip = 0x000055994d931490
    Found by: stack scanning
    6 test-server + 0xe4490
    rsp = 0x00007ffeb8e1e210 rip = 0x000055994d931490
    Found by: stack scanning
    7 test-server!_start + 0x2e
    rsp = 0x00007ffeb8e1e230 rip = 0x000055994d9314be
    Found by: stack scanning
    8 0x7ffeb8e1e238
    rsp = 0x00007ffeb8e1e238 rip = 0x00007ffeb8e1e238
    Found by: call frame info
    9 0x7ffeb8ffb000
    rsp = 0x00007ffeb8e1e2e0 rip = 0x00007ffeb8ffb000
    Found by: stack scanning
    10 0x7f3117376000
    rsp = 0x00007ffeb8e1e350 rip = 0x00007f3117376000
    Found by: stack scanning
    11 test-server + 0xe4490
    rsp = 0x00007ffeb8e1e370 rip = 0x000055994d931490
    Found by: stack scanning

    Thread 1
    0 libpthread-2.31.so + 0x107b1
    rax = 0xfffffffffffffdfc rdx = 0x0000000000000000
    rcx = 0x00007f31151e67b1 rbx = 0x000055994f076c58
    rsi = 0x0000000000000189 rdi = 0x000055994f076c70
    rbp = 0x000055994f076c48 rsp = 0x00007f31149c8d40
    r8 = 0x0000000000000000 r9 = 0x00000000ffffffff
    r10 = 0x00007f31149c8e40 r11 = 0x0000000000000246
    r12 = 0x000055994f076c6c r13 = 0x000055994f076c20
    r14 = 0x000055994f076c70 r15 = 0x00007f31149c8d90
    rip = 0x00007f31151e67b1
    Found by: given as instruction pointer in context
    1 libpthread-2.31.so + 0x10050
    rsp = 0x00007f31149c8d98 rip = 0x00007f31151e6050
    Found by: stack scanning
    2 test-server!std::thread::_State_impl<std::thread::_Invoker<std::tuple<spdlog::details::periodic_worker::periodic_worker(std::function<void ()> const&, std::chrono::duration<long, std::ratio<1l, 1l> >)::{lambda()#1}> > >::_M_run() [gthr-default.h : 871 + 0x5]
    rsp = 0x00007f31149c8e20 rip = 0x000055994d97a5ff
    Found by: stack scanning
    3 libstdc++.so.6.0.28 + 0xd6de4
    rbx = 0x0000000000000000 rbp = 0x000055994f07df10
    rsp = 0x00007f31149c8ea0 r12 = 0x00007ffeb8e1d38e
    r13 = 0x00007ffeb8e1d38f r14 = 0x00007ffeb8e1d390
    r15 = 0x00007f31149c8f80 rip = 0x00007f31150c4de4
    Found by: call frame info
    4 libpthread-2.31.so + 0x9609
    rsp = 0x00007f31149c8ec0 rip = 0x00007f31151df609
    Found by: stack scanning
    5 libc-2.31.so!__GI___clone + 0x43
    rsp = 0x00007f31149c8f80 rip = 0x00007f3114db2293
    Found by: stack scanning

    Loaded modules:
    0x55994d84d000 - 0x55994e85ffff test-server ??? (main)
    0x7f31149d2000 - 0x7f3114a8bfff libfdk-aac.so.1 ???
    0x7f3114c90000 - 0x7f3114e2cfff libc-2.31.so ???
    0x7f3114e82000 - 0x7f3114e96fff libgcc_s.so.1 ???
    0x7f3114e9f000 - 0x7f3114f54fff libm-2.31.so ???
    0x7f3114fee000 - 0x7f3115174fff libstdc++.so.6.0.28 ??? (WARNING: No symbols, libstdc++.so.6.0.28, 03660EC9CDC747F813CD445700A575D30)
    0x7f31151d0000 - 0x7f31151d2fff libdl-2.31.so ???
    0x7f31151d6000 - 0x7f31151edfff libpthread-2.31.so ??? (WARNING: No symbols, libpthread-2.31.so, F76147E554B5FCD0C1562959665D93DF0)
    0x7f31151f9000 - 0x7f311540bfff libcrypto.so.1.1 ???
    0x7f31154cf000 - 0x7f3115539fff libssl.so.1.1 ???
    0x7f3115564000 - 0x7f3115626fff libsioclient_tls.so.1 ???
    0x7f3115665000 - 0x7f311567bfff libswresample.so.3.8.100 ???
    0x7f3115684000 - 0x7f31156fbfff libswscale.so. ???
    0x7f3115717000 - 0x7f31157a0fff libavutil.so.56.60.100 ???
    0x7f31159d3000 - 0x7f3115b94fff libavformat.so. ???
    0x7f3115c3c000 - 0x7f31167e9fff libavcodec.so.58.112.103 ???
    0x7f3117376000 - 0x7f3117399fff ld-2.31.so ???
    0x7ffeb8ffb000 - 0x7ffeb8ffbfff linux-gate.so ???
    leehm@ubuntu:~/Desktop/share/test-1.4.0/test/build$

    对比crash的代码,很遗憾,最终还是无法看见详细的堆栈已经crash的点,不知道是不是库集成问题,亦或是之前编译报错强行注释掉解决编译问题导致
    具体原因暂未可知。。。。。。
    由于项目时间紧,暂时放弃集成使用,暂留做记录,以便后续继续研究

  • 相关阅读:
    命令模式
    装饰模式 decorator
    儒道佛
    Facade模式
    Adapter
    TListView ItemCheck CheckedItems
    观 徼 偶 感
    c# Mid 子窗体 盖住 控件
    pycharm 连接mysql时区问题
    django_drf
  • 原文地址:https://www.cnblogs.com/leehm/p/15048482.html
Copyright © 2020-2023  润新知