GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
gp_debug.h File Reference

A debug message layer. More...

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <core/gp_compiler.h>

Go to the source code of this file.

Data Structures

struct  gp_debug_msg
 Custom debug message handler structure. More...
 

Macros

#define GP_DEBUG(level, ...)    gp_debug_print(level, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
 A debug printf-like macro.
 
#define GP_TODO(...)    gp_debug_print(GP_DEBUG_TODO, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
 A debug TODO printf-like macro.
 
#define GP_WARN(...)    gp_debug_print(GP_DEBUG_WARN, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
 A debug WARN printf-like macro.
 
#define GP_BUG(...)    gp_debug_print(GP_DEBUG_BUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
 A debug BUG printf-like macro.
 
#define GP_FATAL(...)    gp_debug_print(GP_DEBUG_FATAL, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
 A debug FATAL printf-like macro.
 

Enumerations

enum  gp_debug_type { GP_DEBUG_TODO = -1 , GP_DEBUG_WARN = -2 , GP_DEBUG_BUG = -3 , GP_DEBUG_FATAL = -4 }
 A debug level constants. More...
 

Functions

void gp_debug_print (int level, const char *file, const char *function, int line, const char *fmt,...)
 A debug printf handler.
 
void gp_set_debug_level (unsigned int level)
 Sets current debug level.
 
unsigned int gp_get_debug_level (void)
 Returns current debug level.
 
void gp_set_debug_handler (void(*handler)(const struct gp_debug_msg *msg))
 Redirects debug message into a custom handler.
 

Detailed Description

A debug message layer.

Many places of the library uses debug messages to report warnings, bugs, or generally important events i.e. pixmap has been allocated, filter function has been called, etc.

Debug messages are printed into the stderr and could be redirected to custom handler.

The debug level can be set by exporting an enviroment variable GP_DEBUG=level.

The verbosity of the messages could be changed by the debug level. The debug level is an unsigned integer (by default set to '0') and only messages that have debug level lower or equal to debug level are printed.

There are few special debug message types with negative debug level (that means that they are always printed), and as so these are used on various error conditions, see below for more information.

Definition in file gp_debug.h.

Macro Definition Documentation

◆ GP_BUG

#define GP_BUG (   ...)     gp_debug_print(GP_DEBUG_BUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)

A debug BUG printf-like macro.

Parameters
...A printf like format string and parameters.

Definition at line 112 of file gp_debug.h.

◆ GP_DEBUG

#define GP_DEBUG (   level,
  ... 
)     gp_debug_print(level, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)

A debug printf-like macro.

Parameters
levelA debug level usually between 1 and 10
...A printf like format string and parameters.

Definition at line 88 of file gp_debug.h.

◆ GP_FATAL

#define GP_FATAL (   ...)     gp_debug_print(GP_DEBUG_FATAL, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)

A debug FATAL printf-like macro.

Parameters
...A printf like format string and parameters.

Definition at line 120 of file gp_debug.h.

◆ GP_TODO

#define GP_TODO (   ...)     gp_debug_print(GP_DEBUG_TODO, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)

A debug TODO printf-like macro.

Parameters
...A printf like format string and parameters.

Definition at line 96 of file gp_debug.h.

◆ GP_WARN

#define GP_WARN (   ...)     gp_debug_print(GP_DEBUG_WARN, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)

A debug WARN printf-like macro.

Parameters
...A printf like format string and parameters.

Definition at line 104 of file gp_debug.h.

Enumeration Type Documentation

◆ gp_debug_type

A debug level constants.

Messages with debug level 0 are always printed (you should generally avoid using them unless you wan't user to see the message.)

Debug level 1 should be used on object initalization and generally rare and important events.

Debug level > 1 is intended for more verbose reporting, like inner cycles or loop debugging.

Debug levels with negative level are special.

Enumerator
GP_DEBUG_TODO 

Not implemented yet.

Used in stub functions.

GP_DEBUG_WARN 

A warning.

Generally a problem that can be ignored.

GP_DEBUG_BUG 

A library bug.

Library got into an inconsistent state but stil attempts to continue.

GP_DEBUG_FATAL 

A fatal condition.

  • Initialization failed
  • Library foo not compiled in

Definition at line 51 of file gp_debug.h.

Function Documentation

◆ gp_debug_print()

void gp_debug_print ( int  level,
const char *  file,
const char *  function,
int  line,
const char *  fmt,
  ... 
)

A debug printf handler.

Attention
Do not use directly use the GP_DEBUG(), GP_WARN(), ... macros instead.
Parameters
levelA debug level for the mesasge.
fileA file name for the source file the message came from.
functionA function the message came from.
lineA line in the source file the message came from.
fmtA printf-like format string.
...A printf-like paramaters.

◆ gp_get_debug_level()

unsigned int gp_get_debug_level ( void  )

Returns current debug level.

Returns
A current debug level.

◆ gp_set_debug_handler()

void gp_set_debug_handler ( void(*)(const struct gp_debug_msg *msg)  handler)

Redirects debug message into a custom handler.

Parameters
handlerA new debug handler. Pass NULL to disable redirection.

◆ gp_set_debug_level()

void gp_set_debug_level ( unsigned int  level)

Sets current debug level.

The default debug level is 0 that means that all messages with level up to 0 are printed. To get more verbose debugging pass a value between 1 and 10.

Parameters
levelA new debug level.