This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Core dump using __cxa_demangle
- From: "Lee Rhodes" <lee at rhoba dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 18 Jul 2007 12:51:41 -0700
- Subject: Core dump using __cxa_demangle
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.