-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdebug.h
More file actions
122 lines (98 loc) · 5.09 KB
/
debug.h
File metadata and controls
122 lines (98 loc) · 5.09 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef __DEBUG_INCLUDED
#define __DEBUG_INCLUDED
#include "boost/preprocessor/list/for_each.hpp"
// Turns on debugging messages
#ifndef SHOW_DEBUG
#define SHOW_DEBUG 0
#endif
#ifndef PRINT_DEBUG_FILE
#define PRINT_DEBUG_FILE 0
#endif
#ifndef SPIN_ON_ERROR
#define SPIN_ON_ERROR 0
#endif
//#define ENV_GDB_VEC "NVP_GDB_VEC"
/*
#define fopen fopen_orig
#undef fopen
*/
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
extern FILE* _nvp_print_fd;
// use stderr, until we dup it
#define NVP_PRINT_FD ((_nvp_print_fd)?_nvp_print_fd:stderr)
typedef char* charptr;
void xil_printf(FILE* f, const charptr c, ...);
//static inline void _nvp_debug_handoff(void)
/*
#define _nvp_debug_handoff(x) \
{ \
xil_printf(stderr, "Stopping thread and waiting for gdb...\ngdb --pid=%i\n", getpid()); \
fflush(stderr); \
sleep(1); \
volatile int asdf = 1; \
sleep(1); \
while(asdf) {}; \
}
*/
#define _nvp_debug_handoff(x) \
{ \
sleep(1); \
volatile int asdf = 1; \
sleep(1); \
while(asdf) {}; \
}
//void outbyte(char c);
//#define ERROR_NAMES (EPERM) (ENOENT) (ESRCH) (EINTR) (EIO) (ENXIO) (E2BIG) (ENOEXEC) (EBADF) (ECHILD) (EAGAIN) (ENOMEM) (EACCES) (EFAULT) (ENOTBLK) (EBUSY) (EEXIST) (EXDEV) (ENODEV) (ENOTDIR) (EISDIR) (EINVAL) (ENFILE) (EMFILE) (ENOTTY) (ETXTBSY) (EFBIG) (ENOSPC) (ESPIPE) (EROFS) (EMLINK) (EPIPE) (EDOM) (ERANGE) (EDEADLK)
#define ERROR_NAMES_LIST (EPERM, (ENOENT, (ESRCH, (EINTR, (EIO, (ENXIO, (E2BIG, (ENOEXEC, (EBADF, (ECHILD, (EAGAIN, (ENOMEM, (EACCES, (EFAULT, (ENOTBLK, (EBUSY, (EEXIST, (EXDEV, (ENODEV, (ENOTDIR, (EISDIR, (EINVAL, (ENFILE, (EMFILE, (ENOTTY, (ETXTBSY, (EFBIG, (ENOSPC, (ESPIPE, (EROFS, (EMLINK, (EPIPE, (EDOM, (ERANGE, (EDEADLK, BOOST_PP_NIL)))))))))))))))))))))))))))))))))))
#define ERROR_IF_PRINT(r, data, elem) if(data == elem) { DEBUG("errno == %s (%i): %s\n", MK_STR(elem), elem, strerror(elem)); }
// also used in fileops_wrap
//#define PRINTFUNC fprintf
#define PRINTFUNC xil_printf
#if DISABLE_MSG
#define MSG(format, ...) do{}while(0)
#else
#define MSG(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "MSG: "); PRINTFUNC (NVP_PRINT_FD, format, ##__VA_ARGS__); fflush(NVP_PRINT_FD); }while(0)
#endif
#define LOG(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "MSG: "); PRINTFUNC (NVP_PRINT_FD, format, ##__VA_ARGS__); fflush(NVP_PRINT_FD); }while(0)
#define ERROR(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "\033[01;33mNVP_ERROR\e[m (pid %i): " format, getpid(), ##__VA_ARGS__); PRINTFUNC(NVP_PRINT_FD, "ROHAN HERE\n"); if(SPIN_ON_ERROR){ _nvp_debug_handoff(); } }while(0)
extern FILE *debug_fd;
#define DEBUG_FD debug_fd
#if PRINT_DEBUG_FILE
#define DEBUG_FILE(format, ...) do {PRINTFUNC(DEBUG_FD, "\033[01;33mNVP_DEBUG\
\e[m (pid %i): " format, getpid(), ##__VA_ARGS__); }while(0)
#else
#define DEBUG_FILE(format, ...) do{}while(0)
#endif
#if SHOW_DEBUG
#define DEBUG(format, ...) do{char loc; PRINTFUNC(NVP_PRINT_FD, "NVP_DEBUG (PID %i SP %p): " format, getpid(), &loc, ##__VA_ARGS__); fflush(NVP_PRINT_FD); } while(0)
#define WARNING(format, ...) do{PRINTFUNC(NVP_PRINT_FD, "NVP_WARNING (PID %i): " format, getpid(), ##__VA_ARGS__); } while(0)
#define DEBUG_P(format, ...) do{PRINTFUNC(NVP_PRINT_FD, format, ##__VA_ARGS__); } while(0)
#else
#define DEBUG(format, ...) do{}while(0)
#define WARNING(format, ...) do{}while(0)
#define DEBUG_P(format, ...) do{}while(0)
#endif
#define FAIL \
"FFFFFFFFFFFFFFFFFFFFFF AAA IIIIIIIIII LLLLLLLLLLL \n"\
"F::::::::::::::::::::F A:::A I::::::::I L:::::::::L \n"\
"F::::::::::::::::::::F A:::::A I::::::::I L:::::::::L \n"\
"FF::::::FFFFFFFFF::::F A:::::::A II::::::II LL:::::::LL \n"\
" F:::::F FFFFFF A:::::::::A I::::I L:::::L \n"\
" F:::::F A:::::A:::::A I::::I L:::::L \n"\
" F::::::FFFFFFFFFF A:::::A A:::::A I::::I L:::::L \n"\
" F:::::::::::::::F A:::::A A:::::A I::::I L:::::L \n"\
" F:::::::::::::::F A:::::A A:::::A I::::I L:::::L \n"\
" F::::::FFFFFFFFFFA:::::AAAAAAAAA:::::A I::::I L:::::L \n"\
" F:::::F A:::::::::::::::::::::A I::::I L:::::L \n"\
" F:::::F A:::::AAAAAAAAAAAAA:::::A I::::I L:::::L LLLLLL\n"\
"FF:::::::FF A:::::A A:::::A II::::::II LL:::::::LLLLLLLLL:::::L\n"\
"F::::::::FF A:::::A A:::::A I::::::::I L::::::::::::::::::::::L\n"\
"F::::::::FF A:::::A A:::::A I::::::::I L::::::::::::::::::::::L\n"\
"FFFFFFFFFFF AAAAAAA AAAAAAAIIIIIIIIII LLLLLLLLLLLLLLLLLLLLLLLL\n"
#endif
//#define PRINT_ERROR_NAME(errnoin) BOOST_PP_SEQ_FOR_EACH(ERROR_IF_PRINT, errnoin, ERROR_NAMES) // can't use BOOST_PP_SEQ_FOR_EACH within another BOOST_PP_SEQ_FOR_EACH
#define PRINT_ERROR_NAME(errnoin) _nvp_print_error_name(errnoin);
void _nvp_print_error_name(int errnoin);