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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 typedef HANDLE FileHandle; | 10 typedef HANDLE FileHandle; |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 std::string* result) | 538 std::string* result) |
539 : severity_(severity), file_(file), line_(line) { | 539 : severity_(severity), file_(file), line_(line) { |
540 Init(file, line); | 540 Init(file, line); |
541 stream_ << "Check failed: " << *result; | 541 stream_ << "Check failed: " << *result; |
542 delete result; | 542 delete result; |
543 } | 543 } |
544 | 544 |
545 LogMessage::~LogMessage() { | 545 LogMessage::~LogMessage() { |
546 #if !defined(OFFICIAL_BUILD) && !defined(OS_NACL) && !defined(__UCLIBC__) | 546 #if !defined(OFFICIAL_BUILD) && !defined(OS_NACL) && !defined(__UCLIBC__) |
547 if (severity_ == LOG_FATAL) { | 547 if (severity_ == LOG_FATAL) { |
548 // Include a stack trace on a fatal. | 548 if (!base::debug::BeingDebugged()) { |
Lei Zhang
2015/09/04 22:11:31
nit: combine with the if on the line above?
| |
549 base::debug::StackTrace trace; | 549 // Include a stack trace on a fatal, unless a debugger is attached. |
550 stream_ << std::endl; // Newline to separate from log message. | 550 base::debug::StackTrace trace; |
551 trace.OutputToStream(&stream_); | 551 stream_ << std::endl; // Newline to separate from log message. |
552 trace.OutputToStream(&stream_); | |
553 } | |
552 } | 554 } |
553 #endif | 555 #endif |
554 stream_ << std::endl; | 556 stream_ << std::endl; |
555 std::string str_newline(stream_.str()); | 557 std::string str_newline(stream_.str()); |
556 | 558 |
557 // Give any log message handler first dibs on the message. | 559 // Give any log message handler first dibs on the message. |
558 if (log_message_handler && | 560 if (log_message_handler && |
559 log_message_handler(severity_, file_, line_, | 561 log_message_handler(severity_, file_, line_, |
560 message_start_, str_newline)) { | 562 message_start_, str_newline)) { |
561 // The handler took care of it, no further processing. | 563 // The handler took care of it, no further processing. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 if (log_assert_handler) { | 634 if (log_assert_handler) { |
633 // Make a copy of the string for the handler out of paranoia. | 635 // Make a copy of the string for the handler out of paranoia. |
634 log_assert_handler(std::string(stream_.str())); | 636 log_assert_handler(std::string(stream_.str())); |
635 } else { | 637 } else { |
636 // Don't use the string with the newline, get a fresh version to send to | 638 // Don't use the string with the newline, get a fresh version to send to |
637 // the debug message process. We also don't display assertions to the | 639 // the debug message process. We also don't display assertions to the |
638 // user in release mode. The enduser can't do anything with this | 640 // user in release mode. The enduser can't do anything with this |
639 // information, and displaying message boxes when the application is | 641 // information, and displaying message boxes when the application is |
640 // hosed can cause additional problems. | 642 // hosed can cause additional problems. |
641 #ifndef NDEBUG | 643 #ifndef NDEBUG |
642 DisplayDebugMessageInDialog(stream_.str()); | 644 if (!base::debug::BeingDebugged()) { |
645 // Displaying a dialog is unnecessary when debugging and can complicate | |
646 // debugging. | |
647 DisplayDebugMessageInDialog(stream_.str()); | |
648 } | |
643 #endif | 649 #endif |
644 // Crash the process to generate a dump. | 650 // Crash the process to generate a dump. |
645 base::debug::BreakDebugger(); | 651 base::debug::BreakDebugger(); |
646 } | 652 } |
647 } | 653 } |
648 } | 654 } |
649 | 655 |
650 // writes the common header info to the stream | 656 // writes the common header info to the stream |
651 void LogMessage::Init(const char* file, int line) { | 657 void LogMessage::Init(const char* file, int line) { |
652 base::StringPiece filename(file); | 658 base::StringPiece filename(file); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { | 818 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
813 LogMessage(file, line, LOG_ERROR).stream() | 819 LogMessage(file, line, LOG_ERROR).stream() |
814 << "NOTREACHED() hit."; | 820 << "NOTREACHED() hit."; |
815 } | 821 } |
816 | 822 |
817 } // namespace logging | 823 } // namespace logging |
818 | 824 |
819 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 825 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
820 return out << base::WideToUTF8(wstr); | 826 return out << base::WideToUTF8(wstr); |
821 } | 827 } |
OLD | NEW |