-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebugUtil.h
64 lines (46 loc) · 1.55 KB
/
DebugUtil.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// ByteOrder.h
//
// Author: Filippin luca
// luca.filippin@gmail.com
//
#ifndef __DEBUG_UTIL_H__
#define __DEBUG_UTIL_H__
#include <stdio.h>
#define xprintf(file, context, format, ...) do { \
fprintf(file, "[%s:%s(%d)] " format, context, __func__, __LINE__, __VA_ARGS__); \
fflush(file); \
} while(0)
#define eprintf(context, format, ...) xprintf(stderr, context, format, __VA_ARGS__)
#define oprintf(context, format, ...) xprintf(stdout, context, format, __VA_ARGS__)
#if DEBUG_SWITCH
#define DEBUG_DECLARE(x) x
#define DEBUG_OPEN(l) while (l & (DEBUG_SWITCH)) {
#define DEBUG_CLOSE break; }
#define DEBUG_LEVEL(l, x) \
DEBUG_OPEN(l) \
x; \
DEBUG_CLOSE
#else
#define DEBUG_DECLARE(x)
#define DEBUG_LEVEL(l, x)
#endif
typedef enum {
eHexDumpMode_hex_only,
eHexDumpMode_text_only,
eHexDumpMode_hex_and_text
} eHexDumpMode;
char *hex_dump(unsigned char *data, int len, char *buf, int size, int n_chars_break, eHexDumpMode mode, int *n_printed_chars);
#endif
/* Example. In your C source you might define:
[...]
#define DEBUG_BASIC 0x1
#define DEBUG_MEDIUM 0x2
#define DEBUG_EXTD 0x4
#define DEBUG_VERBOSE 0x8
#define DEBUG_SWITCH (DEBUG_BASIC + DEBUG_MEDIUM + DEBUG_EXTD)
#include "DebugUtils.h"
[...]
DEBUG_DECLARE(long time = GetTime());
DEBUG_LEVEL(DEBUG_MEDIUM, printf("TimeStamp(%d): %ld", __LINE__, time))
*/