libdragon
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
7#ifndef __LIBDRAGON_DEBUG_H
8#define __LIBDRAGON_DEBUG_H
9
10#include <stdbool.h>
11#include <stdio.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
40#define DEBUG_FEATURE_LOG_USB (1 << 0)
41
61#define DEBUG_FEATURE_LOG_ISVIEWER (1 << 1)
62
94#define DEBUG_FEATURE_LOG_SD (1 << 2)
95
117#define DEBUG_FEATURE_FILE_SD (1 << 3)
118
119
130#define DEBUG_FEATURE_ALL 0xFF
131
132
133#ifndef NDEBUG
135 bool debug_init_usblog(void);
137 bool debug_init_isviewer(void);
139 bool debug_init_sdlog(const char *fn, const char *openfmt);
141 bool debug_init_sdfs(const char *prefix, int npart);
142
144 void debug_close_sdfs(void);
145
157 static inline bool debug_init(int features)
158 {
159 bool ok = false;
160 if (features & DEBUG_FEATURE_LOG_USB)
161 ok = debug_init_usblog() || ok;
162 if (features & DEBUG_FEATURE_LOG_ISVIEWER)
163 ok = debug_init_isviewer() || ok;
164 if (features & DEBUG_FEATURE_FILE_SD)
165 ok = debug_init_sdfs("sd:/", -1) || ok;
166 if (features & DEBUG_FEATURE_LOG_SD)
167 ok = debug_init_sdlog("sd:/libdragon.log", "a");
168 return ok;
169 }
170
181 #define debugf(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__)
182
196 #define assertf(expr, msg, ...) ({ \
197 if (!(expr)) debug_assert_func_f(__FILE__, __LINE__, __func__, #expr, msg, ##__VA_ARGS__); \
198 })
199
200#else
201 #define debug_init(ch) ({ false; })
202 #define debug_init_usblog() ({ false; })
203 #define debug_init_isviewer() ({ false; })
204 #define debug_init_sdlog(fn,fmt) ({ false; })
205 #define debug_init_sdfs(prefix,np) ({ false; })
206 #define debugf(msg, ...) ({ })
207 #define assertf(expr, msg, ...) ({ })
208#endif
209
229void debug_hexdump(const void *buffer, int size);
230
245void debug_backtrace(void);
246
248void debug_assert_func_f(const char *file, int line, const char *func, const char *failedexpr, const char *msg, ...)
249 __attribute__((noreturn, format(printf, 5, 6)));
250
251#ifdef __cplusplus
252} /* extern "C" */
253#endif
254
255#endif
#define DEBUG_FEATURE_LOG_ISVIEWER
Flag to activate the ISViewer logging channel.
Definition debug.h:61
#define DEBUG_FEATURE_FILE_SD
Flag to activate filesystem access to files on CompactFlash/SD.
Definition debug.h:117
bool debug_init_sdlog(const char *fn, const char *openfmt)
Initialize SD logging.
Definition debug.c:572
#define DEBUG_FEATURE_LOG_USB
Flag to activate the USB logging channel.
Definition debug.h:40
void debug_backtrace(void)
Dump a backtrace (call stack) via debugf.
Definition debug.c:711
#define DEBUG_FEATURE_LOG_SD
Flag to activate the logging on CompactFlash/SD card.
Definition debug.h:94
bool debug_init_isviewer(void)
Initialize ISViewer logging.
Definition debug.c:562
bool debug_init_sdfs(const char *prefix, int npart)
Initialize SD filesystem.
Definition debug.c:583
void debug_assert_func_f(const char *file, int line, const char *func, const char *failedexpr, const char *msg,...)
Underlying implementation function for assert() and assertf.
Definition debug.c:620
bool debug_init_usblog(void)
Initialize USB logging.
Definition debug.c:551
void debug_hexdump(const void *buffer, int size)
Do a hexdump of the specified buffer via debugf.
Definition debug.c:658
void debug_close_sdfs(void)
Shutdown SD filesystem.
Definition debug.c:611