Skip to content

Commit

Permalink
Send debug output to an unused file descriptor
Browse files Browse the repository at this point in the history
It can be redirected with 666>log, or sent to stdout with 666>&1.
  • Loading branch information
Theodore Dubois committed Feb 5, 2018
1 parent da011d9 commit 2377245
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#include <stdio.h>
#include <stdlib.h>

// TODO turn this into function that outputs to a log buffer
#define printk(msg, ...) dprintf(666, msg, ##__VA_ARGS__)

// all line endings should use \r\n so it can work even with the terminal in raw mode
// this is subject to change, so use this macro whenever you output a newline
#define println(msg, ...) printf(msg "\r\n", ##__VA_ARGS__)
// this is subject to change, so use NEWLINE or println whenever you output a newline
#define NEWLINE "\r\n"
#define println(msg, ...) printk(msg NEWLINE, ##__VA_ARGS__)

// debug output utilities
// save me
Expand Down Expand Up @@ -60,12 +64,12 @@ extern int log_override;
#else
#define TRACE__NOP(msg, ...) do {} while(0)
#endif
#define TRACE__(msg, ...) printf(msg, ##__VA_ARGS__)
#define TRACE__(msg, ...) printk(msg, ##__VA_ARGS__)

#define TRACE_(chan, msg, ...) CONCAT(TRACE_, chan)(msg, ##__VA_ARGS__)
#define TRACE(msg, ...) TRACE_(DEFAULT_CHANNEL, msg, ##__VA_ARGS__)
#define TRACELN_(chan, msg, ...) TRACE_(chan, msg "\r\n", ##__VA_ARGS__)
#define TRACELN(msg, ...) TRACE(msg "\r\n", ##__VA_ARGS__)
#define TRACELN(msg, ...) TRACE(msg NEWLINE, ##__VA_ARGS__)
#ifndef DEFAULT_CHANNEL
#define DEFAULT_CHANNEL default
#endif
Expand Down

0 comments on commit 2377245

Please sign in to comment.