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
12 #include <backtrace.h>
13 #endif // V8_LIBC_GLIBC || V8_OS_BSD
18 #include "src/base/platform/platform.h"
23 // Explicit instantiations for commonly used comparisons.
24 #define DEFINE_MAKE_CHECK_OP_STRING(type) \
25 template std::string* MakeCheckOpString<type, type>( \
26 type const&, type const&, char const*);
27 DEFINE_MAKE_CHECK_OP_STRING(int)
28 DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int)
29 DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int)
30 DEFINE_MAKE_CHECK_OP_STRING(unsigned int)
31 DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int)
32 DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int)
33 DEFINE_MAKE_CHECK_OP_STRING(char const*)
34 DEFINE_MAKE_CHECK_OP_STRING(void const*)
35 #undef DEFINE_MAKE_CHECK_OP_STRING
38 // Explicit instantiations for floating point checks.
39 #define DEFINE_CHECK_OP_IMPL(NAME) \
40 template std::string* Check##NAME##Impl<float, float>( \
41 float const& lhs, float const& rhs, char const* msg); \
42 template std::string* Check##NAME##Impl<double, double>( \
43 double const& lhs, double const& rhs, char const* msg);
44 DEFINE_CHECK_OP_IMPL(EQ)
45 DEFINE_CHECK_OP_IMPL(NE)
46 DEFINE_CHECK_OP_IMPL(LE)
47 DEFINE_CHECK_OP_IMPL(LT)
48 DEFINE_CHECK_OP_IMPL(GE)
49 DEFINE_CHECK_OP_IMPL(GT)
50 #undef DEFINE_CHECK_OP_IMPL
53 // Attempts to dump a backtrace (if supported).
54 void DumpBacktrace() {
55 #if V8_LIBC_GLIBC || V8_OS_BSD
57 int size = backtrace(trace, arraysize(trace));
58 OS::PrintError("\n==== C stack trace ===============================\n\n");
60 OS::PrintError("(empty)\n");
62 for (int i = 1; i < size; ++i) {
63 OS::PrintError("%2d: ", i);
65 char* demangled = NULL;
66 if (!dladdr(trace[i], &info) || !info.dli_sname) {
67 OS::PrintError("%p\n", trace[i]);
68 } else if ((demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0))) {
69 OS::PrintError("%s\n", demangled);
72 OS::PrintError("%s\n", info.dli_sname);
80 bt_init_accessor(&acc, BT_SELF);
81 bt_load_memmap(&acc, &memmap);
82 bt_sprn_memmap(&memmap, out, sizeof(out));
85 int size = bt_get_backtrace(&acc, trace, arraysize(trace));
86 OS::PrintError("\n==== C stack trace ===============================\n\n");
88 OS::PrintError("(empty)\n");
90 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"),
91 out, sizeof(out), NULL);
94 bt_unload_memmap(&memmap);
95 bt_release_accessor(&acc);
96 #endif // V8_LIBC_GLIBC || V8_OS_BSD
103 // Contains protection against recursive calls (faults while handling faults).
104 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) {
107 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file,
110 va_start(arguments, format);
111 v8::base::OS::VPrintError(format, arguments);
113 v8::base::OS::PrintError("\n#\n");
114 v8::base::DumpBacktrace();
116 v8::base::OS::Abort();