Skip to content

Commit

Permalink
dynamic_debug: add wildcard support to filter files/functions/modules
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
changbindu authored and torvalds committed Jan 24, 2014
1 parent a3d2cca commit 578b1e0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/dynamic_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* By Greg Banks <[email protected]>
* Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
* Copyright (C) 2011 Bart Van Assche. All Rights Reserved.
* Copyright (C) 2013 Du, Changbin <[email protected]>
*/

#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
Expand All @@ -24,6 +25,7 @@
#include <linux/sysctl.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/parser.h>
#include <linux/string_helpers.h>
#include <linux/uaccess.h>
#include <linux/dynamic_debug.h>
Expand Down Expand Up @@ -147,22 +149,25 @@ 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_wildcard(query->module, dt->mod_name))
continue;

for (i = 0; i < dt->num_ddebugs; i++) {
struct _ddebug *dp = &dt->ddebugs[i];

/* 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_wildcard(query->filename, dp->filename) &&
!match_wildcard(query->filename,
kbasename(dp->filename)) &&
!match_wildcard(query->filename,
trim_prefix(dp->filename)))
continue;

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

/* match against the format */
Expand Down

0 comments on commit 578b1e0

Please sign in to comment.