OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/crash/content/browser/crash_handler_host_linux.h" | 5 #include "components/crash/content/browser/crash_handler_host_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/linux_util.h" | 21 #include "base/linux_util.h" |
22 #include "base/location.h" | 22 #include "base/location.h" |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/path_service.h" | 24 #include "base/path_service.h" |
25 #include "base/posix/eintr_wrapper.h" | 25 #include "base/posix/eintr_wrapper.h" |
26 #include "base/rand_util.h" | 26 #include "base/rand_util.h" |
27 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
28 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
29 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
31 #include "base/threading/thread_task_runner_handle.h" | |
31 #include "breakpad/src/client/linux/handler/exception_handler.h" | 32 #include "breakpad/src/client/linux/handler/exception_handler.h" |
32 #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" | 33 #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" |
33 #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" | 34 #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" |
34 #include "build/build_config.h" | 35 #include "build/build_config.h" |
35 #include "components/crash/content/app/breakpad_linux_impl.h" | 36 #include "components/crash/content/app/breakpad_linux_impl.h" |
36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
37 | 38 |
38 #if defined(OS_ANDROID) && !defined(__LP64__) | 39 #if defined(OS_ANDROID) && !defined(__LP64__) |
39 #include <sys/linux-syscalls.h> | 40 #include <sys/linux-syscalls.h> |
40 | 41 |
41 #define SYS_read __NR_read | 42 #define SYS_read __NR_read |
42 #endif | 43 #endif |
43 | 44 |
44 using content::BrowserThread; | 45 using content::BrowserThread; |
45 using google_breakpad::ExceptionHandler; | 46 using google_breakpad::ExceptionHandler; |
46 | 47 |
47 namespace breakpad { | 48 namespace breakpad { |
48 | 49 |
49 namespace { | 50 namespace { |
50 | 51 |
51 const size_t kNumFDs = 1; | 52 const size_t kNumFDs = 1; |
52 // The length of the control message: | 53 // The length of the control message: |
53 const size_t kControlMsgSize = | 54 const size_t kControlMsgSize = |
54 CMSG_SPACE(kNumFDs * sizeof(int)) + CMSG_SPACE(sizeof(struct ucred)); | 55 CMSG_SPACE(kNumFDs * sizeof(int)) + CMSG_SPACE(sizeof(struct ucred)); |
55 // The length of the regular payload: | 56 // The length of the regular payload: |
56 const size_t kCrashContextSize = sizeof(ExceptionHandler::CrashContext); | 57 const size_t kCrashContextSize = sizeof(ExceptionHandler::CrashContext); |
57 | 58 |
59 // Crashing thread might be in "running" state, i.e. after sys_sendmsg() and | |
60 // before sys_read(). Retry 3 times with interval of 100 ms when translating | |
61 // TID. | |
62 const int kNumAttemptsTranslatingTid = 3; | |
63 const int kRetryIntervalTranslatingTidInMs = 100; | |
64 | |
58 // Handles the crash dump and frees the allocated BreakpadInfo struct. | 65 // Handles the crash dump and frees the allocated BreakpadInfo struct. |
59 void CrashDumpTask(CrashHandlerHostLinux* handler, | 66 void CrashDumpTask(CrashHandlerHostLinux* handler, |
60 std::unique_ptr<BreakpadInfo> info) { | 67 std::unique_ptr<BreakpadInfo> info) { |
61 if (handler->IsShuttingDown() && info->upload) { | 68 if (handler->IsShuttingDown() && info->upload) { |
62 base::DeleteFile(base::FilePath(info->filename), false); | 69 base::DeleteFile(base::FilePath(info->filename), false); |
63 #if defined(ADDRESS_SANITIZER) | 70 #if defined(ADDRESS_SANITIZER) |
64 base::DeleteFile(base::FilePath(info->log_filename), false); | 71 base::DeleteFile(base::FilePath(info->log_filename), false); |
65 #endif | 72 #endif |
66 return; | 73 return; |
67 } | 74 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 // namespaces also have /proc/[pid]/syscall, so we can look through | 280 // namespaces also have /proc/[pid]/syscall, so we can look through |
274 // |actual_crashing_pid|'s thread group and find the thread that's in the | 281 // |actual_crashing_pid|'s thread group and find the thread that's in the |
275 // read syscall with the right arguments. | 282 // read syscall with the right arguments. |
276 | 283 |
277 std::string expected_syscall_data; | 284 std::string expected_syscall_data; |
278 // /proc/[pid]/syscall is formatted as follows: | 285 // /proc/[pid]/syscall is formatted as follows: |
279 // syscall_number arg1 ... arg6 sp pc | 286 // syscall_number arg1 ... arg6 sp pc |
280 // but we just check syscall_number through arg3. | 287 // but we just check syscall_number through arg3. |
281 base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ", | 288 base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ", |
282 SYS_read, tid_fd, tid_buf_addr); | 289 SYS_read, tid_fd, tid_buf_addr); |
290 | |
291 FindCrashingThreadAndDump(crashing_pid, | |
292 expected_syscall_data, | |
293 std::move(crash_context), | |
294 std::move(crash_keys), | |
295 uptime, | |
296 oom_size, | |
297 signal_fd.release(), | |
298 0); | |
299 } | |
300 | |
301 void CrashHandlerHostLinux::FindCrashingThreadAndDump( | |
302 pid_t crashing_pid, | |
303 const std::string& expected_syscall_data, | |
304 std::unique_ptr<char[]> crash_context, | |
305 std::unique_ptr<CrashKeyStorage> crash_keys, | |
306 uint64_t uptime, | |
307 size_t oom_size, | |
308 int signal_fd, | |
309 int attempt) { | |
283 bool syscall_supported = false; | 310 bool syscall_supported = false; |
284 pid_t crashing_tid = | 311 pid_t crashing_tid = -1; |
285 base::FindThreadIDWithSyscall(crashing_pid, | 312 crashing_tid = base::FindThreadIDWithSyscall(crashing_pid, |
Lei Zhang
2016/07/25 18:46:57
Combine with previous line?
wzhong
2016/07/25 19:27:46
Done.
| |
286 expected_syscall_data, | 313 expected_syscall_data, |
287 &syscall_supported); | 314 &syscall_supported); |
315 ++attempt; | |
316 if (crashing_tid == -1 && syscall_supported && | |
317 attempt <= kNumAttemptsTranslatingTid) { | |
318 LOG(WARNING) << "Could not translate tid, attempt = " << attempt | |
319 << " retry ..."; | |
320 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
321 FROM_HERE, | |
322 base::Bind(&CrashHandlerHostLinux::FindCrashingThreadAndDump, | |
323 base::Unretained(this), | |
324 crashing_pid, | |
325 expected_syscall_data, | |
326 base::Passed(&crash_context), | |
327 base::Passed(&crash_keys), | |
328 uptime, | |
329 oom_size, | |
330 signal_fd, | |
331 attempt), | |
332 base::TimeDelta::FromMilliseconds(kRetryIntervalTranslatingTidInMs)); | |
333 return; | |
334 } | |
335 | |
336 | |
288 if (crashing_tid == -1) { | 337 if (crashing_tid == -1) { |
289 // We didn't find the thread we want. Maybe it didn't reach | 338 // We didn't find the thread we want. Maybe it didn't reach |
290 // sys_read() yet or the thread went away. We'll just take a | 339 // sys_read() yet or the thread went away. We'll just take a |
291 // guess here and assume the crashing thread is the thread group | 340 // guess here and assume the crashing thread is the thread group |
292 // leader. If procfs syscall is not supported by the kernel, then | 341 // leader. If procfs syscall is not supported by the kernel, then |
293 // we assume the kernel also does not support TID namespacing and | 342 // we assume the kernel also does not support TID namespacing and |
294 // trust the TID passed by the crashing process. | 343 // trust the TID passed by the crashing process. |
295 LOG(WARNING) << "Could not translate tid - assuming crashing thread is " | 344 LOG(WARNING) << "Could not translate tid - assuming crashing thread is " |
296 "thread group leader; syscall_supported=" << syscall_supported; | 345 "thread group leader; syscall_supported=" << syscall_supported; |
297 crashing_tid = crashing_pid; | 346 crashing_tid = crashing_pid; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 | 380 |
332 | 381 |
333 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( | 382 BrowserThread::GetBlockingPool()->PostSequencedWorkerTask( |
334 worker_pool_token_, | 383 worker_pool_token_, |
335 FROM_HERE, | 384 FROM_HERE, |
336 base::Bind(&CrashHandlerHostLinux::WriteDumpFile, | 385 base::Bind(&CrashHandlerHostLinux::WriteDumpFile, |
337 base::Unretained(this), | 386 base::Unretained(this), |
338 base::Passed(&info), | 387 base::Passed(&info), |
339 base::Passed(&crash_context), | 388 base::Passed(&crash_context), |
340 crashing_pid, | 389 crashing_pid, |
341 signal_fd.release())); | 390 signal_fd)); |
342 } | 391 } |
343 | 392 |
344 void CrashHandlerHostLinux::WriteDumpFile(std::unique_ptr<BreakpadInfo> info, | 393 void CrashHandlerHostLinux::WriteDumpFile(std::unique_ptr<BreakpadInfo> info, |
345 std::unique_ptr<char[]> crash_context, | 394 std::unique_ptr<char[]> crash_context, |
346 pid_t crashing_pid, | 395 pid_t crashing_pid, |
347 int signal_fd) { | 396 int signal_fd) { |
348 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 397 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
349 worker_pool_token_)); | 398 worker_pool_token_)); |
350 | 399 |
351 // Set |info->distro| here because base::GetLinuxDistro() needs to run on a | 400 // Set |info->distro| here because base::GetLinuxDistro() needs to run on a |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 // no-ops. | 484 // no-ops. |
436 shutting_down_ = true; | 485 shutting_down_ = true; |
437 uploader_thread_->Stop(); | 486 uploader_thread_->Stop(); |
438 } | 487 } |
439 | 488 |
440 bool CrashHandlerHostLinux::IsShuttingDown() const { | 489 bool CrashHandlerHostLinux::IsShuttingDown() const { |
441 return shutting_down_; | 490 return shutting_down_; |
442 } | 491 } |
443 | 492 |
444 } // namespace breakpad | 493 } // namespace breakpad |
OLD | NEW |