[PATCH] dynamic_debug: add wildcard support to filter files/functions/modules

From: Du, Changbin
Date: Thu Jul 25 2013 - 09:02:35 EST


From: "Du, Changbin" <changbin.du@xxxxxxxxx>

This patch add wildcard '*'(matches zero or more characters) and '?'
(matches one character) support when qurying debug flags.

Now we can open debug messages using keywords. eg:
1. open debug logs in all usb drivers
echo "file drivers/usb/* +p" > <debugfs>/dynamic_debug/control
2. open debug logs for usb xhci code
echo "file *xhci* +p" > <debugfs>/dynamic_debug/control

Signed-off-by: Du, Changbin <changbin.du@xxxxxxxxx>
---
lib/dynamic_debug.c | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 99fec3a..cdcce58 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -127,6 +127,21 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
query->first_lineno, query->last_lineno);
}

+static int match_pattern(char *pat, char *str)
+{
+ switch (*pat) {
+ case '\0':
+ return !*str;
+ case '*':
+ return match_pattern(pat+1, str) ||
+ (*str && match_pattern(pat, str+1));
+ case '?':
+ return *str && match_pattern(pat+1, str+1);
+ default:
+ return *pat == *str && match_pattern(pat+1, str+1);
+ }
+}
+
/*
* Search the tables for _ddebug's which match the given `query' and
* apply the `flags' and `mask' to them. Returns number of matching
@@ -147,7 +162,7 @@ static int ddebug_change(const struct ddebug_query *query,
list_for_each_entry(dt, &ddebug_tables, link) {

/* match against the module name */
- if (query->module && strcmp(query->module, dt->mod_name))
+ if (query->module && !match_pattern(query->module, dt->mod_name))
continue;

for (i = 0; i < dt->num_ddebugs; i++) {
@@ -155,14 +170,16 @@ static int ddebug_change(const struct ddebug_query *query,

/* match against the source filename */
if (query->filename &&
- strcmp(query->filename, dp->filename) &&
- strcmp(query->filename, kbasename(dp->filename)) &&
- strcmp(query->filename, trim_prefix(dp->filename)))
+ !match_pattern(query->filename, dp->filename) &&
+ !match_pattern(query->filename,
+ kbasename(dp->filename)) &&
+ !match_pattern(query->filename,
+ trim_prefix(dp->filename)))
continue;

/* match against the function */
if (query->function &&
- strcmp(query->function, dp->function))
+ !match_pattern(query->function, dp->function))
continue;

/* match against the format */
--
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/