提交 85f7f6c0 编写于 作者: J Jim Cromie 提交者: Greg Kroah-Hartman

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: NJim Cromie <jim.cromie@gmail.com>
Signed-off-by: NJason Baron <jbaron@redhat.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 574b3725
...@@ -12,7 +12,7 @@ dynamically enabled per-callsite. ...@@ -12,7 +12,7 @@ dynamically enabled per-callsite.
Dynamic debug has even more useful features: Dynamic debug has even more useful features:
* Simple query language allows turning on and off debugging statements by * Simple query language allows turning on and off debugging statements by
matching any combination of: matching any combination of 0 or 1 of:
- source filename - source filename
- function name - function name
...@@ -79,31 +79,24 @@ Command Language Reference ...@@ -79,31 +79,24 @@ Command Language Reference
========================== ==========================
At the lexical level, a command comprises a sequence of words separated At the lexical level, a command comprises a sequence of words separated
by whitespace characters. Note that newlines are treated as word by spaces or tabs. So these are all equivalent:
separators and do *not* end a command or allow multiple commands to
be done together. So these are all equivalent:
nullarbor:~ # echo -c 'file svcsock.c line 1603 +p' > nullarbor:~ # echo -c 'file svcsock.c line 1603 +p' >
<debugfs>/dynamic_debug/control <debugfs>/dynamic_debug/control
nullarbor:~ # echo -c ' file svcsock.c line 1603 +p ' > nullarbor:~ # echo -c ' file svcsock.c line 1603 +p ' >
<debugfs>/dynamic_debug/control <debugfs>/dynamic_debug/control
nullarbor:~ # echo -c 'file svcsock.c\nline 1603 +p' >
<debugfs>/dynamic_debug/control
nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' > nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
<debugfs>/dynamic_debug/control <debugfs>/dynamic_debug/control
Commands are bounded by a write() system call. If you want to do Command submissions are bounded by a write() system call.
multiple commands you need to do a separate "echo" for each, like: Multiple commands can be written together, separated by ';' or '\n'.
nullarbor:~ # echo 'file svcsock.c line 1603 +p' > /proc/dprintk ;\ ~# echo "func pnpacpi_get_resources +p; func pnp_assign_mem +p" \
> echo 'file svcsock.c line 1563 +p' > /proc/dprintk > <debugfs>/dynamic_debug/control
or even like: If your query set is big, you can batch them too:
nullarbor:~ # ( ~# cat query-batch-file > <debugfs>/dynamic_debug/control
> echo 'file svcsock.c line 1603 +p' ;\
> echo 'file svcsock.c line 1563 +p' ;\
> ) > /proc/dprintk
At the syntactical level, a command comprises a sequence of match At the syntactical level, a command comprises a sequence of match
specifications, followed by a flags change specification. specifications, followed by a flags change specification.
......
...@@ -124,13 +124,13 @@ do { \ ...@@ -124,13 +124,13 @@ do { \
} while (0) } while (0)
/* /*
* Search the tables for _ddebug's which match the given * Search the tables for _ddebug's which match the given `query' and
* `query' and apply the `flags' and `mask' to them. Tells * apply the `flags' and `mask' to them. Returns number of matching
* the user which ddebug's were changed, or whether none * callsites, normally the same as number of changes. If verbose,
* were matched. * logs the changes. Takes ddebug_lock.
*/ */
static void ddebug_change(const struct ddebug_query *query, static int ddebug_change(const struct ddebug_query *query,
unsigned int flags, unsigned int mask) unsigned int flags, unsigned int mask)
{ {
int i; int i;
struct ddebug_table *dt; struct ddebug_table *dt;
...@@ -192,6 +192,8 @@ static void ddebug_change(const struct ddebug_query *query, ...@@ -192,6 +192,8 @@ static void ddebug_change(const struct ddebug_query *query,
if (!nfound && verbose) if (!nfound && verbose)
pr_info("no matches for query\n"); pr_info("no matches for query\n");
return nfound;
} }
/* /*
...@@ -449,7 +451,7 @@ static int ddebug_exec_query(char *query_string) ...@@ -449,7 +451,7 @@ static int ddebug_exec_query(char *query_string)
unsigned int flags = 0, mask = 0; unsigned int flags = 0, mask = 0;
struct ddebug_query query; struct ddebug_query query;
#define MAXWORDS 9 #define MAXWORDS 9
int nwords; int nwords, nfound;
char *words[MAXWORDS]; char *words[MAXWORDS];
nwords = ddebug_tokenize(query_string, words, MAXWORDS); nwords = ddebug_tokenize(query_string, words, MAXWORDS);
...@@ -461,8 +463,47 @@ static int ddebug_exec_query(char *query_string) ...@@ -461,8 +463,47 @@ static int ddebug_exec_query(char *query_string)
return -EINVAL; return -EINVAL;
/* actually go and implement the change */ /* actually go and implement the change */
ddebug_change(&query, flags, mask); nfound = ddebug_change(&query, flags, mask);
return 0; 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;
} }
#define PREFIX_SIZE 64 #define PREFIX_SIZE 64
...@@ -615,9 +656,9 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, ...@@ -615,9 +656,9 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
if (verbose) if (verbose)
pr_info("read %d bytes from userspace\n", (int)len); pr_info("read %d bytes from userspace\n", (int)len);
ret = ddebug_exec_query(tmpbuf); ret = ddebug_exec_queries(tmpbuf);
kfree(tmpbuf); kfree(tmpbuf);
if (ret) if (ret < 0)
return ret; return ret;
*offp += len; *offp += len;
...@@ -927,13 +968,15 @@ static int __init dynamic_debug_init(void) ...@@ -927,13 +968,15 @@ static int __init dynamic_debug_init(void)
/* ddebug_query boot param got passed -> set it up */ /* ddebug_query boot param got passed -> set it up */
if (ddebug_setup_string[0] != '\0') { if (ddebug_setup_string[0] != '\0') {
ret = ddebug_exec_query(ddebug_setup_string); ret = ddebug_exec_queries(ddebug_setup_string);
if (ret) if (ret < 0)
pr_warn("Invalid ddebug boot param %s", pr_warn("Invalid ddebug boot param %s",
ddebug_setup_string); ddebug_setup_string);
else else
pr_info("ddebug initialized with string %s", pr_info("%d changes by ddebug_query\n", ret);
ddebug_setup_string);
/* keep tables even on ddebug_query parse error */
ret = 0;
} }
out_free: out_free:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册