Skip to content

Commit 14775b0

Browse files
jimcgregkh
authored andcommitted
dyndbg: accept query terms like file=bar and module=foo
Current code expects "keyword" "arg" as 2 words, space separated. Change to also accept "keyword=arg" form as well, and drop !(nwords%2) requirement. Then in rest of function, use new keyword, arg variables instead of word[i], word[i+1] Acked-by: <[email protected]> Signed-off-by: Jim Cromie <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent aaebe32 commit 14775b0

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

Documentation/admin-guide/dynamic-debug-howto.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ against. Possible keywords are:::
156156
``line-range`` cannot contain space, e.g.
157157
"1-30" is valid range but "1 - 30" is not.
158158

159+
``module=foo`` combined keyword=value form is interchangably accepted
159160

160161
The meanings of each keyword are:
161162

lib/dynamic_debug.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ static int check_set(const char **dest, char *src, char *name)
341341

342342
/*
343343
* Parse words[] as a ddebug query specification, which is a series
344-
* of (keyword, value) pairs chosen from these possibilities:
344+
* of (keyword, value) pairs or combined keyword=value terms,
345+
* chosen from these possibilities:
345346
*
346347
* func <function-name>
347348
* file <full-pathname>
@@ -360,22 +361,34 @@ static int ddebug_parse_query(char *words[], int nwords,
360361
unsigned int i;
361362
int rc = 0;
362363
char *fline;
363-
364-
/* check we have an even number of words */
365-
if (nwords % 2 != 0) {
366-
pr_err("expecting pairs of match-spec <value>\n");
367-
return -EINVAL;
368-
}
364+
char *keyword, *arg;
369365

370366
if (modname)
371367
/* support $modname.dyndbg=<multiple queries> */
372368
query->module = modname;
373369

374-
for (i = 0; i < nwords; i += 2) {
375-
if (!strcmp(words[i], "func")) {
376-
rc = check_set(&query->function, words[i+1], "func");
377-
} else if (!strcmp(words[i], "file")) {
378-
if (check_set(&query->filename, words[i+1], "file"))
370+
for (i = 0; i < nwords; i++) {
371+
/* accept keyword=arg */
372+
vpr_info("%d w:%s\n", i, words[i]);
373+
374+
keyword = words[i];
375+
arg = strchr(keyword, '=');
376+
if (arg) {
377+
*arg++ = '\0';
378+
} else {
379+
i++; /* next word is arg */
380+
if (!(i < nwords)) {
381+
pr_err("missing arg to keyword: %s\n", keyword);
382+
return -EINVAL;
383+
}
384+
arg = words[i];
385+
}
386+
vpr_info("%d key:%s arg:%s\n", i, keyword, arg);
387+
388+
if (!strcmp(keyword, "func")) {
389+
rc = check_set(&query->function, arg, "func");
390+
} else if (!strcmp(keyword, "file")) {
391+
if (check_set(&query->filename, arg, "file"))
379392
return -EINVAL;
380393

381394
/* tail :$info is function or line-range */
@@ -391,18 +404,18 @@ static int ddebug_parse_query(char *words[], int nwords,
391404
if (parse_linerange(query, fline))
392405
return -EINVAL;
393406
}
394-
} else if (!strcmp(words[i], "module")) {
395-
rc = check_set(&query->module, words[i+1], "module");
396-
} else if (!strcmp(words[i], "format")) {
397-
string_unescape_inplace(words[i+1], UNESCAPE_SPACE |
407+
} else if (!strcmp(keyword, "module")) {
408+
rc = check_set(&query->module, arg, "module");
409+
} else if (!strcmp(keyword, "format")) {
410+
string_unescape_inplace(arg, UNESCAPE_SPACE |
398411
UNESCAPE_OCTAL |
399412
UNESCAPE_SPECIAL);
400-
rc = check_set(&query->format, words[i+1], "format");
401-
} else if (!strcmp(words[i], "line")) {
402-
if (parse_linerange(query, words[i+1]))
413+
rc = check_set(&query->format, arg, "format");
414+
} else if (!strcmp(keyword, "line")) {
415+
if (parse_linerange(query, arg))
403416
return -EINVAL;
404417
} else {
405-
pr_err("unknown keyword \"%s\"\n", words[i]);
418+
pr_err("unknown keyword \"%s\"\n", keyword);
406419
return -EINVAL;
407420
}
408421
if (rc)

0 commit comments

Comments
 (0)