| 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 #include <stdio.h> | 13 |
| 14 #include <stdlib.h> | 14 #include <cstdio> |
| 15 #include <cstdlib> |
| 15 | 16 |
| 16 #include "src/base/platform/platform.h" | 17 #include "src/base/platform/platform.h" |
| 17 | 18 |
| 18 namespace v8 { | 19 namespace v8 { |
| 19 namespace base { | 20 namespace base { |
| 20 | 21 |
| 22 // Explicit instantiations for commonly used comparisons. |
| 23 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ |
| 24 template std::string* MakeCheckOpString<type, type>( \ |
| 25 type const&, type const&, char const*); |
| 26 DEFINE_MAKE_CHECK_OP_STRING(int) |
| 27 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(unsigned int) |
| 30 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(char const*) |
| 33 DEFINE_MAKE_CHECK_OP_STRING(void const*) |
| 34 #undef DEFINE_MAKE_CHECK_OP_STRING |
| 35 |
| 36 |
| 37 // Explicit instantiations for floating point checks. |
| 38 #define DEFINE_CHECK_OP_IMPL(NAME) \ |
| 39 template std::string* Check##NAME##Impl<float, float>( \ |
| 40 float const& lhs, float const& rhs, char const* msg); \ |
| 41 template std::string* Check##NAME##Impl<double, double>( \ |
| 42 double const& lhs, double const& rhs, char const* msg); |
| 43 DEFINE_CHECK_OP_IMPL(EQ) |
| 44 DEFINE_CHECK_OP_IMPL(NE) |
| 45 DEFINE_CHECK_OP_IMPL(LE) |
| 46 DEFINE_CHECK_OP_IMPL(LT) |
| 47 DEFINE_CHECK_OP_IMPL(GE) |
| 48 DEFINE_CHECK_OP_IMPL(GT) |
| 49 #undef DEFINE_CHECK_OP_IMPL |
| 50 |
| 51 |
| 21 // Attempts to dump a backtrace (if supported). | 52 // Attempts to dump a backtrace (if supported). |
| 22 void DumpBacktrace() { | 53 void DumpBacktrace() { |
| 23 #if V8_LIBC_GLIBC || V8_OS_BSD | 54 #if V8_LIBC_GLIBC || V8_OS_BSD |
| 24 void* trace[100]; | 55 void* trace[100]; |
| 25 int size = backtrace(trace, arraysize(trace)); | 56 int size = backtrace(trace, arraysize(trace)); |
| 26 char** symbols = backtrace_symbols(trace, size); | 57 char** symbols = backtrace_symbols(trace, size); |
| 27 OS::PrintError("\n==== C stack trace ===============================\n\n"); | 58 OS::PrintError("\n==== C stack trace ===============================\n\n"); |
| 28 if (size == 0) { | 59 if (size == 0) { |
| 29 OS::PrintError("(empty)\n"); | 60 OS::PrintError("(empty)\n"); |
| 30 } else if (symbols == NULL) { | 61 } else if (symbols == NULL) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 61 } else { | 92 } else { |
| 62 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), | 93 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), |
| 63 out, sizeof(out), NULL); | 94 out, sizeof(out), NULL); |
| 64 OS::PrintError(out); | 95 OS::PrintError(out); |
| 65 } | 96 } |
| 66 bt_unload_memmap(&memmap); | 97 bt_unload_memmap(&memmap); |
| 67 bt_release_accessor(&acc); | 98 bt_release_accessor(&acc); |
| 68 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 99 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
| 69 } | 100 } |
| 70 | 101 |
| 71 } } // namespace v8::base | 102 } // namespace base |
| 103 } // namespace v8 |
| 72 | 104 |
| 73 | 105 |
| 74 // Contains protection against recursive calls (faults while handling faults). | 106 // Contains protection against recursive calls (faults while handling faults). |
| 75 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { | 107 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
| 76 fflush(stdout); | 108 fflush(stdout); |
| 77 fflush(stderr); | 109 fflush(stderr); |
| 78 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, | 110 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, |
| 79 line); | 111 line); |
| 80 va_list arguments; | 112 va_list arguments; |
| 81 va_start(arguments, format); | 113 va_start(arguments, format); |
| 82 v8::base::OS::VPrintError(format, arguments); | 114 v8::base::OS::VPrintError(format, arguments); |
| 83 va_end(arguments); | 115 va_end(arguments); |
| 84 v8::base::OS::PrintError("\n#\n"); | 116 v8::base::OS::PrintError("\n#\n"); |
| 85 v8::base::DumpBacktrace(); | 117 v8::base::DumpBacktrace(); |
| 86 fflush(stderr); | 118 fflush(stderr); |
| 87 v8::base::OS::Abort(); | 119 v8::base::OS::Abort(); |
| 88 } | 120 } |
| OLD | NEW |