简体   繁体   English

将gcc升级到5.4.0后cppunit抛出std :: bad_alloc

[英]cppunit throws std::bad_alloc after upgrading gcc to 5.4.0

I've recently updated my Gentoo Linux PC with GCC 5.4.0. 我最近用GCC 5.4.0更新了我的Gentoo Linux PC。

I also recompiled all packages depending on gcc (it was mentioned in gcc upgrade guide for gentoo). 我还根据gcc重新编译了所有软件包(在gentoo的gcc升级指南中提到过)。

Most of programs works well, however my tests, using cppunit, throw std::bad_alloc before starting. 大多数程序运行良好,但是我的测试使用cppunit在启动前抛出std :: bad_alloc。

At first I thought there might be a problem with updated version of cppunit, so I downgraded it to previous version, but the problem still exists. 起初,我认为cppunit的更新版本可能存在问题,因此我将其降级为以前的版本,但是问题仍然存在。

Whenever I start any test, the application immediately throws: 每当我开始任何测试时,应用程序都会立即抛出:

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

I started the application in gdb and printed debug backtrace: 我在gdb中启动了应用程序并打印了调试回溯:

#0  0x00007ffff545d218 in raise () from /lib64/libc.so.6
#1  0x00007ffff545e69a in abort () from /lib64/libc.so.6
#2  0x00007ffff5d8f18d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#3  0x00007ffff5d8d046 in ?? () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#4  0x00007ffff5d8d091 in std::terminate() () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#5  0x00007ffff5d8d297 in __cxa_throw () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#6  0x00007ffff5db5f52 in std::__throw_bad_alloc() () from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/libstdc++.so.6
#7  0x0000000000b2b3ae in __gnu_cxx::new_allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocate
    (this=0x7fffffffda58, __n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/ext/new_allocator.h:102
#8  0x0000000000b2b1e2 in std::allocator_traits<std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::allocate (__a=..., __n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/alloc_traits.h:491
#9  0x0000000000b2b09e in std::__cxx1998::_Vector_base<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_allocate (this=0x7fffffffda58,
    __n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:170
#10 0x0000000000b2af71 in std::__cxx1998::_Vector_base<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_M_create_storage (this=0x7fffffffda58,
    __n=18446741874689290911) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:185
#11 0x0000000000b2acf1 in std::__cxx1998::_Vector_base<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::_Vector_base (this=0x7fffffffda58,
    __n=18446741874689290911, __a=...) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:136
#12 0x0000000000b29c9c in std::__cxx1998::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::vector (this=0x7fffffffda58,
    __x=std::__cxx1998::vector of length -2199020260704, capacity -2199020259433 = {...}) at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/bits/stl_vector.h:320
#13 0x0000000000b29449 in std::__debug::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::vector (this=0x7fffffffda40)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/debug/vector:193
#14 0x0000000000b294ef in CppUnit::TestSuiteBuilderContextBase::TestSuiteBuilderContextBase (this=0x7fffffffda20) at /usr/include/cppunit/extensions/TestSuiteBuilderContext.h:29
#15 0x0000000000b29515 in CppUnit::TestSuiteBuilderContext<Types_Decimal>::TestSuiteBuilderContext (this=0x7fffffffda20, contextBase=...) at /usr/include/cppunit/extensions/TestSuiteBuilderContext.h:106
#16 0x0000000000b28a16 in Types_Decimal::addTestsToSuite (baseContext=...) at ./Tests/../../pCpp/CppUnitTests/Types_Decimal.hpp:10
#17 0x0000000000b28caa in Types_Decimal::suite () at ./Tests/../../pCpp/CppUnitTests/Types_Decimal.hpp:12
#18 0x0000000000b2871f in main () at Types_Decimal.cpp:8

There is no problem with test file itself, because I made no changes to it, and lots of test were working for long time. 测试文件本身没有问题,因为我没有对其进行任何更改,并且许多测试已经进行了很长时间。

After looking into stack trace, I'm pretty curious what happened on frame #12: __x=std::**__cxx1998**::vector of length **-2199020260704**, capacity **-2199020259433** = {...} Why there is cxx1998? 看完堆栈跟踪之后,我很好奇在#12帧上发生了什么: __x=std::**__cxx1998**::vector of length **-2199020260704**, capacity **-2199020259433** = {...}为什么会有cxx1998? Both length and capacity looks pretty insane (uninitialized?). 长度和容量都看起来很疯狂(未初始化?)。

TestSuiteBuilderContext.h:29: TestSuiteBuilderContext.h:29:

void 
TestSuiteBuilderContextBase::addTest( Test *test )
{
  m_suite.addTest( test ); //line 29
}

TestSuite.cpp: TestSuite.cpp:

/// Adds a test to the suite. 
void 
TestSuite::addTest( Test *test )
{ 
  m_tests.push_back( test ); 
}

I came up with partial solution. 我想出了部分解决方案。

It looks like the compile option: 看起来像compile选项:

-D_GLIBCXX_DEBUG

Was causing the problem. 造成了问题。 After removing it - tests run succesfully. 删除后-测试成功运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Qt5抛出std :: bad_alloc - Qt5 throws std::bad_alloc 收到错误“在抛出&#39;std::bad_alloc&#39;what() 的实例后调用终止:std::bad_alloc” - getting error "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc" 在抛出'std :: bad_alloc'的实例后调用终止what():std :: bad_alloc中止 - terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted 在抛出“ std :: bad_alloc”实例的what():std :: bad_alloc实例后终止调用 - terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc" 复制构造函数在调用时会抛出std :: bad_alloc - Copy constructor throws a std::bad_alloc, when it is called 如果new set指针抛出std :: bad_alloc,它是否指向NULL? - Does new set pointer to NULL if it throws std::bad_alloc? 代码抛出std :: bad_alloc,内存不足,或者可能是错误? - code throws std::bad_alloc, not enough memory or can it be a bug? Stringstream到Vector <char> 抛出std :: bad_alloc - Stringstream to Vector<char> throws std::bad_alloc 字符串到向量的转换将引发std :: bad_alloc - string to vector conversion throws std::bad_alloc ASIO写操作抛出std :: bad_alloc:C ++ - ASIO write operation throws std::bad_alloc : C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM