| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project 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 "src/base/logging.h" | 5 #include "src/base/logging.h" |
| 6 | 6 |
| 7 #if V8_LIBC_GLIBC || V8_OS_BSD | 7 #if V8_LIBC_GLIBC || V8_OS_BSD |
| 8 # include <cxxabi.h> | 8 # include <cxxabi.h> |
| 9 # include <execinfo.h> | 9 # include <execinfo.h> |
| 10 #elif V8_OS_QNX | 10 #elif V8_OS_QNX |
| 11 # include <backtrace.h> | 11 # include <backtrace.h> |
| 12 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 12 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
| 13 | 13 |
| 14 #include <cstdio> | 14 #include <cstdio> |
| 15 #include <cstdlib> | 15 #include <cstdlib> |
| 16 | 16 |
| 17 #include "src/base/platform/platform.h" | 17 #include "src/base/platform/platform.h" |
| 18 | 18 |
| 19 namespace v8 { | 19 namespace v8 { |
| 20 namespace base { | 20 namespace base { |
| 21 namespace logging { |
| 21 | 22 |
| 22 // Explicit instantiations for commonly used comparisons. | 23 // Explicit instantiations for commonly used comparisons. |
| 23 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ | 24 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ |
| 24 template std::string* MakeCheckOpString<type, type>( \ | 25 template std::string* MakeCheckOpString<type, type>( \ |
| 25 type const&, type const&, char const*); | 26 type const&, type const&, char const*); |
| 26 DEFINE_MAKE_CHECK_OP_STRING(int) | 27 DEFINE_MAKE_CHECK_OP_STRING(int) |
| 27 DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int) | 28 DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int) |
| 28 DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int) | 29 DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int) |
| 29 DEFINE_MAKE_CHECK_OP_STRING(unsigned int) | 30 DEFINE_MAKE_CHECK_OP_STRING(unsigned int) |
| 30 DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int) | 31 DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int) |
| 31 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int) | 32 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int) |
| 32 DEFINE_MAKE_CHECK_OP_STRING(char const*) | 33 DEFINE_MAKE_CHECK_OP_STRING(char const*) |
| 33 DEFINE_MAKE_CHECK_OP_STRING(void const*) | 34 DEFINE_MAKE_CHECK_OP_STRING(void const*) |
| 34 #undef DEFINE_MAKE_CHECK_OP_STRING | 35 #undef DEFINE_MAKE_CHECK_OP_STRING |
| 35 | 36 |
| 36 | 37 |
| 37 // Explicit instantiations for floating point checks. | 38 // Explicit instantiations for floating point checks. |
| 38 #define DEFINE_CHECK_OP_IMPL(NAME) \ | 39 #define DEFINE_CHECK_OP_IMPL(NAME) \ |
| 39 template std::string* Check##NAME##Impl<float, float>( \ | 40 template std::string* Check##NAME##Impl<float, float>( \ |
| 40 float const& lhs, float const& rhs, char const* msg); \ | 41 float const& lhs, float const& rhs, char const* result); \ |
| 41 template std::string* Check##NAME##Impl<double, double>( \ | 42 template std::string* Check##NAME##Impl<double, double>( \ |
| 42 double const& lhs, double const& rhs, char const* msg); | 43 double const& lhs, double const& rhs, char const* result); |
| 43 DEFINE_CHECK_OP_IMPL(EQ) | 44 DEFINE_CHECK_OP_IMPL(EQ) |
| 44 DEFINE_CHECK_OP_IMPL(NE) | 45 DEFINE_CHECK_OP_IMPL(NE) |
| 45 DEFINE_CHECK_OP_IMPL(LE) | 46 DEFINE_CHECK_OP_IMPL(LE) |
| 46 DEFINE_CHECK_OP_IMPL(LT) | 47 DEFINE_CHECK_OP_IMPL(LT) |
| 47 DEFINE_CHECK_OP_IMPL(GE) | 48 DEFINE_CHECK_OP_IMPL(GE) |
| 48 DEFINE_CHECK_OP_IMPL(GT) | 49 DEFINE_CHECK_OP_IMPL(GT) |
| 49 #undef DEFINE_CHECK_OP_IMPL | 50 #undef DEFINE_CHECK_OP_IMPL |
| 50 | 51 |
| 51 | 52 |
| 53 LogMessage::LogMessage(char const* file, int line, LogSeverity severity) |
| 54 : file_(file), line_(line), severity_(severity) {} |
| 55 |
| 56 |
| 57 LogMessage::LogMessage(char const* file, int line, std::string* result) |
| 58 : LogMessage(file, line, LOG_FATAL, result) {} |
| 59 |
| 60 |
| 61 LogMessage::LogMessage(char const* file, int line, LogSeverity severity, |
| 62 std::string* result) |
| 63 : LogMessage(file, line, severity) { |
| 64 stream() << "Check failed: " << *result; |
| 65 delete result; |
| 66 } |
| 67 |
| 68 |
| 69 LogMessage::~LogMessage() { |
| 70 if (severity_ == LOG_FATAL) { |
| 71 V8_Fatal(file_, line_, "%s", stream_.str().c_str()); |
| 72 } |
| 73 OS::Print("%s\n", stream_.str().c_str()); |
| 74 } |
| 75 |
| 76 |
| 77 namespace { |
| 78 |
| 52 // Attempts to dump a backtrace (if supported). | 79 // Attempts to dump a backtrace (if supported). |
| 80 // TODO(bmeurer): Inline this thing into the caller! |
| 53 void DumpBacktrace() { | 81 void DumpBacktrace() { |
| 54 #if V8_LIBC_GLIBC || V8_OS_BSD | 82 #if V8_LIBC_GLIBC || V8_OS_BSD |
| 55 void* trace[100]; | 83 void* trace[100]; |
| 56 int size = backtrace(trace, arraysize(trace)); | 84 int size = backtrace(trace, arraysize(trace)); |
| 57 char** symbols = backtrace_symbols(trace, size); | 85 char** symbols = backtrace_symbols(trace, size); |
| 58 OS::PrintError("\n==== C stack trace ===============================\n\n"); | 86 OS::PrintError("\n==== C stack trace ===============================\n\n"); |
| 59 if (size == 0) { | 87 if (size == 0) { |
| 60 OS::PrintError("(empty)\n"); | 88 OS::PrintError("(empty)\n"); |
| 61 } else if (symbols == NULL) { | 89 } else if (symbols == NULL) { |
| 62 OS::PrintError("(no symbols)\n"); | 90 OS::PrintError("(no symbols)\n"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 } else { | 120 } else { |
| 93 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), | 121 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), |
| 94 out, sizeof(out), NULL); | 122 out, sizeof(out), NULL); |
| 95 OS::PrintError(out); | 123 OS::PrintError(out); |
| 96 } | 124 } |
| 97 bt_unload_memmap(&memmap); | 125 bt_unload_memmap(&memmap); |
| 98 bt_release_accessor(&acc); | 126 bt_release_accessor(&acc); |
| 99 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 127 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
| 100 } | 128 } |
| 101 | 129 |
| 130 } // namespace |
| 131 |
| 132 } // namespace logging |
| 102 } // namespace base | 133 } // namespace base |
| 103 } // namespace v8 | 134 } // namespace v8 |
| 104 | 135 |
| 105 | 136 |
| 106 // Contains protection against recursive calls (faults while handling faults). | 137 // Contains protection against recursive calls (faults while handling faults). |
| 107 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { | 138 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
| 108 fflush(stdout); | 139 fflush(stdout); |
| 109 fflush(stderr); | 140 fflush(stderr); |
| 110 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, | 141 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, |
| 111 line); | 142 line); |
| 112 va_list arguments; | 143 va_list arguments; |
| 113 va_start(arguments, format); | 144 va_start(arguments, format); |
| 114 v8::base::OS::VPrintError(format, arguments); | 145 v8::base::OS::VPrintError(format, arguments); |
| 115 va_end(arguments); | 146 va_end(arguments); |
| 116 v8::base::OS::PrintError("\n#\n"); | 147 v8::base::OS::PrintError("\n#\n"); |
| 117 v8::base::DumpBacktrace(); | 148 v8::base::logging::DumpBacktrace(); |
| 118 fflush(stderr); | 149 fflush(stderr); |
| 119 v8::base::OS::Abort(); | 150 v8::base::OS::Abort(); |
| 120 } | 151 } |
| OLD | NEW |