2009-02-05 16:51:38 +00:00
|
|
|
/*
|
|
|
|
* lib/dynamic_debug.c
|
|
|
|
*
|
|
|
|
* make pr_debug()/dev_dbg() calls runtime configurable based upon their
|
|
|
|
* source module.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
|
|
|
|
* By Greg Banks <gnb@melbourne.sgi.com>
|
|
|
|
* Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
|
2011-01-23 16:17:24 +00:00
|
|
|
* Copyright (C) 2011 Bart Van Assche. All Rights Reserved.
|
2009-02-05 16:51:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-08-11 18:36:33 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
|
|
|
|
|
2009-02-05 16:51:38 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/ctype.h>
|
2009-12-15 02:01:06 +00:00
|
|
|
#include <linux/string.h>
|
2009-02-05 16:51:38 +00:00
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/dynamic_debug.h>
|
|
|
|
#include <linux/debugfs.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-09-17 15:09:17 +00:00
|
|
|
#include <linux/jump_label.h>
|
2011-01-23 16:17:24 +00:00
|
|
|
#include <linux/hardirq.h>
|
2011-02-03 23:59:58 +00:00
|
|
|
#include <linux/sched.h>
|
2011-08-11 18:36:21 +00:00
|
|
|
#include <linux/device.h>
|
2011-08-11 18:36:48 +00:00
|
|
|
#include <linux/netdevice.h>
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
extern struct _ddebug __start___verbose[];
|
|
|
|
extern struct _ddebug __stop___verbose[];
|
|
|
|
|
|
|
|
struct ddebug_table {
|
|
|
|
struct list_head link;
|
|
|
|
char *mod_name;
|
|
|
|
unsigned int num_ddebugs;
|
|
|
|
struct _ddebug *ddebugs;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ddebug_query {
|
|
|
|
const char *filename;
|
|
|
|
const char *module;
|
|
|
|
const char *function;
|
|
|
|
const char *format;
|
|
|
|
unsigned int first_lineno, last_lineno;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ddebug_iter {
|
|
|
|
struct ddebug_table *table;
|
|
|
|
unsigned int idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_MUTEX(ddebug_lock);
|
|
|
|
static LIST_HEAD(ddebug_tables);
|
|
|
|
static int verbose = 0;
|
2011-12-19 22:12:24 +00:00
|
|
|
module_param(verbose, int, 0644);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
/* Return the last part of a pathname */
|
|
|
|
static inline const char *basename(const char *path)
|
|
|
|
{
|
|
|
|
const char *tail = strrchr(path, '/');
|
|
|
|
return tail ? tail+1 : path;
|
|
|
|
}
|
|
|
|
|
2011-12-19 22:13:12 +00:00
|
|
|
/* Return the path relative to source root */
|
|
|
|
static inline const char *trim_prefix(const char *path)
|
|
|
|
{
|
|
|
|
int skip = strlen(__FILE__) - strlen("lib/dynamic_debug.c");
|
|
|
|
|
|
|
|
if (strncmp(path, __FILE__, skip))
|
|
|
|
skip = 0; /* prefix mismatch, don't skip */
|
|
|
|
|
|
|
|
return path + skip;
|
|
|
|
}
|
|
|
|
|
2011-01-23 16:17:24 +00:00
|
|
|
static struct { unsigned flag:8; char opt_char; } opt_array[] = {
|
|
|
|
{ _DPRINTK_FLAGS_PRINT, 'p' },
|
|
|
|
{ _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
|
|
|
|
{ _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
|
|
|
|
{ _DPRINTK_FLAGS_INCL_LINENO, 'l' },
|
|
|
|
{ _DPRINTK_FLAGS_INCL_TID, 't' },
|
2011-12-19 22:12:44 +00:00
|
|
|
{ _DPRINTK_FLAGS_NONE, '_' },
|
2011-01-23 16:17:24 +00:00
|
|
|
};
|
|
|
|
|
2009-02-05 16:51:38 +00:00
|
|
|
/* format a string into buf[] which describes the _ddebug's flags */
|
|
|
|
static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
|
|
|
|
size_t maxlen)
|
|
|
|
{
|
|
|
|
char *p = buf;
|
2011-01-23 16:17:24 +00:00
|
|
|
int i;
|
2009-02-05 16:51:38 +00:00
|
|
|
|
2011-12-19 22:12:44 +00:00
|
|
|
BUG_ON(maxlen < 6);
|
2011-01-23 16:17:24 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
|
|
|
|
if (dp->flags & opt_array[i].flag)
|
|
|
|
*p++ = opt_array[i].opt_char;
|
2009-02-05 16:51:38 +00:00
|
|
|
if (p == buf)
|
2011-12-19 22:12:44 +00:00
|
|
|
*p++ = '_';
|
2009-02-05 16:51:38 +00:00
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-12-19 22:13:16 +00:00
|
|
|
#define vpr_info_dq(q, msg) \
|
|
|
|
do { \
|
|
|
|
if (verbose) \
|
|
|
|
/* trim last char off format print */ \
|
|
|
|
pr_info("%s: func=\"%s\" file=\"%s\" " \
|
|
|
|
"module=\"%s\" format=\"%.*s\" " \
|
|
|
|
"lineno=%u-%u", \
|
|
|
|
msg, \
|
|
|
|
q->function ? q->function : "", \
|
|
|
|
q->filename ? q->filename : "", \
|
|
|
|
q->module ? q->module : "", \
|
|
|
|
(int)(q->format ? strlen(q->format) - 1 : 0), \
|
|
|
|
q->format ? q->format : "", \
|
|
|
|
q->first_lineno, q->last_lineno); \
|
|
|
|
} while (0)
|
|
|
|
|
2009-02-05 16:51:38 +00:00
|
|
|
/*
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
* Search the tables for _ddebug's which match the given `query' and
|
|
|
|
* apply the `flags' and `mask' to them. Returns number of matching
|
|
|
|
* callsites, normally the same as number of changes. If verbose,
|
|
|
|
* logs the changes. Takes ddebug_lock.
|
2009-02-05 16:51:38 +00:00
|
|
|
*/
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
static int ddebug_change(const struct ddebug_query *query,
|
|
|
|
unsigned int flags, unsigned int mask)
|
2009-02-05 16:51:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct ddebug_table *dt;
|
|
|
|
unsigned int newflags;
|
|
|
|
unsigned int nfound = 0;
|
2011-12-19 22:12:44 +00:00
|
|
|
char flagbuf[10];
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
/* search for matching ddebugs */
|
|
|
|
mutex_lock(&ddebug_lock);
|
|
|
|
list_for_each_entry(dt, &ddebug_tables, link) {
|
|
|
|
|
|
|
|
/* match against the module name */
|
2011-12-19 22:12:39 +00:00
|
|
|
if (query->module && strcmp(query->module, dt->mod_name))
|
2009-02-05 16:51:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0 ; i < dt->num_ddebugs ; i++) {
|
|
|
|
struct _ddebug *dp = &dt->ddebugs[i];
|
|
|
|
|
|
|
|
/* match against the source filename */
|
2011-12-19 22:12:39 +00:00
|
|
|
if (query->filename &&
|
2009-02-05 16:51:38 +00:00
|
|
|
strcmp(query->filename, dp->filename) &&
|
2011-12-19 22:13:12 +00:00
|
|
|
strcmp(query->filename, basename(dp->filename)) &&
|
|
|
|
strcmp(query->filename, trim_prefix(dp->filename)))
|
2009-02-05 16:51:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* match against the function */
|
2011-12-19 22:12:39 +00:00
|
|
|
if (query->function &&
|
2009-02-05 16:51:38 +00:00
|
|
|
strcmp(query->function, dp->function))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* match against the format */
|
2011-12-19 22:12:39 +00:00
|
|
|
if (query->format &&
|
|
|
|
!strstr(dp->format, query->format))
|
2009-02-05 16:51:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* match against the line number range */
|
|
|
|
if (query->first_lineno &&
|
|
|
|
dp->lineno < query->first_lineno)
|
|
|
|
continue;
|
|
|
|
if (query->last_lineno &&
|
|
|
|
dp->lineno > query->last_lineno)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nfound++;
|
|
|
|
|
|
|
|
newflags = (dp->flags & mask) | flags;
|
|
|
|
if (newflags == dp->flags)
|
|
|
|
continue;
|
|
|
|
dp->flags = newflags;
|
|
|
|
if (verbose)
|
2011-12-19 22:12:44 +00:00
|
|
|
pr_info("changed %s:%d [%s]%s =%s\n",
|
2011-12-19 22:13:12 +00:00
|
|
|
trim_prefix(dp->filename), dp->lineno,
|
2009-02-05 16:51:38 +00:00
|
|
|
dt->mod_name, dp->function,
|
|
|
|
ddebug_describe_flags(dp, flagbuf,
|
|
|
|
sizeof(flagbuf)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&ddebug_lock);
|
|
|
|
|
|
|
|
if (!nfound && verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("no matches for query\n");
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
|
|
|
|
return nfound;
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Split the buffer `buf' into space-separated words.
|
2009-02-06 01:54:26 +00:00
|
|
|
* Handles simple " and ' quoting, i.e. without nested,
|
|
|
|
* embedded or escaped \". Return the number of words
|
|
|
|
* or <0 on error.
|
2009-02-05 16:51:38 +00:00
|
|
|
*/
|
|
|
|
static int ddebug_tokenize(char *buf, char *words[], int maxwords)
|
|
|
|
{
|
|
|
|
int nwords = 0;
|
|
|
|
|
2009-02-06 01:54:26 +00:00
|
|
|
while (*buf) {
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
/* Skip leading whitespace */
|
2009-12-15 02:01:06 +00:00
|
|
|
buf = skip_spaces(buf);
|
2009-02-06 01:54:26 +00:00
|
|
|
if (!*buf)
|
|
|
|
break; /* oh, it was trailing whitespace */
|
2011-12-19 22:13:03 +00:00
|
|
|
if (*buf == '#')
|
|
|
|
break; /* token starts comment, skip rest of line */
|
2009-02-06 01:54:26 +00:00
|
|
|
|
2011-12-19 22:11:09 +00:00
|
|
|
/* find `end' of word, whitespace separated or quoted */
|
2009-02-06 01:54:26 +00:00
|
|
|
if (*buf == '"' || *buf == '\'') {
|
|
|
|
int quote = *buf++;
|
|
|
|
for (end = buf ; *end && *end != quote ; end++)
|
|
|
|
;
|
|
|
|
if (!*end)
|
|
|
|
return -EINVAL; /* unclosed quote */
|
|
|
|
} else {
|
|
|
|
for (end = buf ; *end && !isspace(*end) ; end++)
|
|
|
|
;
|
|
|
|
BUG_ON(end == buf);
|
|
|
|
}
|
|
|
|
|
2011-12-19 22:11:09 +00:00
|
|
|
/* `buf' is start of word, `end' is one past its end */
|
2009-02-06 01:54:26 +00:00
|
|
|
if (nwords == maxwords)
|
|
|
|
return -EINVAL; /* ran out of words[] before bytes */
|
|
|
|
if (*end)
|
|
|
|
*end++ = '\0'; /* terminate the word */
|
|
|
|
words[nwords++] = buf;
|
|
|
|
buf = end;
|
|
|
|
}
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
int i;
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("split into words:");
|
2009-02-05 16:51:38 +00:00
|
|
|
for (i = 0 ; i < nwords ; i++)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_cont(" \"%s\"", words[i]);
|
|
|
|
pr_cont("\n");
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nwords;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse a single line number. Note that the empty string ""
|
|
|
|
* is treated as a special case and converted to zero, which
|
|
|
|
* is later treated as a "don't care" value.
|
|
|
|
*/
|
|
|
|
static inline int parse_lineno(const char *str, unsigned int *val)
|
|
|
|
{
|
|
|
|
char *end = NULL;
|
|
|
|
BUG_ON(str == NULL);
|
|
|
|
if (*str == '\0') {
|
|
|
|
*val = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*val = simple_strtoul(str, &end, 10);
|
|
|
|
return end == NULL || end == str || *end != '\0' ? -EINVAL : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo octal escaping in a string, inplace. This is useful to
|
|
|
|
* allow the user to express a query which matches a format
|
|
|
|
* containing embedded spaces.
|
|
|
|
*/
|
|
|
|
#define isodigit(c) ((c) >= '0' && (c) <= '7')
|
|
|
|
static char *unescape(char *str)
|
|
|
|
{
|
|
|
|
char *in = str;
|
|
|
|
char *out = str;
|
|
|
|
|
|
|
|
while (*in) {
|
|
|
|
if (*in == '\\') {
|
|
|
|
if (in[1] == '\\') {
|
|
|
|
*out++ = '\\';
|
|
|
|
in += 2;
|
|
|
|
continue;
|
|
|
|
} else if (in[1] == 't') {
|
|
|
|
*out++ = '\t';
|
|
|
|
in += 2;
|
|
|
|
continue;
|
|
|
|
} else if (in[1] == 'n') {
|
|
|
|
*out++ = '\n';
|
|
|
|
in += 2;
|
|
|
|
continue;
|
|
|
|
} else if (isodigit(in[1]) &&
|
|
|
|
isodigit(in[2]) &&
|
|
|
|
isodigit(in[3])) {
|
|
|
|
*out++ = ((in[1] - '0')<<6) |
|
|
|
|
((in[2] - '0')<<3) |
|
|
|
|
(in[3] - '0');
|
|
|
|
in += 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out++ = *in++;
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2011-12-19 22:12:49 +00:00
|
|
|
static int check_set(const char **dest, char *src, char *name)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (*dest) {
|
|
|
|
rc = -EINVAL;
|
|
|
|
pr_err("match-spec:%s val:%s overridden by %s",
|
|
|
|
name, *dest, src);
|
|
|
|
}
|
|
|
|
*dest = src;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2009-02-05 16:51:38 +00:00
|
|
|
/*
|
|
|
|
* Parse words[] as a ddebug query specification, which is a series
|
|
|
|
* of (keyword, value) pairs chosen from these possibilities:
|
|
|
|
*
|
|
|
|
* func <function-name>
|
|
|
|
* file <full-pathname>
|
|
|
|
* file <base-filename>
|
|
|
|
* module <module-name>
|
|
|
|
* format <escaped-string-to-find-in-format>
|
|
|
|
* line <lineno>
|
|
|
|
* line <first-lineno>-<last-lineno> // where either may be empty
|
2011-12-19 22:12:49 +00:00
|
|
|
*
|
|
|
|
* Only 1 of each type is allowed.
|
|
|
|
* Returns 0 on success, <0 on error.
|
2009-02-05 16:51:38 +00:00
|
|
|
*/
|
|
|
|
static int ddebug_parse_query(char *words[], int nwords,
|
|
|
|
struct ddebug_query *query)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2011-12-19 22:12:49 +00:00
|
|
|
int rc;
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
/* check we have an even number of words */
|
|
|
|
if (nwords % 2 != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
memset(query, 0, sizeof(*query));
|
|
|
|
|
|
|
|
for (i = 0 ; i < nwords ; i += 2) {
|
|
|
|
if (!strcmp(words[i], "func"))
|
2011-12-19 22:12:49 +00:00
|
|
|
rc = check_set(&query->function, words[i+1], "func");
|
2009-02-05 16:51:38 +00:00
|
|
|
else if (!strcmp(words[i], "file"))
|
2011-12-19 22:12:49 +00:00
|
|
|
rc = check_set(&query->filename, words[i+1], "file");
|
2009-02-05 16:51:38 +00:00
|
|
|
else if (!strcmp(words[i], "module"))
|
2011-12-19 22:12:49 +00:00
|
|
|
rc = check_set(&query->module, words[i+1], "module");
|
2009-02-05 16:51:38 +00:00
|
|
|
else if (!strcmp(words[i], "format"))
|
2011-12-19 22:12:49 +00:00
|
|
|
rc = check_set(&query->format, unescape(words[i+1]),
|
|
|
|
"format");
|
2009-02-05 16:51:38 +00:00
|
|
|
else if (!strcmp(words[i], "line")) {
|
|
|
|
char *first = words[i+1];
|
|
|
|
char *last = strchr(first, '-');
|
2011-12-19 22:12:49 +00:00
|
|
|
if (query->first_lineno || query->last_lineno) {
|
|
|
|
pr_err("match-spec:line given 2 times\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2009-02-05 16:51:38 +00:00
|
|
|
if (last)
|
|
|
|
*last++ = '\0';
|
|
|
|
if (parse_lineno(first, &query->first_lineno) < 0)
|
|
|
|
return -EINVAL;
|
2011-12-19 22:12:49 +00:00
|
|
|
if (last) {
|
2009-02-05 16:51:38 +00:00
|
|
|
/* range <first>-<last> */
|
2011-12-19 22:12:49 +00:00
|
|
|
if (parse_lineno(last, &query->last_lineno)
|
|
|
|
< query->first_lineno) {
|
|
|
|
pr_err("last-line < 1st-line\n");
|
2009-02-05 16:51:38 +00:00
|
|
|
return -EINVAL;
|
2011-12-19 22:12:49 +00:00
|
|
|
}
|
2009-02-05 16:51:38 +00:00
|
|
|
} else {
|
|
|
|
query->last_lineno = query->first_lineno;
|
|
|
|
}
|
|
|
|
} else {
|
2011-12-19 22:12:34 +00:00
|
|
|
pr_err("unknown keyword \"%s\"\n", words[i]);
|
2009-02-05 16:51:38 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-12-19 22:12:49 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
2011-12-19 22:13:16 +00:00
|
|
|
vpr_info_dq(query, "parsed");
|
2009-02-05 16:51:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse `str' as a flags specification, format [-+=][p]+.
|
|
|
|
* Sets up *maskp and *flagsp to be used when changing the
|
|
|
|
* flags fields of matched _ddebug's. Returns 0 on success
|
|
|
|
* or <0 on error.
|
|
|
|
*/
|
|
|
|
static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
|
|
|
|
unsigned int *maskp)
|
|
|
|
{
|
|
|
|
unsigned flags = 0;
|
2011-01-23 16:17:24 +00:00
|
|
|
int op = '=', i;
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
switch (*str) {
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
case '=':
|
|
|
|
op = *str++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("op='%c'\n", op);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
for ( ; *str ; ++str) {
|
2011-01-23 16:17:24 +00:00
|
|
|
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
|
|
|
|
if (*str == opt_array[i].opt_char) {
|
|
|
|
flags |= opt_array[i].flag;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
2011-01-23 16:17:24 +00:00
|
|
|
if (i < 0)
|
|
|
|
return -EINVAL;
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("flags=0x%x\n", flags);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
/* calculate final *flagsp, *maskp according to mask and op */
|
|
|
|
switch (op) {
|
|
|
|
case '=':
|
|
|
|
*maskp = 0;
|
|
|
|
*flagsp = flags;
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
*maskp = ~0U;
|
|
|
|
*flagsp = flags;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
*maskp = ~flags;
|
|
|
|
*flagsp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
|
2009-02-05 16:51:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-06 14:11:01 +00:00
|
|
|
static int ddebug_exec_query(char *query_string)
|
|
|
|
{
|
|
|
|
unsigned int flags = 0, mask = 0;
|
|
|
|
struct ddebug_query query;
|
|
|
|
#define MAXWORDS 9
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
int nwords, nfound;
|
2010-08-06 14:11:01 +00:00
|
|
|
char *words[MAXWORDS];
|
|
|
|
|
|
|
|
nwords = ddebug_tokenize(query_string, words, MAXWORDS);
|
|
|
|
if (nwords <= 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (ddebug_parse_query(words, nwords-1, &query))
|
|
|
|
return -EINVAL;
|
|
|
|
if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* actually go and implement the change */
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
nfound = ddebug_change(&query, flags, mask);
|
|
|
|
vpr_info_dq((&query), (nfound) ? "applied" : "no-match");
|
|
|
|
|
|
|
|
return nfound;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle multiple queries in query string, continue on error, return
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *split;
|
|
|
|
int i, errs = 0, exitcode = 0, rc, nfound = 0;
|
|
|
|
|
|
|
|
for (i = 0; query; query = split) {
|
|
|
|
split = strpbrk(query, ";\n");
|
|
|
|
if (split)
|
|
|
|
*split++ = '\0';
|
|
|
|
|
|
|
|
query = skip_spaces(query);
|
|
|
|
if (!query || !*query || *query == '#')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
pr_info("query %d: \"%s\"\n", i, query);
|
|
|
|
|
|
|
|
rc = ddebug_exec_query(query);
|
|
|
|
if (rc < 0) {
|
|
|
|
errs++;
|
|
|
|
exitcode = rc;
|
|
|
|
} else
|
|
|
|
nfound += rc;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
pr_info("processed %d queries, with %d matches, %d errs\n",
|
|
|
|
i, nfound, errs);
|
|
|
|
|
|
|
|
if (exitcode)
|
|
|
|
return exitcode;
|
|
|
|
return nfound;
|
2010-08-06 14:11:01 +00:00
|
|
|
}
|
|
|
|
|
2011-10-04 21:13:19 +00:00
|
|
|
#define PREFIX_SIZE 64
|
|
|
|
|
|
|
|
static int remaining(int wrote)
|
|
|
|
{
|
|
|
|
if (PREFIX_SIZE - wrote > 0)
|
|
|
|
return PREFIX_SIZE - wrote;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
|
2011-01-23 16:17:24 +00:00
|
|
|
{
|
2011-10-04 21:13:19 +00:00
|
|
|
int pos_after_tid;
|
|
|
|
int pos = 0;
|
2011-01-23 16:17:24 +00:00
|
|
|
|
2011-10-04 21:13:19 +00:00
|
|
|
pos += snprintf(buf + pos, remaining(pos), "%s", KERN_DEBUG);
|
|
|
|
if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
|
2011-01-23 16:17:24 +00:00
|
|
|
if (in_interrupt())
|
2011-10-04 21:13:19 +00:00
|
|
|
pos += snprintf(buf + pos, remaining(pos), "%s ",
|
|
|
|
"<intr>");
|
2011-01-23 16:17:24 +00:00
|
|
|
else
|
2011-10-04 21:13:19 +00:00
|
|
|
pos += snprintf(buf + pos, remaining(pos), "[%d] ",
|
|
|
|
task_pid_vnr(current));
|
2011-01-23 16:17:24 +00:00
|
|
|
}
|
2011-10-04 21:13:19 +00:00
|
|
|
pos_after_tid = pos;
|
|
|
|
if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
|
|
|
|
pos += snprintf(buf + pos, remaining(pos), "%s:",
|
|
|
|
desc->modname);
|
|
|
|
if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
|
|
|
|
pos += snprintf(buf + pos, remaining(pos), "%s:",
|
|
|
|
desc->function);
|
|
|
|
if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
|
2011-12-19 22:11:09 +00:00
|
|
|
pos += snprintf(buf + pos, remaining(pos), "%d:",
|
|
|
|
desc->lineno);
|
2011-10-04 21:13:19 +00:00
|
|
|
if (pos - pos_after_tid)
|
|
|
|
pos += snprintf(buf + pos, remaining(pos), " ");
|
|
|
|
if (pos >= PREFIX_SIZE)
|
|
|
|
buf[PREFIX_SIZE - 1] = '\0';
|
2011-08-11 18:36:25 +00:00
|
|
|
|
2011-10-04 21:13:19 +00:00
|
|
|
return buf;
|
2011-08-11 18:36:25 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 16:17:24 +00:00
|
|
|
int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int res;
|
2011-10-04 21:13:19 +00:00
|
|
|
struct va_format vaf;
|
|
|
|
char buf[PREFIX_SIZE];
|
2011-01-23 16:17:24 +00:00
|
|
|
|
|
|
|
BUG_ON(!descriptor);
|
|
|
|
BUG_ON(!fmt);
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
2011-10-04 21:13:19 +00:00
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
|
|
|
res = printk("%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
|
2011-01-23 16:17:24 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__dynamic_pr_debug);
|
|
|
|
|
2011-08-11 18:36:21 +00:00
|
|
|
int __dynamic_dev_dbg(struct _ddebug *descriptor,
|
|
|
|
const struct device *dev, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct va_format vaf;
|
|
|
|
va_list args;
|
|
|
|
int res;
|
2011-10-04 21:13:19 +00:00
|
|
|
char buf[PREFIX_SIZE];
|
2011-08-11 18:36:21 +00:00
|
|
|
|
|
|
|
BUG_ON(!descriptor);
|
|
|
|
BUG_ON(!fmt);
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
2011-10-04 21:13:19 +00:00
|
|
|
res = __dev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
|
2011-08-11 18:36:21 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__dynamic_dev_dbg);
|
|
|
|
|
2011-10-04 21:13:22 +00:00
|
|
|
#ifdef CONFIG_NET
|
|
|
|
|
2011-08-11 18:36:48 +00:00
|
|
|
int __dynamic_netdev_dbg(struct _ddebug *descriptor,
|
|
|
|
const struct net_device *dev, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct va_format vaf;
|
|
|
|
va_list args;
|
|
|
|
int res;
|
2011-10-04 21:13:19 +00:00
|
|
|
char buf[PREFIX_SIZE];
|
2011-08-11 18:36:48 +00:00
|
|
|
|
|
|
|
BUG_ON(!descriptor);
|
|
|
|
BUG_ON(!fmt);
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = &args;
|
2011-10-04 21:13:19 +00:00
|
|
|
res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
|
2011-08-11 18:36:48 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__dynamic_netdev_dbg);
|
|
|
|
|
2011-10-04 21:13:22 +00:00
|
|
|
#endif
|
|
|
|
|
2011-12-19 22:12:29 +00:00
|
|
|
#define DDEBUG_STRING_SIZE 1024
|
|
|
|
static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE];
|
|
|
|
|
2010-08-06 14:11:02 +00:00
|
|
|
static __init int ddebug_setup_query(char *str)
|
|
|
|
{
|
2011-12-19 22:12:29 +00:00
|
|
|
if (strlen(str) >= DDEBUG_STRING_SIZE) {
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_warn("ddebug boot param string too large\n");
|
2010-08-06 14:11:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-19 22:12:29 +00:00
|
|
|
strlcpy(ddebug_setup_string, str, DDEBUG_STRING_SIZE);
|
2010-08-06 14:11:02 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("ddebug_query=", ddebug_setup_query);
|
|
|
|
|
2009-02-05 16:51:38 +00:00
|
|
|
/*
|
|
|
|
* File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
|
|
|
|
* command text from userspace, parses and executes it.
|
|
|
|
*/
|
2011-12-19 22:13:07 +00:00
|
|
|
#define USER_BUF_PAGE 4096
|
2009-02-05 16:51:38 +00:00
|
|
|
static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
|
|
|
|
size_t len, loff_t *offp)
|
|
|
|
{
|
2011-12-19 22:13:07 +00:00
|
|
|
char *tmpbuf;
|
2010-08-06 14:11:01 +00:00
|
|
|
int ret;
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
2011-12-19 22:13:07 +00:00
|
|
|
if (len > USER_BUF_PAGE - 1) {
|
|
|
|
pr_warn("expected <%d bytes into control\n", USER_BUF_PAGE);
|
2009-02-05 16:51:38 +00:00
|
|
|
return -E2BIG;
|
2011-12-19 22:13:07 +00:00
|
|
|
}
|
|
|
|
tmpbuf = kmalloc(len + 1, GFP_KERNEL);
|
|
|
|
if (!tmpbuf)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (copy_from_user(tmpbuf, ubuf, len)) {
|
|
|
|
kfree(tmpbuf);
|
2009-02-05 16:51:38 +00:00
|
|
|
return -EFAULT;
|
2011-12-19 22:13:07 +00:00
|
|
|
}
|
2009-02-05 16:51:38 +00:00
|
|
|
tmpbuf[len] = '\0';
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("read %d bytes from userspace\n", (int)len);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
ret = ddebug_exec_queries(tmpbuf);
|
2011-12-19 22:13:07 +00:00
|
|
|
kfree(tmpbuf);
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
if (ret < 0)
|
2010-08-06 14:11:01 +00:00
|
|
|
return ret;
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
*offp += len;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the iterator to point to the first _ddebug object
|
|
|
|
* and return a pointer to that first object. Returns
|
|
|
|
* NULL if there are no _ddebugs at all.
|
|
|
|
*/
|
|
|
|
static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter)
|
|
|
|
{
|
|
|
|
if (list_empty(&ddebug_tables)) {
|
|
|
|
iter->table = NULL;
|
|
|
|
iter->idx = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
iter->table = list_entry(ddebug_tables.next,
|
|
|
|
struct ddebug_table, link);
|
|
|
|
iter->idx = 0;
|
|
|
|
return &iter->table->ddebugs[iter->idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Advance the iterator to point to the next _ddebug
|
|
|
|
* object from the one the iterator currently points at,
|
|
|
|
* and returns a pointer to the new _ddebug. Returns
|
|
|
|
* NULL if the iterator has seen all the _ddebugs.
|
|
|
|
*/
|
|
|
|
static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter)
|
|
|
|
{
|
|
|
|
if (iter->table == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (++iter->idx == iter->table->num_ddebugs) {
|
|
|
|
/* iterate to next table */
|
|
|
|
iter->idx = 0;
|
|
|
|
if (list_is_last(&iter->table->link, &ddebug_tables)) {
|
|
|
|
iter->table = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
iter->table = list_entry(iter->table->link.next,
|
|
|
|
struct ddebug_table, link);
|
|
|
|
}
|
|
|
|
return &iter->table->ddebugs[iter->idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Seq_ops start method. Called at the start of every
|
|
|
|
* read() call from userspace. Takes the ddebug_lock and
|
|
|
|
* seeks the seq_file's iterator to the given position.
|
|
|
|
*/
|
|
|
|
static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct ddebug_iter *iter = m->private;
|
|
|
|
struct _ddebug *dp;
|
|
|
|
int n = *pos;
|
|
|
|
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
mutex_lock(&ddebug_lock);
|
|
|
|
|
|
|
|
if (!n)
|
|
|
|
return SEQ_START_TOKEN;
|
|
|
|
if (n < 0)
|
|
|
|
return NULL;
|
|
|
|
dp = ddebug_iter_first(iter);
|
|
|
|
while (dp != NULL && --n > 0)
|
|
|
|
dp = ddebug_iter_next(iter);
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Seq_ops next method. Called several times within a read()
|
|
|
|
* call from userspace, with ddebug_lock held. Walks to the
|
|
|
|
* next _ddebug object with a special case for the header line.
|
|
|
|
*/
|
|
|
|
static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct ddebug_iter *iter = m->private;
|
|
|
|
struct _ddebug *dp;
|
|
|
|
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("called m=%p p=%p *pos=%lld\n",
|
|
|
|
m, p, (unsigned long long)*pos);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
if (p == SEQ_START_TOKEN)
|
|
|
|
dp = ddebug_iter_first(iter);
|
|
|
|
else
|
|
|
|
dp = ddebug_iter_next(iter);
|
|
|
|
++*pos;
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Seq_ops show method. Called several times within a read()
|
|
|
|
* call from userspace, with ddebug_lock held. Formats the
|
|
|
|
* current _ddebug as a single human-readable line, with a
|
|
|
|
* special case for the header line.
|
|
|
|
*/
|
|
|
|
static int ddebug_proc_show(struct seq_file *m, void *p)
|
|
|
|
{
|
|
|
|
struct ddebug_iter *iter = m->private;
|
|
|
|
struct _ddebug *dp = p;
|
2011-12-19 22:12:44 +00:00
|
|
|
char flagsbuf[10];
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("called m=%p p=%p\n", m, p);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
if (p == SEQ_START_TOKEN) {
|
|
|
|
seq_puts(m,
|
|
|
|
"# filename:lineno [module]function flags format\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-19 22:12:44 +00:00
|
|
|
seq_printf(m, "%s:%u [%s]%s =%s \"",
|
2011-12-19 22:13:12 +00:00
|
|
|
trim_prefix(dp->filename), dp->lineno,
|
2011-12-19 22:12:44 +00:00
|
|
|
iter->table->mod_name, dp->function,
|
|
|
|
ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
|
2009-02-05 16:51:38 +00:00
|
|
|
seq_escape(m, dp->format, "\t\r\n\"");
|
|
|
|
seq_puts(m, "\"\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Seq_ops stop method. Called at the end of each read()
|
|
|
|
* call from userspace. Drops ddebug_lock.
|
|
|
|
*/
|
|
|
|
static void ddebug_proc_stop(struct seq_file *m, void *p)
|
|
|
|
{
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("called m=%p p=%p\n", m, p);
|
2009-02-05 16:51:38 +00:00
|
|
|
mutex_unlock(&ddebug_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct seq_operations ddebug_proc_seqops = {
|
|
|
|
.start = ddebug_proc_start,
|
|
|
|
.next = ddebug_proc_next,
|
|
|
|
.show = ddebug_proc_show,
|
|
|
|
.stop = ddebug_proc_stop
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2011-12-19 22:11:09 +00:00
|
|
|
* File_ops->open method for <debugfs>/dynamic_debug/control. Does
|
|
|
|
* the seq_file setup dance, and also creates an iterator to walk the
|
|
|
|
* _ddebugs. Note that we create a seq_file always, even for O_WRONLY
|
|
|
|
* files where it's not needed, as doing so simplifies the ->release
|
|
|
|
* method.
|
2009-02-05 16:51:38 +00:00
|
|
|
*/
|
|
|
|
static int ddebug_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct ddebug_iter *iter;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("called\n");
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
|
|
|
|
if (iter == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
err = seq_open(file, &ddebug_proc_seqops);
|
|
|
|
if (err) {
|
|
|
|
kfree(iter);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
((struct seq_file *) file->private_data)->private = iter;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations ddebug_proc_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ddebug_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = seq_release_private,
|
|
|
|
.write = ddebug_proc_write
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new ddebug_table for the given module
|
|
|
|
* and add it to the global list.
|
|
|
|
*/
|
|
|
|
int ddebug_add_module(struct _ddebug *tab, unsigned int n,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct ddebug_table *dt;
|
|
|
|
char *new_name;
|
|
|
|
|
|
|
|
dt = kzalloc(sizeof(*dt), GFP_KERNEL);
|
|
|
|
if (dt == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
new_name = kstrdup(name, GFP_KERNEL);
|
|
|
|
if (new_name == NULL) {
|
|
|
|
kfree(dt);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
dt->mod_name = new_name;
|
|
|
|
dt->num_ddebugs = n;
|
|
|
|
dt->ddebugs = tab;
|
|
|
|
|
|
|
|
mutex_lock(&ddebug_lock);
|
|
|
|
list_add_tail(&dt->link, &ddebug_tables);
|
|
|
|
mutex_unlock(&ddebug_lock);
|
|
|
|
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("%u debug prints in module %s\n", n, dt->mod_name);
|
2009-02-05 16:51:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(ddebug_add_module);
|
|
|
|
|
|
|
|
static void ddebug_table_free(struct ddebug_table *dt)
|
|
|
|
{
|
|
|
|
list_del_init(&dt->link);
|
|
|
|
kfree(dt->mod_name);
|
|
|
|
kfree(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called in response to a module being unloaded. Removes
|
|
|
|
* any ddebug_table's which point at the module.
|
|
|
|
*/
|
2010-07-03 03:07:35 +00:00
|
|
|
int ddebug_remove_module(const char *mod_name)
|
2009-02-05 16:51:38 +00:00
|
|
|
{
|
|
|
|
struct ddebug_table *dt, *nextdt;
|
|
|
|
int ret = -ENOENT;
|
|
|
|
|
|
|
|
if (verbose)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_info("removing module \"%s\"\n", mod_name);
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
mutex_lock(&ddebug_lock);
|
|
|
|
list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
|
|
|
|
if (!strcmp(dt->mod_name, mod_name)) {
|
|
|
|
ddebug_table_free(dt);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&ddebug_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(ddebug_remove_module);
|
|
|
|
|
|
|
|
static void ddebug_remove_all_tables(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&ddebug_lock);
|
|
|
|
while (!list_empty(&ddebug_tables)) {
|
|
|
|
struct ddebug_table *dt = list_entry(ddebug_tables.next,
|
|
|
|
struct ddebug_table,
|
|
|
|
link);
|
|
|
|
ddebug_table_free(dt);
|
|
|
|
}
|
|
|
|
mutex_unlock(&ddebug_lock);
|
|
|
|
}
|
|
|
|
|
2010-08-06 14:11:03 +00:00
|
|
|
static __initdata int ddebug_init_success;
|
|
|
|
|
|
|
|
static int __init dynamic_debug_init_debugfs(void)
|
2009-02-05 16:51:38 +00:00
|
|
|
{
|
|
|
|
struct dentry *dir, *file;
|
2010-08-06 14:11:03 +00:00
|
|
|
|
|
|
|
if (!ddebug_init_success)
|
|
|
|
return -ENODEV;
|
2009-02-05 16:51:38 +00:00
|
|
|
|
|
|
|
dir = debugfs_create_dir("dynamic_debug", NULL);
|
|
|
|
if (!dir)
|
|
|
|
return -ENOMEM;
|
|
|
|
file = debugfs_create_file("control", 0644, dir, NULL,
|
|
|
|
&ddebug_proc_fops);
|
|
|
|
if (!file) {
|
|
|
|
debugfs_remove(dir);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2010-08-06 14:11:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init dynamic_debug_init(void)
|
|
|
|
{
|
|
|
|
struct _ddebug *iter, *iter_start;
|
|
|
|
const char *modname = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
int n = 0;
|
|
|
|
|
2011-12-19 22:12:54 +00:00
|
|
|
if (__start___verbose == __stop___verbose) {
|
|
|
|
pr_warn("_ddebug table is empty in a "
|
|
|
|
"CONFIG_DYNAMIC_DEBUG build");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
iter = __start___verbose;
|
|
|
|
modname = iter->modname;
|
|
|
|
iter_start = iter;
|
|
|
|
for (; iter < __stop___verbose; iter++) {
|
|
|
|
if (strcmp(modname, iter->modname)) {
|
|
|
|
ret = ddebug_add_module(iter_start, n, modname);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
n = 0;
|
|
|
|
modname = iter->modname;
|
|
|
|
iter_start = iter;
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
2011-12-19 22:12:54 +00:00
|
|
|
n++;
|
2009-02-05 16:51:38 +00:00
|
|
|
}
|
2011-12-19 22:12:54 +00:00
|
|
|
ret = ddebug_add_module(iter_start, n, modname);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
2010-08-06 14:11:02 +00:00
|
|
|
|
|
|
|
/* ddebug_query boot param got passed -> set it up */
|
|
|
|
if (ddebug_setup_string[0] != '\0') {
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
ret = ddebug_exec_queries(ddebug_setup_string);
|
|
|
|
if (ret < 0)
|
2011-08-11 18:36:33 +00:00
|
|
|
pr_warn("Invalid ddebug boot param %s",
|
|
|
|
ddebug_setup_string);
|
2010-08-06 14:11:02 +00:00
|
|
|
else
|
dynamic_debug: process multiple debug-queries on a line
Insert ddebug_exec_queries() in place of ddebug_exec_query(). It
splits the query string on [;\n], and calls ddebug_exec_query() on
each. All queries are processed independent of errors, allowing a
query to fail, for example when a module is not installed. Empty
lines and comments are skipped. Errors are counted, and the last
error seen (negative) or the number of callsites found (0 or positive)
is returned. Return code checks are altered accordingly.
With this, multiple queries can be given in ddebug_query, allowing
more selective enabling of callsites. As a side effect, a set of
commands can be batched in:
cat cmd-file > $DBGMT/dynamic_debug/control
We dont want a ddebug_query syntax error to kill the dynamic debug
facility, so dynamic_debug_init() zeros ddebug_exec_queries()'s return
code after logging the appropriate message, so that ddebug tables are
preserved and $DBGMT/dynamic_debug/control file is created. This
would be appropriate even without accepting multiple queries.
This patch also alters ddebug_change() to return number of callsites
matched (which typically is the same as number of callsites changed).
ddebug_exec_query() also returns the number found, or a negative value
if theres a parse error on the query.
Splitting on [;\n] prevents their use in format-specs, but selecting
callsites on punctuation is brittle anyway, meaningful and selective
substrings are more typical.
Note: splitting queries on ';' before handling trailing #comments
means that a ';' also terminates a comment, and text after the ';' is
treated as another query. This trailing query will almost certainly
result in a parse error and thus have no effect other than the error
message. The double corner case with unexpected results is:
ddebug_query="func foo +p # enable foo ; +p"
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Signed-off-by: Jason Baron <jbaron@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2011-12-19 22:13:21 +00:00
|
|
|
pr_info("%d changes by ddebug_query\n", ret);
|
|
|
|
|
|
|
|
/* keep tables even on ddebug_query parse error */
|
|
|
|
ret = 0;
|
2010-08-06 14:11:02 +00:00
|
|
|
}
|
|
|
|
|
2009-02-05 16:51:38 +00:00
|
|
|
out_free:
|
2010-08-06 14:11:03 +00:00
|
|
|
if (ret)
|
2009-02-05 16:51:38 +00:00
|
|
|
ddebug_remove_all_tables();
|
2010-08-06 14:11:03 +00:00
|
|
|
else
|
|
|
|
ddebug_init_success = 1;
|
2009-02-05 16:51:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-08-06 14:11:03 +00:00
|
|
|
/* Allow early initialization for boot messages via boot param */
|
|
|
|
arch_initcall(dynamic_debug_init);
|
|
|
|
/* Debugfs setup must be done later */
|
|
|
|
module_init(dynamic_debug_init_debugfs);
|