Chromium Code Reviews| 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/logging.h" | 5 #include "base/logging.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 typedef pthread_mutex_t* MutexHandle; | 46 typedef pthread_mutex_t* MutexHandle; |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 #include <algorithm> | 49 #include <algorithm> |
| 50 #include <cstring> | 50 #include <cstring> |
| 51 #include <ctime> | 51 #include <ctime> |
| 52 #include <iomanip> | 52 #include <iomanip> |
| 53 #include <ostream> | 53 #include <ostream> |
| 54 #include <string> | 54 #include <string> |
| 55 | 55 |
| 56 #include "base/auto_reset.h" | |
| 56 #include "base/base_switches.h" | 57 #include "base/base_switches.h" |
| 57 #include "base/command_line.h" | 58 #include "base/command_line.h" |
| 58 #include "base/debug/alias.h" | 59 #include "base/debug/alias.h" |
| 60 #include "base/debug/crash_logging.h" | |
| 59 #include "base/debug/debugger.h" | 61 #include "base/debug/debugger.h" |
| 60 #include "base/debug/stack_trace.h" | 62 #include "base/debug/stack_trace.h" |
| 61 #include "base/posix/eintr_wrapper.h" | 63 #include "base/posix/eintr_wrapper.h" |
| 62 #include "base/strings/string_piece.h" | 64 #include "base/strings/string_piece.h" |
| 63 #include "base/strings/string_util.h" | 65 #include "base/strings/string_util.h" |
| 64 #include "base/strings/stringprintf.h" | 66 #include "base/strings/stringprintf.h" |
| 65 #include "base/strings/sys_string_conversions.h" | 67 #include "base/strings/sys_string_conversions.h" |
| 66 #include "base/strings/utf_string_conversions.h" | 68 #include "base/strings/utf_string_conversions.h" |
| 67 #include "base/synchronization/lock_impl.h" | 69 #include "base/synchronization/lock_impl.h" |
| 68 #include "base/threading/platform_thread.h" | 70 #include "base/threading/platform_thread.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 | 121 |
| 120 // Should we pop up fatal debug messages in a dialog? | 122 // Should we pop up fatal debug messages in a dialog? |
| 121 bool show_error_dialogs = false; | 123 bool show_error_dialogs = false; |
| 122 | 124 |
| 123 // An assert handler override specified by the client to be called instead of | 125 // An assert handler override specified by the client to be called instead of |
| 124 // the debug message dialog and process termination. | 126 // the debug message dialog and process termination. |
| 125 LogAssertHandlerFunction log_assert_handler = nullptr; | 127 LogAssertHandlerFunction log_assert_handler = nullptr; |
| 126 // A log message handler that gets notified of every log message we process. | 128 // A log message handler that gets notified of every log message we process. |
| 127 LogMessageHandlerFunction log_message_handler = nullptr; | 129 LogMessageHandlerFunction log_message_handler = nullptr; |
| 128 | 130 |
| 131 void SetLogFatalCrashKey(size_t message_start, | |
| 132 const std::string& string) { | |
| 133 // Nacl targets miss base/debug/crash_logging.cc. | |
|
scottmg
2016/10/05 22:06:21
nit; "NaCl targets do not have ..."
rkuksin
2016/10/06 08:50:33
Done.
| |
| 134 #if !defined(NACL_TC_REV) | |
|
scottmg
2016/10/05 22:06:21
OS_NACL.
rkuksin
2016/10/06 08:50:33
Done.
| |
| 135 // In case of an out-of-memory condition, this code could be reentered when | |
| 136 // constructing and storing the key. Using a static is not thread-safe, but if | |
| 137 // multiple threads are in the process of a fatal crash at the same time, this | |
| 138 // should work. | |
| 139 static bool guarded = false; | |
| 140 if (guarded) { | |
| 141 return; | |
| 142 } | |
| 143 base::AutoReset<bool> guard(&guarded, true); | |
| 144 | |
| 145 CHECK_LE(message_start, string.size()); | |
| 146 std::string message = base::StringPrintf("%s", | |
| 147 string.c_str() + message_start); | |
| 148 base::debug::SetCrashKeyValue("LOG_FATAL", message); | |
|
scottmg
2016/10/05 22:06:21
This takes a StringPiece so no need for the Sprint
rkuksin
2016/10/06 08:50:33
Done.
| |
| 149 #endif // !defined(NACL_TC_REV) | |
| 150 } | |
| 151 | |
| 129 // Helper functions to wrap platform differences. | 152 // Helper functions to wrap platform differences. |
| 130 | 153 |
| 131 int32_t CurrentProcessId() { | 154 int32_t CurrentProcessId() { |
| 132 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
| 133 return GetCurrentProcessId(); | 156 return GetCurrentProcessId(); |
| 134 #elif defined(OS_POSIX) | 157 #elif defined(OS_POSIX) |
| 135 return getpid(); | 158 return getpid(); |
| 136 #endif | 159 #endif |
| 137 } | 160 } |
| 138 | 161 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 if (severity_ == LOG_FATAL && !base::debug::BeingDebugged()) { | 553 if (severity_ == LOG_FATAL && !base::debug::BeingDebugged()) { |
| 531 // Include a stack trace on a fatal, unless a debugger is attached. | 554 // Include a stack trace on a fatal, unless a debugger is attached. |
| 532 base::debug::StackTrace trace; | 555 base::debug::StackTrace trace; |
| 533 stream_ << std::endl; // Newline to separate from log message. | 556 stream_ << std::endl; // Newline to separate from log message. |
| 534 trace.OutputToStream(&stream_); | 557 trace.OutputToStream(&stream_); |
| 535 } | 558 } |
| 536 #endif | 559 #endif |
| 537 stream_ << std::endl; | 560 stream_ << std::endl; |
| 538 std::string str_newline(stream_.str()); | 561 std::string str_newline(stream_.str()); |
| 539 | 562 |
| 563 if (severity_ == LOG_FATAL) { | |
| 564 SetLogFatalCrashKey(message_start_, str_newline); | |
| 565 } | |
| 566 | |
| 540 // Give any log message handler first dibs on the message. | 567 // Give any log message handler first dibs on the message. |
| 541 if (log_message_handler && | 568 if (log_message_handler && |
| 542 log_message_handler(severity_, file_, line_, | 569 log_message_handler(severity_, file_, line_, |
| 543 message_start_, str_newline)) { | 570 message_start_, str_newline)) { |
| 544 // The handler took care of it, no further processing. | 571 // The handler took care of it, no further processing. |
| 545 return; | 572 return; |
| 546 } | 573 } |
| 547 | 574 |
| 548 if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) { | 575 if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) { |
| 549 #if defined(OS_WIN) | 576 #if defined(OS_WIN) |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { | 948 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
| 922 LogMessage(file, line, LOG_ERROR).stream() | 949 LogMessage(file, line, LOG_ERROR).stream() |
| 923 << "NOTREACHED() hit."; | 950 << "NOTREACHED() hit."; |
| 924 } | 951 } |
| 925 | 952 |
| 926 } // namespace logging | 953 } // namespace logging |
| 927 | 954 |
| 928 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 955 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
| 929 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); | 956 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); |
| 930 } | 957 } |
| OLD | NEW |