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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 20 matching lines...) Expand all Loading... | |
31 # include <cxxabi.h> | 31 # include <cxxabi.h> |
32 # include <execinfo.h> | 32 # include <execinfo.h> |
33 #elif V8_OS_QNX | 33 #elif V8_OS_QNX |
34 # include <backtrace.h> | 34 # include <backtrace.h> |
35 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 35 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
36 #include <stdio.h> | 36 #include <stdio.h> |
37 | 37 |
38 #include "platform.h" | 38 #include "platform.h" |
39 #include "v8.h" | 39 #include "v8.h" |
40 | 40 |
41 namespace v8 { | |
42 namespace internal { | |
43 | |
44 intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } | |
41 | 45 |
42 // Attempts to dump a backtrace (if supported). | 46 // Attempts to dump a backtrace (if supported). |
43 static V8_INLINE void DumpBacktrace() { | 47 void DumpBacktrace() { |
44 #if V8_LIBC_GLIBC || V8_OS_BSD | 48 #if V8_LIBC_GLIBC || V8_OS_BSD |
45 void* trace[100]; | 49 void* trace[100]; |
46 int size = backtrace(trace, ARRAY_SIZE(trace)); | 50 int size = backtrace(trace, ARRAY_SIZE(trace)); |
47 char** symbols = backtrace_symbols(trace, size); | 51 char** symbols = backtrace_symbols(trace, size); |
48 i::OS::PrintError("\n==== C stack trace ===============================\n\n"); | 52 OS::PrintError("\n==== C stack trace ===============================\n\n"); |
49 if (size == 0) { | 53 if (size == 0) { |
50 i::OS::PrintError("(empty)\n"); | 54 OS::PrintError("(empty)\n"); |
51 } else if (symbols == NULL) { | 55 } else if (symbols == NULL) { |
52 i::OS::PrintError("(no symbols)\n"); | 56 OS::PrintError("(no symbols)\n"); |
53 } else { | 57 } else { |
54 for (int i = 1; i < size; ++i) { | 58 for (int i = 1; i < size; ++i) { |
55 i::OS::PrintError("%2d: ", i); | 59 OS::PrintError("%2d: ", i); |
56 char mangled[201]; | 60 char mangled[201]; |
57 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT | 61 if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) { // NOLINT |
58 int status; | 62 int status; |
59 size_t length; | 63 size_t length; |
60 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); | 64 char* demangled = abi::__cxa_demangle(mangled, NULL, &length, &status); |
61 i::OS::PrintError("%s\n", demangled != NULL ? demangled : mangled); | 65 OS::PrintError("%s\n", demangled != NULL ? demangled : mangled); |
62 free(demangled); | 66 free(demangled); |
63 } else { | 67 } else { |
64 i::OS::PrintError("??\n"); | 68 OS::PrintError("??\n"); |
65 } | 69 } |
66 } | 70 } |
67 } | 71 } |
68 free(symbols); | 72 free(symbols); |
69 #elif V8_OS_QNX | 73 #elif V8_OS_QNX |
70 char out[1024]; | 74 char out[1024]; |
71 bt_accessor_t acc; | 75 bt_accessor_t acc; |
72 bt_memmap_t memmap; | 76 bt_memmap_t memmap; |
73 bt_init_accessor(&acc, BT_SELF); | 77 bt_init_accessor(&acc, BT_SELF); |
74 bt_load_memmap(&acc, &memmap); | 78 bt_load_memmap(&acc, &memmap); |
75 bt_sprn_memmap(&memmap, out, sizeof(out)); | 79 bt_sprn_memmap(&memmap, out, sizeof(out)); |
76 i::OS::PrintError(out); | 80 OS::PrintError(out); |
77 bt_addr_t trace[100]; | 81 bt_addr_t trace[100]; |
78 int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace)); | 82 int size = bt_get_backtrace(&acc, trace, ARRAY_SIZE(trace)); |
79 i::OS::PrintError("\n==== C stack trace ===============================\n\n"); | 83 OS::PrintError("\n==== C stack trace ===============================\n\n"); |
80 if (size == 0) { | 84 if (size == 0) { |
81 i::OS::PrintError("(empty)\n"); | 85 OS::PrintError("(empty)\n"); |
82 } else { | 86 } else { |
83 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), | 87 bt_sprnf_addrs(&memmap, trace, size, const_cast<char*>("%a\n"), |
84 out, sizeof(out), NULL); | 88 out, sizeof(out), NULL); |
85 i::OS::PrintError(out); | 89 OS::PrintError(out); |
86 } | 90 } |
87 bt_unload_memmap(&memmap); | 91 bt_unload_memmap(&memmap); |
88 bt_release_accessor(&acc); | 92 bt_release_accessor(&acc); |
89 #endif // V8_LIBC_GLIBC || V8_OS_BSD | 93 #endif // V8_LIBC_GLIBC || V8_OS_BSD |
90 } | 94 } |
91 | 95 |
96 } // namespace internal | |
Michael Starzinger
2014/03/14 14:29:19
nit: Can we get the usual one-line incarnation tha
marja
2014/03/17 10:50:07
Done.
marja
2014/03/17 11:09:04
Btw, the header used the two-line style, so made i
| |
97 } // namespace v8 | |
98 | |
92 | 99 |
93 // Contains protection against recursive calls (faults while handling faults). | 100 // Contains protection against recursive calls (faults while handling faults). |
94 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { | 101 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { |
95 i::AllowHandleDereference allow_deref; | 102 i::AllowHandleDereference allow_deref; |
96 i::AllowDeferredHandleDereference allow_deferred_deref; | 103 i::AllowDeferredHandleDereference allow_deferred_deref; |
97 fflush(stdout); | 104 fflush(stdout); |
98 fflush(stderr); | 105 fflush(stderr); |
99 i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line); | 106 i::OS::PrintError("\n\n#\n# Fatal error in %s, line %d\n# ", file, line); |
100 va_list arguments; | 107 va_list arguments; |
101 va_start(arguments, format); | 108 va_start(arguments, format); |
102 i::OS::VPrintError(format, arguments); | 109 i::OS::VPrintError(format, arguments); |
103 va_end(arguments); | 110 va_end(arguments); |
104 i::OS::PrintError("\n#\n"); | 111 i::OS::PrintError("\n#\n"); |
105 DumpBacktrace(); | 112 v8::internal::DumpBacktrace(); |
106 fflush(stderr); | 113 fflush(stderr); |
107 i::OS::Abort(); | 114 i::OS::Abort(); |
108 } | 115 } |
109 | 116 |
110 | 117 |
111 void CheckEqualsHelper(const char* file, | 118 void CheckEqualsHelper(const char* file, |
112 int line, | 119 int line, |
113 const char* expected_source, | 120 const char* expected_source, |
114 v8::Handle<v8::Value> expected, | 121 v8::Handle<v8::Value> expected, |
115 const char* value_source, | 122 const char* value_source, |
(...skipping 13 matching lines...) Expand all Loading... | |
129 const char* unexpected_source, | 136 const char* unexpected_source, |
130 v8::Handle<v8::Value> unexpected, | 137 v8::Handle<v8::Value> unexpected, |
131 const char* value_source, | 138 const char* value_source, |
132 v8::Handle<v8::Value> value) { | 139 v8::Handle<v8::Value> value) { |
133 if (unexpected->Equals(value)) { | 140 if (unexpected->Equals(value)) { |
134 v8::String::Utf8Value value_str(value); | 141 v8::String::Utf8Value value_str(value); |
135 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", | 142 V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s", |
136 unexpected_source, value_source, *value_str); | 143 unexpected_source, value_source, *value_str); |
137 } | 144 } |
138 } | 145 } |
139 | |
140 | |
141 namespace v8 { namespace internal { | |
142 | |
143 intptr_t HeapObjectTagMask() { return kHeapObjectTagMask; } | |
144 | |
145 } } // namespace v8::internal | |
OLD | NEW |