42#error "CHECKPOINTS require assertions to be enabled!"
51extern FILE* g_ckpt_file;
52extern int g_ckpt_enabled;
53extern int g_ckpt_record;
55#define CHECKPOINTS_INIT() do { \
56 if (getenv("CHECKPOINTS")) {\
57 if (strcmp(getenv("CHECKPOINTS"),"record") == 0) { \
58 g_ckpt_file = fopen("__debug_ckpt.log", "w"); assert(g_ckpt_file); \
60 } else if (strcmp(getenv("CHECKPOINTS"),"check") == 0) { \
61 g_ckpt_file = fopen("__debug_ckpt.log", "r"); assert(g_ckpt_file); \
72#define CHECKPOINTS_FINALIZE() do {if (g_ckpt_file) fclose(g_ckpt_file); g_ckpt_file = NULL;} while (0)
74#define CHECKPOINT_MARK(str, ...) do { \
76 if (g_ckpt_record) { \
77 fprintf(g_ckpt_file, "MARK: " str "\n", __VA_ARGS__); \
79 char buffer_ckpt[4096]; \
81 snprintf(buffer_ckpt, 4095, "MARK: " str "\n", __VA_ARGS__); \
82 pos = ftell(g_ckpt_file); \
84 while (!feof(g_ckpt_file)) { \
85 char buffer_file[4096]; \
86 assert(fgets(buffer_file, 4095, g_ckpt_file) != NULL); \
87 if (strncmp(buffer_file, buffer_ckpt, 4096)==0) { \
92 if (!g_ckpt_enabled) fseek(g_ckpt_file, pos, SEEK_SET); \
96#define CHECKPOINT(str, ...) do { \
98 if (g_ckpt_record) { \
99 fprintf(g_ckpt_file, str "\n", __VA_ARGS__); \
100 } else if (g_ckpt_enabled) { \
101 char buffer_file[4096], buffer_ckpt[4096]; \
102 assert(fgets(buffer_file, 4095, g_ckpt_file) != NULL); \
103 snprintf(buffer_ckpt, 4095, str "\n", __VA_ARGS__); \
104 if (strncmp(buffer_file, buffer_ckpt, 4096)!=0) { \
105 fprintf(stderr, "Checkpoint failed (at %ld):\nFile: %sExec: %s", ftell(g_ckpt_file), buffer_file, buffer_ckpt); \
113#if !defined(CHECKPOINTS)
114#define CHECKPOINTS_INIT()
115#define CHECKPOINTS_FINALIZE()
116#define CHECKPOINT_MARK(str, ...)
117#define CHECKPOINT(str, ...)
Header that is included in every other header.