1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
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.
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.
30 #if V8_LIBC_GLIBC || V8_OS_BSD
32 # include <execinfo.h>
34 # include <backtrace.h>
35 #endif // V8_LIBC_GLIBC || V8_OS_BSD
42 // Attempts to dump a backtrace (if supported).
43 static V8_INLINE void DumpBacktrace() {
44 #if V8_LIBC_GLIBC || V8_OS_BSD
46 int size = backtrace(trace, ARRAY_SIZE(trace));
47 char** symbols = backtrace_symbols(trace, size);
48 i::OS::PrintError("\n==== C stack trace ===============================\n\n");
50 i::OS::PrintError("(empty)\n");
51 } else if (symbols == NULL) {
52 i::OS::PrintError("(no symbols)\n");
54 for (int i = 1; i < size; ++i) {
55 i::OS::PrintError("%2d: ", i);
57 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
60 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
61 i::OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
64 i::OS::PrintError("??\n");
73 bt_init_accessor(&acc, BT_SELF);
74 bt_load_memmap(&acc, &memmap);
75 bt_sprn_memmap(&memmap, out, sizeof(out));
76 i::OS::PrintError(out);
78 int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace));
79 i::OS::PrintError("\n==== C stack trace ===============================\n\n");
81 i::OS::PrintError("(empty)\n");
83 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"),
84 out, sizeof(out), NULL);
85 i::OS::PrintError(out);
87 bt_unload_memmap(&memmap);
88 bt_release_accessor(&acc);
89 #endif // V8_LIBC_GLIBC || V8_OS_BSD
93 // Contains protection against recursive calls (faults while handling faults).
94 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
95 i::AllowHandleDereference allow_deref;
96 i::AllowDeferredHandleDereference allow_deferred_deref;
99 i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line);
101 va_start(arguments, format);
102 i::OS::VPrintError(format, arguments);
104 i::OS::PrintError("\n#\n");
111 void CheckEqualsHelper(const char* file,
113 const char* expected_source,
114 v8::Handle<v8::Value> expected,
115 const char* value_source,
116 v8::Handle<v8::Value> value) {
117 if (!expected->Equals(value)) {
118 v8::String::Utf8Value value_str(value);
119 v8::String::Utf8Value expected_str(expected);
121 "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s",
122 expected_source, value_source, *expected_str, *value_str);
127 void CheckNonEqualsHelper(const char* file,
129 const char* unexpected_source,
130 v8::Handle<v8::Value> unexpected,
131 const char* value_source,
132 v8::Handle<v8::Value> value) {
133 if (unexpected->Equals(value)) {
134 v8::String::Utf8Value value_str(value);
135 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s",
136 unexpected_source, value_source, *value_str);
141 namespace v8 { namespace internal {
143 intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }
145 } } // namespace v8::internal