vendredi 24 mai 2019

Why segmentation fault happened when i define a const string in a google test programe?

I want to run unit test with google test, but got Segmentation fault. I have just define a global const string, and RUN_ALL_TESTS, why?

the gdb result is :

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (1 ms total)
[  PASSED  ] 0 tests.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6fe415c in __GI___libc_free (mem=0x603588) at malloc.c:2947
2947    malloc.c: No such file or directory.


And flowing is the backtrace:

(gdb) bt
#0  0x00007ffff6fe415c in __GI___libc_free (mem=0x603588) at malloc.c:2947
#1  0x00007ffff75fa36f in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#2  0x00007ffff7bb25ba in void std::_Destroy<std::string>(std::string*) () from /home/caros/src/secsdk/datasecurity-upgrade/external/libgtest.so
#3  0x00007ffff7bb04bd in void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) () from /home/caros/src/secsdk/datasecurity-upgrade/external/libgtest.so
#4  0x00007ffff7bac65c in void std::_Destroy<std::string*>(std::string*, std::string*) () from /home/caros/src/secsdk/datasecurity-upgrade/external/libgtest.so
#5  0x00007ffff7ba68f3 in void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) () from /home/caros/src/secsdk/datasecurity-upgrade/external/libgtest.so
#6  0x00007ffff7ba08b2 in std::vector<std::string, std::allocator<std::string> >::~vector() () from /home/caros/src/secsdk/datasecurity-upgrade/external/libgtest.so
#7  0x00007ffff6f9d53a in __cxa_finalize (d=0x7ffff7b2b440) at cxa_finalize.c:56
#8  0x00007ffff78b7ea3 in __do_global_dtors_aux () from /home/caros/src/secsdk/datasecurity-upgrade/external/libgmock.so
#9  0x00007fffffffd5e0 in ?? ()
#10 0x00007ffff7dea7da in _dl_fini () at dl-fini.c:252
Backtrace stopped: frame did not save the PC


This is my whole source code:

#include <iostream>                                                             
#include "gtest/gtest.h"
#include "gmock/gmock.h"
const std::string fsdfsdf = "sdfsdfsd";
int main(int argc, char* argv[]) {
    testing::InitGoogleMock(&argc, argv);
    RUN_ALL_TESTS();
    return 0;
}


I expect the programe finished without segmentation fault.

Aucun commentaire:

Enregistrer un commentaire