| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 int status_fd = open("/proc/self/status", O_RDONLY); | 150 int status_fd = open("/proc/self/status", O_RDONLY); |
| 151 if (status_fd == -1) | 151 if (status_fd == -1) |
| 152 return false; | 152 return false; |
| 153 | 153 |
| 154 // We assume our line will be in the first 1024 characters and that we can | 154 // We assume our line will be in the first 1024 characters and that we can |
| 155 // read this much all at once. In practice this will generally be true. | 155 // read this much all at once. In practice this will generally be true. |
| 156 // This simplifies and speeds up things considerably. | 156 // This simplifies and speeds up things considerably. |
| 157 char buf[1024]; | 157 char buf[1024]; |
| 158 | 158 |
| 159 ssize_t num_read = HANDLE_EINTR(read(status_fd, buf, sizeof(buf))); | 159 ssize_t num_read = HANDLE_EINTR(read(status_fd, buf, sizeof(buf))); |
| 160 if (HANDLE_EINTR(close(status_fd)) < 0) | 160 if (IGNORE_EINTR(close(status_fd)) < 0) |
| 161 return false; | 161 return false; |
| 162 | 162 |
| 163 if (num_read <= 0) | 163 if (num_read <= 0) |
| 164 return false; | 164 return false; |
| 165 | 165 |
| 166 StringPiece status(buf, num_read); | 166 StringPiece status(buf, num_read); |
| 167 StringPiece tracer("TracerPid:\t"); | 167 StringPiece tracer("TracerPid:\t"); |
| 168 | 168 |
| 169 StringPiece::size_type pid_index = status.find(tracer); | 169 StringPiece::size_type pid_index = status.find(tracer); |
| 170 if (pid_index == StringPiece::npos) | 170 if (pid_index == StringPiece::npos) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 // attach the debugger, inspect the state of the program and then resume it by | 262 // attach the debugger, inspect the state of the program and then resume it by |
| 263 // setting the 'go' variable above. | 263 // setting the 'go' variable above. |
| 264 #elif defined(NDEBUG) | 264 #elif defined(NDEBUG) |
| 265 // Terminate the program after signaling the debug break. | 265 // Terminate the program after signaling the debug break. |
| 266 _exit(1); | 266 _exit(1); |
| 267 #endif | 267 #endif |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace debug | 270 } // namespace debug |
| 271 } // namespace base | 271 } // namespace base |
| OLD | NEW |