linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dynamic_debug: add wildcard support to filter files/functions/modules
@ 2013-07-25 13:02 Du, Changbin
  2013-07-25 16:47 ` Joe Perches
  0 siblings, 1 reply; 24+ messages in thread
From: Du, Changbin @ 2013-07-25 13:02 UTC (permalink / raw)
  To: jbaron; +Cc: linux-kernel, changbin.du

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

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@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2013-11-16  8:25 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-25 13:02 [PATCH] dynamic_debug: add wildcard support to filter files/functions/modules Du, Changbin
2013-07-25 16:47 ` Joe Perches
2013-07-30  3:59   ` Jason Baron
2013-10-28 15:29     ` [PATCH v2] " Du, Changbin
2013-10-28 16:30       ` Joe Perches
2013-10-29  8:04         ` Changbin Du
2013-10-29 13:33           ` [PATCH v3] " Du, Changbin
2013-10-29 16:20             ` Joe Perches
2013-10-30  6:58               ` Changbin Du
2013-10-30 13:57                 ` Changbin Du
2013-10-30 14:21                   ` [PATCH v4 1/2] " Du, Changbin
2013-10-30 14:21                   ` [PATCH v4 2/2] dynamic-debug-howto.txt: update since new wildcard support Du, Changbin
2013-10-29 20:21             ` [PATCH v3] dynamic_debug: add wildcard support to filter files/functions/modules Marcel Holtmann
2013-10-30  6:24               ` Changbin Du
2013-10-31 22:52       ` [PATCH v2] " Andrew Morton
2013-10-31 23:30         ` Joe Perches
2013-11-07  3:04           ` Changbin Du
2013-11-07  3:11           ` Changbin Du
2013-11-07  6:12             ` Joe Perches
2013-11-15  4:01               ` Changbin Du
2013-11-16  8:24                 ` [PATCH v5 0/3] add wildcard support for dynamic debug Du, Changbin
2013-11-16  8:24                 ` [PATCH v5 1/3] lib/parser.c: add match_wildcard function Du, Changbin
2013-11-16  8:24                 ` [PATCH v5 2/3] dynamic_debug: add wildcard support to filter files/functions/modules Du, Changbin
2013-11-16  8:24                 ` [PATCH v5 3/3] dynamic-debug-howto.txt: update since new wildcard support Du, Changbin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).