C++ Valgrind在std::string析构函数上捕获SIGSEGV
一段时间以来,我一直在尝试调试一个相对较少、不可能按需生产的产品,我认为今天提供了迄今为止最有用的C++ Valgrind在std::string析构函数上捕获SIGSEGV,c++,linux,string,c++11,valgrind,C++,Linux,String,C++11,Valgrind,一段时间以来,我一直在尝试调试一个相对较少、不可能按需生产的产品,我认为今天提供了迄今为止最有用的valgrind输出。以下是相关行: ==25808== Conditional jump or move depends on uninitialised value(s) ==25808== at 0x4EF14CE: std::basic_string<char, std::char_traits<char>, std::allocator<char> &g
valgrind
输出。以下是相关行:
==25808== Conditional jump or move depends on uninitialised value(s)
==25808== at 0x4EF14CE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EA7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
==25808==
==25808== Use of uninitialised value of size 8
==25808== at 0x4E9264D: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x4EF14DE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EA7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
==25808==
==25808== Conditional jump or move depends on uninitialised value(s)
==25808== at 0x4C2C272: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==25808== by 0x4EF14DE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EA7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
==25808==
==25808== Invalid free() / delete / delete[] / realloc()
==25808== at 0x4C2C2BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==25808== by 0x4EF14DE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EA7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
==25808== Address 0x5c343e8 is in the Data segment of /lib/x86_64-linux-gnu/libc-2.19.so
==25808==
==25808== Conditional jump or move depends on uninitialised value(s)
==25808== at 0x4EF14CE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EC7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
==25808==
==25808== Use of uninitialised value of size 8
==25808== at 0x4E9264D: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x4EF14DE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EC7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
==25808==
==25808==
==25808== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==25808== Bad permissions for mapped region at address 0x58EF4D4
==25808== at 0x4E9264D: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x4EF14DE: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==25808== by 0x491EC7: app::symbol_parameters::~symbol_parameters() (App.h:26)
==25808== by 0x4B7E04: app::AddSymbol(std::string, int, unsigned long) (xyz_symbol_add.cpp:43)
==25808== by 0x4B3269: AppStartup(int, char**, char const*) (AppBase.cpp:332)
==25808== by 0x48CE74: main (App.cpp:54)
xyz_符号添加cpp:18-43
struct symbol_parameters
{
string symbol;
};
//...
void AddSymbol(string sym, int32_t psn, uint64_t pr)
{
string symb=format_symbol_local(sym);
//...
symbol_parameters p{symb};
//...
下面是格式\u符号\u本地()
AppBase.cpp:327-333
for(LibAbcCallBack::Position position : xyz_params.position_list)
{
if(position.quantity > 0)
{
AddSymbol(position.symbol, position.quantity);
}
}
最后,App.cpp:54只是main()
的一行,调用AppStartup()
。没什么奇怪的
虽然
valgrind
对大多数函数的名称有异议,但我很难从输出中得到任何有用的东西。我应该从这里看哪里?可能与此无关,但您没有向AddSymbol()传递3个参数是的,很抱歉。声明中默认为零。=)试着把它略读到一个完整的、最少可验证的例子。这可能很难,但在此期间,您可以找到错误。这对我来说是一个未定义的行为,使用您提供的几个代码段是不可能找到的。为什么在头文件和源文件中都有结构定义(symbol\u parameters
)?我同意Daniel的观点。重复的结构定义非常可疑,特别是因为您的/…
位置似乎表明它们不匹配。(是吗?)
string format_symbol_local(string symbol)
{
// convert .PR to -
size_t found = symbol.find(".PR");
if(string::npos==found) return symbol;
return symbol.replace(found,3,"-");
}
for(LibAbcCallBack::Position position : xyz_params.position_list)
{
if(position.quantity > 0)
{
AddSymbol(position.symbol, position.quantity);
}
}