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
3 // found in the LICENSE file.
7 #if V8_LIBC_GLIBC || V8_OS_BSD
11 # include <backtrace.h>
12 #endif // V8_LIBC_GLIBC || V8_OS_BSD
21 intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; }
23 // Attempts to dump a backtrace (if supported).
24 void DumpBacktrace() {
25 #if V8_LIBC_GLIBC || V8_OS_BSD
27 int size = backtrace(trace, ARRAY_SIZE(trace));
28 char** symbols = backtrace_symbols(trace, size);
29 OS::PrintError("\n==== C stack trace ===============================\n\n");
31 OS::PrintError("(empty)\n");
32 } else if (symbols == NULL) {
33 OS::PrintError("(no symbols)\n");
35 for (int i = 1; i < size; ++i) {
36 OS::PrintError("%2d: ", i);
38 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
41 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
42 OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
45 OS::PrintError("??\n");
54 bt_init_accessor(&acc, BT_SELF);
55 bt_load_memmap(&acc, &memmap);
56 bt_sprn_memmap(&memmap, out, sizeof(out));
59 int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace));
60 OS::PrintError("\n==== C stack trace ===============================\n\n");
62 OS::PrintError("(empty)\n");
64 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"),
65 out, sizeof(out), NULL);
68 bt_unload_memmap(&memmap);
69 bt_release_accessor(&acc);
70 #endif // V8_LIBC_GLIBC || V8_OS_BSD
73 } } // namespace v8::internal
76 // Contains protection against recursive calls (faults while handling faults).
77 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
80 i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line);
82 va_start(arguments, format);
83 i::OS::VPrintError(format, arguments);
85 i::OS::PrintError("\n#\n");
86 v8::internal::DumpBacktrace();
92 void CheckEqualsHelper(const char* file,
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);
102 "CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s",
103 expected_source, value_source, *expected_str, *value_str);
108 void CheckNonEqualsHelper(const char* file,
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);