diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 318a15b1e..12a4f3aec 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -183,6 +183,7 @@ set(source_files model/realtime-simulator-impl.cc model/wall-clock-synchronizer.cc model/matrix-array.cc + model/demangle.cc ) # Define core lib headers @@ -211,6 +212,7 @@ set(header_files model/config.h model/default-deleter.h model/default-simulator-impl.h + model/demangle.h model/deprecated.h model/des-metrics.h model/double.h diff --git a/src/core/model/callback.cc b/src/core/model/callback.cc index 3971a5358..7389e4b83 100644 --- a/src/core/model/callback.cc +++ b/src/core/model/callback.cc @@ -88,67 +88,3 @@ CallbackValue::DeserializeFromString(std::string value, Ptr= 3) - -#include -#include - -namespace ns3 -{ - -std::string -CallbackImplBase::Demangle(const std::string& mangled) -{ - NS_LOG_FUNCTION(mangled); - - int status; - char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &status); - - std::string ret; - if (status == 0) - { - NS_ASSERT(demangled); - ret = demangled; - } - else if (status == -1) - { - NS_LOG_UNCOND("Callback demangling failed: Memory allocation failure occurred."); - ret = mangled; - } - else if (status == -2) - { - NS_LOG_UNCOND("Callback demangling failed: Mangled name is not a valid under the C++ ABI " - "mangling rules."); - ret = mangled; - } - else if (status == -3) - { - NS_LOG_UNCOND("Callback demangling failed: One of the arguments is invalid."); - ret = mangled; - } - else - { - NS_LOG_UNCOND("Callback demangling failed: status " << status); - ret = mangled; - } - - if (demangled) - { - std::free(demangled); - } - return ret; -} - -} // namespace ns3 - -#else - -std::string -ns3::CallbackImplBase::Demangle(const std::string& mangled) -{ - NS_LOG_FUNCTION(this << mangled); - return mangled; -} - -#endif diff --git a/src/core/model/callback.h b/src/core/model/callback.h index df4a2dfb8..26a7561bf 100644 --- a/src/core/model/callback.h +++ b/src/core/model/callback.h @@ -23,6 +23,7 @@ #include "attribute-helper.h" #include "attribute.h" +#include "demangle.h" #include "fatal-error.h" #include "ptr.h" #include "simple-ref-count.h" @@ -99,12 +100,6 @@ class CallbackImplBase : public SimpleRefCount virtual std::string GetTypeid() const = 0; protected: - /** - * \param [in] mangled The mangled string - * \return The demangled form of mangled - */ - static std::string Demangle(const std::string& mangled); - /** * Helper to get the C++ typeid as a string. * diff --git a/src/core/model/demangle.cc b/src/core/model/demangle.cc new file mode 100644 index 000000000..1c288b239 --- /dev/null +++ b/src/core/model/demangle.cc @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2005,2006 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + * Modified by: Gabriel Ferreira + * Moved the Demangle function out of CallbackImplBase + */ + +#include "demangle.h" + +#include "assert.h" +#include "log.h" + +NS_LOG_COMPONENT_DEFINE("Demangle"); + +#if (__GNUC__ >= 3) + +#include +#include + +std::string +ns3::Demangle(const std::string& mangled) +{ + NS_LOG_FUNCTION(mangled); + + int status; + char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &status); + + std::string ret; + if (status == 0) + { + NS_ASSERT(demangled); + ret = demangled; + } + else if (status == -1) + { + NS_LOG_DEBUG("Demangling failed: Memory allocation failure occurred."); + ret = mangled; + } + else if (status == -2) + { + NS_LOG_DEBUG("Demangling failed: Mangled name is not a valid under the C++ ABI " + "mangling rules."); + ret = mangled; + } + else if (status == -3) + { + NS_LOG_DEBUG("Demangling failed: One of the arguments is invalid."); + ret = mangled; + } + else + { + NS_LOG_DEBUG("Demangling failed: status " << status); + ret = mangled; + } + + if (demangled) + { + std::free(demangled); + } + return ret; +} + +#else + +std::string +ns3::Demangle(const std::string& mangled) +{ + NS_LOG_FUNCTION(mangled); + return mangled; +} + +#endif diff --git a/src/core/model/demangle.h b/src/core/model/demangle.h new file mode 100644 index 000000000..bb5711006 --- /dev/null +++ b/src/core/model/demangle.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2005,2006 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + * Modified by: Gabriel Ferreira + * Moved the Demangle function out of CallbackImplBase + */ + +#ifndef NS3_DEMANGLE_H +#define NS3_DEMANGLE_H + +#include + +namespace ns3 +{ +/** + * \param [in] mangled The mangled string + * \return The demangled form of mangled + */ +std::string Demangle(const std::string& mangled); +}; // namespace ns3 + +#endif // NS3_DEMANGLE_H