1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "tensorflow/stream_executor/lib/demangle.h" 17 18 #if (__GNUC__ >= 4 || (__GNUC__ >= 3 && __GNUC_MINOR__ >= 4)) && \ 19 !defined(__mips__) 20 # define HAS_CXA_DEMANGLE 1 21 #else 22 # define HAS_CXA_DEMANGLE 0 23 #endif 24 25 #include <stdlib.h> 26 #if HAS_CXA_DEMANGLE 27 #include <cxxabi.h> 28 #endif 29 30 namespace perftools { 31 namespace gputools { 32 namespace port { 33 34 // The API reference of abi::__cxa_demangle() can be found in 35 // libstdc++'s manual. 36 // https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html 37 string Demangle(const char *mangled) { 38 string demangled; 39 int status = 0; 40 char *result = nullptr; 41 #if HAS_CXA_DEMANGLE 42 result = abi::__cxa_demangle(mangled, nullptr, nullptr, &status); 43 #endif 44 if (status == 0 && result != nullptr) { // Demangling succeeded. 45 demangled.append(result); 46 free(result); 47 } 48 return demangled; 49 } 50 51 } // namespace port 52 } // namespace gputools 53 } // namespace perftools 54