ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 28 | #include "checks.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 29 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 30 | #if V8_LIBC_GLIBC || V8_OS_BSD |
| 31 | # include <cxxabi.h> |
| 32 | # include <execinfo.h> |
| 33 | #endif // V8_LIBC_GLIBC || V8_OS_BSD |
| 34 | #include <stdio.h> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | |
| 36 | #include "platform.h" |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 37 | #include "v8.h" |
| 38 | |
| 39 | |
| 40 | // Attempts to dump a backtrace (if supported). |
| 41 | static V8_INLINE void DumpBacktrace() { |
| 42 | #if V8_LIBC_GLIBC || V8_OS_BSD |
| 43 | void* trace[100]; |
| 44 | int size = backtrace(trace, ARRAY_SIZE(trace)); |
| 45 | char** symbols = backtrace_symbols(trace, size); |
| 46 | i::OS::PrintError("\n==== C stack trace ===============================\n\n"); |
| 47 | if (size == 0) { |
| 48 | i::OS::PrintError("(empty)\n"); |
| 49 | } else if (symbols == NULL) { |
| 50 | i::OS::PrintError("(no symbols)\n"); |
| 51 | } else { |
| 52 | for (int i = 1; i < size; ++i) { |
| 53 | i::OS::PrintError("%2d: ", i); |
| 54 | char mangled[201]; |
| 55 | if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT |
| 56 | int status; |
| 57 | size_t length; |
| 58 | char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); |
| 59 | i::OS::PrintError("%s\n", demangled != NULL ? demangled : mangled); |
| 60 | free(demangled); |
| 61 | } else { |
| 62 | i::OS::PrintError("??\n"); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | free(symbols); |
| 67 | #endif // V8_LIBC_GLIBC || V8_OS_BSD |
| 68 | } |
| 69 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | // Contains protection against recursive calls (faults while handling faults). |
| 72 | extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
rossberg@chromium.org | 79e7902 | 2013-06-03 15:43:46 +0000 | [diff] [blame] | 73 | i::AllowHandleDereference allow_deref; |
| 74 | i::AllowDeferredHandleDereference allow_deferred_deref; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 75 | fflush(stdout); |
| 76 | fflush(stderr); |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 77 | i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line); |
| 78 | va_list arguments; |
| 79 | va_start(arguments, format); |
| 80 | i::OS::VPrintError(format, arguments); |
| 81 | va_end(arguments); |
| 82 | i::OS::PrintError("\n#\n"); |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 83 | DumpBacktrace(); |
| 84 | fflush(stderr); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 85 | i::OS::Abort(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
| 89 | void CheckEqualsHelper(const char* file, |
| 90 | int line, |
| 91 | const char* expected_source, |
| 92 | v8::Handle<v8::Value> expected, |
| 93 | const char* value_source, |
| 94 | v8::Handle<v8::Value> value) { |
| 95 | if (!expected->Equals(value)) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 96 | v8::String::Utf8Value value_str(value); |
| 97 | v8::String::Utf8Value expected_str(expected); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | V8_Fatal(file, line, |
| 99 | "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s", |
| 100 | expected_source, value_source, *expected_str, *value_str); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void CheckNonEqualsHelper(const char* file, |
| 106 | int line, |
| 107 | const char* unexpected_source, |
| 108 | v8::Handle<v8::Value> unexpected, |
| 109 | const char* value_source, |
| 110 | v8::Handle<v8::Value> value) { |
| 111 | if (unexpected->Equals(value)) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 112 | v8::String::Utf8Value value_str(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 113 | V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", |
| 114 | unexpected_source, value_source, *value_str); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | |
| 119 | void API_Fatal(const char* location, const char* format, ...) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 120 | i::OS::PrintError("\n#\n# Fatal error in %s\n# ", location); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | va_list arguments; |
| 122 | va_start(arguments, format); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 123 | i::OS::VPrintError(format, arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 124 | va_end(arguments); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 125 | i::OS::PrintError("\n#\n\n"); |
| 126 | i::OS::Abort(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 128 | |
| 129 | |
| 130 | namespace v8 { namespace internal { |
| 131 | |
| 132 | bool EnableSlowAsserts() { return FLAG_enable_slow_asserts; } |
| 133 | |
| 134 | intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } |
| 135 | |
| 136 | } } // namespace v8::internal |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 137 | |