possible reasons that can cause a Linux application to crash in release mode but work fine in debug mode
-
Greetings, fellow developers! I have encountered a peculiar issue while building my application, which incorporates Boost, Qt5, and RapidXML. I have compiled both release and debug versions of my app, but the release version crashes with a segmentation fault when reading some XML documents. The callstack of the error can be found at frame in the RapidXML function "get_attribute.
Here is gdb output with backtrace:(gdb) r Starting program: /mnt/reader1.6src/build10/bin/reader [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7fffe452f700 (LWP 4168)] [New Thread 0x7fffe0b93700 (LWP 4169)] [New Thread 0x7fffd6ee1700 (LWP 4170)] [New Thread 0x7fffd66e0700 (LWP 4171)] [New Thread 0x7fffd5edf700 (LWP 4172)] [New Thread 0x7fffd56de700 (LWP 4173)] [New Thread 0x7fffd4edd700 (LWP 4174)] [New Thread 0x7fffbffff700 (LWP 4175)] [New Thread 0x7fffbf7fe700 (LWP 4176)] [New Thread 0x7fffbeffd700 (LWP 4177)] [New Thread 0x7fffbe7fc700 (LWP 4178)] [New Thread 0x7fffbdffb700 (LWP 4179)] [New Thread 0x7fffbd7fa700 (LWP 4180)] [New Thread 0x7fffbcb90700 (LWP 4181)] [New Thread 0x7fff9ffff700 (LWP 4182)] Thread 1 "reader" received signal SIGSEGV, Segmentation fault. #0 0x0000000000583e54 in rapidxml::xml_attribute<char>* get_attribute<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(rapidxml::xml_node<char> const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) () #1 0x00000000007b21bc in rapidxml::xml_attribute<char>* get_attribute<double>(rapidxml::xml_node<char> const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double&) () #2 0x0000000000588088 in core::calibrations::PolynomialApprox::from_xml_node(rapidxml::xml_node<char> const*) () #3 0x0000000000581ccf in core::calibrations::Calibration::from_xml_node(rapidxml::xml_node<char> const*) () #4 0x00000000005acee1 in core::results::Series::load_doc_xml(std::istream&) () #5 0x00000000005aee58 in core::results::Series::loadHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () #6 0x00000000005aefa9 in core::results::Series::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () #7 0x00000000006b0a3b in gui::results::TableModel::load(QString const&, QString const&) () #8 0x0000000000633068 in gui::ReaderApp::Init2() () #9 0x00000000006359f1 in gui::ReaderApp::ReaderApp(int&, char**) () #10 0x00000000005792ef in main ()
However, to my surprise, the same application works perfectly fine when run in debug mode.
I have been developing this app for Windows x32 and compiled it for Linux x64. I have found that the segmentation fault occurs when a string is being created, as seen through disassembly debugging in release mode. I am using an older version of RapidXML and Boost 1.6.7, along with Qt 5.15.
I am eager to understand the cause of this discrepancy in behavior between the release and debug versions. Could any of you, with your vast experience and knowledge, shed some light on this issue and provide possible solutions? Your assistance would be greatly appreciated.
-
Hi and welcome to devnet,
The usual suspect is: check all your variable initialisation especially the pointers.
-
Hi and welcome to devnet,
The usual suspect is: check all your variable initialisation especially the pointers.
@SGaist
Thanks a lot for you answer! Always with pleasure! -
@SGaist
Thanks a lot for you answer! Always with pleasure!- On linux run your code with strace:
strace your release app
Maybe you can find something.
2 .Run valgrind to check the debug build and maybe you can find something suspicious(for example, uninitialized variables).
3. Check all #if DEBUG block code to see if something is missing for release. - On linux run your code with strace: