[PATCH] include: add BUG_WARN macro for internal bug cases.

Peter Hutterer peter.hutterer at who-t.net
Tue Nov 8 21:14:50 PST 2011


There are plenty of cases that can only be triggered by a real bug in the
server and doing the ErrorF dance manually everywhere is a tad painful and
the error message is usually used only to find the spot in the file anyway.

Plus, reading BUG_WARN somewhere is a good indicator to the casual reader
that this isn't intended behaviour.

Note that this is intentionally different to the BUG_ON behaviour on the
kernel, we do not FatalError the server. It's just a warning + stacktrace.
If the bug is really fatal, call FatalError.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 include/misc.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/include/misc.h b/include/misc.h
index dc03911..0584f08 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -359,4 +359,11 @@ typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
 extern _X_EXPORT unsigned long globalSerialNumber;
 extern _X_EXPORT unsigned long serverGeneration;
 
+#define BUG_WARN(cond)                                                    \
+          do { if (cond) {                                                \
+              ErrorF("BUG: triggered 'if (" #cond ")'\nBUG: %s:%d in %s()\n",     \
+                      __FILE__, __LINE__, __func__);                      \
+              xorg_backtrace();                                           \
+          } } while(0)
+
 #endif /* MISC_H */
-- 
1.7.7


More information about the xorg-devel mailing list