OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "build/build_config.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> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #endif | 26 #endif |
27 | 27 |
28 #if defined(OS_MACOSX) | 28 #if defined(OS_MACOSX) |
29 #include <AvailabilityMacros.h> | 29 #include <AvailabilityMacros.h> |
30 #endif | 30 #endif |
31 | 31 |
32 #if defined(OS_MACOSX) || defined(OS_BSD) | 32 #if defined(OS_MACOSX) || defined(OS_BSD) |
33 #include <sys/sysctl.h> | 33 #include <sys/sysctl.h> |
34 #endif | 34 #endif |
35 | 35 |
| 36 #if defined(OS_FREEBSD) |
| 37 #include <sys/user.h> |
| 38 #endif |
| 39 |
36 #include <ostream> | 40 #include <ostream> |
37 | 41 |
38 #include "base/basictypes.h" | 42 #include "base/basictypes.h" |
39 #include "base/eintr_wrapper.h" | 43 #include "base/eintr_wrapper.h" |
40 #include "base/logging.h" | 44 #include "base/logging.h" |
41 #include "base/memory/scoped_ptr.h" | 45 #include "base/memory/scoped_ptr.h" |
42 #include "base/safe_strerror_posix.h" | 46 #include "base/safe_strerror_posix.h" |
43 #include "base/string_piece.h" | 47 #include "base/string_piece.h" |
44 #include "base/stringprintf.h" | 48 #include "base/stringprintf.h" |
45 | 49 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0); | 105 int sysctl_result = sysctl(mib, arraysize(mib), &info, &info_size, NULL, 0); |
102 DCHECK_EQ(sysctl_result, 0); | 106 DCHECK_EQ(sysctl_result, 0); |
103 if (sysctl_result != 0) { | 107 if (sysctl_result != 0) { |
104 is_set = true; | 108 is_set = true; |
105 being_debugged = false; | 109 being_debugged = false; |
106 return being_debugged; | 110 return being_debugged; |
107 } | 111 } |
108 | 112 |
109 // This process is being debugged if the P_TRACED flag is set. | 113 // This process is being debugged if the P_TRACED flag is set. |
110 is_set = true; | 114 is_set = true; |
111 #if defined(OS_BSD) | 115 #if defined(OS_FREEBSD) |
| 116 being_debugged = (info.ki_flag & P_TRACED) != 0; |
| 117 #elif defined(OS_BSD) |
112 being_debugged = (info.p_flag & P_TRACED) != 0; | 118 being_debugged = (info.p_flag & P_TRACED) != 0; |
113 #else | 119 #else |
114 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; | 120 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; |
115 #endif | 121 #endif |
116 return being_debugged; | 122 return being_debugged; |
117 } | 123 } |
118 | 124 |
119 #elif defined(OS_LINUX) || defined(OS_ANDROID) | 125 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
120 | 126 |
121 // We can look in /proc/self/status for TracerPid. We are likely used in crash | 127 // We can look in /proc/self/status for TracerPid. We are likely used in crash |
(...skipping 23 matching lines...) Expand all Loading... |
145 | 151 |
146 StringPiece::size_type pid_index = status.find(tracer); | 152 StringPiece::size_type pid_index = status.find(tracer); |
147 if (pid_index == StringPiece::npos) | 153 if (pid_index == StringPiece::npos) |
148 return false; | 154 return false; |
149 | 155 |
150 // Our pid is 0 without a debugger, assume this for any pid starting with 0. | 156 // Our pid is 0 without a debugger, assume this for any pid starting with 0. |
151 pid_index += tracer.size(); | 157 pid_index += tracer.size(); |
152 return pid_index < status.size() && status[pid_index] != '0'; | 158 return pid_index < status.size() && status[pid_index] != '0'; |
153 } | 159 } |
154 | 160 |
155 #elif defined(OS_NACL) | 161 #else |
156 | 162 |
157 bool BeingDebugged() { | 163 bool BeingDebugged() { |
158 NOTIMPLEMENTED(); | 164 NOTIMPLEMENTED(); |
159 return false; | 165 return false; |
160 } | 166 } |
161 | 167 |
162 #else | 168 #endif |
163 | |
164 bool BeingDebugged() { | |
165 // TODO(benl): can we determine this under FreeBSD? | |
166 NOTIMPLEMENTED(); | |
167 return false; | |
168 } | |
169 | |
170 #endif // defined(OS_FREEBSD) | |
171 | 169 |
172 // We want to break into the debugger in Debug mode, and cause a crash dump in | 170 // We want to break into the debugger in Debug mode, and cause a crash dump in |
173 // Release mode. Breakpad behaves as follows: | 171 // Release mode. Breakpad behaves as follows: |
174 // | 172 // |
175 // +-------+-----------------+-----------------+ | 173 // +-------+-----------------+-----------------+ |
176 // | OS | Dump on SIGTRAP | Dump on SIGABRT | | 174 // | OS | Dump on SIGTRAP | Dump on SIGABRT | |
177 // +-------+-----------------+-----------------+ | 175 // +-------+-----------------+-----------------+ |
178 // | Linux | N | Y | | 176 // | Linux | N | Y | |
179 // | Mac | Y | N | | 177 // | Mac | Y | N | |
180 // +-------+-----------------+-----------------+ | 178 // +-------+-----------------+-----------------+ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 210 |
213 void BreakDebugger() { | 211 void BreakDebugger() { |
214 DEBUG_BREAK(); | 212 DEBUG_BREAK(); |
215 #if defined(NDEBUG) | 213 #if defined(NDEBUG) |
216 _exit(1); | 214 _exit(1); |
217 #endif | 215 #endif |
218 } | 216 } |
219 | 217 |
220 } // namespace debug | 218 } // namespace debug |
221 } // namespace base | 219 } // namespace base |
OLD | NEW |