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.
5 #include "src/base/logging.h"
7 #if V8_LIBC_GLIBC || V8_OS_BSD
11 # include <backtrace.h>
12 #endif // V8_LIBC_GLIBC || V8_OS_BSD
17 #include "src/base/platform/platform.h"
22 // Explicit instantiations for commonly used comparisons.
23 #define DEFINE_MAKE_CHECK_OP_STRING(type) \
24 template std::string* MakeCheckOpString<type, type>( \
25 type const&, type const&, char const*);
26 DEFINE_MAKE_CHECK_OP_STRING(int)
27 DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int)
28 DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int)
29 DEFINE_MAKE_CHECK_OP_STRING(unsigned int)
30 DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int)
31 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int)
32 DEFINE_MAKE_CHECK_OP_STRING(char const*)
33 DEFINE_MAKE_CHECK_OP_STRING(void const*)
34 #undef DEFINE_MAKE_CHECK_OP_STRING
37 // Explicit instantiations for floating point checks.
38 #define DEFINE_CHECK_OP_IMPL(NAME) \
39 template std::string* Check##NAME##Impl<float, float>( \
40 float const& lhs, float const& rhs, char const* msg); \
41 template std::string* Check##NAME##Impl<double, double>( \
42 double const& lhs, double const& rhs, char const* msg);
43 DEFINE_CHECK_OP_IMPL(EQ)
44 DEFINE_CHECK_OP_IMPL(NE)
45 DEFINE_CHECK_OP_IMPL(LE)
46 DEFINE_CHECK_OP_IMPL(LT)
47 DEFINE_CHECK_OP_IMPL(GE)
48 DEFINE_CHECK_OP_IMPL(GT)
49 #undef DEFINE_CHECK_OP_IMPL
52 // Attempts to dump a backtrace (if supported).
53 void DumpBacktrace() {
54 #if V8_LIBC_GLIBC || V8_OS_BSD
56 int size = backtrace(trace, arraysize(trace));
57 char** symbols = backtrace_symbols(trace, size);
58 OS::PrintError("\n==== C stack trace ===============================\n\n");
60 OS::PrintError("(empty)\n");
61 } else if (symbols == NULL) {
62 OS::PrintError("(no symbols)\n");
64 for (int i = 1; i < size; ++i) {
65 OS::PrintError("%2d: ", i);
67 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT
70 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
71 OS::PrintError("%s\n", demangled != NULL ? demangled : mangled);
74 OS::PrintError("??\n");
83 bt_init_accessor(&acc, BT_SELF);
84 bt_load_memmap(&acc, &memmap);
85 bt_sprn_memmap(&memmap, out, sizeof(out));
88 int size = bt_get_backtrace(&acc, trace, arraysize(trace));
89 OS::PrintError("\n==== C stack trace ===============================\n\n");
91 OS::PrintError("(empty)\n");
93 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"),
94 out, sizeof(out), NULL);
97 bt_unload_memmap(&memmap);
98 bt_release_accessor(&acc);
99 #endif // V8_LIBC_GLIBC || V8_OS_BSD
106 // Contains protection against recursive calls (faults while handling faults).
107 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
110 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file,
113 va_start(arguments, format);
114 v8::base::OS::VPrintError(format, arguments);
116 v8::base::OS::PrintError("\n#\n");
117 v8::base::DumpBacktrace();
119 v8::base::OS::Abort();