Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / tools / perf / util / parse-regs-options.c
blob646ecf736aadb78b8b747065a867a24f90e740b8
1 #include "perf.h"
2 #include "util/util.h"
3 #include "util/debug.h"
4 #include <subcmd/parse-options.h>
5 #include "util/parse-regs-options.h"
7 int
8 parse_regs(const struct option *opt, const char *str, int unset)
10 uint64_t *mode = (uint64_t *)opt->value;
11 const struct sample_reg *r;
12 char *s, *os = NULL, *p;
13 int ret = -1;
15 if (unset)
16 return 0;
19 * cannot set it twice
21 if (*mode)
22 return -1;
24 /* str may be NULL in case no arg is passed to -I */
25 if (str) {
26 /* because str is read-only */
27 s = os = strdup(str);
28 if (!s)
29 return -1;
31 for (;;) {
32 p = strchr(s, ',');
33 if (p)
34 *p = '\0';
36 if (!strcmp(s, "?")) {
37 fprintf(stderr, "available registers: ");
38 for (r = sample_reg_masks; r->name; r++) {
39 fprintf(stderr, "%s ", r->name);
41 fputc('\n', stderr);
42 /* just printing available regs */
43 return -1;
45 for (r = sample_reg_masks; r->name; r++) {
46 if (!strcasecmp(s, r->name))
47 break;
49 if (!r->name) {
50 ui__warning("unknown register %s,"
51 " check man page\n", s);
52 goto error;
55 *mode |= r->mask;
57 if (!p)
58 break;
60 s = p + 1;
63 ret = 0;
65 /* default to all possible regs */
66 if (*mode == 0)
67 *mode = PERF_REGS_MASK;
68 error:
69 free(os);
70 return ret;