Results 1 to 4 of 4
Hi all,
I've searched for hints about problems with g++ and exception handling, but most of the articles I've run across are a few years old, so I'm not sure ...
- 06-23-2011 #1Just Joined!
- Join Date
- Jun 2011
- Location
- California
- Posts
- 2
Exception processing with g++ and stack unwind crash on free()
Hi all,
I've searched for hints about problems with g++ and exception handling, but most of the articles I've run across are a few years old, so I'm not sure that they're relevant. Sometimes it seems that the objects are not freed properly during stack unwind when exiting a frame with an exception. Here's some sample code:
This code works fine on Ubuntu and on Windows, but on my embedded ARM target, there is a segmentation violation when freeing one of the strings in the vector. If I remove the throw, it also works fine on the target.Code:#include <iostream> #include <vector> #include <string> #include <stdexcept> using namespace std; void RunThrowTest2() { typedef std::vector<std::string> StringArray; StringArray testArray; testArray.push_back("THROWBAD"); testArray.push_back("ONE"); testArray.push_back("TWO"); testArray.push_back("THREE"); testArray.push_back("FOUR"); testArray.push_back("FIVE"); for (StringArray::const_iterator it = testArray.begin(); it != testArray.end(); ++it) cout << *it << " "; cout << endl; throw invalid_argument("Throwing example exception"); } void RunThrowTest() { int ctr = 0; while(true) { try { cout << "count=" << ++ctr << " "; RunThrowTest2(); } catch(...) { } } } int main(int argc, char* argv[]) { RunThrowTest(); }
The target versions are:
Linux 2.6.32 with uclibc libraries
g++ 4.4.4
libstdc++ 6.0.13
I'm wondering the following:
- Does the code look like it should work, and if not why?
- Do you all know of any special problems with g++ or std::vector or Linux on an ARM that would account for this kind of crash?
- Is there a command-line option needed? (I've used -fexceptions)
- Is there a special way to build g++ or the libraries that enables or disables proper handling of unwind?
Thanks
- 06-24-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
It looks ok to me. Have you looked at the bugzilla entries for g++ 4.4.4 at GNU for the ARM tool chain? Also, does the exception occur on the first call to RunThrowTest2()? Or only after some number of iterations? Finally, are you building your code on an x86 system using the ARM tool chain, or are you building it natively on your target platform?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-24-2011 #3Just Joined!
- Join Date
- Jun 2011
- Location
- California
- Posts
- 2
Thanks for your response.
I'll have a look at Bugzilla. I've compiled the program both using a cross-compiler from Ubuntu and using the locally-installed toolchain with the same result. The program crashes on the first iteration on the target.
- 06-24-2011 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Ok. The code is simple enough. I'll give it a try on my ARM board (running Debian Etch) and get back to you. My kernel and compiler are somewhat older than yours, so it will be interesting to see if this may be a regression or not.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote