breakpad不会在擦除迭代器上生成两次minidump

时间:2017-09-01 06:58:31

标签: minidump google-breakpad

我发现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,获取&#34;分段错误&#34;但是没有生成小型转储。

如果我取消注释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)。

1 个答案:

答案 0 :(得分:2)

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

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

指向堆栈损坏的一些其他数据点是代码与clang++一起使用。此外,只要我们将std::vector<int> sum;更改为std::vector<int>* sum,这将确保我们不会损坏堆栈,就会将minidump写入磁盘。