]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - lib/dynamic_debug.c
sparc: fix bad merge of sparc Kconfig
[karo-tx-linux.git] / lib / dynamic_debug.c
index 8675717c0f16e6fbb1989edffbda0ebeec00e4cd..7ca29a0a3019685291e33a8b3df86669f9378dea 100644 (file)
@@ -338,7 +338,7 @@ static int check_set(const char **dest, char *src, char *name)
  * Returns 0 on success, <0 on error.
  */
 static int ddebug_parse_query(char *words[], int nwords,
-                              struct ddebug_query *query)
+                       struct ddebug_query *query, const char *modname)
 {
        unsigned int i;
        int rc;
@@ -348,6 +348,10 @@ static int ddebug_parse_query(char *words[], int nwords,
                return -EINVAL;
        memset(query, 0, sizeof(*query));
 
+       if (modname)
+               /* support $modname.dyndbg=<multiple queries> */
+               query->module = modname;
+
        for (i = 0 ; i < nwords ; i += 2) {
                if (!strcmp(words[i], "func"))
                        rc = check_set(&query->function, words[i+1], "func");
@@ -444,7 +448,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
        return 0;
 }
 
-static int ddebug_exec_query(char *query_string)
+static int ddebug_exec_query(char *query_string, const char *modname)
 {
        unsigned int flags = 0, mask = 0;
        struct ddebug_query query;
@@ -455,7 +459,7 @@ static int ddebug_exec_query(char *query_string)
        nwords = ddebug_tokenize(query_string, words, MAXWORDS);
        if (nwords <= 0)
                return -EINVAL;
-       if (ddebug_parse_query(words, nwords-1, &query))
+       if (ddebug_parse_query(words, nwords-1, &query, modname))
                return -EINVAL;
        if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
                return -EINVAL;
@@ -471,7 +475,7 @@ static int ddebug_exec_query(char *query_string)
    last error or number of matching callsites.  Module name is either
    in param (for boot arg) or perhaps in query string.
 */
-static int ddebug_exec_queries(char *query)
+static int ddebug_exec_queries(char *query, const char *modname)
 {
        char *split;
        int i, errs = 0, exitcode = 0, rc, nfound = 0;
@@ -487,7 +491,7 @@ static int ddebug_exec_queries(char *query)
 
                vpr_info("query %d: \"%s\"\n", i, query);
 
-               rc = ddebug_exec_query(query);
+               rc = ddebug_exec_query(query, modname);
                if (rc < 0) {
                        errs++;
                        exitcode = rc;
@@ -652,7 +656,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
        tmpbuf[len] = '\0';
        vpr_info("read %d bytes from userspace\n", (int)len);
 
-       ret = ddebug_exec_queries(tmpbuf);
+       ret = ddebug_exec_queries(tmpbuf, NULL);
        kfree(tmpbuf);
        if (ret < 0)
                return ret;
@@ -862,6 +866,46 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 }
 EXPORT_SYMBOL_GPL(ddebug_add_module);
 
+/* helper for ddebug_dyndbg_(boot|module)_param_cb */
+static int ddebug_dyndbg_param_cb(char *param, char *val,
+                               const char *modname, int on_err)
+{
+       char *sep;
+
+       sep = strchr(param, '.');
+       if (sep) {
+               /* needed only for ddebug_dyndbg_boot_param_cb */
+               *sep = '\0';
+               modname = param;
+               param = sep + 1;
+       }
+       if (strcmp(param, "dyndbg"))
+               return on_err; /* determined by caller */
+
+       ddebug_exec_queries((val ? val : "+p"), modname);
+
+       return 0; /* query failure shouldnt stop module load */
+}
+
+/* handle both dyndbg and $module.dyndbg params at boot */
+static int ddebug_dyndbg_boot_param_cb(char *param, char *val,
+                               const char *unused)
+{
+       vpr_info("%s=\"%s\"\n", param, val);
+       return ddebug_dyndbg_param_cb(param, val, NULL, 0);
+}
+
+/*
+ * modprobe foo finds foo.params in boot-args, strips "foo.", and
+ * passes them to load_module().  This callback gets unknown params,
+ * processes dyndbg params, rejects others.
+ */
+int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)
+{
+       vpr_info("module: %s %s=\"%s\"\n", module, param, val);
+       return ddebug_dyndbg_param_cb(param, val, module, -ENOENT);
+}
+
 static void ddebug_table_free(struct ddebug_table *dt)
 {
        list_del_init(&dt->link);
@@ -929,8 +973,10 @@ static int __init dynamic_debug_init(void)
 {
        struct _ddebug *iter, *iter_start;
        const char *modname = NULL;
+       char *cmdline;
        int ret = 0;
-       int n = 0;
+       int n = 0, entries = 0, modct = 0;
+       int verbose_bytes = 0;
 
        if (__start___verbose == __stop___verbose) {
                pr_warn("_ddebug table is empty in a "
@@ -941,10 +987,15 @@ static int __init dynamic_debug_init(void)
        modname = iter->modname;
        iter_start = iter;
        for (; iter < __stop___verbose; iter++) {
+               entries++;
+               verbose_bytes += strlen(iter->modname) + strlen(iter->function)
+                       + strlen(iter->filename) + strlen(iter->format);
+
                if (strcmp(modname, iter->modname)) {
+                       modct++;
                        ret = ddebug_add_module(iter_start, n, modname);
                        if (ret)
-                               goto out_free;
+                               goto out_err;
                        n = 0;
                        modname = iter->modname;
                        iter_start = iter;
@@ -953,29 +1004,45 @@ static int __init dynamic_debug_init(void)
        }
        ret = ddebug_add_module(iter_start, n, modname);
        if (ret)
-               goto out_free;
+               goto out_err;
+
+       ddebug_init_success = 1;
+       vpr_info("%d modules, %d entries and %d bytes in ddebug tables,"
+               " %d bytes in (readonly) verbose section\n",
+               modct, entries, (int)( modct * sizeof(struct ddebug_table)),
+               verbose_bytes + (int)(__stop___verbose - __start___verbose));
 
-       /* ddebug_query boot param got passed -> set it up */
+       /* apply ddebug_query boot param, dont unload tables on err */
        if (ddebug_setup_string[0] != '\0') {
-               ret = ddebug_exec_queries(ddebug_setup_string);
+               pr_warn("ddebug_query param name is deprecated,"
+                       " change it to dyndbg\n");
+               ret = ddebug_exec_queries(ddebug_setup_string, NULL);
                if (ret < 0)
                        pr_warn("Invalid ddebug boot param %s",
                                ddebug_setup_string);
                else
                        pr_info("%d changes by ddebug_query\n", ret);
-
-               /* keep tables even on ddebug_query parse error */
-               ret = 0;
        }
+       /* now that ddebug tables are loaded, process all boot args
+        * again to find and activate queries given in dyndbg params.
+        * While this has already been done for known boot params, it
+        * ignored the unknown ones (dyndbg in particular).  Reusing
+        * parse_args avoids ad-hoc parsing.  This will also attempt
+        * to activate queries for not-yet-loaded modules, which is
+        * slightly noisy if verbose, but harmless.
+        */
+       cmdline = kstrdup(saved_command_line, GFP_KERNEL);
+       parse_args("dyndbg params", cmdline, NULL,
+                  0, 0, 0, &ddebug_dyndbg_boot_param_cb);
+       kfree(cmdline);
+       return 0;
 
-out_free:
-       if (ret)
-               ddebug_remove_all_tables();
-       else
-               ddebug_init_success = 1;
+out_err:
+       ddebug_remove_all_tables();
        return 0;
 }
 /* Allow early initialization for boot messages via boot param */
-arch_initcall(dynamic_debug_init);
+early_initcall(dynamic_debug_init);
+
 /* Debugfs setup must be done later */
-module_init(dynamic_debug_init_debugfs);
+fs_initcall(dynamic_debug_init_debugfs);