Ring Daemon
Loading...
Searching...
No Matches
trace-tools.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2026 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#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
38{
39 int err;
40 char* raw;
41 std::string ret;
42
43 raw = abi::__cxa_demangle(typeid(T).name(), 0, 0, &err);
44
45 if (0 == err) {
46 ret = raw;
47 } else {
48 ret = typeid(T).name();
49 }
50
51 std::free(raw);
52
53 return ret;
54}
55
56#else
57template<typename T>
58std::string
60{
61 return typeid(T).name();
62}
63#endif
std::string demangle()
Definition trace-tools.h:59