]> git.tdb.fi Git - libs/core.git/blob - source/debug/demangle.cpp
053fd52bc4a867a9a1f8d3f63641fdf4962d0f4b
[libs/core.git] / source / debug / demangle.cpp
1 /* $Id$
2
3 This file is part of libmspcore
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <cstdlib>
9 #ifdef __GNUC__
10 #include <cxxabi.h>
11 #endif
12 #include "demangle.h"
13
14 using namespace std;
15
16 namespace Msp {
17 namespace Debug {
18
19 string demangle(const string &sym)
20 {
21 #ifdef __GNUC__
22         int status;
23         char *dm = abi::__cxa_demangle(sym.c_str(), 0, 0, &status);
24         
25         string result;
26         if(status==0)
27                 result = dm;
28         else
29                 result = sym;
30         
31         free(dm);
32
33         return result;
34 #else
35         return sym;
36 #endif
37 }
38
39 } // namespace Debug
40 } // namespace Msp