[C++-sig] Re: Re: debuging
Adam Hupp
hupp at cs.wisc.edu
Wed Nov 20 04:34:34 CET 2002
On Tue, Nov 19, 2002 at 06:05:13PM -0500, David Abrahams wrote:
> >
> > What is the problem? Write the demangler? Can you explain it a
> > little, please?
>
> That's part of it. See:
>
> http://mail.python.org/pipermail/c++-sig/2002-June/001277.html
Unless I'm missing something, with g++ >= 3.1 you can use
abi::__cxa_demangle to do this. Attached is an example. Docs can be
found at
http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.2/namespaceabi.html
-Adam
-------------- next part --------------
#include <boost/python.hpp>
#include <typeinfo>
#include <iostream>
#include <vector>
#include <exception>
#include <cxxabi.h>
using namespace boost;
using namespace std;
ostream& operator<<(ostream& os, const python::type_info& type)
{
int status;
char* demangle = abi::__cxa_demangle(type.name(), 0, 0, &status);
if(status == 0) {
os << demangle;
free(demangle);
} else if(status == -2)
os << "Error: " << type.name() << " is not a valid name under the C++ ABI mangling rules";
else if(status == -1)
throw bad_alloc();
return os;
}
void printType(const python::type_info& type)
{
cout << type.name() << " => ";
::operator<<(cout, type) << endl;
}
void test()
{
const char* b;
printType(python::type_info(typeid(b)));
vector<int> c;
printType(python::type_info(typeid(c)));
printType(python::type_info(typeid(&printType)));
}
BOOST_PYTHON_MODULE(test_debug)
{
python::def("test", &test);
}
More information about the Cplusplus-sig
mailing list