navit  0.5.3-trunk
debug.c File Reference
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <glib.h>
#include <sys/time.h>
#include "config.h"
#include "file.h"
#include "item.h"
#include "debug.h"
#include <unistd.h>

Data Structures

struct  malloc_head
 
struct  malloc_tail
 

Macros

#define DEFAULT_DEBUG_LEVEL   lvl_error
 
#define GLOBAL_DEBUG_LEVEL_UNSET   lvl_unset
 
#define __builtin_return_address(x)   NULL
 

Functions

static void sigsegv (int sig)
 
void debug_init (const char *program_name)
 
static void debug_update_level (gpointer key, gpointer value, gpointer user_data)
 
void debug_set_global_level (dbg_level level, int override_old_value)
 
void debug_level_set (const char *name, dbg_level level)
 
static dbg_level parse_dbg_level (struct attr *dbg_level_attr, struct attr *level_attr)
 
struct debugdebug_new (struct attr *parent, struct attr **attrs)
 
dbg_level debug_level_get (const char *message_category)
 
static void debug_timestamp (char *buffer)
 Write a timestamp to a string buffer. More...
 
static char * dbg_level_to_string (dbg_level level)
 
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)
 
void * debug_realloc (const char *where, int line, const char *func, void *ptr, 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)
 

Variables

dbg_level max_debug_level =DEFAULT_DEBUG_LEVEL
 
dbg_level global_debug_level =GLOBAL_DEBUG_LEVEL_UNSET
 
int segv_level =0
 
int timestamp_prefix =0
 
static int dummy
 
static GHashTable * debug_hash
 
static gchar * gdb_program
 
static FILE * debug_fp
 
struct malloc_headmalloc_heads
 
int mallocs
 
int debug_malloc_size
 
int debug_malloc_size_m
 

Macro Definition Documentation

◆ __builtin_return_address

#define __builtin_return_address (   x)    NULL

◆ DEFAULT_DEBUG_LEVEL

#define DEFAULT_DEBUG_LEVEL   lvl_error

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 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 General Public License for more details.

You should have received a copy of the GNU 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.

◆ GLOBAL_DEBUG_LEVEL_UNSET

#define GLOBAL_DEBUG_LEVEL_UNSET   lvl_unset

Function Documentation

◆ dbg_level_to_string()

static char* dbg_level_to_string ( dbg_level  level)
static

References lvl_debug, lvl_error, lvl_info, lvl_unset, and lvl_warning.

Referenced by debug_vprintf().

◆ 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 *  message_category)

◆ 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_timestamp()

static void debug_timestamp ( char *  buffer)
static

Write a timestamp to a string buffer.

Timestamp has the format "HH:MM:SS:mmm|" (with mmm=milliseconds), or under Windows "SSSSS:uuuuuu|" (with uuuuuu=microseconds)

Parameters
[out]bufferThe buffer to write to
Warning
Buffer overflow may occur on buffer, if it is less than 14-bytes long (13 chars will be stored at max)

Referenced by debug_vprintf().

◆ debug_update_level()

static void debug_update_level ( gpointer  key,
gpointer  value,
gpointer  user_data 
)
static

References max_debug_level, and value.

Referenced by debug_level_set().

◆ 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().

◆ parse_dbg_level()

static dbg_level parse_dbg_level ( struct attr dbg_level_attr,
struct attr level_attr 
)
static

◆ sigsegv()

static void sigsegv ( int  sig)
static

References exit, gdb_program, and segv_level.

Referenced by debug_init(), and debug_level_set().

Variable Documentation

◆ debug_fp

FILE* debug_fp
static

◆ debug_hash

GHashTable* debug_hash
static

◆ debug_malloc_size

int debug_malloc_size

Referenced by debug_free(), and debug_malloc().

◆ debug_malloc_size_m

int debug_malloc_size_m

Referenced by debug_malloc().

◆ dummy

int dummy
static

Referenced by debug_new().

◆ gdb_program

gchar* gdb_program
static

Referenced by debug_finished(), debug_init(), and sigsegv().

◆ global_debug_level

◆ malloc_heads

struct malloc_head * malloc_heads

◆ mallocs

int mallocs

◆ max_debug_level

◆ segv_level

int segv_level =0

Referenced by debug_level_set(), and sigsegv().

◆ timestamp_prefix

int timestamp_prefix =0

Referenced by debug_level_set(), and debug_vprintf().