| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "base/debug_util.h" | 6 #include "base/debug_util.h" |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <stdio.h> | 10 #include <stdio.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 #if defined(OS_MACOSX) |
| 17 #include <AvailabilityMacros.h> |
| 18 #endif |
| 19 |
| 16 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 17 #include "base/compat_execinfo.h" | 21 #include "base/compat_execinfo.h" |
| 18 #include "base/eintr_wrapper.h" | 22 #include "base/eintr_wrapper.h" |
| 19 #include "base/logging.h" | 23 #include "base/logging.h" |
| 20 #include "base/scoped_ptr.h" | 24 #include "base/scoped_ptr.h" |
| 21 #include "base/string_piece.h" | 25 #include "base/string_piece.h" |
| 22 | 26 |
| 23 // static | 27 // static |
| 24 bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) { | 28 bool DebugUtil::SpawnDebuggerOnProcess(unsigned /* process_id */) { |
| 25 NOTIMPLEMENTED(); | 29 NOTIMPLEMENTED(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // static | 113 // static |
| 110 void DebugUtil::BreakDebugger() { | 114 void DebugUtil::BreakDebugger() { |
| 111 #if defined(ARCH_CPU_ARM_FAMILY) | 115 #if defined(ARCH_CPU_ARM_FAMILY) |
| 112 asm("bkpt 0"); | 116 asm("bkpt 0"); |
| 113 #else | 117 #else |
| 114 asm("int3"); | 118 asm("int3"); |
| 115 #endif | 119 #endif |
| 116 } | 120 } |
| 117 | 121 |
| 118 StackTrace::StackTrace() { | 122 StackTrace::StackTrace() { |
| 119 if (backtrace == NULL) { | 123 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |
| 124 if (!backtrace) { |
| 120 count_ = 0; | 125 count_ = 0; |
| 121 } else { | 126 return; |
| 122 // Though the backtrace API man page does not list any possible negative | |
| 123 // return values, we take no chance. | |
| 124 count_ = std::max(backtrace(trace_, arraysize(trace_)), 0); | |
| 125 } | 127 } |
| 128 #endif |
| 129 // Though the backtrace API man page does not list any possible negative |
| 130 // return values, we take no chance. |
| 131 count_ = std::max(backtrace(trace_, arraysize(trace_)), 0); |
| 126 } | 132 } |
| 127 | 133 |
| 128 void StackTrace::PrintBacktrace() { | 134 void StackTrace::PrintBacktrace() { |
| 129 if (backtrace_symbols_fd != NULL) { | 135 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |
| 130 fflush(stderr); | 136 if (!backtrace_symbols_fd) |
| 131 backtrace_symbols_fd(trace_, count_, STDERR_FILENO); | 137 return; |
| 132 } | 138 #endif |
| 139 fflush(stderr); |
| 140 backtrace_symbols_fd(trace_, count_, STDERR_FILENO); |
| 133 } | 141 } |
| 134 | 142 |
| 135 void StackTrace::OutputToStream(std::ostream* os) { | 143 void StackTrace::OutputToStream(std::ostream* os) { |
| 136 if (backtrace_symbols != NULL) { | 144 #if defined(OS_MACOSX) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 |
| 137 scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace_, count_)); | 145 if (!backtrace_symbols) |
| 146 return; |
| 147 #endif |
| 148 scoped_ptr_malloc<char*> trace_symbols(backtrace_symbols(trace_, count_)); |
| 138 | 149 |
| 139 // If we can't retrieve the symbols, print an error and just dump the raw | 150 // If we can't retrieve the symbols, print an error and just dump the raw |
| 140 // addresses. | 151 // addresses. |
| 141 if (trace_symbols.get() == NULL) { | 152 if (trace_symbols.get() == NULL) { |
| 142 (*os) << "Unable get symbols for backtrace (" << strerror(errno) | 153 (*os) << "Unable get symbols for backtrace (" << strerror(errno) |
| 143 << "). Dumping raw addresses in trace:\n"; | 154 << "). Dumping raw addresses in trace:\n"; |
| 144 for (int i = 0; i < count_; ++i) { | 155 for (int i = 0; i < count_; ++i) { |
| 145 (*os) << "\t" << trace_[i] << "\n"; | 156 (*os) << "\t" << trace_[i] << "\n"; |
| 146 } | 157 } |
| 147 } else { | 158 } else { |
| 148 (*os) << "Backtrace:\n"; | 159 (*os) << "Backtrace:\n"; |
| 149 for (int i = 0; i < count_; ++i) { | 160 for (int i = 0; i < count_; ++i) { |
| 150 (*os) << "\t" << trace_symbols.get()[i] << "\n"; | 161 (*os) << "\t" << trace_symbols.get()[i] << "\n"; |
| 151 } | |
| 152 } | 162 } |
| 153 } | 163 } |
| 154 } | 164 } |
| OLD | NEW |