Ticket #977: debug.diff

File debug.diff, 3.5 KB (added by sleske, 8 years ago)

Patch to add global debug level & -d

  • navit/navit/debug.c

    commit 547b98bc71966f18bea1aa447af9a659fecd12a3
    Author: Sebastian Leske <Sebastian.Leske@sleske.name>
    Date:   Mon Dec 12 18:39:34 2011 +0100
    
        new "global" debug level; activate option -d
    
    diff --git a/navit/navit/debug.c b/navit/navit/debug.c
    index 0a2502d..0b08aaf 100644
    a b static struct sockaddr_in debug_sin; 
    5252#endif
    5353
    5454
    55 int debug_level=0;
     55int max_debug_level=0;
     56int global_debug_level=0;
    5657int segv_level=0;
    5758int timestamp_prefix=0;
    5859
    debug_init(const char *program_name) 
    99100static void
    100101debug_update_level(gpointer key, gpointer value, gpointer user_data)
    101102{
    102         if (debug_level < GPOINTER_TO_INT(value))
    103                 debug_level = GPOINTER_TO_INT(value);
     103        if (max_debug_level < GPOINTER_TO_INT(value))
     104                max_debug_level = GPOINTER_TO_INT(value);
    104105}
    105106
    106107void
    debug_level_set(const char *name, int level) 
    114115                        signal(SIGSEGV, NULL);
    115116        } else if (!strcmp(name, "timestamps")) {
    116117                timestamp_prefix=level;
     118        } else if (!strcmp(name, "global")) {
     119                global_debug_level=level;
    117120        } else {
    118                 debug_level=0;
     121                max_debug_level=0;
    119122                g_hash_table_insert(debug_hash, g_strdup(name), GINT_TO_POINTER(level));
    120123                g_hash_table_foreach(debug_hash, debug_update_level, NULL);
    121124        }
    debug_vprintf(int level, const char *module, const int mlen, const char *functio 
    204207        FILE *fp=debug_fp;
    205208
    206209        sprintf(buffer, "%s:%s", module, function);
    207         if (debug_level_get(module) >= level || debug_level_get(buffer) >= level) {
     210        if (global_debug_level >= level || debug_level_get(module) >= level || debug_level_get(buffer) >= level) {
    208211#if defined(DEBUG_WIN32_CE_MESSAGEBOX)
    209212                wchar_t muni[4096];
    210213#endif
  • navit/navit/debug.h

    diff --git a/navit/navit/debug.h b/navit/navit/debug.h
    index 31cdab3..922def0 100644
    a b extern "C" { 
    3131#define __PRETTY_FUNCTION__ __FUNCTION__
    3232#endif
    3333
    34 extern int debug_level;
     34extern int max_debug_level;
    3535#define dbg_str2(x) #x
    3636#define dbg_str1(x) dbg_str2(x)
    3737#define dbg_module dbg_str1(MODULE)
    38 #define dbg(level,...) { if (debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
     38#define dbg(level,...) { if (max_debug_level >= level) debug_printf(level,dbg_module,strlen(dbg_module),__PRETTY_FUNCTION__, strlen(__PRETTY_FUNCTION__),1,__VA_ARGS__); }
    3939#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)))
    4040
    4141#ifdef DEBUG_MALLOC
  • navit/navit/start_real.c

    diff --git a/navit/navit/start_real.c b/navit/navit/start_real.c
    index 5dc3d18..375430d 100644
    a b char **main_argv; 
    5757static void
    5858print_usage(void)
    5959{
    60         printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the debug output level to <n>. (TODO)\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n"));
     60        printf(_("navit usage:\nnavit [options] [configfile]\n\t-c <file>: use <file> as config file\n\t-d <n>: set the global debug output level to <n>.\n\t-h: print this usage info and exit.\n\t-v: Print the version and exit.\n"));
    6161}
    6262
    6363
    int main_real(int argc, char **argv) 
    130130                    config_file = optarg;
    131131                                break;
    132132                        case 'd':
    133                                 printf("TODO Verbose option is set to `%s'\n", optarg);
     133                                debug_level_set("global", atoi(optarg));
    134134                                break;
    135135                        case 'e':
    136136                                command=optarg;