| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <sys/syscall.h> | 6 #include <sys/syscall.h> |
| 7 #include <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <unordered_map> | 11 #include <unordered_map> |
| 12 | 12 |
| 13 #include "base/debug/crash_logging.h" | 13 #include "base/debug/crash_logging.h" |
| 14 #include "base/debug/debugging_flags.h" |
| 14 #include "base/debug/stack_trace.h" | 15 #include "base/debug/stack_trace.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/posix/eintr_wrapper.h" | 18 #include "base/posix/eintr_wrapper.h" |
| 18 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "chrome/common/crash_keys.h" | 22 #include "chrome/common/crash_keys.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const int ret = IGNORE_EINTR(syscall(SYS_close, fd)); | 113 const int ret = IGNORE_EINTR(syscall(SYS_close, fd)); |
| 113 // Captures errno and restores it later in case it is changed. | 114 // Captures errno and restores it later in case it is changed. |
| 114 const ErrnoCapture close_errno; | 115 const ErrnoCapture close_errno; |
| 115 | 116 |
| 116 // Return if tracking is not enabled for the current process. | 117 // Return if tracking is not enabled for the current process. |
| 117 if (!g_stack_tracker || !g_stack_tracker->ShouldTrack()) | 118 if (!g_stack_tracker || !g_stack_tracker->ShouldTrack()) |
| 118 return ret; | 119 return ret; |
| 119 | 120 |
| 120 // Capture stack for successful close. | 121 // Capture stack for successful close. |
| 121 if (ret == 0) { | 122 if (ret == 0) { |
| 122 #if HAVE_TRACE_STACK_FRAME_POINTERS && !defined(MEMORY_SANITIZER) | 123 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) && !defined(MEMORY_SANITIZER) |
| 123 // Use TraceStackFramePointers because the backtrack() based default | 124 // Use TraceStackFramePointers because the backtrack() based default |
| 124 // capturing gets only the last stack frame and is not useful. | 125 // capturing gets only the last stack frame and is not useful. |
| 125 // With the exception of when MSAN is enabled. See comments for why | 126 // With the exception of when MSAN is enabled. See comments for why |
| 126 // StackTraceTest.TraceStackFramePointers is disabled in MSAN builds. | 127 // StackTraceTest.TraceStackFramePointers is disabled in MSAN builds. |
| 127 const void* frames[64]; | 128 const void* frames[64]; |
| 128 const size_t frame_count = | 129 const size_t frame_count = |
| 129 base::debug::TraceStackFramePointers(frames, arraysize(frames), 0); | 130 base::debug::TraceStackFramePointers(frames, arraysize(frames), 0); |
| 130 g_stack_tracker->SetStack(fd, base::debug::StackTrace(frames, frame_count)); | 131 g_stack_tracker->SetStack(fd, base::debug::StackTrace(frames, frame_count)); |
| 131 #else | 132 #else |
| 132 // Use default StackTrace when TraceStackFramePointers is not available. | 133 // Use default StackTrace when TraceStackFramePointers is not available. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 const base::debug::StackTrace* GetLastCloseStackForTest(int fd) { | 179 const base::debug::StackTrace* GetLastCloseStackForTest(int fd) { |
| 179 return g_stack_tracker ? g_stack_tracker->GetStack(fd) : nullptr; | 180 return g_stack_tracker ? g_stack_tracker->GetStack(fd) : nullptr; |
| 180 } | 181 } |
| 181 | 182 |
| 182 void SetCloseTrackingIgnorePidForTest(bool ignore_pid) { | 183 void SetCloseTrackingIgnorePidForTest(bool ignore_pid) { |
| 183 DCHECK(g_stack_tracker); | 184 DCHECK(g_stack_tracker); |
| 184 g_stack_tracker->set_ignore_pid(ignore_pid); | 185 g_stack_tracker->set_ignore_pid(ignore_pid); |
| 185 } | 186 } |
| 186 | 187 |
| 187 } // namespace chromeos | 188 } // namespace chromeos |
| OLD | NEW |