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 "base/debug_util.h" | 6 #include "base/debug_util.h" |
| 6 | 7 |
| 8 #if defined(OS_LINUX) | |
| 9 #include <unistd.h> | |
| 10 #include <execinfo.h> | |
| 11 #endif | |
| 12 | |
| 13 #include <stdio.h> | |
| 7 #include <fcntl.h> | 14 #include <fcntl.h> |
| 8 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 9 #include <sys/sysctl.h> | 16 #include <sys/sysctl.h> |
| 10 #include <sys/types.h> | 17 #include <sys/types.h> |
| 11 #include <unistd.h> | 18 #include <unistd.h> |
| 12 | 19 |
| 13 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 14 #include "base/logging.h" | 21 #include "base/logging.h" |
| 15 #include "base/string_piece.h" | 22 #include "base/string_piece.h" |
| 16 | 23 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 pid_index += tracer.size(); | 90 pid_index += tracer.size(); |
| 84 return pid_index < status.size() && status[pid_index] != '0'; | 91 return pid_index < status.size() && status[pid_index] != '0'; |
| 85 } | 92 } |
| 86 | 93 |
| 87 #endif // OS_LINUX | 94 #endif // OS_LINUX |
| 88 | 95 |
| 89 // static | 96 // static |
| 90 void DebugUtil::BreakDebugger() { | 97 void DebugUtil::BreakDebugger() { |
| 91 asm ("int3"); | 98 asm ("int3"); |
| 92 } | 99 } |
| 100 | |
| 101 #if defined(OS_LINUX) | |
| 102 | |
| 103 StackTrace::StackTrace() { | |
| 104 static const unsigned kMaxCallers = 256; | |
| 105 | |
| 106 void* callers[kMaxCallers]; | |
| 107 int count = backtrace(callers, kMaxCallers); | |
| 108 trace_.resize(count); | |
| 109 memcpy(&trace_[0], callers, sizeof(void*) * count); | |
| 110 } | |
| 111 | |
| 112 void StackTrace::PrintBacktrace() { | |
| 113 fflush(stderr); | |
| 114 backtrace_symbols_fd(&trace_[0], trace_.size(), STDERR_FILENO); | |
| 115 } | |
| 116 | |
| 117 #elif defined(OS_MACOSX) | |
| 118 | |
| 119 // TODO(port): complete this code | |
| 120 StackTrace::StackTrace() { } | |
| 121 | |
| 122 StackTrace::PrintBacktrace() { | |
| 123 NOTIMPLEMENTED(); | |
| 124 fprintf(stderr, "<printing stacktraces not implemented>\n"); | |
|
Evan Martin
2009/01/16 18:30:08
you won't need this anymore with the above
| |
| 125 } | |
| 126 | |
| 127 #endif // defined(OS_MACOSX) | |
| 128 | |
| 129 const void *const *StackTrace::Addresses(size_t* count) { | |
| 130 *count = trace_.size(); | |
| 131 if (trace_.size()) | |
| 132 return &trace_[0]; | |
| 133 return NULL; | |
| 134 } | |
| OLD | NEW |