| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // The prefix used for mangled symbols, per the Itanium C++ ABI: | 59 // The prefix used for mangled symbols, per the Itanium C++ ABI: |
| 60 // http://www.codesourcery.com/cxx-abi/abi.html#mangling | 60 // http://www.codesourcery.com/cxx-abi/abi.html#mangling |
| 61 const char kMangledSymbolPrefix[] = "_Z"; | 61 const char kMangledSymbolPrefix[] = "_Z"; |
| 62 | 62 |
| 63 // Characters that can be used for symbols, generated by Ruby: | 63 // Characters that can be used for symbols, generated by Ruby: |
| 64 // (('a'..'z').to_a+('A'..'Z').to_a+('0'..'9').to_a + ['_']).join | 64 // (('a'..'z').to_a+('A'..'Z').to_a+('0'..'9').to_a + ['_']).join |
| 65 const char kSymbolCharacters[] = | 65 const char kSymbolCharacters[] = |
| 66 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; | 66 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
| 67 #endif // !defined(USE_SYMBOLIZE) && defined(__GLIBCXX__) | 67 #endif // !defined(USE_SYMBOLIZE) && defined(__GLIBCXX__) |
| 68 | 68 |
| 69 #if !defined(USE_SYMBOLIZE) | 69 #if !defined(__UCLIBC__) && !defined(USE_SYMBOLIZE) |
| 70 // Demangles C++ symbols in the given text. Example: | 70 // Demangles C++ symbols in the given text. Example: |
| 71 // | 71 // |
| 72 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" | 72 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" |
| 73 // => | 73 // => |
| 74 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" | 74 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" |
| 75 void DemangleSymbols(std::string* text) { | 75 void DemangleSymbols(std::string* text) { |
| 76 // Note: code in this function is NOT async-signal safe (std::string uses | 76 // Note: code in this function is NOT async-signal safe (std::string uses |
| 77 // malloc internally). | 77 // malloc internally). |
| 78 | 78 |
| 79 #if defined(__GLIBCXX__) && !defined(__UCLIBC__) | 79 #if defined(__GLIBCXX__) |
| 80 | 80 |
| 81 std::string::size_type search_from = 0; | 81 std::string::size_type search_from = 0; |
| 82 while (search_from < text->size()) { | 82 while (search_from < text->size()) { |
| 83 // Look for the start of a mangled symbol, from search_from. | 83 // Look for the start of a mangled symbol, from search_from. |
| 84 std::string::size_type mangled_start = | 84 std::string::size_type mangled_start = |
| 85 text->find(kMangledSymbolPrefix, search_from); | 85 text->find(kMangledSymbolPrefix, search_from); |
| 86 if (mangled_start == std::string::npos) { | 86 if (mangled_start == std::string::npos) { |
| 87 break; // Mangled symbol not found. | 87 break; // Mangled symbol not found. |
| 88 } | 88 } |
| 89 | 89 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 // Insert the demangled symbol. | 106 // Insert the demangled symbol. |
| 107 text->insert(mangled_start, demangled_symbol.get()); | 107 text->insert(mangled_start, demangled_symbol.get()); |
| 108 // Next time, we'll start right after the demangled symbol we inserted. | 108 // Next time, we'll start right after the demangled symbol we inserted. |
| 109 search_from = mangled_start + strlen(demangled_symbol.get()); | 109 search_from = mangled_start + strlen(demangled_symbol.get()); |
| 110 } else { | 110 } else { |
| 111 // Failed to demangle. Retry after the "_Z" we just found. | 111 // Failed to demangle. Retry after the "_Z" we just found. |
| 112 search_from = mangled_start + 2; | 112 search_from = mangled_start + 2; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 #endif // defined(__GLIBCXX__) && !defined(__UCLIBC__) | 116 #else // defined(__GLIBCXX__) |
| 117 (void)text; // Avoid an unused warning. |
| 118 #endif // defined(__GLIBCXX__) |
| 117 } | 119 } |
| 118 #endif // !defined(USE_SYMBOLIZE) | 120 #endif // !defined(__UCLIBC__) && !defined(USE_SYMBOLIZE) |
| 119 | 121 |
| 120 class BacktraceOutputHandler { | 122 class BacktraceOutputHandler { |
| 121 public: | 123 public: |
| 122 virtual void HandleOutput(const char* output) = 0; | 124 virtual void HandleOutput(const char* output) = 0; |
| 123 | 125 |
| 124 protected: | 126 protected: |
| 125 virtual ~BacktraceOutputHandler() {} | 127 virtual ~BacktraceOutputHandler() {} |
| 126 }; | 128 }; |
| 127 | 129 |
| 128 #if !defined(__UCLIBC__) | 130 #if !defined(__UCLIBC__) |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 *ptr = *start; | 806 *ptr = *start; |
| 805 *start++ = ch; | 807 *start++ = ch; |
| 806 } | 808 } |
| 807 return buf; | 809 return buf; |
| 808 } | 810 } |
| 809 | 811 |
| 810 } // namespace internal | 812 } // namespace internal |
| 811 | 813 |
| 812 } // namespace debug | 814 } // namespace debug |
| 813 } // namespace base | 815 } // namespace base |
| OLD | NEW |