Change per-file debug and verbose levels to be per-module, the way
authorKevin P. Fleming <kpfleming@digium.com>
Tue, 23 Mar 2010 14:22:27 +0000 (14:22 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Tue, 23 Mar 2010 14:22:27 +0000 (14:22 +0000)
users expect them to work.

'core set debug' and 'core set verbose' can optionally change the
level for a specific filename; however, this is actually for a
specific source file name, not the module that source file is included
in. With examples like chan_sip, chan_iax2, chan_misdn and others
consisting of multiple source files, this will not lead to the
behavior that users expect. If they want to set the debug level for
chan_sip, they want it set for all of chan_sip, and not to have to
also set it for reqresp_parser and other files that comprise the
chan_sip module.

This patch changes this functionality to be module-name based instead
of file-name based.

To make this work, some Makefile modifications were required to ensure
that the AST_MODULE definition is present in each object file produced
for each module as well.

Review: https://reviewboard.asterisk.org/r/574/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@253917 65c4cc65-6c06-0410-ace0-fbb531ad65f3

CHANGES
Makefile.moddir_rules
channels/Makefile
codecs/Makefile
include/asterisk/logger.h
include/asterisk/options.h
main/Makefile
main/cli.c
pbx/Makefile
res/Makefile

diff --git a/CHANGES b/CHANGES
index df47a32..12e3614 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -426,6 +426,17 @@ Miscellaneous
  * chan_dahdi now supports reporting alarms over AMI either by channel or span via
    the reportalarms config option.
 
+CLI Changes
+-----------
+ * The 'core set debug' and 'core set verbose' commands, in previous versions, could
+   optionally accept a filename, to apply the setting only to the code generated from
+   that source file when Asterisk was built. However, there are some modules in Asterisk
+   that are composed of multiple source files, so this did not result in the behavior
+   that users expected. In this version, 'core set debug' and 'core set verbose'
+   can optionally accept *module* names instead (with or without the .so extension),
+   which applies the setting to the entire module specified, regardless of which source
+   files it was built from.
+
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.6.1 to Asterisk 1.6.2  -------------
 ------------------------------------------------------------------------------
index 72d4c2a..00494a8 100644 (file)
@@ -54,10 +54,16 @@ endif
 
 # Both C++ and C++ sources need their module name in AST_MODULE
 # We also pass whatever _INCLUDE list is generated by menuselect
-# (they are stored in file 'makeopts')
+# (they are stored in file 'makeopts'). This is also necessary
+# for components used to build modules, which can't be determined
+# by the rules in this file, so the MOD_ASTCFLAGS definition
+# is used to collect the required flags for a module... which can
+# then be used any place they are required.
+
+MOD_ASTCFLAGS=-DAST_MODULE=\"$(1)\" $(MENUSELECT_OPTS_$(1):%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$(1)),$(value $(dep)_INCLUDE))
 
 $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \
-       _ASTCFLAGS+= -DAST_MODULE=\"$*\" $(MENUSELECT_OPTS_$*:%=-D%) $(foreach dep,$(MENUSELECT_DEPENDS_$*),$(value $(dep)_INCLUDE))
+       _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*)
 
 ifeq ($(findstring $(OSARCH), mingw32 cygwin ),)
    # don't define -fPIC on mingw32 and cygwin, it is the default
index 516b548..c8f4d80 100644 (file)
@@ -70,8 +70,11 @@ dist-clean::
        rm -f h323/Makefile
 
 $(if $(filter chan_iax2,$(EMBEDDED_MODS)),modules.link,chan_iax2.so): iax2-parser.o iax2-provision.o
+iax2-parser.o iax2-provision.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_iax2)
 $(if $(filter chan_sip,$(EMBEDDED_MODS)),modules.link,chan_sip.so): $(subst .c,.o,$(wildcard sip/*.c))
+$(subst .c,.o,$(wildcard sip/*.c)): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_sip)
 $(if $(filter chan_dahdi,$(EMBEDDED_MODS)),modules.link,chan_dahdi.so): sig_analog.o sig_pri.o
+sig_analog.o sig_pri.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_dahdi)
 
 ifneq ($(filter chan_h323,$(EMBEDDED_MODS)),)
 modules.link: h323/libchanh323.a
@@ -94,8 +97,10 @@ misdn_config.o: _ASTCFLAGS+=-Imisdn
 misdn/isdn_lib.o: _ASTCFLAGS+=-Wno-strict-aliasing
 
 $(if $(filter chan_misdn,$(EMBEDDED_MODS)),modules.link,chan_misdn.so): misdn_config.o misdn/isdn_lib.o misdn/isdn_msg_parser.o
+misdn_config.o misdn/isdn_lib.o misdn/isdn_msg_parser.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_misdn)
 
 $(if $(filter chan_oss,$(EMBEDDED_MODS)),modules.link,chan_oss.so): console_video.o vgrabbers.o console_board.o
+console_video.o vgrabbers.o console_board.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_oss)
 
 chan_usbradio.o: ./xpmr/xpmr.c ./xpmr/xpmr.h ./xpmr/xpmr_coef.h
 
index 4d00591..846c163 100644 (file)
@@ -50,3 +50,4 @@ $(LIBILBC):
 $(if $(filter codec_ilbc,$(EMBEDDED_MODS)),modules.link,codec_ilbc.so): $(LIBILBC)
 
 $(if $(filter codec_g722,$(EMBEDDED_MODS)),modules.link,codec_g722.so): g722/g722_encode.o g722/g722_decode.o
+g722/g722_encode.o g722/g722_decode.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,codec_g722)
index 75d07d6..c829843 100644 (file)
@@ -181,18 +181,18 @@ void ast_console_toggle_loglevel(int fd, int level, int state);
 #define NUMLOGLEVELS 6
 
 /*!
- * \brief Get the debug level for a file
+ * \brief Get the debug level for a module
  * \param file the filename
  * \return the debug level
  */
-unsigned int ast_debug_get_by_file(const char *file);
+unsigned int ast_debug_get_by_module(const char *module);
 
 /*!
- * \brief Get the debug level for a file
+ * \brief Get the verbose level for a module
  * \param file the filename
- * \return the debug level
+ * \return the verbose level
  */
-unsigned int ast_verbose_get_by_file(const char *file);
+unsigned int ast_verbose_get_by_module(const char *module);
 
 /*!
  * \brief Register a new logger level
@@ -231,11 +231,11 @@ void ast_logger_unregister_level(const char *name);
  *        to get logged
  */
 #define ast_debug(level, ...) do {       \
-       if (option_debug >= (level) || (ast_opt_dbg_file && ast_debug_get_by_file(__FILE__) >= (level)) ) \
+       if (option_debug >= (level) || (ast_opt_dbg_module && ast_debug_get_by_module(AST_MODULE) >= (level)) ) \
                ast_log(AST_LOG_DEBUG, __VA_ARGS__); \
 } while (0)
 
-#define VERBOSITY_ATLEAST(level) (option_verbose >= (level) || (ast_opt_verb_file && ast_verbose_get_by_file(__FILE__) >= (level)))
+#define VERBOSITY_ATLEAST(level) (option_verbose >= (level) || (ast_opt_verb_module && ast_verbose_get_by_module(AST_MODULE) >= (level)))
 
 #define ast_verb(level, ...) do { \
        if (VERBOSITY_ATLEAST((level)) ) { \
index d3305be..c76e833 100644 (file)
@@ -78,10 +78,10 @@ enum ast_option_flags {
        AST_OPT_FLAG_ALWAYS_FORK = (1 << 21),
        /*! Disable log/verbose output to remote consoles */
        AST_OPT_FLAG_MUTE = (1 << 22),
-       /*! There is a per-file debug setting */
-       AST_OPT_FLAG_DEBUG_FILE = (1 << 23),
-       /*! There is a per-file verbose setting */
-       AST_OPT_FLAG_VERBOSE_FILE = (1 << 24),
+       /*! There is a per-module debug setting */
+       AST_OPT_FLAG_DEBUG_MODULE = (1 << 23),
+       /*! There is a per-module verbose setting */
+       AST_OPT_FLAG_VERBOSE_MODULE = (1 << 24),
        /*! Terminal colors should be adjusted for a light-colored background */
        AST_OPT_FLAG_LIGHT_BACKGROUND = (1 << 25),
        /*! Count Initiated seconds in CDR's */
@@ -119,10 +119,10 @@ enum ast_option_flags {
 #define ast_opt_internal_timing                ast_test_flag(&ast_options, AST_OPT_FLAG_INTERNAL_TIMING)
 #define ast_opt_always_fork            ast_test_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK)
 #define ast_opt_mute                   ast_test_flag(&ast_options, AST_OPT_FLAG_MUTE)
-#define ast_opt_dbg_file               ast_test_flag(&ast_options, AST_OPT_FLAG_DEBUG_FILE)
-#define ast_opt_verb_file              ast_test_flag(&ast_options, AST_OPT_FLAG_VERBOSE_FILE)
-#define ast_opt_light_background               ast_test_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND)
-#define ast_opt_force_black_background         ast_test_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND)
+#define ast_opt_dbg_module             ast_test_flag(&ast_options, AST_OPT_FLAG_DEBUG_MODULE)
+#define ast_opt_verb_module            ast_test_flag(&ast_options, AST_OPT_FLAG_VERBOSE_MODULE)
+#define ast_opt_light_background       ast_test_flag(&ast_options, AST_OPT_FLAG_LIGHT_BACKGROUND)
+#define ast_opt_force_black_background ast_test_flag(&ast_options, AST_OPT_FLAG_FORCE_BLACK_BACKGROUND)
 #define ast_opt_hide_connect           ast_test_flag(&ast_options, AST_OPT_FLAG_HIDE_CONSOLE_CONNECT)
 #define ast_opt_lock_confdir           ast_test_flag(&ast_options, AST_OPT_FLAG_LOCK_CONFIG_DIR)
 
index ade3968..a019a08 100644 (file)
@@ -165,6 +165,8 @@ ifneq ($(findstring ENABLE_UPLOADS,$(MENUSELECT_CFLAGS)),)
 GMIMELDFLAGS+=$(GMIME_LIB)
 endif
 
+$(OBJS): _ASTCFLAGS+=-DAST_MODULE=\"core\"
+
 $(MAIN_TGT): $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) asterisk.exports
        @$(CC) -c -o buildinfo.o $(_ASTCFLAGS) buildinfo.c $(ASTCFLAGS)
        $(ECHO_PREFIX) echo "   [LD] $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS) -> $@"
index 6d227fb..99dc1b5 100644 (file)
@@ -77,20 +77,20 @@ AST_MUTEX_DEFINE_STATIC(permsconfiglock);
 static AST_RWLIST_HEAD_STATIC(cli_perms, usergroup_cli_perm);
 
 /*!
- * \brief map a debug or verbose value to a filename
+ * \brief map a debug or verbose level to a module name
  */
-struct ast_debug_file {
+struct module_level {
        unsigned int level;
-       AST_RWLIST_ENTRY(ast_debug_file) entry;
-       char filename[0];
+       AST_RWLIST_ENTRY(module_level) entry;
+       char module[0];
 };
 
-AST_RWLIST_HEAD(debug_file_list, ast_debug_file);
+AST_RWLIST_HEAD(module_level_list, module_level);
 
-/*! list of filenames and their debug settings */
-static struct debug_file_list debug_files;
-/*! list of filenames and their verbose settings */
-static struct debug_file_list verbose_files;
+/*! list of module names and their debug levels */
+static struct module_level_list debug_modules;
+/*! list of module names and their verbose levels */
+static struct module_level_list verbose_modules;
 
 AST_THREADSTORAGE(ast_cli_buf);
 
@@ -115,36 +115,36 @@ void ast_cli(int fd, const char *fmt, ...)
        }
 }
 
-unsigned int ast_debug_get_by_file(const char *file) 
+unsigned int ast_debug_get_by_module(const char *module) 
 {
-       struct ast_debug_file *adf;
+       struct module_level *ml;
        unsigned int res = 0;
 
-       AST_RWLIST_RDLOCK(&debug_files);
-       AST_LIST_TRAVERSE(&debug_files, adf, entry) {
-               if (!strncasecmp(adf->filename, file, strlen(adf->filename))) {
-                       res = adf->level;
+       AST_RWLIST_RDLOCK(&debug_modules);
+       AST_LIST_TRAVERSE(&debug_modules, ml, entry) {
+               if (!strcasecmp(ml->module, module)) {
+                       res = ml->level;
                        break;
                }
        }
-       AST_RWLIST_UNLOCK(&debug_files);
+       AST_RWLIST_UNLOCK(&debug_modules);
 
        return res;
 }
 
-unsigned int ast_verbose_get_by_file(const char *file) 
+unsigned int ast_verbose_get_by_module(const char *module) 
 {
-       struct ast_debug_file *adf;
+       struct module_level *ml;
        unsigned int res = 0;
 
-       AST_RWLIST_RDLOCK(&verbose_files);
-       AST_LIST_TRAVERSE(&verbose_files, adf, entry) {
-               if (!strncasecmp(adf->filename, file, strlen(file))) {
-                       res = adf->level;
+       AST_RWLIST_RDLOCK(&verbose_modules);
+       AST_LIST_TRAVERSE(&verbose_modules, ml, entry) {
+               if (!strcasecmp(ml->module, module)) {
+                       res = ml->level;
                        break;
                }
        }
-       AST_RWLIST_UNLOCK(&verbose_files);
+       AST_RWLIST_UNLOCK(&verbose_modules);
 
        return res;
 }
@@ -305,17 +305,17 @@ static char *handle_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args
  * \brief Find the debug or verbose file setting 
  * \arg debug 1 for debug, 0 for verbose
  */
-static struct ast_debug_file *find_debug_file(const char *fn, unsigned int debug)
+static struct module_level *find_module_level(const char *module, unsigned int debug)
 {
-       struct ast_debug_file *df = NULL;
-       struct debug_file_list *dfl = debug ? &debug_files : &verbose_files;
+       struct module_level *ml;
+       struct module_level_list *mll = debug ? &debug_modules : &verbose_modules;
 
-       AST_LIST_TRAVERSE(dfl, df, entry) {
-               if (!strcasecmp(df->filename, fn))
-                       break;
+       AST_LIST_TRAVERSE(mll, ml, entry) {
+               if (!strcasecmp(ml->module, module))
+                       return ml;
        }
 
-       return df;
+       return NULL;
 }
 
 static char *complete_number(const char *partial, unsigned int min, unsigned int max, int n)
@@ -369,23 +369,22 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
        const char *argv3 = a->argv ? S_OR(a->argv[3], "") : "";
        int *dst;
        char *what;
-       struct debug_file_list *dfl;
-       struct ast_debug_file *adf;
-       const char *fn;
+       struct module_level_list *mll;
+       struct module_level *ml;
 
        switch (cmd) {
        case CLI_INIT:
                e->command = "core set {debug|verbose}";
                e->usage =
 #if !defined(LOW_MEMORY)
-                       "Usage: core set {debug|verbose} [atleast] <level> [filename]\n"
+                       "Usage: core set {debug|verbose} [atleast] <level> [module]\n"
 #else
                        "Usage: core set {debug|verbose} [atleast] <level>\n"
 #endif
                        "       core set {debug|verbose} off\n"
 #if !defined(LOW_MEMORY)
-                       "       Sets level of debug or verbose messages to be displayed or \n"
-                       "       sets a filename to display debug messages from.\n"
+                       "       Sets level of debug or verbose messages to be displayed or\n"
+                       "       sets a module name to display debug messages from.\n"
 #else
                        "       Sets level of debug or verbose messages to be displayed.\n"
 #endif
@@ -440,13 +439,14 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
                unsigned int debug = (*what == 'C');
                newlevel = 0;
 
-               dfl = debug ? &debug_files : &verbose_files;
+               mll = debug ? &debug_modules : &verbose_modules;
 
-               AST_RWLIST_WRLOCK(dfl);
-               while ((adf = AST_RWLIST_REMOVE_HEAD(dfl, entry)))
-                       ast_free(adf);
-               ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
-               AST_RWLIST_UNLOCK(dfl);
+               AST_RWLIST_WRLOCK(mll);
+               while ((ml = AST_RWLIST_REMOVE_HEAD(mll, entry))) {
+                       ast_free(ml);
+               }
+               ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
+               AST_RWLIST_UNLOCK(mll);
 
                goto done;
        }
@@ -458,43 +458,47 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
                return CLI_SHOWUSAGE;
        if (argc == e->args + atleast + 2) {
                unsigned int debug = (*what == 'C');
-               dfl = debug ? &debug_files : &verbose_files;
+               char *mod = ast_strdupa(argv[e->args + atleast + 1]);
 
-               fn = argv[e->args + atleast + 1];
+               mll = debug ? &debug_modules : &verbose_modules;
+
+               if ((strlen(mod) > 3) && !strcasecmp(mod + strlen(mod) - 3, ".so")) {
+                       mod[strlen(mod) - 3] = '\0';
+               }
 
-               AST_RWLIST_WRLOCK(dfl);
+               AST_RWLIST_WRLOCK(mll);
 
-               if ((adf = find_debug_file(fn, debug)) && !newlevel) {
-                       AST_RWLIST_REMOVE(dfl, adf, entry);
-                       if (AST_RWLIST_EMPTY(dfl))
-                               ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
-                       AST_RWLIST_UNLOCK(dfl);
-                       ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, adf->level, fn);
-                       ast_free(adf);
+               if ((ml = find_module_level(mod, debug)) && !newlevel) {
+                       AST_RWLIST_REMOVE(mll, ml, entry);
+                       if (AST_RWLIST_EMPTY(mll))
+                               ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
+                       AST_RWLIST_UNLOCK(mll);
+                       ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, ml->level, mod);
+                       ast_free(ml);
                        return CLI_SUCCESS;
                }
 
-               if (adf) {
-                       if ((atleast && newlevel < adf->level) || adf->level == newlevel) {
-                               ast_cli(fd, "%s is %d for '%s'\n", what, adf->level, fn);
-                               AST_RWLIST_UNLOCK(dfl);
+               if (ml) {
+                       if ((atleast && newlevel < ml->level) || ml->level == newlevel) {
+                               ast_cli(fd, "%s is %d for '%s'\n", what, ml->level, mod);
+                               AST_RWLIST_UNLOCK(mll);
                                return CLI_SUCCESS;
                        }
-               } else if (!(adf = ast_calloc(1, sizeof(*adf) + strlen(fn) + 1))) {
-                       AST_RWLIST_UNLOCK(dfl);
+               } else if (!(ml = ast_calloc(1, sizeof(*ml) + strlen(mod) + 1))) {
+                       AST_RWLIST_UNLOCK(mll);
                        return CLI_FAILURE;
                }
 
-               oldval = adf->level;
-               adf->level = newlevel;
-               strcpy(adf->filename, fn);
+               oldval = ml->level;
+               ml->level = newlevel;
+               strcpy(ml->module, mod);
 
-               ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+               ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE);
 
-               AST_RWLIST_INSERT_TAIL(dfl, adf, entry);
-               AST_RWLIST_UNLOCK(dfl);
+               AST_RWLIST_INSERT_TAIL(mll, ml, entry);
+               AST_RWLIST_UNLOCK(mll);
 
-               ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, adf->level, adf->filename);
+               ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, ml->level, ml->module);
 
                return CLI_SUCCESS;
        }
index 99d97f2..a328dc4 100644 (file)
@@ -32,3 +32,4 @@ dundi-parser.o: _ASTCFLAGS+=-I.
 pbx_gtkconsole.o: _ASTCFLAGS+=-Wno-strict-prototypes
 
 $(if $(filter pbx_dundi,$(EMBEDDED_MODS)),modules.link,pbx_dundi.so): dundi-parser.o
+dundi-parser.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,pbx_dundi)
index aeb3170..2f2abe2 100644 (file)
@@ -37,13 +37,14 @@ ael/ael_lex.o: _ASTCFLAGS+=-I. -Iael -Wno-unused
 ael/ael.tab.o: ael/ael.tab.c ael/ael.tab.h ../include/asterisk/ael_structs.h
 ael/ael.tab.o: _ASTCFLAGS+=-I. -Iael -DYYENABLE_NLS=0
 
-ais/clm.o ais/evt.o: _ASTCFLAGS+=${AIS_INCLUDE}
-
 $(if $(filter res_ais,$(EMBEDDED_MODS)),modules.link,res_ais.so): ais/clm.o ais/evt.o
+ais/clm.o ais/evt.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_ais)
 
 $(if $(filter res_snmp,$(EMBEDDED_MODS)),modules.link,res_snmp.so): snmp/agent.o
+snmp/agent.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_snmp)
 
 $(if $(filter res_ael_share,$(EMBEDDED_MODS)),modules.link,res_ael_share.so): ael/ael_lex.o ael/ael.tab.o ael/pval.o
+ael/ael_lex.o ael/ael.tab.o ael/pval.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_ael_share)
 
 ifneq ($(findstring REBUILD_PARSERS,$(MENUSELECT_CFLAGS)),)
 ael/ael_lex.c: ael/ael.flex