OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/logging.h" | 5 #include "src/base/logging.h" |
6 | 6 |
7 #if V8_LIBC_GLIBC || V8_OS_BSD | |
8 #include <cxxabi.h> | |
9 #include <dlfcn.h> | |
10 #include <execinfo.h> | |
11 #elif V8_OS_QNX | |
12 #include <backtrace.h> | |
13 #endif // V8_LIBC_GLIBC || V8_OS_BSD | |
14 | |
15 #include <cstdio> | 7 #include <cstdio> |
16 #include <cstdlib> | 8 #include <cstdlib> |
17 | 9 |
| 10 #include "src/base/debug/stack_trace.h" |
18 #include "src/base/platform/platform.h" | 11 #include "src/base/platform/platform.h" |
19 | 12 |
20 namespace v8 { | 13 namespace v8 { |
21 namespace base { | 14 namespace base { |
22 | 15 |
23 // Explicit instantiations for commonly used comparisons. | 16 // Explicit instantiations for commonly used comparisons. |
24 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ | 17 #define DEFINE_MAKE_CHECK_OP_STRING(type) \ |
25 template std::string* MakeCheckOpString<type, type>( \ | 18 template std::string* MakeCheckOpString<type, type>( \ |
26 type const&, type const&, char const*); | 19 type const&, type const&, char const*); |
27 DEFINE_MAKE_CHECK_OP_STRING(int) | 20 DEFINE_MAKE_CHECK_OP_STRING(int) |
(...skipping 14 matching lines...) Expand all Loading... |
42 template std::string* Check##NAME##Impl<double, double>( \ | 35 template std::string* Check##NAME##Impl<double, double>( \ |
43 double const& lhs, double const& rhs, char const* msg); | 36 double const& lhs, double const& rhs, char const* msg); |
44 DEFINE_CHECK_OP_IMPL(EQ) | 37 DEFINE_CHECK_OP_IMPL(EQ) |
45 DEFINE_CHECK_OP_IMPL(NE) | 38 DEFINE_CHECK_OP_IMPL(NE) |
46 DEFINE_CHECK_OP_IMPL(LE) | 39 DEFINE_CHECK_OP_IMPL(LE) |
47 DEFINE_CHECK_OP_IMPL(LT) | 40 DEFINE_CHECK_OP_IMPL(LT) |
48 DEFINE_CHECK_OP_IMPL(GE) | 41 DEFINE_CHECK_OP_IMPL(GE) |
49 DEFINE_CHECK_OP_IMPL(GT) | 42 DEFINE_CHECK_OP_IMPL(GT) |
50 #undef DEFINE_CHECK_OP_IMPL | 43 #undef DEFINE_CHECK_OP_IMPL |
51 | 44 |
52 | |
53 // Attempts to dump a backtrace (if supported). | |
54 void DumpBacktrace() { | |
55 #if V8_LIBC_GLIBC || V8_OS_BSD | |
56 void* trace[100]; | |
57 int size = backtrace(trace, arraysize(trace)); | |
58 OS::PrintError("\n==== C stack trace ===============================\n\n"); | |
59 if (size == 0) { | |
60 OS::PrintError("(empty)\n"); | |
61 } else { | |
62 for (int i = 1; i < size; ++i) { | |
63 OS::PrintError("%2d: ", i); | |
64 Dl_info info; | |
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); | |
70 free(demangled); | |
71 } else { | |
72 OS::PrintError("%s\n", info.dli_sname); | |
73 } | |
74 } | |
75 } | |
76 #elif V8_OS_QNX | |
77 char out[1024]; | |
78 bt_accessor_t acc; | |
79 bt_memmap_t memmap; | |
80 bt_init_accessor(&acc, BT_SELF); | |
81 bt_load_memmap(&acc, &memmap); | |
82 bt_sprn_memmap(&memmap, out, sizeof(out)); | |
83 OS::PrintError(out); | |
84 bt_addr_t trace[100]; | |
85 int size = bt_get_backtrace(&acc, trace, arraysize(trace)); | |
86 OS::PrintError("\n==== C stack trace ===============================\n\n"); | |
87 if (size == 0) { | |
88 OS::PrintError("(empty)\n"); | |
89 } else { | |
90 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), | |
91 out, sizeof(out), NULL); | |
92 OS::PrintError(out); | |
93 } | |
94 bt_unload_memmap(&memmap); | |
95 bt_release_accessor(&acc); | |
96 #endif // V8_LIBC_GLIBC || V8_OS_BSD | |
97 } | |
98 | |
99 } // namespace base | 45 } // namespace base |
100 } // namespace v8 | 46 } // namespace v8 |
101 | 47 |
102 | 48 |
103 // Contains protection against recursive calls (faults while handling faults). | 49 // Contains protection against recursive calls (faults while handling faults). |
104 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { | 50 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
105 fflush(stdout); | 51 fflush(stdout); |
106 fflush(stderr); | 52 fflush(stderr); |
107 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, | 53 v8::base::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, |
108 line); | 54 line); |
109 va_list arguments; | 55 va_list arguments; |
110 va_start(arguments, format); | 56 va_start(arguments, format); |
111 v8::base::OS::VPrintError(format, arguments); | 57 v8::base::OS::VPrintError(format, arguments); |
112 va_end(arguments); | 58 va_end(arguments); |
113 v8::base::OS::PrintError("\n#\n"); | 59 v8::base::OS::PrintError("\n#\n"); |
114 v8::base::DumpBacktrace(); | 60 |
| 61 v8::base::debug::StackTrace trace; |
| 62 trace.Print(); |
| 63 |
115 fflush(stderr); | 64 fflush(stderr); |
| 65 // Avoid dumping stack trace on abort signal. |
| 66 v8::base::debug::DisableSignalStackDump(); |
116 v8::base::OS::Abort(); | 67 v8::base::OS::Abort(); |
117 } | 68 } |
OLD | NEW |