navit  0.5.3-trunk
debug.h File Reference
#include <stdarg.h>
#include <string.h>

Go to the source code of this file.

Macros

#define dbg_str2(x)   #x
 
#define dbg_str1(x)   dbg_str2(x)
 
#define dbg_module   dbg_str1(MODULE)
 
#define dbg(level, ...)   { if (max_debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
 
#define dbg_assert(expr)   ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))
 
#define DEBUG_MODULE_GLOBAL   "global"
 
#define g_free_func   g_free
 
#define dbg_guard(x)   x
 

Enumerations

enum  dbg_level {
  lvl_unset =-1 , lvl_error , lvl_warning , lvl_info ,
  lvl_debug
}
 

Functions

void debug_init (const char *program_name)
 
void debug_level_set (const char *name, dbg_level level)
 
struct debugdebug_new (struct attr *parent, struct attr **attrs)
 
dbg_level debug_level_get (const char *name)
 
void debug_vprintf (dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt, va_list ap)
 Write a log message. More...
 
void debug_printf (dbg_level level, const char *module, const int mlen, const char *function, const int flen, int prefix, const char *fmt,...)
 
void debug_assert_fail (const char *module, const int mlen, const char *function, const int flen, const char *file, int line, const char *expr)
 
void debug_destroy (void)
 
void debug_set_logfile (const char *path)
 
void debug_dump_mallocs (void)
 
void * debug_malloc (const char *where, int line, const char *func, int size)
 
void * debug_malloc0 (const char *where, int line, const char *func, int size)
 
char * debug_strdup (const char *where, int line, const char *func, const char *ptr)
 
char * debug_guard (const char *where, int line, const char *func, char *str)
 
void debug_free (const char *where, int line, const char *func, void *ptr)
 
void debug_free_func (void *ptr)
 
void debug_finished (void)
 
void * debug_realloc (const char *where, int line, const char *func, void *ptr, int size)
 
void debug_set_global_level (dbg_level level, int override_old_value)
 

Variables

dbg_level max_debug_level
 

Macro Definition Documentation

◆ dbg

#define dbg (   level,
  ... 
)    { if (max_debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }

◆ dbg_assert

#define dbg_assert (   expr)    ((expr) ? (void) 0 : debug_assert_fail(dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),__FILE__,__LINE__,dbg_str1(expr)))

◆ dbg_guard

#define dbg_guard (   x)    x

◆ dbg_module

#define dbg_module   dbg_str1(MODULE)

◆ dbg_str1

#define dbg_str1 (   x)    dbg_str2(x)

◆ dbg_str2

#define dbg_str2 (   x)    #x

◆ DEBUG_MODULE_GLOBAL

#define DEBUG_MODULE_GLOBAL   "global"

◆ g_free_func

#define g_free_func   g_free

Enumeration Type Documentation

◆ dbg_level

enum dbg_level

Navit, a modular navigation system. Copyright (C) 2005-2008 Navit Team

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.

You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Possible debug levels (inspired by SLF4J).

Enumerator
lvl_unset 

Internal use only, do not use for logging.

lvl_error 

Error: something did not work.

lvl_warning 

Warning: something may not have worked.

lvl_info 

Informational message. Should make sense to non-programmers.

lvl_debug 

Debug output: (almost) anything goes.

Function Documentation

◆ debug_assert_fail()

void debug_assert_fail ( const char *  module,
const int  mlen,
const char *  function,
const int  flen,
const char *  file,
int  line,
const char *  expr 
)

References debug_printf(), and lvl_error.

◆ debug_destroy()

void debug_destroy ( void  )

References debug_fp.

Referenced by debug_finished(), and debug_set_logfile().

◆ debug_dump_mallocs()

◆ debug_finished()

void debug_finished ( void  )

◆ debug_free()

void debug_free ( const char *  where,
int  line,
const char *  func,
void *  ptr 
)

◆ debug_free_func()

void debug_free_func ( void *  ptr)

References debug_free().

◆ debug_guard()

char* debug_guard ( const char *  where,
int  line,
const char *  func,
char *  str 
)

References debug_strdup().

◆ debug_init()

void debug_init ( const char *  program_name)

References debug_fp, debug_hash, gdb_program, and sigsegv().

Referenced by main_real().

◆ debug_level_get()

dbg_level debug_level_get ( const char *  name)

◆ debug_level_set()

void debug_level_set ( const char *  name,
dbg_level  level 
)

◆ debug_malloc()

◆ debug_malloc0()

void* debug_malloc0 ( const char *  where,
int  line,
const char *  func,
int  size 
)

References debug_malloc(), and size.

◆ debug_new()

struct debug* debug_new ( struct attr parent,
struct attr **  attrs 
)

◆ debug_printf()

void debug_printf ( dbg_level  level,
const char *  module,
const int  mlen,
const char *  function,
const int  flen,
int  prefix,
const char *  fmt,
  ... 
)

References debug_vprintf().

Referenced by debug_assert_fail(), and profile_timer().

◆ debug_realloc()

void* debug_realloc ( const char *  where,
int  line,
const char *  func,
void *  ptr,
int  size 
)

References debug_free(), debug_malloc(), and size.

◆ debug_set_global_level()

void debug_set_global_level ( dbg_level  level,
int  override_old_value 
)

◆ debug_set_logfile()

void debug_set_logfile ( const char *  path)

References debug_destroy(), and debug_fp.

Referenced by main_real().

◆ debug_strdup()

char* debug_strdup ( const char *  where,
int  line,
const char *  func,
const char *  ptr 
)

References debug_malloc(), and size.

Referenced by debug_guard().

◆ debug_vprintf()

void debug_vprintf ( dbg_level  level,
const char *  module,
const int  mlen,
const char *  function,
const int  flen,
int  prefix,
const char *  fmt,
va_list  ap 
)

Write a log message.

Parameters
levelThe level of the message. The message will only be written if level is higher than the minimum (global, per module or per function)
moduleThe name of the module that is initiating the log message
mlenThe length of string module
functionThe name of the function that is initiating the log message
flenThe length of string function
prefixForce prepending the message with context information (a timestamp, if timestamp_prefix is set), and the module and function name
fmtThe format string that specifies how subsequent arguments are output
apA list of arguments to use for substitution in the format string

References dbg_assert, dbg_level_to_string(), debug_fp, debug_level_get(), debug_timestamp(), global_debug_level, and timestamp_prefix.

Referenced by debug_printf(), logfn(), and profile_timer().

Variable Documentation

◆ max_debug_level

dbg_level max_debug_level
extern