Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 1 | /* |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2023 Savoir-faire Linux Inc. |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 3 | * |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 4 | * This program is free software: you can redistribute it and/or modify |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 5 | * it under the terms of the GNU General Public License as published by |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 6 | * the Free Software Foundation, either version 3 of the License, or |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 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 |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
Adrien Béraud | cb75362 | 2023-07-17 22:32:49 -0400 | [diff] [blame] | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 16 | */ |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 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 | |
| 35 | template<typename T> |
| 36 | std::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 |
| 56 | template<typename T> |
| 57 | std::string demangle() |
| 58 | { |
| 59 | return typeid(T).name(); |
| 60 | } |
| 61 | #endif |