libdragon
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_DEBUG_H
7#define __LIBDRAGON_DEBUG_H
8
9#include <stdbool.h>
10#include <stdio.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
39#define DEBUG_FEATURE_LOG_USB (1 << 0)
40
60#define DEBUG_FEATURE_LOG_ISVIEWER (1 << 1)
61
93#define DEBUG_FEATURE_LOG_SD (1 << 2)
94
116#define DEBUG_FEATURE_FILE_SD (1 << 3)
117
118
129#define DEBUG_FEATURE_ALL 0xFF
130
131
132#ifndef NDEBUG
134 bool debug_init_usblog(void);
136 bool debug_init_isviewer(void);
138 bool debug_init_sdlog(const char *fn, const char *openfmt);
140 bool debug_init_sdfs(const char *prefix, int npart);
141
143 void debug_close_sdfs(void);
144
156 static inline bool debug_init(int features)
157 {
158 bool ok = false;
159 if (features & DEBUG_FEATURE_LOG_USB)
160 ok = debug_init_usblog() || ok;
161 if (features & DEBUG_FEATURE_LOG_ISVIEWER)
162 ok = debug_init_isviewer() || ok;
163 if (features & DEBUG_FEATURE_FILE_SD)
164 ok = debug_init_sdfs("sd:/", -1) || ok;
165 if (features & DEBUG_FEATURE_LOG_SD)
166 ok = debug_init_sdlog("sd:/libdragon.log", "a");
167 return ok;
168 }
169
180 #define debugf(msg, ...) fprintf(stderr, msg, ##__VA_ARGS__)
181
195 #define assertf(expr, msg, ...) ({ \
196 if (!(expr)) debug_assert_func_f(__FILE__, __LINE__, __func__, #expr, msg, ##__VA_ARGS__); \
197 })
198
199#else
200 #define debug_init(ch) ({ false; })
201 #define debug_init_usblog() ({ false; })
202 #define debug_init_isviewer() ({ false; })
203 #define debug_init_sdlog(fn,fmt) ({ false; })
204 #define debug_init_sdfs(prefix,np) ({ false; })
205 #define debugf(msg, ...) ({ })
206 #define assertf(expr, msg, ...) ({ })
207#endif
208
228void debug_hexdump(const void *buffer, int size);
229
244void debug_backtrace(void);
245
247void debug_assert_func_f(const char *file, int line, const char *func, const char *failedexpr, const char *msg, ...)
248 __attribute__((noreturn, format(printf, 5, 6)));
249
250#ifdef __cplusplus
251} /* extern "C" */
252#endif
253
254#endif
#define DEBUG_FEATURE_LOG_ISVIEWER
Flag to activate the ISViewer logging channel.
Definition debug.h:60
#define DEBUG_FEATURE_FILE_SD
Flag to activate filesystem access to files on CompactFlash/SD.
Definition debug.h:116
bool debug_init_sdlog(const char *fn, const char *openfmt)
Initialize SD logging.
Definition debug.c:571
#define DEBUG_FEATURE_LOG_USB
Flag to activate the USB logging channel.
Definition debug.h:39
void debug_backtrace(void)
Dump a backtrace (call stack) via debugf.
Definition debug.c:710
#define DEBUG_FEATURE_LOG_SD
Flag to activate the logging on CompactFlash/SD card.
Definition debug.h:93
bool debug_init_isviewer(void)
Initialize ISViewer logging.
Definition debug.c:561
bool debug_init_sdfs(const char *prefix, int npart)
Initialize SD filesystem.
Definition debug.c:582
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:619
bool debug_init_usblog(void)
Initialize USB logging.
Definition debug.c:550
void debug_hexdump(const void *buffer, int size)
Do a hexdump of the specified buffer via debugf.
Definition debug.c:657
void debug_close_sdfs(void)
Shutdown SD filesystem.
Definition debug.c:610