Chromium Code Reviews| 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 <execinfo.h> | 9 #include <execinfo.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <sys/param.h> | 13 #include <sys/param.h> |
| 14 #include <sys/stat.h> | 14 #include <sys/stat.h> |
| 15 #if !defined(OS_NACL) | 15 #if !defined(OS_NACL) && !defined(OS_ANDROID) |
| 16 #include <sys/sysctl.h> | 16 #include <sys/sysctl.h> |
| 17 #endif | 17 #endif |
| 18 #include <sys/types.h> | 18 #include <sys/types.h> |
| 19 #include <unistd.h> | 19 #include <unistd.h> |
| 20 | 20 |
| 21 #include <string> | 21 #include <string> |
| 22 #include <vector> | 22 #include <vector> |
| 23 | 23 |
| 24 #if defined(__GLIBCXX__) | 24 #if defined(__GLIBCXX__) |
| 25 #include <cxxabi.h> | 25 #include <cxxabi.h> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 36 #include "base/logging.h" | 36 #include "base/logging.h" |
| 37 #include "base/memory/scoped_ptr.h" | 37 #include "base/memory/scoped_ptr.h" |
| 38 #include "base/safe_strerror_posix.h" | 38 #include "base/safe_strerror_posix.h" |
| 39 #include "base/string_piece.h" | 39 #include "base/string_piece.h" |
| 40 #include "base/stringprintf.h" | 40 #include "base/stringprintf.h" |
| 41 | 41 |
| 42 #if defined(USE_SYMBOLIZE) | 42 #if defined(USE_SYMBOLIZE) |
| 43 #include "base/third_party/symbolize/symbolize.h" | 43 #include "base/third_party/symbolize/symbolize.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 #if defined(OS_ANDROID) | |
| 47 #include <execinfo.h> | |
| 48 #include "base/threading/platform_thread.h" | |
| 49 #endif | |
| 50 | |
| 46 namespace base { | 51 namespace base { |
| 47 namespace debug { | 52 namespace debug { |
| 48 | 53 |
| 49 bool SpawnDebuggerOnProcess(unsigned /* process_id */) { | 54 bool SpawnDebuggerOnProcess(unsigned /* process_id */) { |
| 50 NOTIMPLEMENTED(); | 55 NOTIMPLEMENTED(); |
| 51 return false; | 56 return false; |
| 52 } | 57 } |
| 53 | 58 |
| 54 #if defined(OS_MACOSX) | 59 #if defined(OS_MACOSX) |
| 55 | 60 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 86 being_debugged = false; | 91 being_debugged = false; |
| 87 return being_debugged; | 92 return being_debugged; |
| 88 } | 93 } |
| 89 | 94 |
| 90 // This process is being debugged if the P_TRACED flag is set. | 95 // This process is being debugged if the P_TRACED flag is set. |
| 91 is_set = true; | 96 is_set = true; |
| 92 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; | 97 being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0; |
| 93 return being_debugged; | 98 return being_debugged; |
| 94 } | 99 } |
| 95 | 100 |
| 96 #elif defined(OS_LINUX) | 101 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 97 | 102 |
| 98 // We can look in /proc/self/status for TracerPid. We are likely used in crash | 103 // We can look in /proc/self/status for TracerPid. We are likely used in crash |
| 99 // handling, so we are careful not to use the heap or have side effects. | 104 // handling, so we are careful not to use the heap or have side effects. |
| 100 // Another option that is common is to try to ptrace yourself, but then we | 105 // Another option that is common is to try to ptrace yourself, but then we |
| 101 // can't detach without forking(), and that's not so great. | 106 // can't detach without forking(), and that's not so great. |
| 102 // static | 107 // static |
| 103 bool BeingDebugged() { | 108 bool BeingDebugged() { |
| 104 int status_fd = open("/proc/self/status", O_RDONLY); | 109 int status_fd = open("/proc/self/status", O_RDONLY); |
| 105 if (status_fd == -1) | 110 if (status_fd == -1) |
| 106 return false; | 111 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 // | OS | Dump on SIGTRAP | Dump on SIGABRT | | 158 // | OS | Dump on SIGTRAP | Dump on SIGABRT | |
| 154 // +-------+-----------------+-----------------+ | 159 // +-------+-----------------+-----------------+ |
| 155 // | Linux | N | Y | | 160 // | Linux | N | Y | |
| 156 // | Mac | Y | N | | 161 // | Mac | Y | N | |
| 157 // +-------+-----------------+-----------------+ | 162 // +-------+-----------------+-----------------+ |
| 158 // | 163 // |
| 159 // Thus we do the following: | 164 // Thus we do the following: |
| 160 // Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. | 165 // Linux: Debug mode, send SIGTRAP; Release mode, send SIGABRT. |
| 161 // Mac: Always send SIGTRAP. | 166 // Mac: Always send SIGTRAP. |
| 162 | 167 |
| 163 #if defined(NDEBUG) && !defined(OS_MACOSX) | 168 #if defined(NDEBUG) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 164 #define DEBUG_BREAK() abort() | 169 #define DEBUG_BREAK() abort() |
| 165 #elif defined(OS_NACL) | 170 #elif defined(OS_NACL) |
| 166 // The NaCl verifier doesn't let use use int3. For now, we call abort(). We | 171 // The NaCl verifier doesn't let use use int3. For now, we call abort(). We |
| 167 // should ask for advice from some NaCl experts about the optimum thing here. | 172 // should ask for advice from some NaCl experts about the optimum thing here. |
| 168 // http://code.google.com/p/nativeclient/issues/detail?id=645 | 173 // http://code.google.com/p/nativeclient/issues/detail?id=645 |
| 169 #define DEBUG_BREAK() abort() | 174 #define DEBUG_BREAK() abort() |
| 170 #elif defined(ARCH_CPU_ARM_FAMILY) | 175 #elif defined(ARCH_CPU_ARM_FAMILY) |
| 176 #if defined(OS_ANDROID) | |
| 177 // Use GDB to set |go| to 1 to resume execution. | |
| 178 #define DEBUG_BREAK() do { \ | |
| 179 volatile int go = 0; \ | |
| 180 while (!go) { base::PlatformThread::Sleep(100); } \ | |
| 181 } while (0) | |
| 182 #else | |
| 183 // ARM && !ANDROID | |
| 171 #define DEBUG_BREAK() asm("bkpt 0") | 184 #define DEBUG_BREAK() asm("bkpt 0") |
|
brettw
2011/06/24 22:23:57
Sorry I don't have much background in this. Why do
michaelbai
2011/06/24 23:30:44
For this issue, I have to get it back to you later
John Grabowski
2011/06/28 17:27:23
In general, Android is Java based. Android has a
brettw
2011/06/29 16:42:28
Can a comment be added to this effect?
michaelbai
2011/06/29 17:18:46
Done.
| |
| 185 #endif | |
| 172 #else | 186 #else |
| 173 #define DEBUG_BREAK() asm("int3") | 187 #define DEBUG_BREAK() asm("int3") |
| 174 #endif | 188 #endif |
| 175 | 189 |
| 176 void BreakDebugger() { | 190 void BreakDebugger() { |
| 177 DEBUG_BREAK(); | 191 DEBUG_BREAK(); |
| 178 #if defined(NDEBUG) | 192 #if defined(NDEBUG) |
| 179 _exit(1); | 193 _exit(1); |
| 180 #endif | 194 #endif |
| 181 } | 195 } |
| 182 | 196 |
| 183 } // namespace debug | 197 } // namespace debug |
| 184 } // namespace base | 198 } // namespace base |
| OLD | NEW |