On Thu, Jun 13, 2019 at 03:15:14PM -0300, Arnaldo Carvalho de Melo wrote: [...]
> > > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > > > > index 1a2a605cf068..eb70a4b71755 100644 > > > > --- a/tools/perf/builtin-trace.c > > > > +++ b/tools/perf/builtin-trace.c > > > > @@ -1529,6 +1529,7 @@ static int trace__read_syscall_info(struct trace > > > > *trace, int id) > > > > static int trace__validate_ev_qualifier(struct trace *trace) > > > > { > > > > int err = 0, i; > > > > + bool printed_invalid_prefix = false; > > > > size_t nr_allocated; > > > > struct str_node *pos; > > > > > > > > @@ -1555,14 +1556,15 @@ static int trace__validate_ev_qualifier(struct > > > > trace *trace) > > > > if (id >= 0) > > > > goto matches; > > > > > > > > - if (err == 0) { > > > > - fputs("Error:\tInvalid syscall ", > > > > trace->output); > > > > - err = -EINVAL; > > > > + if (!printed_invalid_prefix) { > > > > + pr_debug("Skipping unknown syscalls: "); > > > > + printed_invalid_prefix = true; > > > > } else { > > > > - fputs(", ", trace->output); > > > > + pr_debug(", "); > > > > } > > > > > > > > - fputs(sc, trace->output); > > > > + pr_debug("%s", sc); > > > > + continue; > > > > > > Here adds 'continue' so that we want to let ev_qualifier_ids.entries > > > to only store valid system call ids. But this is not sufficient, > > > because we have initialized ev_qualifier_ids.nr at the beginning of > > > the function: > > > > > > trace->ev_qualifier_ids.nr = strlist__nr_entries(trace->ev_qualifier); > > > This sentence will set ids number to the string table's length; but > > > actually some strings are not really supported; this leads to some > > > items in trace->ev_qualifier_ids.entries[] will be not initialized > > > properly. > > > > > > If we want to get neat entries and entry number, I suggest at the > > > beginning of the function we use variable 'nr_allocated' to store > > > string table length and use it to allocate entries: > > > > > > nr_allocated = strlist__nr_entries(trace->ev_qualifier); > > > trace->ev_qualifier_ids.entries = malloc(nr_allocated * > > > > > > sizeof(trace->ev_qualifier_ids.entries[0])); > > > > > > If we find any matched string, then increment the nr field under > > > 'matches' tag: > > > > > > matches: > > > trace->ev_qualifier_ids.nr++; > > > trace->ev_qualifier_ids.entries[i++] = id; > > > > > > This can ensure the entries[0..nr-1] has valid id and we can use > > > ev_qualifier_ids.nr to maintain the valid system call numbers. > > > > yeah, you're right, I'll address these issues in a followup patch, > > tomorrow. > > This is equivalent and I think the smallest patch, I'll add one on top > doing what you suggested about nr_allocated getting the > strlist__nr_entries() and also will rename i to nr_used to contrast with > nr_allocated, and then at the end set ev_qualifier_ids.nr to nr_used. Thanks for this patch, I tested below changes and 'perf trace' works well. You could add my test tag: Tested-by: Leo Yan <leo....@linaro.org> > - Arnaldo > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > index eb70a4b71755..bd1f00e7a2eb 100644 > --- a/tools/perf/builtin-trace.c > +++ b/tools/perf/builtin-trace.c > @@ -1528,9 +1528,9 @@ static int trace__read_syscall_info(struct trace > *trace, int id) > > static int trace__validate_ev_qualifier(struct trace *trace) > { > - int err = 0, i; > + int err = 0; > bool printed_invalid_prefix = false; > - size_t nr_allocated; > + size_t nr_allocated, i; > struct str_node *pos; > > trace->ev_qualifier_ids.nr = strlist__nr_entries(trace->ev_qualifier); > @@ -1575,7 +1575,7 @@ static int trace__validate_ev_qualifier(struct trace > *trace) > id = syscalltbl__strglobmatch_next(trace->sctbl, sc, > &match_next); > if (id < 0) > break; > - if (nr_allocated == trace->ev_qualifier_ids.nr) { > + if (nr_allocated == i) { > void *entries; > > nr_allocated += 8; > @@ -1588,11 +1588,11 @@ static int trace__validate_ev_qualifier(struct trace > *trace) > } > trace->ev_qualifier_ids.entries = entries; > } > - trace->ev_qualifier_ids.nr++; > trace->ev_qualifier_ids.entries[i++] = id; > } > } > > + trace->ev_qualifier_ids.nr = i; > out: > if (printed_invalid_prefix) > pr_debug("\n");