base/debug_util_posix.cc
// Demangles C++ symbols in the given text. Example:
//
// "sconsbuild/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]"
// =>
// "sconsbuild/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]"
Demangles C++ symbols in the given text.
Demangles C ++ symbols in the given text .
void DemangleSymbols(std::string* text) {
#if defined(__GLIBCXX__)
  std::string::size_type search_from = 0;
  while (search_from < text->size()) {
    std::string::size_type mangled_start =
        text->find(kMangledSymbolPrefix, search_from);
    if (mangled_start == std::string::npos) {
      break;  
    }
    std::string::size_type mangled_end =
        text->find_first_not_of(kSymbolCharacters, mangled_start);
    if (mangled_end == std::string::npos) {
      mangled_end = text->size();
    }
    std::string mangled_symbol =
        text->substr(mangled_start, mangled_end - mangled_start);
    int status = 0;
    scoped_ptr_malloc<char> demangled_symbol(
        abi::__cxa_demangle(mangled_symbol.c_str(), NULL, 0, &status));
    if (status == 0) {  
      text->erase(mangled_start, mangled_end - mangled_start);
      text->insert(mangled_start, demangled_symbol.get());
      search_from = mangled_start + strlen(demangled_symbol.get());
    } else {
      search_from = mangled_start + 2;
    }
  }
#endif  
}
void DemangleSymbols ( std :: string * text ) { #if defined ( __GLIBCXX__ ) std :: string :: size_type search_from = 0 ; while ( search_from < text -> size ( ) ) { std :: string :: size_type mangled_start = text -> find ( kMangledSymbolPrefix , search_from ) ; if ( mangled_start == std :: string :: npos ) { break ; } std :: string :: size_type mangled_end = text -> find_first_not_of ( kSymbolCharacters , mangled_start ) ; if ( mangled_end == std :: string :: npos ) { mangled_end = text -> size ( ) ; } std :: string mangled_symbol = text -> substr ( mangled_start , mangled_end - mangled_start ) ; int status = 0 ; scoped_ptr_malloc < char > demangled_symbol ( abi :: __cxa_demangle ( mangled_symbol . c_str ( ) , NULL , 0 , & status ) ) ; if ( status == 0 ) { text -> erase ( mangled_start , mangled_end - mangled_start ) ; text -> insert ( mangled_start , demangled_symbol . get ( ) ) ; search_from = mangled_start + strlen ( demangled_symbol . get ( ) ) ; } else { search_from = mangled_start + 2 ; } } #endif }
Demangles C++ symbols in the given text.
Demangles C ++ symbols in the given text .
// Look for the start of a mangled symbol, from search_from. // Mangled symbol not found. // Look for the end of the mangled symbol. // Try to demangle the mangled symbol candidate. // Demangling is successful. // Remove the mangled symbol. // Insert the demangled symbol. // Next time, we'll start right after the demangled symbol we inserted. // Failed to demangle.  Retry after the "_Z" we just found. // defined(__GLIBCXX__)