OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_CHECKS_H_ | 5 #ifndef V8_BASE_LOGGING_H_ |
6 #define V8_CHECKS_H_ | 6 #define V8_BASE_LOGGING_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "include/v8stdint.h" | 10 #include "include/v8stdint.h" |
11 #include "src/base/build_config.h" | 11 #include "src/base/build_config.h" |
12 | 12 |
13 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); | 13 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); |
14 | 14 |
15 | 15 |
16 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during | 16 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during |
17 // development, but they should not be relied on in the final product. | 17 // development, but they should not be relied on in the final product. |
18 #ifdef DEBUG | 18 #ifdef DEBUG |
19 #define FATAL(msg) \ | 19 #define FATAL(msg) \ |
20 V8_Fatal(__FILE__, __LINE__, "%s", (msg)) | 20 V8_Fatal(__FILE__, __LINE__, "%s", (msg)) |
21 #define UNIMPLEMENTED() \ | 21 #define UNIMPLEMENTED() \ |
22 V8_Fatal(__FILE__, __LINE__, "unimplemented code") | 22 V8_Fatal(__FILE__, __LINE__, "unimplemented code") |
23 #define UNREACHABLE() \ | 23 #define UNREACHABLE() \ |
24 V8_Fatal(__FILE__, __LINE__, "unreachable code") | 24 V8_Fatal(__FILE__, __LINE__, "unreachable code") |
25 #else | 25 #else |
26 #define FATAL(msg) \ | 26 #define FATAL(msg) \ |
27 V8_Fatal("", 0, "%s", (msg)) | 27 V8_Fatal("", 0, "%s", (msg)) |
28 #define UNIMPLEMENTED() \ | 28 #define UNIMPLEMENTED() \ |
29 V8_Fatal("", 0, "unimplemented code") | 29 V8_Fatal("", 0, "unimplemented code") |
30 #define UNREACHABLE() ((void) 0) | 30 #define UNREACHABLE() ((void) 0) |
31 #endif | 31 #endif |
32 | 32 |
33 // Simulator specific helpers. | |
34 // We can't use USE_SIMULATOR here because it isn't defined yet. | |
35 #if V8_TARGET_ARCH_ARM64 && !V8_HOST_ARCH_ARM64 | |
36 // TODO(all): If possible automatically prepend an indicator like | |
37 // UNIMPLEMENTED or LOCATION. | |
38 #define ASM_UNIMPLEMENTED(message) \ | |
39 __ Debug(message, __LINE__, NO_PARAM) | |
40 #define ASM_UNIMPLEMENTED_BREAK(message) \ | |
41 __ Debug(message, __LINE__, \ | |
42 FLAG_ignore_asm_unimplemented_break ? NO_PARAM : BREAK) | |
43 #define ASM_LOCATION(message) \ | |
44 __ Debug("LOCATION: " message, __LINE__, NO_PARAM) | |
45 #else | |
46 #define ASM_UNIMPLEMENTED(message) | |
47 #define ASM_UNIMPLEMENTED_BREAK(message) | |
48 #define ASM_LOCATION(message) | |
49 #endif | |
50 | |
51 | 33 |
52 // The CHECK macro checks that the given condition is true; if not, it | 34 // The CHECK macro checks that the given condition is true; if not, it |
53 // prints a message to stderr and aborts. | 35 // prints a message to stderr and aborts. |
54 #define CHECK(condition) do { \ | 36 #define CHECK(condition) do { \ |
55 if (!(condition)) { \ | 37 if (!(condition)) { \ |
56 V8_Fatal(__FILE__, __LINE__, "CHECK(%s) failed", #condition); \ | 38 V8_Fatal(__FILE__, __LINE__, "CHECK(%s) failed", #condition); \ |
57 } \ | 39 } \ |
58 } while (0) | 40 } while (0) |
59 | 41 |
60 | 42 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 #define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \ | 217 #define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \ |
236 #unexpected, unexpected, #value, value) | 218 #unexpected, unexpected, #value, value) |
237 | 219 |
238 | 220 |
239 #define CHECK_GT(a, b) CHECK((a) > (b)) | 221 #define CHECK_GT(a, b) CHECK((a) > (b)) |
240 #define CHECK_GE(a, b) CHECK((a) >= (b)) | 222 #define CHECK_GE(a, b) CHECK((a) >= (b)) |
241 #define CHECK_LT(a, b) CHECK((a) < (b)) | 223 #define CHECK_LT(a, b) CHECK((a) < (b)) |
242 #define CHECK_LE(a, b) CHECK((a) <= (b)) | 224 #define CHECK_LE(a, b) CHECK((a) <= (b)) |
243 | 225 |
244 | 226 |
245 #ifdef DEBUG | |
246 #ifndef OPTIMIZED_DEBUG | |
247 #define ENABLE_SLOW_ASSERTS 1 | |
248 #endif | |
249 #endif | |
250 | |
251 namespace v8 { | 227 namespace v8 { |
252 namespace internal { | 228 namespace base { |
253 #ifdef ENABLE_SLOW_ASSERTS | |
254 #define SLOW_ASSERT(condition) \ | |
255 CHECK(!v8::internal::FLAG_enable_slow_asserts || (condition)) | |
256 extern bool FLAG_enable_slow_asserts; | |
257 #else | |
258 #define SLOW_ASSERT(condition) ((void) 0) | |
259 const bool FLAG_enable_slow_asserts = false; | |
260 #endif | |
261 | 229 |
262 // Exposed for making debugging easier (to see where your function is being | 230 // Exposed for making debugging easier (to see where your function is being |
263 // called, just add a call to DumpBacktrace). | 231 // called, just add a call to DumpBacktrace). |
264 void DumpBacktrace(); | 232 void DumpBacktrace(); |
265 | 233 |
266 } } // namespace v8::internal | 234 } } // namespace v8::base |
267 | 235 |
268 | 236 |
269 // The ASSERT macro is equivalent to CHECK except that it only | 237 // The ASSERT macro is equivalent to CHECK except that it only |
270 // generates code in debug builds. | 238 // generates code in debug builds. |
271 #ifdef DEBUG | 239 #ifdef DEBUG |
272 #define ASSERT_RESULT(expr) CHECK(expr) | 240 #define ASSERT_RESULT(expr) CHECK(expr) |
273 #define ASSERT(condition) CHECK(condition) | 241 #define ASSERT(condition) CHECK(condition) |
274 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2) | 242 #define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2) |
275 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2) | 243 #define ASSERT_NE(v1, v2) CHECK_NE(v1, v2) |
276 #define ASSERT_GE(v1, v2) CHECK_GE(v1, v2) | 244 #define ASSERT_GE(v1, v2) CHECK_GE(v1, v2) |
(...skipping 12 matching lines...) Expand all Loading... |
289 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) | 257 #define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p) |
290 | 258 |
291 // "Extra checks" are lightweight checks that are enabled in some release | 259 // "Extra checks" are lightweight checks that are enabled in some release |
292 // builds. | 260 // builds. |
293 #ifdef ENABLE_EXTRA_CHECKS | 261 #ifdef ENABLE_EXTRA_CHECKS |
294 #define EXTRA_CHECK(condition) CHECK(condition) | 262 #define EXTRA_CHECK(condition) CHECK(condition) |
295 #else | 263 #else |
296 #define EXTRA_CHECK(condition) ((void) 0) | 264 #define EXTRA_CHECK(condition) ((void) 0) |
297 #endif | 265 #endif |
298 | 266 |
299 #endif // V8_CHECKS_H_ | 267 #endif // V8_BASE_LOGGING_H_ |
OLD | NEW |