OLD | NEW |
1 // Copyright (c) 2010 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/debugger.h" | 5 #include "base/debug/debugger.h" |
| 6 #include "build/build_config.h" |
6 | 7 |
7 #include <errno.h> | 8 #include <errno.h> |
8 #include <fcntl.h> | 9 #include <fcntl.h> |
9 #include <stdio.h> | 10 #include <stdio.h> |
10 #include <stdlib.h> | 11 #include <stdlib.h> |
11 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 13 #if !defined(OS_NACL) |
12 #include <sys/sysctl.h> | 14 #include <sys/sysctl.h> |
| 15 #endif |
13 #include <sys/types.h> | 16 #include <sys/types.h> |
14 #include <unistd.h> | 17 #include <unistd.h> |
15 | 18 |
16 #include <string> | 19 #include <string> |
17 #include <vector> | 20 #include <vector> |
18 | 21 |
19 #if defined(__GLIBCXX__) | 22 #if defined(__GLIBCXX__) |
20 #include <cxxabi.h> | 23 #include <cxxabi.h> |
21 #endif | 24 #endif |
22 | 25 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 | 121 |
119 StringPiece::size_type pid_index = status.find(tracer); | 122 StringPiece::size_type pid_index = status.find(tracer); |
120 if (pid_index == StringPiece::npos) | 123 if (pid_index == StringPiece::npos) |
121 return false; | 124 return false; |
122 | 125 |
123 // Our pid is 0 without a debugger, assume this for any pid starting with 0. | 126 // Our pid is 0 without a debugger, assume this for any pid starting with 0. |
124 pid_index += tracer.size(); | 127 pid_index += tracer.size(); |
125 return pid_index < status.size() && status[pid_index] != '0'; | 128 return pid_index < status.size() && status[pid_index] != '0'; |
126 } | 129 } |
127 | 130 |
| 131 #elif defined(OS_NACL) |
| 132 |
| 133 bool BeingDebugged() { |
| 134 NOTIMPLEMENTED(); |
| 135 return false; |
| 136 } |
| 137 |
128 #elif defined(OS_FREEBSD) | 138 #elif defined(OS_FREEBSD) |
129 | 139 |
130 bool DebugUtil::BeingDebugged() { | 140 bool DebugUtil::BeingDebugged() { |
131 // TODO(benl): can we determine this under FreeBSD? | 141 // TODO(benl): can we determine this under FreeBSD? |
132 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
133 return false; | 143 return false; |
134 } | 144 } |
135 | 145 |
136 #endif // defined(OS_FREEBSD) | 146 #endif // defined(OS_FREEBSD) |
137 | 147 |
138 // We want to break into the debugger in Debug mode, and cause a crash dump in | 148 // We want to break into the debugger in Debug mode, and cause a crash dump in |
139 // Release mode. Breakpad behaves as follows: | 149 // Release mode. Breakpad behaves as follows: |
140 // | 150 // |
141 // +-------+-----------------+-----------------+ | 151 // +-------+-----------------+-----------------+ |
142 // | OS | Dump on SIGTRAP | Dump on SIGABRT | | 152 // | OS | Dump on SIGTRAP | Dump on SIGABRT | |
143 // +-------+-----------------+-----------------+ | 153 // +-------+-----------------+-----------------+ |
144 // | Linux | N | Y | | 154 // | Linux | N | Y | |
145 // | Mac | Y | N | | 155 // | Mac | Y | N | |
146 // +-------+-----------------+-----------------+ | 156 // +-------+-----------------+-----------------+ |
147 // | 157 // |
148 // Thus we do the following: | 158 // Thus we do the following: |
149 // Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. | 159 // Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. |
150 // Mac: Always send SIGTRAP. | 160 // Mac: Always send SIGTRAP. |
151 | 161 |
152 #if defined(NDEBUG) && !defined(OS_MACOSX) | 162 #if defined(NDEBUG) && !defined(OS_MACOSX) |
153 #define DEBUG_BREAK() abort() | 163 #define DEBUG_BREAK() abort() |
| 164 #elif defined(OS_NACL) |
| 165 // The NaCl verifier doesn't let use use int3. For now, we call abort(). We |
| 166 // should ask for advice from some NaCl experts about the optimum thing here. |
| 167 #define DEBUG_BREAK() abort() |
154 #elif defined(ARCH_CPU_ARM_FAMILY) | 168 #elif defined(ARCH_CPU_ARM_FAMILY) |
155 #define DEBUG_BREAK() asm("bkpt 0") | 169 #define DEBUG_BREAK() asm("bkpt 0") |
156 #else | 170 #else |
157 #define DEBUG_BREAK() asm("int3") | 171 #define DEBUG_BREAK() asm("int3") |
158 #endif | 172 #endif |
159 | 173 |
160 void BreakDebugger() { | 174 void BreakDebugger() { |
161 DEBUG_BREAK(); | 175 DEBUG_BREAK(); |
162 } | 176 } |
163 | 177 |
164 } // namespace debug | 178 } // namespace debug |
165 } // namespace base | 179 } // namespace base |
OLD | NEW |