Skip to content

Commit 42f0781

Browse files
jimcgregkh
authored andcommitted
dyndbg: fix problem parsing format="foo bar"
commit 14775b0 ("dyndbg: accept query terms like file=bar and module=foo") added the combined keyword=value parsing poorly; revert most of it, keeping the keyword & arg change. Instead, fix the tokenizer for the new input, by terminating the keyword (an unquoted word) on '=' as well as space, thus letting the tokenizer work on the quoted argument, like it would have previously. Also add a few debug-prints to show more parsing context, into tokenizer and parse-query, and use "keyword, value" in others. Fixes: 14775b0 ("dyndbg: accept query terms like file=bar and module=foo") Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Link: https://lore.kernel.org/r/20200831182210.850852-4-jim.cromie@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a2d375e commit 42f0781

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

lib/dynamic_debug.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
237237
{
238238
int nwords = 0;
239239

240+
vpr_info("entry, buf:'%s'\n", buf);
240241
while (*buf) {
241242
char *end;
242243

@@ -247,6 +248,8 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
247248
if (*buf == '#')
248249
break; /* token starts comment, skip rest of line */
249250

251+
vpr_info("start-of-word:%d '%s'\n", nwords, buf);
252+
250253
/* find `end' of word, whitespace separated or quoted */
251254
if (*buf == '"' || *buf == '\'') {
252255
int quote = *buf++;
@@ -257,7 +260,9 @@ static int ddebug_tokenize(char *buf, char *words[], int maxwords)
257260
return -EINVAL; /* unclosed quote */
258261
}
259262
} else {
260-
for (end = buf; *end && !isspace(*end); end++)
263+
for (end = buf;
264+
*end && *end != '=' && !isspace(*end);
265+
end++)
261266
;
262267
BUG_ON(end == buf);
263268
}
@@ -373,30 +378,21 @@ static int ddebug_parse_query(char *words[], int nwords,
373378
unsigned int i;
374379
int rc = 0;
375380
char *fline;
376-
char *keyword, *arg;
377381

378-
if (modname)
382+
if (nwords % 2 != 0) {
383+
pr_err("expecting pairs of match-spec <value>\n");
384+
return -EINVAL;
385+
}
386+
if (modname) {
379387
/* support $modname.dyndbg=<multiple queries> */
388+
vpr_info("module:%s queries:'%s'\n", modname);
380389
query->module = modname;
390+
}
391+
for (i = 0; i < nwords; i += 2) {
392+
char *keyword = words[i];
393+
char *arg = words[i+1];
381394

382-
for (i = 0; i < nwords; i++) {
383-
/* accept keyword=arg */
384-
vpr_info("%d w:%s\n", i, words[i]);
385-
386-
keyword = words[i];
387-
arg = strchr(keyword, '=');
388-
if (arg) {
389-
*arg++ = '\0';
390-
} else {
391-
i++; /* next word is arg */
392-
if (!(i < nwords)) {
393-
pr_err("missing arg to keyword: %s\n", keyword);
394-
return -EINVAL;
395-
}
396-
arg = words[i];
397-
}
398-
vpr_info("%d key:%s arg:%s\n", i, keyword, arg);
399-
395+
vpr_info("keyword:'%s' value:'%s'\n", keyword, arg);
400396
if (!strcmp(keyword, "func")) {
401397
rc = check_set(&query->function, arg, "func");
402398
} else if (!strcmp(keyword, "file")) {

0 commit comments

Comments
 (0)