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

2013-11-14 Thread Changbin Du
2013/11/7 Joe Perches :
> On Thu, 2013-11-07 at 11:11 +0800, Changbin Du wrote:
>> 2013/11/1 Joe Perches :
>> match_ functions in lib/parser.c just do simple match, they
>> doesn't support wildcards.
>> So it's not useful for us.
>
> It's not meant to be useful so much as be a possible
> generic location for your match_regex function.
>
I misunderstood you. This is a appropriate file to place the matching function.
I have moved it to this file.

I checked the regex_match_foo  functions in  trace_events_filter.c. Per my
reading, I think it's a little tedious, and only support '*' character. They are
glued with tracing framework. So i gave up to re-used them.

I will send new version patch set to you later.

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


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

2013-11-14 Thread Changbin Du
2013/11/7 Joe Perches j...@perches.com:
 On Thu, 2013-11-07 at 11:11 +0800, Changbin Du wrote:
 2013/11/1 Joe Perches j...@perches.com:
 match_foo functions in lib/parser.c just do simple match, they
 doesn't support wildcards.
 So it's not useful for us.

 It's not meant to be useful so much as be a possible
 generic location for your match_regex function.

I misunderstood you. This is a appropriate file to place the matching function.
I have moved it to this file.

I checked the regex_match_foo  functions in  trace_events_filter.c. Per my
reading, I think it's a little tedious, and only support '*' character. They are
glued with tracing framework. So i gave up to re-used them.

I will send new version patch set to you later.

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


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

2013-11-06 Thread Joe Perches
On Thu, 2013-11-07 at 11:11 +0800, Changbin Du wrote:
> 2013/11/1 Joe Perches :
> > On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
> >> On Mon, 28 Oct 2013 23:29:10 +0800 "Du, Changbin"  
> >> wrote:
> > []
> >> > +/* check if the string matches given pattern which includes wildcards */
> >> > +static int match_pattern(const char *pattern, const char *string)
> > []
> >> No, something like this should be in lib/ so that other callers can use
> >> it.  We already have at least one copy handy in
> >> drivers/ata/libata-core.c:glob_match().  A better approach would be to
> >> move that glob_match() into lib/glob_match.c then teach dynamic_debug
> >> to use it.
> >>
> >> There are probably other private globbing functions lying around the
> >> kernel, but it's rather a hard thing to grep for...
> >
> > Maybe use lib/parser.c where the other match_ functions
> > are already.
> 
> match_ functions in lib/parser.c just do simple match, they
> doesn't support wildcards.
> So it's not useful for us.

It's not meant to be useful so much as be a possible
generic location for your match_regex function.


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


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

2013-11-06 Thread Changbin Du
2013/11/1 Joe Perches :
> On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
>> On Mon, 28 Oct 2013 23:29:10 +0800 "Du, Changbin"  
>> wrote:
> []
>> > +/* check if the string matches given pattern which includes wildcards */
>> > +static int match_pattern(const char *pattern, const char *string)
> []
>> No, something like this should be in lib/ so that other callers can use
>> it.  We already have at least one copy handy in
>> drivers/ata/libata-core.c:glob_match().  A better approach would be to
>> move that glob_match() into lib/glob_match.c then teach dynamic_debug
>> to use it.
>>
>> There are probably other private globbing functions lying around the
>> kernel, but it's rather a hard thing to grep for...
>
> Maybe use lib/parser.c where the other match_ functions
> are already.

match_ functions in lib/parser.c just do simple match, they
doesn't support wildcards.
So it's not useful for us.

>
> match_glob has the disadvantage that it's recursive too.
>

As you mentioned before, we cannot use it since strings are given from
userspace. :)

> trace has:
>
> kernel/trace/trace_events_filter.c:static int regex_match_full(char *str, 
> struct regex *r, int len)
> kernel/trace/trace_events_filter.c:static int regex_match_front(char *str, 
> struct regex *r, int len)
> kernel/trace/trace_events_filter.c:static int regex_match_middle(char *str, 
> struct regex *r, int len)
> kernel/trace/trace_events_filter.c:static int regex_match_end(char *str, 
> struct regex *r, int len)
>
> but there probably aren't many more that could be converted.

Trace filter support wildcards, but it seems the match algorithm
couples with trace code. I'll try to see
if it can be split.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-11-06 Thread Changbin Du
2013/11/1 Joe Perches :
> On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
>> On Mon, 28 Oct 2013 23:29:10 +0800 "Du, Changbin"  
>> wrote:
> []
>> > +/* check if the string matches given pattern which includes wildcards */
>> > +static int match_pattern(const char *pattern, const char *string)
> []
>> No, something like this should be in lib/ so that other callers can use
>> it.  We already have at least one copy handy in
>> drivers/ata/libata-core.c:glob_match().  A better approach would be to
>> move that glob_match() into lib/glob_match.c then teach dynamic_debug
>> to use it.
>>
>> There are probably other private globbing functions lying around the
>> kernel, but it's rather a hard thing to grep for...
>
> Maybe use lib/parser.c where the other match_ functions
> are already.

match_ functions in lib/parser.c just do simple match, they
doesn't support wildcards.
So it's not useful for us.

>
> match_glob has the disadvantage that it's recursive too.
>

As you mentioned before, we cannot use it since strings are given from
userspace. :)

> trace has:
>
> kernel/trace/trace_events_filter.c:static int regex_match_full(char *str, 
> struct regex *r, int len)
> kernel/trace/trace_events_filter.c:static int regex_match_front(char *str, 
> struct regex *r, int len)
> kernel/trace/trace_events_filter.c:static int regex_match_middle(char *str, 
> struct regex *r, int len)
> kernel/trace/trace_events_filter.c:static int regex_match_end(char *str, 
> struct regex *r, int len)
>
> but there probably aren't many more that could be converted.

Trace filter support wildcards, but it seems the match algorithm
couples with trace code. I'll try to see
if it can be split.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-11-06 Thread Changbin Du
2013/11/1 Joe Perches j...@perches.com:
 On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
 On Mon, 28 Oct 2013 23:29:10 +0800 Du, Changbin changbin...@gmail.com 
 wrote:
 []
  +/* check if the string matches given pattern which includes wildcards */
  +static int match_pattern(const char *pattern, const char *string)
 []
 No, something like this should be in lib/ so that other callers can use
 it.  We already have at least one copy handy in
 drivers/ata/libata-core.c:glob_match().  A better approach would be to
 move that glob_match() into lib/glob_match.c then teach dynamic_debug
 to use it.

 There are probably other private globbing functions lying around the
 kernel, but it's rather a hard thing to grep for...

 Maybe use lib/parser.c where the other match_foo functions
 are already.

match_foo functions in lib/parser.c just do simple match, they
doesn't support wildcards.
So it's not useful for us.


 match_glob has the disadvantage that it's recursive too.


As you mentioned before, we cannot use it since strings are given from
userspace. :)

 trace has:

 kernel/trace/trace_events_filter.c:static int regex_match_full(char *str, 
 struct regex *r, int len)
 kernel/trace/trace_events_filter.c:static int regex_match_front(char *str, 
 struct regex *r, int len)
 kernel/trace/trace_events_filter.c:static int regex_match_middle(char *str, 
 struct regex *r, int len)
 kernel/trace/trace_events_filter.c:static int regex_match_end(char *str, 
 struct regex *r, int len)

 but there probably aren't many more that could be converted.

Trace filter support wildcards, but it seems the match algorithm
couples with trace code. I'll try to see
if it can be split.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-11-06 Thread Changbin Du
2013/11/1 Joe Perches j...@perches.com:
 On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
 On Mon, 28 Oct 2013 23:29:10 +0800 Du, Changbin changbin...@gmail.com 
 wrote:
 []
  +/* check if the string matches given pattern which includes wildcards */
  +static int match_pattern(const char *pattern, const char *string)
 []
 No, something like this should be in lib/ so that other callers can use
 it.  We already have at least one copy handy in
 drivers/ata/libata-core.c:glob_match().  A better approach would be to
 move that glob_match() into lib/glob_match.c then teach dynamic_debug
 to use it.

 There are probably other private globbing functions lying around the
 kernel, but it's rather a hard thing to grep for...

 Maybe use lib/parser.c where the other match_foo functions
 are already.

match_foo functions in lib/parser.c just do simple match, they
doesn't support wildcards.
So it's not useful for us.


 match_glob has the disadvantage that it's recursive too.


As you mentioned before, we cannot use it since strings are given from
userspace. :)

 trace has:

 kernel/trace/trace_events_filter.c:static int regex_match_full(char *str, 
 struct regex *r, int len)
 kernel/trace/trace_events_filter.c:static int regex_match_front(char *str, 
 struct regex *r, int len)
 kernel/trace/trace_events_filter.c:static int regex_match_middle(char *str, 
 struct regex *r, int len)
 kernel/trace/trace_events_filter.c:static int regex_match_end(char *str, 
 struct regex *r, int len)

 but there probably aren't many more that could be converted.

Trace filter support wildcards, but it seems the match algorithm
couples with trace code. I'll try to see
if it can be split.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-11-06 Thread Joe Perches
On Thu, 2013-11-07 at 11:11 +0800, Changbin Du wrote:
 2013/11/1 Joe Perches j...@perches.com:
  On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
  On Mon, 28 Oct 2013 23:29:10 +0800 Du, Changbin changbin...@gmail.com 
  wrote:
  []
   +/* check if the string matches given pattern which includes wildcards */
   +static int match_pattern(const char *pattern, const char *string)
  []
  No, something like this should be in lib/ so that other callers can use
  it.  We already have at least one copy handy in
  drivers/ata/libata-core.c:glob_match().  A better approach would be to
  move that glob_match() into lib/glob_match.c then teach dynamic_debug
  to use it.
 
  There are probably other private globbing functions lying around the
  kernel, but it's rather a hard thing to grep for...
 
  Maybe use lib/parser.c where the other match_foo functions
  are already.
 
 match_foo functions in lib/parser.c just do simple match, they
 doesn't support wildcards.
 So it's not useful for us.

It's not meant to be useful so much as be a possible
generic location for your match_regex function.


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


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

2013-10-31 Thread Joe Perches
On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
> On Mon, 28 Oct 2013 23:29:10 +0800 "Du, Changbin"  
> wrote:
[]
> > +/* check if the string matches given pattern which includes wildcards */
> > +static int match_pattern(const char *pattern, const char *string)
[]
> No, something like this should be in lib/ so that other callers can use
> it.  We already have at least one copy handy in
> drivers/ata/libata-core.c:glob_match().  A better approach would be to
> move that glob_match() into lib/glob_match.c then teach dynamic_debug
> to use it.
> 
> There are probably other private globbing functions lying around the
> kernel, but it's rather a hard thing to grep for...

Maybe use lib/parser.c where the other match_ functions
are already.

match_glob has the disadvantage that it's recursive too.

trace has:

kernel/trace/trace_events_filter.c:static int regex_match_full(char *str, 
struct regex *r, int len)
kernel/trace/trace_events_filter.c:static int regex_match_front(char *str, 
struct regex *r, int len)
kernel/trace/trace_events_filter.c:static int regex_match_middle(char *str, 
struct regex *r, int len)
kernel/trace/trace_events_filter.c:static int regex_match_end(char *str, struct 
regex *r, int len)

but there probably aren't many more that could be converted.

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


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

2013-10-31 Thread Andrew Morton
On Mon, 28 Oct 2013 23:29:10 +0800 "Du, Changbin"  wrote:

> 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" > /dynamic_debug/control
> 2.  open debug logs for usb xhci code
> echo "file *xhci* +p" > /dynamic_debug/control

This patch would be a lot easier to understand (and hence review) if
you had remembered to update Documentation/dynamic-debug-howto.txt!

> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query 
> *query, const char *msg)
>query->first_lineno, query->last_lineno);
>  }
>  
> +/* check if the string matches given pattern which includes wildcards */
> +static int match_pattern(const char *pattern, const char *string)

No, something like this should be in lib/ so that other callers can use
it.  We already have at least one copy handy in
drivers/ata/libata-core.c:glob_match().  A better approach would be to
move that glob_match() into lib/glob_match.c then teach dynamic_debug
to use it.

There are probably other private globbing functions lying around the
kernel, but it's rather a hard thing to grep for...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-10-31 Thread Andrew Morton
On Mon, 28 Oct 2013 23:29:10 +0800 Du, Changbin changbin...@gmail.com wrote:

 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

This patch would be a lot easier to understand (and hence review) if
you had remembered to update Documentation/dynamic-debug-howto.txt!

 --- a/lib/dynamic_debug.c
 +++ b/lib/dynamic_debug.c
 @@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query 
 *query, const char *msg)
query-first_lineno, query-last_lineno);
  }
  
 +/* check if the string matches given pattern which includes wildcards */
 +static int match_pattern(const char *pattern, const char *string)

No, something like this should be in lib/ so that other callers can use
it.  We already have at least one copy handy in
drivers/ata/libata-core.c:glob_match().  A better approach would be to
move that glob_match() into lib/glob_match.c then teach dynamic_debug
to use it.

There are probably other private globbing functions lying around the
kernel, but it's rather a hard thing to grep for...
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-10-31 Thread Joe Perches
On Thu, 2013-10-31 at 15:52 -0700, Andrew Morton wrote:
 On Mon, 28 Oct 2013 23:29:10 +0800 Du, Changbin changbin...@gmail.com 
 wrote:
[]
  +/* check if the string matches given pattern which includes wildcards */
  +static int match_pattern(const char *pattern, const char *string)
[]
 No, something like this should be in lib/ so that other callers can use
 it.  We already have at least one copy handy in
 drivers/ata/libata-core.c:glob_match().  A better approach would be to
 move that glob_match() into lib/glob_match.c then teach dynamic_debug
 to use it.
 
 There are probably other private globbing functions lying around the
 kernel, but it's rather a hard thing to grep for...

Maybe use lib/parser.c where the other match_foo functions
are already.

match_glob has the disadvantage that it's recursive too.

trace has:

kernel/trace/trace_events_filter.c:static int regex_match_full(char *str, 
struct regex *r, int len)
kernel/trace/trace_events_filter.c:static int regex_match_front(char *str, 
struct regex *r, int len)
kernel/trace/trace_events_filter.c:static int regex_match_middle(char *str, 
struct regex *r, int len)
kernel/trace/trace_events_filter.c:static int regex_match_end(char *str, struct 
regex *r, int len)

but there probably aren't many more that could be converted.

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


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

2013-10-29 Thread Changbin Du
Hello, Joe,

Thanks for your comments. I will update the patch. And now I am trying
to remove all the two goto statements. Agree with you, we can use a
while statement instead.

I will send you the new patch for you to review when it's done.


2013/10/29 Joe Perches 
>
> On Mon, 2013-10-28 at 23:29 +0800, Du, Changbin wrote:
> > From: "Du, Changbin" 
>
> trivial notes:
>
> > This patch add wildcard '*'(matches zero or more characters) and '?'
> > (matches one character) support when qurying debug flags.
>
> > diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> []
> > @@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query 
> > *query, const char *msg)
> >query->first_lineno, query->last_lineno);
> >  }
> >
> > +/* check if the string matches given pattern which includes wildcards */
> > +static int match_pattern(const char *pattern, const char *string)
>
> bool match_pattern
>
> > +{
> > + const char *s, *p;
> > + int star = 0;
>
> bool star = false;
>
> > +
> > +loop:
> > + for (s = string, p = pattern; *s; ++s, ++p) {
> > + switch (*p) {
> > + case '?':
> > + break;
> > + case '*':
> > + star = 1;
> > + string = s;
> > + pattern = p;
> > + if (!*++pattern)
> > + return 1;
> > + goto loop;
> > + default:
> > + if (*s != *p)
> > + goto star_check;
>
> star = false;
>
> > + break;
> > + }
> > + }
> > + if (*p == '*')
> > + ++p;
> > + return (!*p);
>
> Don't need parentheses.
>
> > +
> > +star_check:
> > + if (!star)
> > + return 0;
> > + string++;
> > + goto loop;
> > +}
>
> The star_check: label block seems like it'd be
> better in the switch case as it's only used once.
>
> Maybe the thing would be more readable with a
> while loop
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-10-29 Thread Changbin Du
Hello, Joe,

Thanks for your comments. I will update the patch. And now I am trying
to remove all the two goto statements. Agree with you, we can use a
while statement instead.

I will send you the new patch for you to review when it's done.


2013/10/29 Joe Perches j...@perches.com

 On Mon, 2013-10-28 at 23:29 +0800, Du, Changbin wrote:
  From: Du, Changbin changbin...@gmail.com

 trivial notes:

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

  diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
 []
  @@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query 
  *query, const char *msg)
 query-first_lineno, query-last_lineno);
   }
 
  +/* check if the string matches given pattern which includes wildcards */
  +static int match_pattern(const char *pattern, const char *string)

 bool match_pattern

  +{
  + const char *s, *p;
  + int star = 0;

 bool star = false;

  +
  +loop:
  + for (s = string, p = pattern; *s; ++s, ++p) {
  + switch (*p) {
  + case '?':
  + break;
  + case '*':
  + star = 1;
  + string = s;
  + pattern = p;
  + if (!*++pattern)
  + return 1;
  + goto loop;
  + default:
  + if (*s != *p)
  + goto star_check;

 star = false;

  + break;
  + }
  + }
  + if (*p == '*')
  + ++p;
  + return (!*p);

 Don't need parentheses.

  +
  +star_check:
  + if (!star)
  + return 0;
  + string++;
  + goto loop;
  +}

 The star_check: label block seems like it'd be
 better in the switch case as it's only used once.

 Maybe the thing would be more readable with a
 while loop

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


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

2013-10-28 Thread Joe Perches
On Mon, 2013-10-28 at 23:29 +0800, Du, Changbin wrote:
> From: "Du, Changbin" 

trivial notes:

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

> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
[]
> @@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query 
> *query, const char *msg)
>query->first_lineno, query->last_lineno);
>  }
>  
> +/* check if the string matches given pattern which includes wildcards */
> +static int match_pattern(const char *pattern, const char *string)

bool match_pattern

> +{
> + const char *s, *p;
> + int star = 0;

bool star = false;

> +
> +loop:
> + for (s = string, p = pattern; *s; ++s, ++p) {
> + switch (*p) {
> + case '?':
> + break;
> + case '*':
> + star = 1;
> + string = s;
> + pattern = p;
> + if (!*++pattern)
> + return 1;
> + goto loop;
> + default:
> + if (*s != *p)
> + goto star_check;

star = false;

> + break;
> + }
> + }
> + if (*p == '*')
> + ++p;
> + return (!*p);

Don't need parentheses.

> +
> +star_check:
> + if (!star)
> + return 0;
> + string++;
> + goto loop;
> +}

The star_check: label block seems like it'd be
better in the switch case as it's only used once.

Maybe the thing would be more readable with a
while loop

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


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

2013-10-28 Thread Du, Changbin
From: "Du, Changbin" 

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" > /dynamic_debug/control
2.  open debug logs for usb xhci code
echo "file *xhci* +p" > /dynamic_debug/control

Signed-off-by: Du, Changbin 
---
changes since v1:
rewrite match_pattern using non-recursion method.
---
 lib/dynamic_debug.c | 47 ++-
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c37aeac..d239207 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query *query, 
const char *msg)
 query->first_lineno, query->last_lineno);
 }
 
+/* check if the string matches given pattern which includes wildcards */
+static int match_pattern(const char *pattern, const char *string)
+{
+   const char *s, *p;
+   int star = 0;
+
+loop:
+   for (s = string, p = pattern; *s; ++s, ++p) {
+   switch (*p) {
+   case '?':
+   break;
+   case '*':
+   star = 1;
+   string = s;
+   pattern = p;
+   if (!*++pattern)
+   return 1;
+   goto loop;
+   default:
+   if (*s != *p)
+   goto star_check;
+   break;
+   }
+   }
+   if (*p == '*')
+   ++p;
+   return (!*p);
+
+star_check:
+   if (!star)
+   return 0;
+   string++;
+   goto loop;
+}
+
 /*
  * 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 +182,7 @@ static int ddebug_change(const struct ddebug_query *query,
list_for_each_entry(dt, _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 +190,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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-10-28 Thread Du, Changbin
From: Du, Changbin changbin...@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...@gmail.com
---
changes since v1:
rewrite match_pattern using non-recursion method.
---
 lib/dynamic_debug.c | 47 ++-
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c37aeac..d239207 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query *query, 
const char *msg)
 query-first_lineno, query-last_lineno);
 }
 
+/* check if the string matches given pattern which includes wildcards */
+static int match_pattern(const char *pattern, const char *string)
+{
+   const char *s, *p;
+   int star = 0;
+
+loop:
+   for (s = string, p = pattern; *s; ++s, ++p) {
+   switch (*p) {
+   case '?':
+   break;
+   case '*':
+   star = 1;
+   string = s;
+   pattern = p;
+   if (!*++pattern)
+   return 1;
+   goto loop;
+   default:
+   if (*s != *p)
+   goto star_check;
+   break;
+   }
+   }
+   if (*p == '*')
+   ++p;
+   return (!*p);
+
+star_check:
+   if (!star)
+   return 0;
+   string++;
+   goto loop;
+}
+
 /*
  * 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 +182,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 +190,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 majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2013-10-28 Thread Joe Perches
On Mon, 2013-10-28 at 23:29 +0800, Du, Changbin wrote:
 From: Du, Changbin changbin...@gmail.com

trivial notes:

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

 diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
[]
 @@ -127,6 +127,41 @@ static void vpr_info_dq(const struct ddebug_query 
 *query, const char *msg)
query-first_lineno, query-last_lineno);
  }
  
 +/* check if the string matches given pattern which includes wildcards */
 +static int match_pattern(const char *pattern, const char *string)

bool match_pattern

 +{
 + const char *s, *p;
 + int star = 0;

bool star = false;

 +
 +loop:
 + for (s = string, p = pattern; *s; ++s, ++p) {
 + switch (*p) {
 + case '?':
 + break;
 + case '*':
 + star = 1;
 + string = s;
 + pattern = p;
 + if (!*++pattern)
 + return 1;
 + goto loop;
 + default:
 + if (*s != *p)
 + goto star_check;

star = false;

 + break;
 + }
 + }
 + if (*p == '*')
 + ++p;
 + return (!*p);

Don't need parentheses.

 +
 +star_check:
 + if (!star)
 + return 0;
 + string++;
 + goto loop;
 +}

The star_check: label block seems like it'd be
better in the switch case as it's only used once.

Maybe the thing would be more readable with a
while loop

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