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 #include <stdio.h> |
14 #include <cstdio> | 14 #include <stdlib.h> |
15 #include <cstdlib> | |
16 | 15 |
17 #include "src/base/platform/platform.h" | 16 #include "src/base/platform/platform.h" |
18 | 17 |
19 namespace v8 { | 18 namespace v8 { |
20 namespace base { | 19 namespace base { |
21 | 20 |
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 | |
52 // Attempts to dump a backtrace (if supported). | 21 // Attempts to dump a backtrace (if supported). |
53 void DumpBacktrace() { | 22 void DumpBacktrace() { |
54 #if V8_LIBC_GLIBC || V8_OS_BSD | 23 #if V8_LIBC_GLIBC || V8_OS_BSD |
55 void* trace[100]; | 24 void* trace[100]; |
56 int size = backtrace(trace, arraysize(trace)); | 25 int size = backtrace(trace, arraysize(trace)); |
57 char** symbols = backtrace_symbols(trace, size); | 26 char** symbols = backtrace_symbols(trace, size); |
58 OS::PrintError("\n==== C stack trace ===============================\n\n"); | 27 OS::PrintError("\n==== C stack trace ===============================\n\n"); |
59 if (size == 0) { | 28 if (size == 0) { |
60 OS::PrintError("(empty)\n"); | 29 OS::PrintError("(empty)\n"); |
61 } else if (symbols == NULL) { | 30 } else if (symbols == NULL) { |
(...skipping 30 matching lines...) Expand all Loading... |
92 } else { | 61 } else { |
93 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), | 62 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), |
94 out, sizeof(out), NULL); | 63 out, sizeof(out), NULL); |
95 OS::PrintError(out); | 64 OS::PrintError(out); |
96 } | 65 } |
97 bt_unload_memmap(&memmap); | 66 bt_unload_memmap(&memmap); |
98 bt_release_accessor(&acc); | 67 bt_release_accessor(&acc); |
99 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 68 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
100 } | 69 } |
101 | 70 |
102 } // namespace base | 71 } } // namespace v8::base |
103 } // namespace v8 | |
104 | 72 |
105 | 73 |
106 // Contains protection against recursive calls (faults while handling faults). | 74 // Contains protection against recursive calls (faults while handling faults). |
107 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { | 75 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
108 fflush(stdout); | 76 fflush(stdout); |
109 fflush(stderr); | 77 fflush(stderr); |
110 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, | 78 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, |
111 line); | 79 line); |
112 va_list arguments; | 80 va_list arguments; |
113 va_start(arguments, format); | 81 va_start(arguments, format); |
114 v8::base::OS::VPrintError(format, arguments); | 82 v8::base::OS::VPrintError(format, arguments); |
115 va_end(arguments); | 83 va_end(arguments); |
116 v8::base::OS::PrintError("\n#\n"); | 84 v8::base::OS::PrintError("\n#\n"); |
117 v8::base::DumpBacktrace(); | 85 v8::base::DumpBacktrace(); |
118 fflush(stderr); | 86 fflush(stderr); |
119 v8::base::OS::Abort(); | 87 v8::base::OS::Abort(); |
120 } | 88 } |
OLD | NEW |