diff options
author | Thierry Reding <treding@nvidia.com> | 2014-08-26 17:33:58 +0200 |
---|---|---|
committer | Marcel Ziswiler <marcel.ziswiler@toradex.com> | 2014-10-11 01:08:03 +0200 |
commit | ea3202b23728c2191b25c74096a13c562977c30d (patch) | |
tree | 17c02be3fca91bae1c9c4ac3f7b9595521ce163a | |
parent | b321af0100f768487fbc4c5078b491c8379308d8 (diff) |
Add pr_fmt() macro
This macro can be overridden in source files (before including common.h)
and can be used to specify a prefix for debug and error messages. An
example of how to use this is shown below:
#define pr_fmt(fmt) "foo: " fmt
#include <common.h>
...
debug("bar");
The resulting message will read:
foo: bar
Acked-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Thierry Reding <treding@nvidia.com>
-rw-r--r-- | include/common.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/include/common.h b/include/common.h index d5020c8c45..0a7949127d 100644 --- a/include/common.h +++ b/include/common.h @@ -96,15 +96,19 @@ typedef volatile unsigned char vu_char; #define _DEBUG 0 #endif +#ifndef pr_fmt +#define pr_fmt(fmt) fmt +#endif + /* * Output a debug text when condition "cond" is met. The "cond" should be * computed by a preprocessor in the best case, allowing for the best * optimization. */ -#define debug_cond(cond, fmt, args...) \ - do { \ - if (cond) \ - printf(fmt, ##args); \ +#define debug_cond(cond, fmt, args...) \ + do { \ + if (cond) \ + printf(pr_fmt(fmt), ##args); \ } while (0) #define debug(fmt, args...) \ @@ -126,7 +130,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned line, __assert_fail(#x, __FILE__, __LINE__, __func__); }) #define error(fmt, args...) do { \ - printf("ERROR: " fmt "\nat %s:%d/%s()\n", \ + printf("ERROR: " pr_fmt(fmt) "\nat %s:%d/%s()\n", \ ##args, __FILE__, __LINE__, __func__); \ } while (0) |