2

我发现 breakpad 有时无法处理 sigsegv。我写了一个简单的例子来重现它:

#include <vector>
#include <breakpad/client/linux/handler/exception_handler.h>

int InitBreakpad()
{
    char core_file_folder[] = "/tmp/cores/";
    google_breakpad::MinidumpDescriptor descriptor(core_file_folder);
    auto exception_handler_ =
        new google_breakpad::ExceptionHandler(descriptor,
        nullptr,
        nullptr,
        nullptr,
        true,
        -1);
}
int main()
{
     InitBreakpad();

     // int* ptr = nullptr;
     // *ptr = 1;
     std::vector<int> sum;
     sum.push_back(1);
     auto it = sum.begin();
     sum.erase(it);
     sum.erase(it);

     return 0;
}

gcc 是 4.8.5 而我的 comiple cmd 是

g++ test_breakpad.cpp -I./include -I./include/breakpad -L./lib -lbreakpad -lbreakpad_client -std=c++11 -lpthread

运行 a.out,得到“Segmentation fault”,但没有生成 minidump。

如果我取消注释 nullptr write,breakpad 工作!

我应该怎么做才能纠正它?

GDB 调试输出:

(gdb) b google_breakpad::ExceptionHandler::~ExceptionHandler()
Breakpoint 2 at 0x402ed0: file src/client/linux/handler/exception_handler.cc, line 264.
(gdb) c
The program is not being run.
(gdb) r
Starting program: /home/zen/tmp/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, google_breakpad::ExceptionHandler::ExceptionHandler (this=0x619040, descriptor=..., filter=0x0, callback=0x0, callback_context=0x0, install_handler=true, server_fd=-1) at src/client/linux/handler/exception_handler.cc:224
224     ExceptionHandler::ExceptionHandler(const MinidumpDescriptor& descriptor,
Missing separate debuginfos, use: debuginfo-install glibc-2.17-157.el7_3.1.x86_64 libgcc-4.8.5-11.el7.x86_64 libstdc++-4.8.5-11.el7.x86_64
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff712f19d in __memmove_ssse3_back () from /lib64/libc.so.6
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff712f19d in __memmove_ssse3_back () from /lib64/libc.so.6
(gdb) c
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.

我从进程转储中尝试了breakpad,但仍然一无所获(nullptr write works)。

4

1 回答 1

2

经过一些调试后,我认为sum.erase(it)在您的示例中没有创建小型转储的原因是由于堆栈损坏。

在调试时,您可以看到变量g_handler_stack_insrc/client/linux/handler/exception_handler.cc已正确初始化,并且google_breakpad::ExceptionHandler实例已正确添加到向量中。然而,当google_breakpad::ExceptionHandler::SignalHandler被调用时,尽管没有调用google_breakpad::ExceptionHandler::~ExceptionHandler或任何std::vector会改变向量的方法,向量仍被报告为空。

指向堆栈损坏的一些进一步数据点是代码与clang++. 此外,一旦我们将 更改std::vector<int> sum;为 a std::vector<int>* sum,这将确保我们不会破坏堆栈,minidump 就会被写入磁盘。

于 2017-09-01T15:51:56.573 回答