From 9c38422fc4cf853c3104fada2a3851c79df2a66f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 9 Nov 2011 14:37:26 +1000 Subject: include: add BUG_WARN macro for internal bug cases. 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 Reviewed-by: Chase Douglas Reviewed-by: Alan Coopersmith --- include/misc.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/misc.h b/include/misc.h index 2e8dd1b89..ef86fa539 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 */ -- cgit v1.2.3