Commit | Line | Data |
---|---|---|
44d13f19 MD |
1 | #ifndef _LTTNG_BUG_H |
2 | #define _LTTNG_BUG_H | |
3 | ||
4 | /* | |
3f12fcef | 5 | * lttng/bug.h |
44d13f19 MD |
6 | * |
7 | * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
a60d70e6 MD |
9 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
10 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | |
11 | * | |
12 | * Permission is hereby granted to use or copy this program | |
13 | * for any purpose, provided the above notices are retained on all copies. | |
14 | * Permission to modify the code and to distribute modified code is granted, | |
15 | * provided the above notices are retained, and a notice that the code was | |
16 | * modified is included with the above copyright notice. | |
44d13f19 MD |
17 | */ |
18 | ||
3f12fcef MD |
19 | #include <urcu/compiler.h> |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | ||
23 | #define LTTNG_BUG_ON(condition) \ | |
24 | do { \ | |
25 | if (caa_unlikely(condition)) { \ | |
26 | fprintf(stderr, \ | |
27 | "LTTng BUG in file %s, line %d.\n", \ | |
28 | __FILE__, __LINE__); \ | |
29 | exit(EXIT_FAILURE); \ | |
30 | } \ | |
31 | } while (0) | |
32 | ||
33 | #define LTTNG_BUILD_BUG_ON(condition) \ | |
a6352fd4 MD |
34 | ((void) sizeof(char[-!!(condition)])) |
35 | ||
44d13f19 | 36 | /** |
3f12fcef | 37 | * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime |
44d13f19 MD |
38 | * @condition: the condition which should be false. |
39 | * | |
40 | * If the condition is a constant and true, the compiler will generate a build | |
41 | * error. If the condition is not constant, a BUG will be triggered at runtime | |
42 | * if the condition is ever true. If the condition is constant and false, no | |
43 | * code is emitted. | |
44 | */ | |
3f12fcef | 45 | #define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \ |
44d13f19 MD |
46 | do { \ |
47 | if (__builtin_constant_p(condition)) \ | |
3f12fcef | 48 | LTTNG_BUILD_BUG_ON(condition); \ |
44d13f19 | 49 | else \ |
3f12fcef | 50 | LTTNG_BUG_ON(condition); \ |
44d13f19 MD |
51 | } while (0) |
52 | ||
53 | #endif |