[PATCH v8-RESEND 22/33] dyndbg: split multi-query strings with %

Jim Cromie posted 33 patches 1 year, 9 months ago
[PATCH v8-RESEND 22/33] dyndbg: split multi-query strings with %
Posted by Jim Cromie 1 year, 9 months ago
Multi-query strings have long allowed:

  modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
  modprobe drm dyndbg=<<EOX
     class DRM_UT_CORE +p
     class DRM_UT_KMS +p
  EOX

More recently, the need for quoting was avoided by treating a comma
like a space/token-terminator:

  modprobe drm dyndbg=class,DRM_UT_CORE,+p\;class,DRM_UT_KMS,+p

That worked, but it left unfinished business; the semicolon in the
example above is a shell special-char (one of the bash control
operators), so it is brittle when passed in/down/around scripts.  In
particular, it fails when passed to vng (virtme-ng).

So this patch adds '%' to the existing ';' and '\n' multi-cmd
separators, which is more shell-friendly, and also avoids quoting and
escaping hassles.

NOTE: it does break format matching on '%' patterns:

bash-5.2# ddcmd 'format "find-me: %foo" +p'
[  203.900581] dyndbg: read 26 bytes from userspace
[  203.900883] dyndbg: query 0: "format "find-me: " mod:*
[  203.901118] dyndbg: unclosed quote: find-me:
[  203.901355] dyndbg: tokenize failed
[  203.901529] dyndbg: query 1: "foo" +p" mod:*
[  203.901957] dyndbg: split into words: "foo"" "+p"
[  203.902243] dyndbg: op='+' flags=0x1 maskp=0xffffffff
[  203.902458] dyndbg: expecting pairs of match-spec <value>
[  203.902703] dyndbg: query parse failed
[  203.902871] dyndbg: processed 2 queries, with 0 matches, 2 errs
bash: echo: write error: Invalid argument

The '%' splits the input into 2 queries, and both fail.  Given the
limited utility of matching against the working parts of a format
string "foo: %d bar %s", nothing is actually lost here.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 lib/dynamic_debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c1bc728cb050..625838bd74aa 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -596,7 +596,7 @@ static int ddebug_exec_queries(char *query, const char *modname)
 	int i, errs = 0, exitcode = 0, rc, nfound = 0;
 
 	for (i = 0; query; query = split) {
-		split = strpbrk(query, ";\n");
+		split = strpbrk(query, "%;\n");
 		if (split)
 			*split++ = '\0';
 
-- 
2.45.0
Re: [PATCH v8-RESEND 22/33] dyndbg: split multi-query strings with %
Posted by Łukasz Bartosik 1 year, 8 months ago
On Thu, May 16, 2024 at 7:45 PM Jim Cromie <jim.cromie@gmail.com> wrote:
>
> Multi-query strings have long allowed:

Missing been ?

>
>   modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
>   modprobe drm dyndbg=<<EOX
>      class DRM_UT_CORE +p
>      class DRM_UT_KMS +p
>   EOX
>
> More recently, the need for quoting was avoided by treating a comma
> like a space/token-terminator:
>
>   modprobe drm dyndbg=class,DRM_UT_CORE,+p\;class,DRM_UT_KMS,+p
>
> That worked, but it left unfinished business; the semicolon in the
> example above is a shell special-char (one of the bash control
> operators), so it is brittle when passed in/down/around scripts.  In
> particular, it fails when passed to vng (virtme-ng).
>
> So this patch adds '%' to the existing ';' and '\n' multi-cmd
> separators, which is more shell-friendly, and also avoids quoting and
> escaping hassles.
>
> NOTE: it does break format matching on '%' patterns:
>
> bash-5.2# ddcmd 'format "find-me: %foo" +p'
> [  203.900581] dyndbg: read 26 bytes from userspace
> [  203.900883] dyndbg: query 0: "format "find-me: " mod:*
> [  203.901118] dyndbg: unclosed quote: find-me:
> [  203.901355] dyndbg: tokenize failed
> [  203.901529] dyndbg: query 1: "foo" +p" mod:*
> [  203.901957] dyndbg: split into words: "foo"" "+p"
> [  203.902243] dyndbg: op='+' flags=0x1 maskp=0xffffffff
> [  203.902458] dyndbg: expecting pairs of match-spec <value>
> [  203.902703] dyndbg: query parse failed
> [  203.902871] dyndbg: processed 2 queries, with 0 matches, 2 errs
> bash: echo: write error: Invalid argument
>
> The '%' splits the input into 2 queries, and both fail.  Given the
> limited utility of matching against the working parts of a format
> string "foo: %d bar %s", nothing is actually lost here.
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> ---
>  lib/dynamic_debug.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
> index c1bc728cb050..625838bd74aa 100644
> --- a/lib/dynamic_debug.c
> +++ b/lib/dynamic_debug.c
> @@ -596,7 +596,7 @@ static int ddebug_exec_queries(char *query, const char *modname)
>         int i, errs = 0, exitcode = 0, rc, nfound = 0;
>
>         for (i = 0; query; query = split) {
> -               split = strpbrk(query, ";\n");
> +               split = strpbrk(query, "%;\n");
>                 if (split)
>                         *split++ = '\0';
>
> --
> 2.45.0
>
Re: [PATCH v8-RESEND 22/33] dyndbg: split multi-query strings with %
Posted by jim.cromie@gmail.com 1 year, 8 months ago
On Tue, May 21, 2024 at 5:58 AM Łukasz Bartosik <ukaszb@chromium.org> wrote:
>
> On Thu, May 16, 2024 at 7:45 PM Jim Cromie <jim.cromie@gmail.com> wrote:
> >
> > Multi-query strings have long allowed:

... input like:  (Im using it like a verb)

> Missing been ?

this is an alternative.
maybe s/strings/commands/ too

> >
> >   modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
> >   modprobe drm dyndbg=<<EOX
> >      class DRM_UT_CORE +p
> >      class DRM_UT_KMS +p
> >   EOX
> >
Re: [PATCH v8-RESEND 22/33] dyndbg: split multi-query strings with %
Posted by Łukasz Bartosik 1 year, 8 months ago
On Tue, May 21, 2024 at 6:08 PM <jim.cromie@gmail.com> wrote:
>
> On Tue, May 21, 2024 at 5:58 AM Łukasz Bartosik <ukaszb@chromium.org> wrote:
> >
> > On Thu, May 16, 2024 at 7:45 PM Jim Cromie <jim.cromie@gmail.com> wrote:
> > >
> > > Multi-query strings have long allowed:
>
> ... input like:  (Im using it like a verb)
>
> > Missing been ?
>
> this is an alternative.

I see

> maybe s/strings/commands/ too
>

I like commands more

> > >
> > >   modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
> > >   modprobe drm dyndbg=<<EOX
> > >      class DRM_UT_CORE +p
> > >      class DRM_UT_KMS +p
> > >   EOX
> > >
Re: [PATCH v8-RESEND 22/33] dyndbg: split multi-query strings with %
Posted by jim.cromie@gmail.com 1 year, 8 months ago
On Wed, May 22, 2024 at 10:57 AM Łukasz Bartosik <ukaszb@chromium.org> wrote:
>
> On Tue, May 21, 2024 at 6:08 PM <jim.cromie@gmail.com> wrote:
> >
> > On Tue, May 21, 2024 at 5:58 AM Łukasz Bartosik <ukaszb@chromium.org> wrote:
> > >
> > > On Thu, May 16, 2024 at 7:45 PM Jim Cromie <jim.cromie@gmail.com> wrote:
> > > >
> > > > Multi-query strings have long allowed:
> >
> > ... input like:  (Im using it like a verb)
> >
> > > Missing been ?
> >
> > this is an alternative.
>
> I see
>
> > maybe s/strings/commands/ too
> >
>
> I like commands more
>
> > > >
> > > >   modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
> > > >   modprobe drm dyndbg=<<EOX
> > > >      class DRM_UT_CORE +p
> > > >      class DRM_UT_KMS +p
> > > >   EOX
> > > >

I did reword it - to:

Subject: [PATCH v8d 22/36] dyndbg: split multi-query strings with %

Since commit
85f7f6c0edb8 ("dynamic_debug: process multiple debug-queries on a line")

Multi-query commands have been allowed:

  modprobe drm dyndbg="class DRM_UT_CORE +p; class DRM_UT_KMS +p"
  modprobe drm dyndbg=<<EOX
     class DRM_UT_CORE +p
     class DRM_UT_KMS +p
  EOX


the other thing I didnt do was add an example writing to >control explicitly,
but they are equivalent.