libexcept
1.1.19
Stack trace along C++ exceptions
libexcept
demangle.cpp
Go to the documentation of this file.
1
// Copyright (c) 2019-2025 Made to Order Software Corp. All Rights Reserved
2
//
3
// https://snapwebsites.org/project/libexcept
4
// contact@m2osw.com
5
//
6
// This program is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
10
//
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License along
17
// with this program; if not, write to the Free Software Foundation, Inc.,
18
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20
// self
21
//
22
#include "
libexcept/demangle.h
"
23
24
25
// C++
26
//
27
#include <cxxabi.h>
28
#include <memory>
29
30
39
namespace
libexcept
40
{
41
42
43
95
std::string
demangle_cpp_name
(
char
const
* type_id_name)
96
{
97
#if 1
98
int
status(0);
99
100
std::unique_ptr<char, void(*)(
void
*)> res {
101
abi::__cxa_demangle(type_id_name,
nullptr
,
nullptr
, &status),
102
std::free
103
};
104
105
return
status == 0
106
? res.get()
107
: type_id_name;
108
#else
109
// keeping the fallback in case the ABI stops working over time
110
// this is "very" slow since it runs an external tool (c++filt)
111
//
112
std::string cppfilt(
"c++filt "
113
+ raw_function_name);
114
std::unique_ptr<FILE,
decltype
(&::pclose)> p(popen(cppfilt.c_str(),
"r"
), &::pclose);
115
for
(;;)
116
{
117
int
const
c(fgetc(p.get()));
118
if
(c == EOF)
119
{
120
break
;
121
}
122
if
(c !=
'\n'
)
123
{
124
result += c;
125
}
126
}
127
#endif
128
}
129
130
131
132
}
133
// namespace libexcept
134
// vim: ts=4 sw=4 et
demangle.h
Declarations of demangle functions we support.
libexcept
Definition
version.h:27
libexcept::demangle_cpp_name
std::string demangle_cpp_name(char const *type_id_name)
Demangle the specified type string.
Definition
demangle.cpp:95
This document is part of the
Snap! Websites Project
.
Copyright by
Made to Order Software Corp.