A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
demangle.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * Modified by: Gabriel Ferreira <gabrielcarvfer@gmail.com>
8 * Moved the Demangle function out of CallbackImplBase
9 */
10
11#include "demangle.h"
12
13#include "assert.h"
14#include "log.h"
15
16NS_LOG_COMPONENT_DEFINE("Demangle");
17
18#if (__GNUC__ >= 3)
19
20#include <cstdlib>
21#include <cxxabi.h>
22
23std::string
24ns3::Demangle(const std::string& mangled)
25{
26 NS_LOG_FUNCTION(mangled);
27
28 int status;
29 char* demangled = abi::__cxa_demangle(mangled.c_str(), nullptr, nullptr, &status);
30
31 std::string ret;
32 if (status == 0)
33 {
34 NS_ASSERT(demangled);
35 ret = demangled;
36 }
37 else if (status == -1)
38 {
39 NS_LOG_DEBUG("Demangling failed: Memory allocation failure occurred.");
40 ret = mangled;
41 }
42 else if (status == -2)
43 {
44 NS_LOG_DEBUG("Demangling failed: Mangled name is not a valid under the C++ ABI "
45 "mangling rules.");
46 ret = mangled;
47 }
48 else if (status == -3)
49 {
50 NS_LOG_DEBUG("Demangling failed: One of the arguments is invalid.");
51 ret = mangled;
52 }
53 else
54 {
55 NS_LOG_DEBUG("Demangling failed: status " << status);
56 ret = mangled;
57 }
58
59 if (demangled)
60 {
61 std::free(demangled);
62 }
63 return ret;
64}
65
66#else
67
68std::string
69ns3::Demangle(const std::string& mangled)
70{
71 NS_LOG_FUNCTION(mangled);
72 return mangled;
73}
74
75#endif
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
std::string Demangle(const std::string &mangled)
Definition demangle.cc:69