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 <ostream> | 21 #include <ostream> |
21 #include <string> | 22 #include <string> |
22 #include <vector> | 23 #include <vector> |
23 | 24 |
24 #include "base/memory/free_deleter.h" | |
25 | |
26 #if defined(__GLIBCXX__) | 25 #if defined(__GLIBCXX__) |
27 #include <cxxabi.h> | 26 #include <cxxabi.h> |
28 #endif | 27 #endif |
29 #if !defined(__UCLIBC__) | 28 #if !defined(__UCLIBC__) |
30 #include <execinfo.h> | 29 #include <execinfo.h> |
31 #endif | 30 #endif |
32 | 31 |
33 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
34 #include <AvailabilityMacros.h> | 33 #include <AvailabilityMacros.h> |
35 #endif | 34 #endif |
36 | 35 |
37 #include "base/debug/debugger.h" | 36 #include "base/debug/debugger.h" |
38 #include "base/debug/proc_maps_linux.h" | 37 #include "base/debug/proc_maps_linux.h" |
39 #include "base/logging.h" | 38 #include "base/logging.h" |
40 #include "base/macros.h" | 39 #include "base/macros.h" |
41 #include "base/memory/scoped_ptr.h" | 40 #include "base/memory/free_deleter.h" |
42 #include "base/memory/singleton.h" | 41 #include "base/memory/singleton.h" |
43 #include "base/numerics/safe_conversions.h" | 42 #include "base/numerics/safe_conversions.h" |
44 #include "base/posix/eintr_wrapper.h" | 43 #include "base/posix/eintr_wrapper.h" |
45 #include "base/strings/string_number_conversions.h" | 44 #include "base/strings/string_number_conversions.h" |
46 #include "build/build_config.h" | 45 #include "build/build_config.h" |
47 | 46 |
48 #if defined(USE_SYMBOLIZE) | 47 #if defined(USE_SYMBOLIZE) |
49 #include "base/third_party/symbolize/symbolize.h" | 48 #include "base/third_party/symbolize/symbolize.h" |
50 #endif | 49 #endif |
51 | 50 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 std::string::size_type mangled_end = | 91 std::string::size_type mangled_end = |
93 text->find_first_not_of(kSymbolCharacters, mangled_start); | 92 text->find_first_not_of(kSymbolCharacters, mangled_start); |
94 if (mangled_end == std::string::npos) { | 93 if (mangled_end == std::string::npos) { |
95 mangled_end = text->size(); | 94 mangled_end = text->size(); |
96 } | 95 } |
97 std::string mangled_symbol = | 96 std::string mangled_symbol = |
98 text->substr(mangled_start, mangled_end - mangled_start); | 97 text->substr(mangled_start, mangled_end - mangled_start); |
99 | 98 |
100 // Try to demangle the mangled symbol candidate. | 99 // Try to demangle the mangled symbol candidate. |
101 int status = 0; | 100 int status = 0; |
102 scoped_ptr<char, base::FreeDeleter> demangled_symbol( | 101 std::unique_ptr<char, base::FreeDeleter> demangled_symbol( |
103 abi::__cxa_demangle(mangled_symbol.c_str(), NULL, 0, &status)); | 102 abi::__cxa_demangle(mangled_symbol.c_str(), NULL, 0, &status)); |
104 if (status == 0) { // Demangling is successful. | 103 if (status == 0) { // Demangling is successful. |
105 // Remove the mangled symbol. | 104 // Remove the mangled symbol. |
106 text->erase(mangled_start, mangled_end - mangled_start); | 105 text->erase(mangled_start, mangled_end - mangled_start); |
107 // Insert the demangled symbol. | 106 // Insert the demangled symbol. |
108 text->insert(mangled_start, demangled_symbol.get()); | 107 text->insert(mangled_start, demangled_symbol.get()); |
109 // 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. |
110 search_from = mangled_start + strlen(demangled_symbol.get()); | 109 search_from = mangled_start + strlen(demangled_symbol.get()); |
111 } else { | 110 } else { |
112 // Failed to demangle. Retry after the "_Z" we just found. | 111 // Failed to demangle. Retry after the "_Z" we just found. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 handler->HandleOutput("<unknown>"); | 172 handler->HandleOutput("<unknown>"); |
174 | 173 |
175 handler->HandleOutput("\n"); | 174 handler->HandleOutput("\n"); |
176 } | 175 } |
177 #else | 176 #else |
178 bool printed = false; | 177 bool printed = false; |
179 | 178 |
180 // Below part is async-signal unsafe (uses malloc), so execute it only | 179 // Below part is async-signal unsafe (uses malloc), so execute it only |
181 // when we are not executing the signal handler. | 180 // when we are not executing the signal handler. |
182 if (in_signal_handler == 0) { | 181 if (in_signal_handler == 0) { |
183 scoped_ptr<char*, FreeDeleter> | 182 std::unique_ptr<char*, FreeDeleter> trace_symbols( |
184 trace_symbols(backtrace_symbols(trace, size)); | 183 backtrace_symbols(trace, size)); |
185 if (trace_symbols.get()) { | 184 if (trace_symbols.get()) { |
186 for (size_t i = 0; i < size; ++i) { | 185 for (size_t i = 0; i < size; ++i) { |
187 std::string trace_symbol = trace_symbols.get()[i]; | 186 std::string trace_symbol = trace_symbols.get()[i]; |
188 DemangleSymbols(&trace_symbol); | 187 DemangleSymbols(&trace_symbol); |
189 handler->HandleOutput(trace_symbol.c_str()); | 188 handler->HandleOutput(trace_symbol.c_str()); |
190 handler->HandleOutput("\n"); | 189 handler->HandleOutput("\n"); |
191 } | 190 } |
192 | 191 |
193 printed = true; | 192 printed = true; |
194 } | 193 } |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 *ptr = *start; | 804 *ptr = *start; |
806 *start++ = ch; | 805 *start++ = ch; |
807 } | 806 } |
808 return buf; | 807 return buf; |
809 } | 808 } |
810 | 809 |
811 } // namespace internal | 810 } // namespace internal |
812 | 811 |
813 } // namespace debug | 812 } // namespace debug |
814 } // namespace base | 813 } // namespace base |
OLD | NEW |