blob: 3e1f0ff150018296934e50fffede35997546aff1 [file] [log] [blame]
Adrien Béraud612b55b2023-05-29 10:42:04 -04001/*
Adrien Béraudcb753622023-07-17 22:32:49 -04002 * Copyright (C) 2004-2023 Savoir-faire Linux Inc.
Adrien Béraud612b55b2023-05-29 10:42:04 -04003 *
Adrien Béraudcb753622023-07-17 22:32:49 -04004 * This program is free software: you can redistribute it and/or modify
Adrien Béraud612b55b2023-05-29 10:42:04 -04005 * it under the terms of the GNU General Public License as published by
Adrien Béraudcb753622023-07-17 22:32:49 -04006 * the Free Software Foundation, either version 3 of the License, or
Adrien Béraud612b55b2023-05-29 10:42:04 -04007 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Adrien Béraudcb753622023-07-17 22:32:49 -040011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Adrien Béraud612b55b2023-05-29 10:42:04 -040012 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
Adrien Béraudcb753622023-07-17 22:32:49 -040015 * along with this program. If not, see <https://www.gnu.org/licenses/>.
Adrien Béraud612b55b2023-05-29 10:42:04 -040016 */
Adrien Béraud612b55b2023-05-29 10:42:04 -040017#pragma once
18
19#ifdef ENABLE_TRACEPOINTS
20/*
21 * GCC Only. We use these instead of classic __FILE__ and __LINE__ because
22 * these are evaluated where invoked and not at expansion time. See GCC manual.
23 */
24# define CURRENT_FILENAME() __builtin_FILE()
25# define CURRENT_LINE() __builtin_LINE()
26#else
27# define CURRENT_FILENAME() ""
28# define CURRENT_LINE() 0
29#endif
30
31#ifdef HAVE_CXXABI_H
32#include <cxxabi.h>
33#include <string>
34
35template<typename T>
36std::string demangle()
37{
38 int err;
39 char *raw;
40 std::string ret;
41
42 raw = abi::__cxa_demangle(typeid(T).name(), 0, 0, &err);
43
44 if (0 == err) {
45 ret = raw;
46 } else {
47 ret = typeid(T).name();
48 }
49
50 std::free(raw);
51
52 return ret;
53}
54
55#else
56template<typename T>
57std::string demangle()
58{
59 return typeid(T).name();
60}
61#endif