![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <WNS/demangle.hpp> 00029 00030 # if defined(__GNUC__) && __GNUC__ >= 3 00031 // Demangle using cxxabi.h 00032 #include <malloc.h> 00033 #include <cxxabi.h> 00034 std::string 00035 wns::demangle(const std::string& symbol) 00036 { 00037 // demangle the symbol name 00038 // mangeld symbol names are always longer than the demangled versions 00039 int status = 0; 00040 char* demangledName = abi::__cxa_demangle(symbol.c_str(), NULL, NULL, &status); 00041 00042 // Mangling did not succeed. Return the symbol name instead. 00043 if (status != 0) 00044 { 00045 // possible reasons are: 00046 // -1: A memory allocation failure occurred 00047 // -2: "symbol" is no valid name under the C++ ABI mangling rules 00048 // -3: One of the arguments is invalid. 00049 return symbol; 00050 } 00051 00052 // Mangling succeeded. 00053 // Copy into string since ... 00054 std::string result (demangledName); 00055 // ... we need to free the memory before returning 00056 free(demangledName); 00057 return result; 00058 } 00059 00060 #else 00061 // Can't demangle 00062 std::string 00063 wns::demangle(const std::string& symbol) 00064 { 00065 return symbol; 00066 } 00067 #endif // _GNU_SOURCE
1.5.5