Home | History | Annotate | Download | only in sanitizer_common
      1 //===-- sanitizer_symbolizer_itanium.cc -----------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is shared between the sanitizer run-time libraries.
     11 // Itanium C++ ABI-specific implementation of symbolizer parts.
     12 //===----------------------------------------------------------------------===//
     13 #if defined(__APPLE__) || defined(__linux__)
     14 
     15 #include "sanitizer_symbolizer.h"
     16 
     17 #include <stdlib.h>
     18 
     19 // C++ demangling function, as required by Itanium C++ ABI. This is weak,
     20 // because we do not require a C++ ABI library to be linked to a program
     21 // using sanitizers; if it's not present, we'll just use the mangled name.
     22 namespace __cxxabiv1 {
     23   extern "C" char *__cxa_demangle(const char *mangled, char *buffer,
     24                                   size_t *length, int *status)
     25     SANITIZER_WEAK_ATTRIBUTE;
     26 }
     27 
     28 const char *__sanitizer::Demangle(const char *MangledName) {
     29   // FIXME: __cxa_demangle aggressively insists on allocating memory.
     30   // There's not much we can do about that, short of providing our
     31   // own demangler (libc++abi's implementation could be adapted so that
     32   // it does not allocate). For now, we just call it anyway, and we leak
     33   // the returned value.
     34   if (__cxxabiv1::__cxa_demangle)
     35     if (const char *Demangled =
     36           __cxxabiv1::__cxa_demangle(MangledName, 0, 0, 0))
     37       return Demangled;
     38 
     39   return MangledName;
     40 }
     41 
     42 #endif  // __APPLE__ || __linux__
     43