GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_debug.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2024 Cyril Hrubis <metan@ucw.cz>
4 */
5
28#ifndef CORE_GP_DEBUG_H
29#define CORE_GP_DEBUG_H
30
31#include <stdio.h>
32#include <stdint.h>
33#include <stdlib.h>
34#include <unistd.h>
35#include <core/gp_compiler.h>
36
79
80#define GP_DEFAULT_DEBUG_LEVEL 0
81
88#define GP_DEBUG(level, ...) \
89 gp_debug_print(level, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
90
96#define GP_TODO(...) \
97 gp_debug_print(GP_DEBUG_TODO, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
98
104#define GP_WARN(...) \
105 gp_debug_print(GP_DEBUG_WARN, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
106
112#define GP_BUG(...) \
113 gp_debug_print(GP_DEBUG_BUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
114
120#define GP_FATAL(...) \
121 gp_debug_print(GP_DEBUG_FATAL, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
122
135void gp_debug_print(int level, const char *file, const char *function, int line,
136 const char *fmt, ...) GP_FMT_PRINTF(5, 6);
137
146void gp_set_debug_level(unsigned int level);
147
153unsigned int gp_get_debug_level(void);
154
160 int level;
162 const char *file;
164 const char *fn;
166 unsigned int line;
168 const char *msg;
169};
170
176void gp_set_debug_handler(void (*handler)(const struct gp_debug_msg *msg));
177
178#endif /* CORE_GP_DEBUG_H */
A compiler dependent macros.
#define GP_FMT_PRINTF(fmt, list)
Expands to format printf attribute when supported by the compiler.
Definition gp_compiler.h:30
gp_debug_type
A debug level constants.
Definition gp_debug.h:51
@ GP_DEBUG_FATAL
A fatal condition.
Definition gp_debug.h:77
@ GP_DEBUG_BUG
A library bug.
Definition gp_debug.h:70
@ GP_DEBUG_WARN
A warning.
Definition gp_debug.h:63
@ GP_DEBUG_TODO
Not implemented yet.
Definition gp_debug.h:57
void gp_set_debug_level(unsigned int level)
Sets current debug level.
void gp_set_debug_handler(void(*handler)(const struct gp_debug_msg *msg))
Redirects debug message into a custom handler.
unsigned int gp_get_debug_level(void)
Returns current debug level.
void gp_debug_print(int level, const char *file, const char *function, int line, const char *fmt,...)
A debug printf handler.
Custom debug message handler structure.
Definition gp_debug.h:158
const char * file
A source file the message came from.
Definition gp_debug.h:162
const char * msg
The debug message.
Definition gp_debug.h:168
const char * fn
A function the message came from.
Definition gp_debug.h:164
int level
Message debug level, see gp_debug_type.
Definition gp_debug.h:160
unsigned int line
A line the source file the message came from.
Definition gp_debug.h:166