我一直试图调试一个相对不常见,不可能生产的按需memory issue一段时间了,我认为今天提供了最有用的{{1}到目前为止输出。以下是相关部分:
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)
最直接抱怨的行:
App.h:26-40
valgrind
xyz_symbol_add.cpp:18-43
struct symbol_parameters
{
string symbol;
//...
};
这里是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};
//...
format_symbol_local()
AppBase.cpp:327-333
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,"-");
}
最后,App.cpp:54只是来自for(LibAbcCallBack::Position position : xyz_params.position_list)
{
if(position.quantity > 0)
{
AddSymbol(position.symbol, position.quantity);
}
}
的一行,调用main()
。没有什么可以令人惊讶的。
虽然AppStartup()
所涉及的大多数函数都有名称,但我很难从输出中获得任何有用的东西。我应该从哪里看?