Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #if defined(OS_LINUX) | |
| 9 #include <unistd.h> | |
|
agl
2009/01/16 22:02:47
unistd is needed for STDERR_FILENO
| |
| 10 #include <execinfo.h> | 8 #include <execinfo.h> |
| 11 #endif | 9 #include <fcntl.h> |
| 12 | |
| 13 #include <stdio.h> | 10 #include <stdio.h> |
| 14 #include <fcntl.h> | |
| 15 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 16 #include <sys/sysctl.h> | 12 #include <sys/sysctl.h> |
| 17 #include <sys/types.h> | 13 #include <sys/types.h> |
| 18 #include <unistd.h> | 14 #include <unistd.h> |
| 19 | 15 |
| 20 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 21 #include "base/logging.h" | 17 #include "base/logging.h" |
| 22 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 23 | 19 |
| 24 // static | 20 // static |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 return pid_index < status.size() && status[pid_index] != '0'; | 87 return pid_index < status.size() && status[pid_index] != '0'; |
| 92 } | 88 } |
| 93 | 89 |
| 94 #endif // OS_LINUX | 90 #endif // OS_LINUX |
| 95 | 91 |
| 96 // static | 92 // static |
| 97 void DebugUtil::BreakDebugger() { | 93 void DebugUtil::BreakDebugger() { |
| 98 asm ("int3"); | 94 asm ("int3"); |
| 99 } | 95 } |
| 100 | 96 |
| 101 #if defined(OS_LINUX) | |
| 102 | |
| 103 StackTrace::StackTrace() { | 97 StackTrace::StackTrace() { |
| 104 static const unsigned kMaxCallers = 256; | 98 static const int kMaxCallers = 256; |
| 105 | 99 |
| 106 void* callers[kMaxCallers]; | 100 void* callers[kMaxCallers]; |
| 107 int count = backtrace(callers, kMaxCallers); | 101 int count = backtrace(callers, kMaxCallers); |
| 108 trace_.resize(count); | 102 trace_.resize(count); |
| 109 memcpy(&trace_[0], callers, sizeof(void*) * count); | 103 memcpy(&trace_[0], callers, sizeof(void*) * count); |
| 110 } | 104 } |
| 111 | 105 |
| 112 void StackTrace::PrintBacktrace() { | 106 void StackTrace::PrintBacktrace() { |
| 113 fflush(stderr); | 107 fflush(stderr); |
| 114 backtrace_symbols_fd(&trace_[0], trace_.size(), STDERR_FILENO); | 108 backtrace_symbols_fd(&trace_[0], trace_.size(), STDERR_FILENO); |
| 115 } | 109 } |
| 116 | |
| 117 #elif defined(OS_MACOSX) | |
| 118 | |
| 119 // TODO(port): complete this code | |
| 120 StackTrace::StackTrace() { } | |
| 121 | |
| 122 void StackTrace::PrintBacktrace() { | |
| 123 NOTIMPLEMENTED(); | |
| 124 } | |
| 125 | |
| 126 #endif // defined(OS_MACOSX) | |
| 127 | |
| 128 const void *const *StackTrace::Addresses(size_t* count) { | |
| 129 *count = trace_.size(); | |
| 130 if (trace_.size()) | |
| 131 return &trace_[0]; | |
| 132 return NULL; | |
| 133 } | |
| OLD | NEW |