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 // Slightly adapted for inclusion in V8. | 5 // Slightly adapted for inclusion in V8. |
6 // Copyright 2016 the V8 project authors. All rights reserved. | 6 // Copyright 2016 the V8 project authors. All rights reserved. |
7 | 7 |
8 #include "src/base/debug/stack_trace.h" | 8 #include "src/base/debug/stack_trace.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
11 #include <fcntl.h> | 11 #include <fcntl.h> |
12 #include <signal.h> | 12 #include <signal.h> |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 #include <sys/param.h> | 17 #include <sys/param.h> |
18 #include <sys/stat.h> | 18 #include <sys/stat.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 #include <unistd.h> | 20 #include <unistd.h> |
21 | 21 |
22 #include <map> | 22 #include <map> |
23 #include <memory> | 23 #include <memory> |
24 #include <ostream> | 24 #include <ostream> |
25 #include <string> | 25 #include <string> |
26 #include <vector> | 26 #include <vector> |
27 | 27 |
28 #if V8_LIBC_GLIBC || V8_OS_BSD | 28 #if V8_LIBC_GLIBC || V8_OS_BSD || V8_LIBC_UCLIBC |
29 #include <cxxabi.h> | 29 #include <cxxabi.h> |
30 #include <execinfo.h> | 30 #include <execinfo.h> |
31 #endif | 31 #endif |
32 #if V8_OS_MACOSX | 32 #if V8_OS_MACOSX |
33 #include <AvailabilityMacros.h> | 33 #include <AvailabilityMacros.h> |
34 #endif | 34 #endif |
35 | 35 |
36 #include "src/base/build_config.h" | 36 #include "src/base/build_config.h" |
37 #include "src/base/free_deleter.h" | 37 #include "src/base/free_deleter.h" |
38 #include "src/base/logging.h" | 38 #include "src/base/logging.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 // Demangles C++ symbols in the given text. Example: | 71 // Demangles C++ symbols in the given text. Example: |
72 // | 72 // |
73 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" | 73 // "out/Debug/base_unittests(_ZN10StackTraceC1Ev+0x20) [0x817778c]" |
74 // => | 74 // => |
75 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" | 75 // "out/Debug/base_unittests(StackTrace::StackTrace()+0x20) [0x817778c]" |
76 void DemangleSymbols(std::string* text) { | 76 void DemangleSymbols(std::string* text) { |
77 // Note: code in this function is NOT async-signal safe (std::string uses | 77 // Note: code in this function is NOT async-signal safe (std::string uses |
78 // malloc internally). | 78 // malloc internally). |
79 | 79 |
80 #if V8_LIBC_GLIBC || V8_OS_BSD | 80 #if V8_LIBC_GLIBC || V8_OS_BSD || V8_LIBC_UCLIBC |
81 | 81 |
82 std::string::size_type search_from = 0; | 82 std::string::size_type search_from = 0; |
83 while (search_from < text->size()) { | 83 while (search_from < text->size()) { |
84 // Look for the start of a mangled symbol, from search_from. | 84 // Look for the start of a mangled symbol, from search_from. |
85 std::string::size_type mangled_start = | 85 std::string::size_type mangled_start = |
86 text->find(kMangledSymbolPrefix, search_from); | 86 text->find(kMangledSymbolPrefix, search_from); |
87 if (mangled_start == std::string::npos) { | 87 if (mangled_start == std::string::npos) { |
88 break; // Mangled symbol not found. | 88 break; // Mangled symbol not found. |
89 } | 89 } |
90 | 90 |
(...skipping 16 matching lines...) Expand all Loading... |
107 // Insert the demangled symbol. | 107 // Insert the demangled symbol. |
108 text->insert(mangled_start, demangled_symbol.get()); | 108 text->insert(mangled_start, demangled_symbol.get()); |
109 // Next time, we'll start right after the demangled symbol we inserted. | 109 // Next time, we'll start right after the demangled symbol we inserted. |
110 search_from = mangled_start + strlen(demangled_symbol.get()); | 110 search_from = mangled_start + strlen(demangled_symbol.get()); |
111 } else { | 111 } else { |
112 // Failed to demangle. Retry after the "_Z" we just found. | 112 // Failed to demangle. Retry after the "_Z" we just found. |
113 search_from = mangled_start + 2; | 113 search_from = mangled_start + 2; |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 117 #endif // V8_LIBC_GLIBC || V8_OS_BSD || V8_LIBC_UCLIBC |
118 } | 118 } |
119 | 119 |
120 class BacktraceOutputHandler { | 120 class BacktraceOutputHandler { |
121 public: | 121 public: |
122 virtual void HandleOutput(const char* output) = 0; | 122 virtual void HandleOutput(const char* output) = 0; |
123 | 123 |
124 protected: | 124 protected: |
125 virtual ~BacktraceOutputHandler() {} | 125 virtual ~BacktraceOutputHandler() {} |
126 }; | 126 }; |
127 | 127 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 *start++ = ch; | 437 *start++ = ch; |
438 } | 438 } |
439 return buf; | 439 return buf; |
440 } | 440 } |
441 | 441 |
442 } // namespace internal | 442 } // namespace internal |
443 | 443 |
444 } // namespace debug | 444 } // namespace debug |
445 } // namespace base | 445 } // namespace base |
446 } // namespace v8 | 446 } // namespace v8 |
OLD | NEW |