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 | |
| 28 | #include <stdarg.h> |
| 29 | |
| 30 | #include "v8.h" |
| 31 | |
| 32 | #include "platform.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | // TODO(isolates): is it necessary to lift this? |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 35 | static int fatal_error_handler_nesting_depth = 0; |
| 36 | |
| 37 | // Contains protection against recursive calls (faults while handling faults). |
| 38 | extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 39 | fflush(stdout); |
| 40 | fflush(stderr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | fatal_error_handler_nesting_depth++; |
| 42 | // First time we try to print an error message |
| 43 | if (fatal_error_handler_nesting_depth < 2) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 44 | i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | va_list arguments; |
| 46 | va_start(arguments, format); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 47 | i::OS::VPrintError(format, arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | va_end(arguments); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 49 | i::OS::PrintError("\n#\n"); |
| 50 | i::OS::DumpBacktrace(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | } |
| 52 | // First two times we may try to print a stack dump. |
| 53 | if (fatal_error_handler_nesting_depth < 3) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 54 | if (i::FLAG_stack_trace_on_abort) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | // Call this one twice on double fault |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 56 | i::Isolate::Current()->PrintStack(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 57 | } |
| 58 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 59 | i::OS::Abort(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
| 63 | void CheckEqualsHelper(const char* file, |
| 64 | int line, |
| 65 | const char* expected_source, |
| 66 | v8::Handle<v8::Value> expected, |
| 67 | const char* value_source, |
| 68 | v8::Handle<v8::Value> value) { |
| 69 | if (!expected->Equals(value)) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 70 | v8::String::Utf8Value value_str(value); |
| 71 | v8::String::Utf8Value expected_str(expected); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 72 | V8_Fatal(file, line, |
| 73 | "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s", |
| 74 | expected_source, value_source, *expected_str, *value_str); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | void CheckNonEqualsHelper(const char* file, |
| 80 | int line, |
| 81 | const char* unexpected_source, |
| 82 | v8::Handle<v8::Value> unexpected, |
| 83 | const char* value_source, |
| 84 | v8::Handle<v8::Value> value) { |
| 85 | if (unexpected->Equals(value)) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 86 | v8::String::Utf8Value value_str(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 87 | V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", |
| 88 | unexpected_source, value_source, *value_str); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | |
| 93 | void API_Fatal(const char* location, const char* format, ...) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 94 | i::OS::PrintError("\n#\n# Fatal error in %s\n# ", location); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | va_list arguments; |
| 96 | va_start(arguments, format); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 97 | i::OS::VPrintError(format, arguments); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 98 | va_end(arguments); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 99 | i::OS::PrintError("\n#\n\n"); |
| 100 | i::OS::Abort(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 102 | |
| 103 | |
| 104 | namespace v8 { namespace internal { |
| 105 | |
| 106 | bool EnableSlowAsserts() { return FLAG_enable_slow_asserts; } |
| 107 | |
| 108 | intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } |
| 109 | |
| 110 | } } // namespace v8::internal |
ager@chromium.org | beb2571 | 2010-11-29 08:02:25 +0000 | [diff] [blame] | 111 | |