diff options
author | Taeung Song <treeze.taeung@gmail.com> | 2017-04-07 20:52:24 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-04-11 15:22:22 -0400 |
commit | 4597cf0664d2fad785509dedfed22f8fe8951ebb (patch) | |
tree | 1298004463bccfbbdab9172bf1fbcd34c5272e0d /tools/perf/util/annotate.c | |
parent | c9d1c93421e3b3c7051b193c9cf648a3bc55cb3e (diff) |
perf annotate: Refactor the code to parse disassemble lines with {l,r}trim()
When parsing disassemble lines, use ltrim() and rtrim() to strip them,
not using just while loop and isspace().
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1491612748-1605-2-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r-- | tools/perf/util/annotate.c | 42 |
1 files changed, 7 insertions, 35 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 44ed6652b02f..204790db10f1 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c | |||
@@ -387,9 +387,7 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map *m | |||
387 | if (comment == NULL) | 387 | if (comment == NULL) |
388 | return 0; | 388 | return 0; |
389 | 389 | ||
390 | while (comment[0] != '\0' && isspace(comment[0])) | 390 | comment = ltrim(comment); |
391 | ++comment; | ||
392 | |||
393 | comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name); | 391 | comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name); |
394 | comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); | 392 | comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); |
395 | 393 | ||
@@ -434,9 +432,7 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *ops | |||
434 | if (comment == NULL) | 432 | if (comment == NULL) |
435 | return 0; | 433 | return 0; |
436 | 434 | ||
437 | while (comment[0] != '\0' && isspace(comment[0])) | 435 | comment = ltrim(comment); |
438 | ++comment; | ||
439 | |||
440 | comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); | 436 | comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); |
441 | 437 | ||
442 | return 0; | 438 | return 0; |
@@ -785,10 +781,7 @@ static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, str | |||
785 | 781 | ||
786 | static int disasm_line__parse(char *line, const char **namep, char **rawp) | 782 | static int disasm_line__parse(char *line, const char **namep, char **rawp) |
787 | { | 783 | { |
788 | char *name = line, tmp; | 784 | char tmp, *name = ltrim(line); |
789 | |||
790 | while (isspace(name[0])) | ||
791 | ++name; | ||
792 | 785 | ||
793 | if (name[0] == '\0') | 786 | if (name[0] == '\0') |
794 | return -1; | 787 | return -1; |
@@ -806,12 +799,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) | |||
806 | goto out_free_name; | 799 | goto out_free_name; |
807 | 800 | ||
808 | (*rawp)[0] = tmp; | 801 | (*rawp)[0] = tmp; |
809 | 802 | *rawp = ltrim(*rawp); | |
810 | if ((*rawp)[0] != '\0') { | ||
811 | (*rawp)++; | ||
812 | while (isspace((*rawp)[0])) | ||
813 | ++(*rawp); | ||
814 | } | ||
815 | 803 | ||
816 | return 0; | 804 | return 0; |
817 | 805 | ||
@@ -1156,7 +1144,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map, | |||
1156 | { | 1144 | { |
1157 | struct annotation *notes = symbol__annotation(sym); | 1145 | struct annotation *notes = symbol__annotation(sym); |
1158 | struct disasm_line *dl; | 1146 | struct disasm_line *dl; |
1159 | char *line = NULL, *parsed_line, *tmp, *tmp2, *c; | 1147 | char *line = NULL, *parsed_line, *tmp, *tmp2; |
1160 | size_t line_len; | 1148 | size_t line_len; |
1161 | s64 line_ip, offset = -1; | 1149 | s64 line_ip, offset = -1; |
1162 | regmatch_t match[2]; | 1150 | regmatch_t match[2]; |
@@ -1167,15 +1155,8 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map, | |||
1167 | if (!line) | 1155 | if (!line) |
1168 | return -1; | 1156 | return -1; |
1169 | 1157 | ||
1170 | while (line_len != 0 && isspace(line[line_len - 1])) | ||
1171 | line[--line_len] = '\0'; | ||
1172 | |||
1173 | c = strchr(line, '\n'); | ||
1174 | if (c) | ||
1175 | *c = 0; | ||
1176 | |||
1177 | line_ip = -1; | 1158 | line_ip = -1; |
1178 | parsed_line = line; | 1159 | parsed_line = rtrim(line); |
1179 | 1160 | ||
1180 | /* /filename:linenr ? Save line number and ignore. */ | 1161 | /* /filename:linenr ? Save line number and ignore. */ |
1181 | if (regexec(&file_lineno, line, 2, match, 0) == 0) { | 1162 | if (regexec(&file_lineno, line, 2, match, 0) == 0) { |
@@ -1183,16 +1164,7 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map, | |||
1183 | return 0; | 1164 | return 0; |
1184 | } | 1165 | } |
1185 | 1166 | ||
1186 | /* | 1167 | tmp = ltrim(parsed_line); |
1187 | * Strip leading spaces: | ||
1188 | */ | ||
1189 | tmp = line; | ||
1190 | while (*tmp) { | ||
1191 | if (*tmp != ' ') | ||
1192 | break; | ||
1193 | tmp++; | ||
1194 | } | ||
1195 | |||
1196 | if (*tmp) { | 1168 | if (*tmp) { |
1197 | /* | 1169 | /* |
1198 | * Parse hexa addresses followed by ':' | 1170 | * Parse hexa addresses followed by ':' |