Skip to content

Commit

Permalink
dyndbg: refactor parse_linerange out of ddebug_parse_query
Browse files Browse the repository at this point in the history
Make the code-block reusable to later handle "file foo.c:101-200" etc.
This is a 99% code move, with reindent, function wrap&call, +pr_debug.

no functional changes.

Acked-by: <jbaron@akamai.com>
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Link: https://lore.kernel.org/r/20200719231058.1586423-13-jim.cromie@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jim Cromie authored and Greg Kroah-Hartman committed Jul 24, 2020
1 parent f62fc08 commit 8037072
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions lib/dynamic_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,41 @@ static inline int parse_lineno(const char *str, unsigned int *val)
return 0;
}

static int parse_linerange(struct ddebug_query *query, const char *first)
{
char *last = strchr(first, '-');

if (query->first_lineno || query->last_lineno) {
pr_err("match-spec: line used 2x\n");
return -EINVAL;
}
if (last)
*last++ = '\0';
if (parse_lineno(first, &query->first_lineno) < 0)
return -EINVAL;
if (last) {
/* range <first>-<last> */
if (parse_lineno(last, &query->last_lineno) < 0)
return -EINVAL;

/* special case for last lineno not specified */
if (query->last_lineno == 0)
query->last_lineno = UINT_MAX;

if (query->last_lineno < query->first_lineno) {
pr_err("last-line:%d < 1st-line:%d\n",
query->last_lineno,
query->first_lineno);
return -EINVAL;
}
} else {
query->last_lineno = query->first_lineno;
}
vpr_info("parsed line %d-%d\n", query->first_lineno,
query->last_lineno);
return 0;
}

static int check_set(const char **dest, char *src, char *name)
{
int rc = 0;
Expand Down Expand Up @@ -348,34 +383,8 @@ static int ddebug_parse_query(char *words[], int nwords,
UNESCAPE_SPECIAL);
rc = check_set(&query->format, words[i+1], "format");
} else if (!strcmp(words[i], "line")) {
char *first = words[i+1];
char *last = strchr(first, '-');
if (query->first_lineno || query->last_lineno) {
pr_err("match-spec: line used 2x\n");
return -EINVAL;
}
if (last)
*last++ = '\0';
if (parse_lineno(first, &query->first_lineno) < 0)
if (parse_linerange(query, words[i+1]))
return -EINVAL;
if (last) {
/* range <first>-<last> */
if (parse_lineno(last, &query->last_lineno) < 0)
return -EINVAL;

/* special case for last lineno not specified */
if (query->last_lineno == 0)
query->last_lineno = UINT_MAX;

if (query->last_lineno < query->first_lineno) {
pr_err("last-line:%d < 1st-line:%d\n",
query->last_lineno,
query->first_lineno);
return -EINVAL;
}
} else {
query->last_lineno = query->first_lineno;
}
} else {
pr_err("unknown keyword \"%s\"\n", words[i]);
return -EINVAL;
Expand Down

0 comments on commit 8037072

Please sign in to comment.