In the user interface program I created for a personal library I used
the boost program options to provide two command line options to the
user. The first is to report a help menu and the second is input used
with the library's API. What I am getting is that there is a segfault in
destructor for the variable map. Here is the backtrace:
#0 0xb7469099 in __gnu_cxx::__exchange_and_add () from /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/libstdc++.so.6
#1 0xb744e039 in std::basic_string::~basic_string ()
from /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/libstdc++.so.6
#2 0x0804d7c2 in ~pair (this=0x8054dc8) at /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_pair.h:69
#3 0x0804d801 in __gnu_cxx::new_allocator >::destroy
(this=0xbfa75d93, __p=0x8054dc8) at /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/ext/new_allocator.h:109
#4 0x0804e1ad in std::_Rb_tree, std::_Select1st >, std::lessstd::string, std::allocator > >::destroy_node (this=0xbfa75e98, __p=0x8054db8)
at /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_tree.h:391
#5 0x0804e232 in std::_Rb_tree, std::_Select1st >, std::lessstd::string, std::allocator > >::_M_erase (this=0xbfa75e98, __x=0x8054db8)
at /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_tree.h:1266
#6 0x0804e261 in ~_Rb_tree (this=0xbfa75e98) at /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_tree.h:578
#7 0x0804e2b1 in ~map (this=0xbfa75e98) at /usr/lib/gcc/i686-pc-linux-gnu/4.1.1/include/g++-v4/bits/stl_map.h:93
#8 0x0804e31a in ~variables_map (this=0xbfa75e90) at /usr/include/boost/program_options/variables_map.hpp:110
#9 0x0804bec6 in main (ac=2, av=0xbfa75ff4) at pe_reverse.cpp:48
My system information is:
gcc-4.1.1-r3 (Gentoo x86)
boost-1.33.1-r1 (compiled with debug flag on and no symbols stripped)
My user interface program is below. Now you will notice that I am not
using the value retrieve from the "file" command line option. What I
noticed was that regardless what value "file" contained it was the
presence of the --file command line option which triggered the
segmentation fault. So I just hardwired my program so that I could check
to see if I could track down the segfault.
#include
#include <iostream>
#include
#include
int main ( int ac, char** av )
{
// Declare the supported options.
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("file", boost::program_options::valuestd::string(), "file to reverse");
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc), vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
}
if (vm.count("file")) {
std::cout << "File to analyze was set to "
<< vm["file"].asstd::string() << "." << std::endl;
}
/*
else {
std::cout << "File to analyze was not set." << std::endl;
return 0;
}
*/
try
{
libreverse::api::Reverse r_obj;
r_obj.execute ( "kernel32.dll", //vm["file"].asstd::string(),
libreverse::api::Input_Types::BINARY,
libreverse::api::Output_Types::CPLUSPLUS );
}
catch ( errors::Parsing_Exception& pe )
{
std::cerr << "Exception: " << pe.name() << std::endl;
std::cerr << pe.what() << std::endl;
}
return 0;
}
I cannot see what is wrong. Now GCC had a minor revision update lately
from 4.1.1-r2. Perhaps what I am running into is a non-boost library
which is called by the program options and giving back a bad value.
Stephen