blob: ccd65cdf834cb59072d237908cb8d611f82e114a [file] [log] [blame]
Adrien BĂ©raud612b55b2023-05-29 10:42:04 -04001/*
2 * Copyright (C) 2022-2023 Savoir-faire Linux Inc.
3 *
4 * Author: Olivier Dion <olivier.dion@savoirfairelinux.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 3 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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#pragma once
22
23#ifdef ENABLE_TRACEPOINTS
24/*
25 * GCC Only. We use these instead of classic __FILE__ and __LINE__ because
26 * these are evaluated where invoked and not at expansion time. See GCC manual.
27 */
28# define CURRENT_FILENAME() __builtin_FILE()
29# define CURRENT_LINE() __builtin_LINE()
30#else
31# define CURRENT_FILENAME() ""
32# define CURRENT_LINE() 0
33#endif
34
35#ifdef HAVE_CXXABI_H
36#include <cxxabi.h>
37#include <string>
38
39template<typename T>
40std::string demangle()
41{
42 int err;
43 char *raw;
44 std::string ret;
45
46 raw = abi::__cxa_demangle(typeid(T).name(), 0, 0, &err);
47
48 if (0 == err) {
49 ret = raw;
50 } else {
51 ret = typeid(T).name();
52 }
53
54 std::free(raw);
55
56 return ret;
57}
58
59#else
60template<typename T>
61std::string demangle()
62{
63 return typeid(T).name();
64}
65#endif