diff options
Diffstat (limited to 'ubifs-utils/common/defs.h')
-rw-r--r-- | ubifs-utils/common/defs.h | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/ubifs-utils/common/defs.h b/ubifs-utils/common/defs.h index 485c50c..6d99a2f 100644 --- a/ubifs-utils/common/defs.h +++ b/ubifs-utils/common/defs.h @@ -8,8 +8,10 @@ #include <stdlib.h> #include <stdio.h> +#include <unistd.h> #include <limits.h> #include <errno.h> +#include <execinfo.h> #include "ubifs.h" @@ -22,10 +24,52 @@ extern struct ubifs_info info_; enum { MKFS_PROGRAM_TYPE = 0 }; -#define dbg_msg(lvl, fmt, ...) do {if (info_.debug_level >= lvl) \ - printf("%s: %s: " fmt "\n", PROGRAM_NAME, __FUNCTION__, ##__VA_ARGS__); \ +enum { ERR_LEVEL = 1, WARN_LEVEL, INFO_LEVEL, DEBUG_LEVEL }; + +#define pr_debug(fmt, ...) do { if (info_.debug_level >= DEBUG_LEVEL) \ + printf("<DEBUG> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \ + info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \ +} while(0) + +#define pr_notice(fmt, ...) do { if (info_.debug_level >= INFO_LEVEL) \ + printf("<INFO> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \ + info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \ +} while(0) + +#define pr_warn(fmt, ...) do { if (info_.debug_level >= WARN_LEVEL) \ + printf("<WARN> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \ + info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \ +} while(0) + +#define pr_err(fmt, ...) do { if (info_.debug_level >= ERR_LEVEL) \ + printf("<ERROR> %s[%d] (%s): %s: " fmt, PROGRAM_NAME, getpid(), \ + info_.dev_name, __FUNCTION__, ##__VA_ARGS__); \ } while(0) +#define pr_cont(fmt, ...) do { if (info_.debug_level >= ERR_LEVEL) \ + printf(fmt, ##__VA_ARGS__); \ +} while(0) + +static inline void dump_stack(void) +{ +#define STACK_SIZE 512 + int j, nptrs; + void *buffer[STACK_SIZE]; + char **strings; + + if (info_.debug_level < ERR_LEVEL) + return; + + nptrs = backtrace(buffer, STACK_SIZE); + strings = backtrace_symbols(buffer, nptrs); + + printf("dump_stack:\n"); + for (j = 0; j < nptrs; j++) + printf("%s\n", strings[j]); + + free(strings); +} + #define unlikely(x) (x) #define do_div(n,base) ({ \ |