Core dump using __cxa_demangle

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Using __cxa_demangle seems to work ok as long as the mangled code is
obtained from typeid().  I wanted to test out the other return status codes
by feeding the function non-valid mangled codes (e.g. "abc"). However,the
program aborts abruptly with a coredump. Placing the call in a "universal"
try catch(...) block doesn't seem to catch anything, so I presume no
exception is being thrown.  

My call is structured like this:

#include <cxxabi.h> 
using namespace std;
using namespace __cxxabiv1;

string demangle(const char* mangled) {
      char* outbuf = 0;
      size_t length;
      int status;
      std::ostringstream oss;	
      try {
            outbuf = __cxa_demangle(mangled, outbuf, &length, &status);
      } catch (...) {
            cout << "Exception occurred! "
                  << "Status: " << status
                  << ", Len: " << length;
            return oss.str();
	}
      string out = outbuf;
      if (status == 0) {
            oss << out;
      } else {
            switch (status) {
                  case 1: oss << "__cxa_demangle(): "
                        "Memory allocation failure occured.";
                        break;
                  case 2: oss << "__cxa_demangle(): "
                        "mangled is not a valid name under the C++ ABI
mangling rules.";
                        break;
                  case 3: oss << "__cxa_demangle(): "
                        "One of the arguments is invalid.";
                        break;
                  default: oss << "__cxa_demangle(): "
                        "Invalid return from __cxa_demangle().";
            }
		oss << " Status: " << status << ", Len: " << length;	
      }
      if ((length > 0)) free(outbuf);
      return oss.str();
}

Is this expected behavior? 
Does there exist a safer demangler routine that is more robust?
Perhaps my call is not structured correctly.

Any help would be appreciated.
Thanks.

Lee.


 


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux