| 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> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 #include <sys/param.h> | 14 #include <sys/param.h> |
| 15 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 16 #include <sys/types.h> | 16 #include <sys/types.h> |
| 17 #include <unistd.h> | 17 #include <unistd.h> |
| 18 | 18 |
| 19 #include <map> | 19 #include <map> |
| 20 #include <memory> | 20 #include <memory> |
| 21 #include <ostream> | 21 #include <ostream> |
| 22 #include <string> | 22 #include <string> |
| 23 #include <vector> | 23 #include <vector> |
| 24 | 24 |
| 25 #if defined(__GLIBCXX__) | 25 #if !defined(USE_SYMBOLIZE) |
| 26 #include <cxxabi.h> | 26 #include <cxxabi.h> |
| 27 #endif | 27 #endif |
| 28 #if !defined(__UCLIBC__) | 28 #if !defined(__UCLIBC__) |
| 29 #include <execinfo.h> | 29 #include <execinfo.h> |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
| 33 #include <AvailabilityMacros.h> | 33 #include <AvailabilityMacros.h> |
| 34 #endif | 34 #endif |
| 35 | 35 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 #include "base/third_party/symbolize/symbolize.h" | 51 #include "base/third_party/symbolize/symbolize.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 namespace base { | 54 namespace base { |
| 55 namespace debug { | 55 namespace debug { |
| 56 | 56 |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 volatile sig_atomic_t in_signal_handler = 0; | 59 volatile sig_atomic_t in_signal_handler = 0; |
| 60 | 60 |
| 61 #if !defined(USE_SYMBOLIZE) && defined(__GLIBCXX__) | 61 #if !defined(USE_SYMBOLIZE) |
| 62 // The prefix used for mangled symbols, per the Itanium C++ ABI: | 62 // The prefix used for mangled symbols, per the Itanium C++ ABI: |
| 63 // http://www.codesourcery.com/cxx-abi/abi.html#mangling | 63 // http://www.codesourcery.com/cxx-abi/abi.html#mangling |
| 64 const char kMangledSymbolPrefix[] = "_Z"; | 64 const char kMangledSymbolPrefix[] = "_Z"; |
| 65 | 65 |
| 66 // Characters that can be used for symbols, generated by Ruby: | 66 // Characters that can be used for symbols, generated by Ruby: |
| 67 // (('a'..'z').to_a+('A'..'Z').to_a+('0'..'9').to_a + ['_']).join | 67 // (('a'..'z').to_a+('A'..'Z').to_a+('0'..'9').to_a + ['_']).join |
| 68 const char kSymbolCharacters[] = | 68 const char kSymbolCharacters[] = |
| 69 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; | 69 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
| 70 #endif // !defined(USE_SYMBOLIZE) && defined(__GLIBCXX__) | 70 #endif // !defined(USE_SYMBOLIZE) |
| 71 | 71 |
| 72 #if !defined(USE_SYMBOLIZE) | 72 #if !defined(USE_SYMBOLIZE) |
| 73 // Demangles C++ symbols in the given text. Example: | 73 // Demangles C++ symbols in the given text. Example: |
| 74 // | 74 // |
| 75 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" | 75 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" |
| 76 // => | 76 // => |
| 77 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" | 77 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" |
| 78 void DemangleSymbols(std::string* text) { | 78 void DemangleSymbols(std::string* text) { |
| 79 // Note: code in this function is NOT async-signal safe (std::string uses | 79 // Note: code in this function is NOT async-signal safe (std::string uses |
| 80 // malloc internally). | 80 // malloc internally). |
| 81 | 81 |
| 82 #if defined(__GLIBCXX__) && !defined(__UCLIBC__) | 82 #if !defined(__UCLIBC__) |
| 83 | 83 |
| 84 std::string::size_type search_from = 0; | 84 std::string::size_type search_from = 0; |
| 85 while (search_from < text->size()) { | 85 while (search_from < text->size()) { |
| 86 // Look for the start of a mangled symbol, from search_from. | 86 // Look for the start of a mangled symbol, from search_from. |
| 87 std::string::size_type mangled_start = | 87 std::string::size_type mangled_start = |
| 88 text->find(kMangledSymbolPrefix, search_from); | 88 text->find(kMangledSymbolPrefix, search_from); |
| 89 if (mangled_start == std::string::npos) { | 89 if (mangled_start == std::string::npos) { |
| 90 break; // Mangled symbol not found. | 90 break; // Mangled symbol not found. |
| 91 } | 91 } |
| 92 | 92 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 text->erase(mangled_start, mangled_end - mangled_start); | 108 text->erase(mangled_start, mangled_end - mangled_start); |
| 109 // Insert the demangled symbol. | 109 // Insert the demangled symbol. |
| 110 text->insert(mangled_start, demangled_symbol.get()); | 110 text->insert(mangled_start, demangled_symbol.get()); |
| 111 // Next time, we'll start right after the demangled symbol we inserted. | 111 // Next time, we'll start right after the demangled symbol we inserted. |
| 112 search_from = mangled_start + strlen(demangled_symbol.get()); | 112 search_from = mangled_start + strlen(demangled_symbol.get()); |
| 113 } else { | 113 } else { |
| 114 // Failed to demangle. Retry after the "_Z" we just found. | 114 // Failed to demangle. Retry after the "_Z" we just found. |
| 115 search_from = mangled_start + 2; | 115 search_from = mangled_start + 2; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 #endif // !defined(__UCLIBC__) |
| 119 #endif // defined(__GLIBCXX__) && !defined(__UCLIBC__) | |
| 120 } | 119 } |
| 121 #endif // !defined(USE_SYMBOLIZE) | 120 #endif // !defined(USE_SYMBOLIZE) |
| 122 | 121 |
| 123 class BacktraceOutputHandler { | 122 class BacktraceOutputHandler { |
| 124 public: | 123 public: |
| 125 virtual void HandleOutput(const char* output) = 0; | 124 virtual void HandleOutput(const char* output) = 0; |
| 126 | 125 |
| 127 protected: | 126 protected: |
| 128 virtual ~BacktraceOutputHandler() {} | 127 virtual ~BacktraceOutputHandler() {} |
| 129 }; | 128 }; |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 *ptr = *start; | 807 *ptr = *start; |
| 809 *start++ = ch; | 808 *start++ = ch; |
| 810 } | 809 } |
| 811 return buf; | 810 return buf; |
| 812 } | 811 } |
| 813 | 812 |
| 814 } // namespace internal | 813 } // namespace internal |
| 815 | 814 |
| 816 } // namespace debug | 815 } // namespace debug |
| 817 } // namespace base | 816 } // namespace base |
| OLD | NEW |