| 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/checks.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 #include <stdio.h> |
| 14 #include <stdlib.h> |
| 14 | 15 |
| 15 #include "src/platform.h" | 16 #include "src/base/platform/platform.h" |
| 16 #include "src/v8.h" | |
| 17 | 17 |
| 18 namespace v8 { | 18 namespace v8 { |
| 19 namespace internal { | 19 namespace base { |
| 20 | |
| 21 intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } | |
| 22 | 20 |
| 23 // Attempts to dump a backtrace (if supported). | 21 // Attempts to dump a backtrace (if supported). |
| 24 void DumpBacktrace() { | 22 void DumpBacktrace() { |
| 25 #if V8_LIBC_GLIBC || V8_OS_BSD | 23 #if V8_LIBC_GLIBC || V8_OS_BSD |
| 26 void* trace[100]; | 24 void* trace[100]; |
| 27 int size = backtrace(trace, ARRAY_SIZE(trace)); | 25 int size = backtrace(trace, ARRAY_SIZE(trace)); |
| 28 char** symbols = backtrace_symbols(trace, size); | 26 char** symbols = backtrace_symbols(trace, size); |
| 29 OS::PrintError("\n==== C stack trace ===============================\n\n"); | 27 OS::PrintError("\n==== C stack trace ===============================\n\n"); |
| 30 if (size == 0) { | 28 if (size == 0) { |
| 31 OS::PrintError("(empty)\n"); | 29 OS::PrintError("(empty)\n"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } else { | 61 } else { |
| 64 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), | 62 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), |
| 65 out, sizeof(out), NULL); | 63 out, sizeof(out), NULL); |
| 66 OS::PrintError(out); | 64 OS::PrintError(out); |
| 67 } | 65 } |
| 68 bt_unload_memmap(&memmap); | 66 bt_unload_memmap(&memmap); |
| 69 bt_release_accessor(&acc); | 67 bt_release_accessor(&acc); |
| 70 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 68 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
| 71 } | 69 } |
| 72 | 70 |
| 73 } } // namespace v8::internal | 71 } } // namespace v8::base |
| 74 | 72 |
| 75 | 73 |
| 76 // Contains protection against recursive calls (faults while handling faults). | 74 // Contains protection against recursive calls (faults while handling faults). |
| 77 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, ...) { |
| 78 fflush(stdout); | 76 fflush(stdout); |
| 79 fflush(stderr); | 77 fflush(stderr); |
| 80 i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line); | 78 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, |
| 79 line); |
| 81 va_list arguments; | 80 va_list arguments; |
| 82 va_start(arguments, format); | 81 va_start(arguments, format); |
| 83 i::OS::VPrintError(format, arguments); | 82 v8::base::OS::VPrintError(format, arguments); |
| 84 va_end(arguments); | 83 va_end(arguments); |
| 85 i::OS::PrintError("\n#\n"); | 84 v8::base::OS::PrintError("\n#\n"); |
| 86 v8::internal::DumpBacktrace(); | 85 v8::base::DumpBacktrace(); |
| 87 fflush(stderr); | 86 fflush(stderr); |
| 88 i::OS::Abort(); | 87 v8::base::OS::Abort(); |
| 89 } | 88 } |
| 90 | |
| 91 | |
| 92 void CheckEqualsHelper(const char* file, | |
| 93 int line, | |
| 94 const char* expected_source, | |
| 95 v8::Handle<v8::Value> expected, | |
| 96 const char* value_source, | |
| 97 v8::Handle<v8::Value> value) { | |
| 98 if (!expected->Equals(value)) { | |
| 99 v8::String::Utf8Value value_str(value); | |
| 100 v8::String::Utf8Value expected_str(expected); | |
| 101 V8_Fatal(file, line, | |
| 102 "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s", | |
| 103 expected_source, value_source, *expected_str, *value_str); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 | |
| 108 void CheckNonEqualsHelper(const char* file, | |
| 109 int line, | |
| 110 const char* unexpected_source, | |
| 111 v8::Handle<v8::Value> unexpected, | |
| 112 const char* value_source, | |
| 113 v8::Handle<v8::Value> value) { | |
| 114 if (unexpected->Equals(value)) { | |
| 115 v8::String::Utf8Value value_str(value); | |
| 116 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", | |
| 117 unexpected_source, value_source, *value_str); | |
| 118 } | |
| 119 } | |
| OLD | NEW |