OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_util.h" | 5 #include "base/debug_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
12 #include <sys/sysctl.h> | 12 #include <sys/sysctl.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
| 16 #include <string> |
| 17 #include <vector> |
| 18 |
16 #if defined(__GLIBCXX__) | 19 #if defined(__GLIBCXX__) |
17 #include <cxxabi.h> | 20 #include <cxxabi.h> |
18 #endif | 21 #endif |
19 | 22 |
20 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
21 #include <AvailabilityMacros.h> | 24 #include <AvailabilityMacros.h> |
22 #endif | 25 #endif |
23 | 26 |
24 #include <iostream> | 27 #include <iostream> |
25 #include <string> | 28 #include <string> |
26 | 29 |
27 #include "base/basictypes.h" | 30 #include "base/basictypes.h" |
28 #include "base/compat_execinfo.h" | 31 #include "base/compat_execinfo.h" |
29 #include "base/eintr_wrapper.h" | 32 #include "base/eintr_wrapper.h" |
30 #include "base/logging.h" | 33 #include "base/logging.h" |
31 #include "base/safe_strerror_posix.h" | 34 #include "base/safe_strerror_posix.h" |
32 #include "base/scoped_ptr.h" | 35 #include "base/scoped_ptr.h" |
33 #include "base/string_piece.h" | 36 #include "base/string_piece.h" |
34 #include "base/string_util.h" | 37 #include "base/stringprintf.h" |
35 | 38 |
36 #if defined(USE_SYMBOLIZE) | 39 #if defined(USE_SYMBOLIZE) |
37 #include "base/third_party/symbolize/symbolize.h" | 40 #include "base/third_party/symbolize/symbolize.h" |
38 #endif | 41 #endif |
39 | 42 |
40 namespace { | 43 namespace { |
41 // The prefix used for mangled symbols, per the Itanium C++ ABI: | 44 // The prefix used for mangled symbols, per the Itanium C++ ABI: |
42 // http://www.codesourcery.com/cxx-abi/abi.html#mangling | 45 // http://www.codesourcery.com/cxx-abi/abi.html#mangling |
43 const char kMangledSymbolPrefix[] = "_Z"; | 46 const char kMangledSymbolPrefix[] = "_Z"; |
44 | 47 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 105 |
103 #if defined(USE_SYMBOLIZE) | 106 #if defined(USE_SYMBOLIZE) |
104 for (int i = 0; i < size; ++i) { | 107 for (int i = 0; i < size; ++i) { |
105 char symbol[1024]; | 108 char symbol[1024]; |
106 // Subtract by one as return address of function may be in the next | 109 // Subtract by one as return address of function may be in the next |
107 // function when a function is annotated as noreturn. | 110 // function when a function is annotated as noreturn. |
108 if (google::Symbolize(static_cast<char *>(trace[i]) - 1, | 111 if (google::Symbolize(static_cast<char *>(trace[i]) - 1, |
109 symbol, sizeof(symbol))) { | 112 symbol, sizeof(symbol))) { |
110 // Don't call DemangleSymbols() here as the symbol is demangled by | 113 // Don't call DemangleSymbols() here as the symbol is demangled by |
111 // google::Symbolize(). | 114 // google::Symbolize(). |
112 trace_strings->push_back(StringPrintf("%s [%p]", symbol, trace[i])); | 115 trace_strings->push_back( |
| 116 base::StringPrintf("%s [%p]", symbol, trace[i])); |
113 symbolized = true; | 117 symbolized = true; |
114 } else { | 118 } else { |
115 trace_strings->push_back(StringPrintf("%p", trace[i])); | 119 trace_strings->push_back(base::StringPrintf("%p", trace[i])); |
116 } | 120 } |
117 } | 121 } |
118 #else | 122 #else |
119 scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace, size)); | 123 scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace, size)); |
120 if (trace_symbols.get()) { | 124 if (trace_symbols.get()) { |
121 for (int i = 0; i < size; ++i) { | 125 for (int i = 0; i < size; ++i) { |
122 std::string trace_symbol = trace_symbols.get()[i]; | 126 std::string trace_symbol = trace_symbols.get()[i]; |
123 DemangleSymbols(&trace_symbol); | 127 DemangleSymbols(&trace_symbol); |
124 trace_strings->push_back(trace_symbol); | 128 trace_strings->push_back(trace_symbol); |
125 } | 129 } |
126 symbolized = true; | 130 symbolized = true; |
127 } else { | 131 } else { |
128 for (int i = 0; i < size; ++i) { | 132 for (int i = 0; i < size; ++i) { |
129 trace_strings->push_back(StringPrintf("%p", trace[i])); | 133 trace_strings->push_back(base::StringPrintf("%p", trace[i])); |
130 } | 134 } |
131 } | 135 } |
132 #endif // defined(USE_SYMBOLIZE) | 136 #endif // defined(USE_SYMBOLIZE) |
133 | 137 |
134 return symbolized; | 138 return symbolized; |
135 } | 139 } |
136 | 140 |
137 } // namespace | 141 } // namespace |
138 | 142 |
139 // static | 143 // static |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 (*os) << "Backtrace:\n"; | 297 (*os) << "Backtrace:\n"; |
294 } else { | 298 } else { |
295 (*os) << "Unable get symbols for backtrace (" << safe_strerror(errno) | 299 (*os) << "Unable get symbols for backtrace (" << safe_strerror(errno) |
296 << "). Dumping raw addresses in trace:\n"; | 300 << "). Dumping raw addresses in trace:\n"; |
297 } | 301 } |
298 | 302 |
299 for (size_t i = 0; i < trace_strings.size(); ++i) { | 303 for (size_t i = 0; i < trace_strings.size(); ++i) { |
300 (*os) << "\t" << trace_strings[i] << "\n"; | 304 (*os) << "\t" << trace_strings[i] << "\n"; |
301 } | 305 } |
302 } | 306 } |
OLD | NEW |