Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> |
| 3 | * |
| 4 | * Parts came from builtin-annotate.c, see those files for further |
| 5 | * copyright notes. |
| 6 | * |
| 7 | * Released under the GPL v2. (and only v2, not any later version) |
| 8 | */ |
| 9 | |
| 10 | #include "util.h" |
Namhyung Kim | 48c65bd | 2014-02-20 10:32:53 +0900 | [diff] [blame] | 11 | #include "ui/ui.h" |
| 12 | #include "sort.h" |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 13 | #include "build-id.h" |
| 14 | #include "color.h" |
| 15 | #include "cache.h" |
| 16 | #include "symbol.h" |
| 17 | #include "debug.h" |
| 18 | #include "annotate.h" |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 19 | #include "evsel.h" |
Peter Zijlstra | 70fbe05 | 2016-09-05 16:08:12 -0300 | [diff] [blame] | 20 | #include "block-range.h" |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 21 | #include "arch/common.h" |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 22 | #include <regex.h> |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 23 | #include <pthread.h> |
Jiri Olsa | 4383db8 | 2012-10-27 23:18:29 +0200 | [diff] [blame] | 24 | #include <linux/bitops.h> |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 25 | #include <sys/utsname.h> |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 26 | |
Andi Kleen | f69b64f | 2011-09-15 14:31:41 -0700 | [diff] [blame] | 27 | const char *disassembler_style; |
Maciek Borzecki | 7a4ec93 | 2012-09-04 12:32:30 +0200 | [diff] [blame] | 28 | const char *objdump_path; |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 29 | static regex_t file_lineno; |
Andi Kleen | f69b64f | 2011-09-15 14:31:41 -0700 | [diff] [blame] | 30 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 31 | static struct ins_ops *ins__find(struct arch *arch, const char *name); |
Arnaldo Carvalho de Melo | 2a1ff81 | 2016-11-24 11:37:08 -0300 | [diff] [blame^] | 32 | static void ins__sort(struct arch *arch); |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 33 | static int disasm_line__parse(char *line, const char **namep, char **rawp); |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 34 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 35 | struct arch { |
| 36 | const char *name; |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 37 | struct ins *instructions; |
| 38 | size_t nr_instructions; |
Arnaldo Carvalho de Melo | 2a1ff81 | 2016-11-24 11:37:08 -0300 | [diff] [blame^] | 39 | size_t nr_instructions_allocated; |
| 40 | struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const char *name); |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 41 | bool sorted_instructions; |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 42 | struct { |
| 43 | char comment_char; |
Arnaldo Carvalho de Melo | 9c2fb45 | 2016-11-16 15:50:38 -0300 | [diff] [blame] | 44 | char skip_functions_char; |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 45 | } objdump; |
| 46 | }; |
| 47 | |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 48 | static struct ins_ops call_ops; |
| 49 | static struct ins_ops dec_ops; |
| 50 | static struct ins_ops jump_ops; |
| 51 | static struct ins_ops mov_ops; |
| 52 | static struct ins_ops nop_ops; |
| 53 | static struct ins_ops lock_ops; |
| 54 | static struct ins_ops ret_ops; |
| 55 | |
Arnaldo Carvalho de Melo | 2a1ff81 | 2016-11-24 11:37:08 -0300 | [diff] [blame^] | 56 | static int arch__grow_instructions(struct arch *arch) |
| 57 | { |
| 58 | struct ins *new_instructions; |
| 59 | size_t new_nr_allocated; |
| 60 | |
| 61 | if (arch->nr_instructions_allocated == 0 && arch->instructions) |
| 62 | goto grow_from_non_allocated_table; |
| 63 | |
| 64 | new_nr_allocated = arch->nr_instructions_allocated + 128; |
| 65 | new_instructions = realloc(arch->instructions, new_nr_allocated * sizeof(struct ins)); |
| 66 | if (new_instructions == NULL) |
| 67 | return -1; |
| 68 | |
| 69 | out_update_instructions: |
| 70 | arch->instructions = new_instructions; |
| 71 | arch->nr_instructions_allocated = new_nr_allocated; |
| 72 | return 0; |
| 73 | |
| 74 | grow_from_non_allocated_table: |
| 75 | new_nr_allocated = arch->nr_instructions + 128; |
| 76 | new_instructions = calloc(new_nr_allocated, sizeof(struct ins)); |
| 77 | if (new_instructions == NULL) |
| 78 | return -1; |
| 79 | |
| 80 | memcpy(new_instructions, arch->instructions, arch->nr_instructions); |
| 81 | goto out_update_instructions; |
| 82 | } |
| 83 | |
| 84 | static __maybe_unused int arch__associate_ins_ops(struct arch* arch, const char *name, struct ins_ops *ops) |
| 85 | { |
| 86 | struct ins *ins; |
| 87 | |
| 88 | if (arch->nr_instructions == arch->nr_instructions_allocated && |
| 89 | arch__grow_instructions(arch)) |
| 90 | return -1; |
| 91 | |
| 92 | ins = &arch->instructions[arch->nr_instructions]; |
| 93 | ins->name = strdup(name); |
| 94 | if (!ins->name) |
| 95 | return -1; |
| 96 | |
| 97 | ins->ops = ops; |
| 98 | arch->nr_instructions++; |
| 99 | |
| 100 | ins__sort(arch); |
| 101 | return 0; |
| 102 | } |
| 103 | |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 104 | #include "arch/arm/annotate/instructions.c" |
| 105 | #include "arch/x86/annotate/instructions.c" |
| 106 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 107 | static struct arch architectures[] = { |
| 108 | { |
| 109 | .name = "arm", |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 110 | .instructions = arm__instructions, |
| 111 | .nr_instructions = ARRAY_SIZE(arm__instructions), |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 112 | .objdump = { |
| 113 | .comment_char = ';', |
Arnaldo Carvalho de Melo | 9c2fb45 | 2016-11-16 15:50:38 -0300 | [diff] [blame] | 114 | .skip_functions_char = '+', |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 115 | }, |
| 116 | }, |
| 117 | { |
| 118 | .name = "x86", |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 119 | .instructions = x86__instructions, |
| 120 | .nr_instructions = ARRAY_SIZE(x86__instructions), |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 121 | .objdump = { |
| 122 | .comment_char = '#', |
| 123 | }, |
| 124 | }, |
| 125 | }; |
| 126 | |
Arnaldo Carvalho de Melo | c46219ac | 2012-05-12 13:26:20 -0300 | [diff] [blame] | 127 | static void ins__delete(struct ins_operands *ops) |
| 128 | { |
Arnaldo Carvalho de Melo | 3995614 | 2015-03-05 15:27:28 -0300 | [diff] [blame] | 129 | if (ops == NULL) |
| 130 | return; |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 131 | zfree(&ops->source.raw); |
| 132 | zfree(&ops->source.name); |
| 133 | zfree(&ops->target.raw); |
| 134 | zfree(&ops->target.name); |
Arnaldo Carvalho de Melo | c46219ac | 2012-05-12 13:26:20 -0300 | [diff] [blame] | 135 | } |
| 136 | |
Arnaldo Carvalho de Melo | 5417072 | 2012-05-07 18:54:16 -0300 | [diff] [blame] | 137 | static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, |
| 138 | struct ins_operands *ops) |
| 139 | { |
| 140 | return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw); |
| 141 | } |
| 142 | |
| 143 | int ins__scnprintf(struct ins *ins, char *bf, size_t size, |
| 144 | struct ins_operands *ops) |
| 145 | { |
| 146 | if (ins->ops->scnprintf) |
| 147 | return ins->ops->scnprintf(ins, bf, size, ops); |
| 148 | |
| 149 | return ins__raw_scnprintf(ins, bf, size, ops); |
| 150 | } |
| 151 | |
Arnaldo Carvalho de Melo | 9c2fb45 | 2016-11-16 15:50:38 -0300 | [diff] [blame] | 152 | static int call__parse(struct arch *arch, struct ins_operands *ops, struct map *map) |
Arnaldo Carvalho de Melo | d86b059 | 2012-04-18 16:07:38 -0300 | [diff] [blame] | 153 | { |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 154 | char *endptr, *tok, *name; |
| 155 | |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 156 | ops->target.addr = strtoull(ops->raw, &endptr, 16); |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 157 | |
| 158 | name = strchr(endptr, '<'); |
| 159 | if (name == NULL) |
| 160 | goto indirect_call; |
| 161 | |
| 162 | name++; |
| 163 | |
Arnaldo Carvalho de Melo | 9c2fb45 | 2016-11-16 15:50:38 -0300 | [diff] [blame] | 164 | if (arch->objdump.skip_functions_char && |
| 165 | strchr(name, arch->objdump.skip_functions_char)) |
Russell King | cfef25b | 2015-12-06 23:07:13 +0000 | [diff] [blame] | 166 | return -1; |
Russell King | cfef25b | 2015-12-06 23:07:13 +0000 | [diff] [blame] | 167 | |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 168 | tok = strchr(name, '>'); |
| 169 | if (tok == NULL) |
| 170 | return -1; |
| 171 | |
| 172 | *tok = '\0'; |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 173 | ops->target.name = strdup(name); |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 174 | *tok = '>'; |
| 175 | |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 176 | return ops->target.name == NULL ? -1 : 0; |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 177 | |
| 178 | indirect_call: |
Ravi Bangoria | 88a7fcf | 2016-08-19 18:29:35 +0530 | [diff] [blame] | 179 | tok = strchr(endptr, '*'); |
| 180 | if (tok == NULL) { |
Arnaldo Carvalho de Melo | 5f62d4f | 2016-09-19 17:26:11 -0300 | [diff] [blame] | 181 | struct symbol *sym = map__find_symbol(map, map->map_ip(map, ops->target.addr)); |
| 182 | if (sym != NULL) |
| 183 | ops->target.name = strdup(sym->name); |
| 184 | else |
| 185 | ops->target.addr = 0; |
Arnaldo Carvalho de Melo | e8ea156 | 2012-05-11 12:28:55 -0300 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 189 | ops->target.addr = strtoull(tok + 1, NULL, 16); |
Arnaldo Carvalho de Melo | d86b059 | 2012-04-18 16:07:38 -0300 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 193 | static int call__scnprintf(struct ins *ins, char *bf, size_t size, |
Arnaldo Carvalho de Melo | 5417072 | 2012-05-07 18:54:16 -0300 | [diff] [blame] | 194 | struct ins_operands *ops) |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 195 | { |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 196 | if (ops->target.name) |
| 197 | return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->target.name); |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 198 | |
Arnaldo Carvalho de Melo | e8ea156 | 2012-05-11 12:28:55 -0300 | [diff] [blame] | 199 | if (ops->target.addr == 0) |
| 200 | return ins__raw_scnprintf(ins, bf, size, ops); |
| 201 | |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 202 | return scnprintf(bf, size, "%-6.6s *%" PRIx64, ins->name, ops->target.addr); |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 203 | } |
| 204 | |
Arnaldo Carvalho de Melo | d86b059 | 2012-04-18 16:07:38 -0300 | [diff] [blame] | 205 | static struct ins_ops call_ops = { |
Arnaldo Carvalho de Melo | d223288 | 2012-04-20 15:26:47 -0300 | [diff] [blame] | 206 | .parse = call__parse, |
| 207 | .scnprintf = call__scnprintf, |
Arnaldo Carvalho de Melo | d86b059 | 2012-04-18 16:07:38 -0300 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | bool ins__is_call(const struct ins *ins) |
| 211 | { |
| 212 | return ins->ops == &call_ops; |
| 213 | } |
| 214 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 215 | static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map *map __maybe_unused) |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 216 | { |
Arnaldo Carvalho de Melo | c7e6ead | 2012-04-20 14:38:46 -0300 | [diff] [blame] | 217 | const char *s = strchr(ops->raw, '+'); |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 218 | |
Adrian Hunter | bbb7f84 | 2013-08-07 14:38:54 +0300 | [diff] [blame] | 219 | ops->target.addr = strtoull(ops->raw, NULL, 16); |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 220 | |
Arnaldo Carvalho de Melo | fb29fa58 | 2012-04-25 14:16:03 -0300 | [diff] [blame] | 221 | if (s++ != NULL) |
Adrian Hunter | bbb7f84 | 2013-08-07 14:38:54 +0300 | [diff] [blame] | 222 | ops->target.offset = strtoull(s, NULL, 16); |
Arnaldo Carvalho de Melo | fb29fa58 | 2012-04-25 14:16:03 -0300 | [diff] [blame] | 223 | else |
| 224 | ops->target.offset = UINT64_MAX; |
| 225 | |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Arnaldo Carvalho de Melo | c7e6ead | 2012-04-20 14:38:46 -0300 | [diff] [blame] | 229 | static int jump__scnprintf(struct ins *ins, char *bf, size_t size, |
Arnaldo Carvalho de Melo | 5417072 | 2012-05-07 18:54:16 -0300 | [diff] [blame] | 230 | struct ins_operands *ops) |
Arnaldo Carvalho de Melo | 28548d7 | 2012-04-19 10:16:27 -0300 | [diff] [blame] | 231 | { |
Arnaldo Carvalho de Melo | 44d1a3e | 2012-04-25 08:00:23 -0300 | [diff] [blame] | 232 | return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset); |
Arnaldo Carvalho de Melo | 28548d7 | 2012-04-19 10:16:27 -0300 | [diff] [blame] | 233 | } |
| 234 | |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 235 | static struct ins_ops jump_ops = { |
Arnaldo Carvalho de Melo | c7e6ead | 2012-04-20 14:38:46 -0300 | [diff] [blame] | 236 | .parse = jump__parse, |
| 237 | .scnprintf = jump__scnprintf, |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | bool ins__is_jump(const struct ins *ins) |
| 241 | { |
| 242 | return ins->ops == &jump_ops; |
| 243 | } |
| 244 | |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 245 | static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep) |
| 246 | { |
| 247 | char *endptr, *name, *t; |
| 248 | |
| 249 | if (strstr(raw, "(%rip)") == NULL) |
| 250 | return 0; |
| 251 | |
| 252 | *addrp = strtoull(comment, &endptr, 16); |
| 253 | name = strchr(endptr, '<'); |
| 254 | if (name == NULL) |
| 255 | return -1; |
| 256 | |
| 257 | name++; |
| 258 | |
| 259 | t = strchr(name, '>'); |
| 260 | if (t == NULL) |
| 261 | return 0; |
| 262 | |
| 263 | *t = '\0'; |
| 264 | *namep = strdup(name); |
| 265 | *t = '>'; |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 270 | static int lock__parse(struct arch *arch, struct ins_operands *ops, struct map *map) |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 271 | { |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 272 | ops->locked.ops = zalloc(sizeof(*ops->locked.ops)); |
| 273 | if (ops->locked.ops == NULL) |
| 274 | return 0; |
| 275 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 276 | if (disasm_line__parse(ops->raw, &ops->locked.ins.name, &ops->locked.ops->raw) < 0) |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 277 | goto out_free_ops; |
| 278 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 279 | ops->locked.ins.ops = ins__find(arch, ops->locked.ins.name); |
Rabin Vincent | 0fb9f2a | 2015-01-18 20:00:21 +0100 | [diff] [blame] | 280 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 281 | if (ops->locked.ins.ops == NULL) |
Namhyung Kim | 2ba34aa | 2012-11-10 02:27:13 +0900 | [diff] [blame] | 282 | goto out_free_ops; |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 283 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 284 | if (ops->locked.ins.ops->parse && |
| 285 | ops->locked.ins.ops->parse(arch, ops->locked.ops, map) < 0) |
Rabin Vincent | be81908 | 2015-01-18 20:00:20 +0100 | [diff] [blame] | 286 | goto out_free_ops; |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 287 | |
| 288 | return 0; |
| 289 | |
| 290 | out_free_ops: |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 291 | zfree(&ops->locked.ops); |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static int lock__scnprintf(struct ins *ins, char *bf, size_t size, |
| 296 | struct ins_operands *ops) |
| 297 | { |
| 298 | int printed; |
| 299 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 300 | if (ops->locked.ins.ops == NULL) |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 301 | return ins__raw_scnprintf(ins, bf, size, ops); |
| 302 | |
| 303 | printed = scnprintf(bf, size, "%-6.6s ", ins->name); |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 304 | return printed + ins__scnprintf(&ops->locked.ins, bf + printed, |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 305 | size - printed, ops->locked.ops); |
| 306 | } |
| 307 | |
Arnaldo Carvalho de Melo | c46219ac | 2012-05-12 13:26:20 -0300 | [diff] [blame] | 308 | static void lock__delete(struct ins_operands *ops) |
| 309 | { |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 310 | struct ins *ins = &ops->locked.ins; |
Rabin Vincent | 0fb9f2a | 2015-01-18 20:00:21 +0100 | [diff] [blame] | 311 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 312 | if (ins->ops && ins->ops->free) |
Rabin Vincent | 0fb9f2a | 2015-01-18 20:00:21 +0100 | [diff] [blame] | 313 | ins->ops->free(ops->locked.ops); |
| 314 | else |
| 315 | ins__delete(ops->locked.ops); |
| 316 | |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 317 | zfree(&ops->locked.ops); |
| 318 | zfree(&ops->target.raw); |
| 319 | zfree(&ops->target.name); |
Arnaldo Carvalho de Melo | c46219ac | 2012-05-12 13:26:20 -0300 | [diff] [blame] | 320 | } |
| 321 | |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 322 | static struct ins_ops lock_ops = { |
Arnaldo Carvalho de Melo | c46219ac | 2012-05-12 13:26:20 -0300 | [diff] [blame] | 323 | .free = lock__delete, |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 324 | .parse = lock__parse, |
| 325 | .scnprintf = lock__scnprintf, |
| 326 | }; |
| 327 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 328 | static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map *map __maybe_unused) |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 329 | { |
| 330 | char *s = strchr(ops->raw, ','), *target, *comment, prev; |
| 331 | |
| 332 | if (s == NULL) |
| 333 | return -1; |
| 334 | |
| 335 | *s = '\0'; |
| 336 | ops->source.raw = strdup(ops->raw); |
| 337 | *s = ','; |
Arnaldo Carvalho de Melo | 48000a1 | 2014-12-17 17:24:45 -0300 | [diff] [blame] | 338 | |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 339 | if (ops->source.raw == NULL) |
| 340 | return -1; |
| 341 | |
| 342 | target = ++s; |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 343 | comment = strchr(s, arch->objdump.comment_char); |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 344 | |
Alex Converse | 1e2bb04 | 2014-08-14 14:03:00 -0700 | [diff] [blame] | 345 | if (comment != NULL) |
| 346 | s = comment - 1; |
| 347 | else |
| 348 | s = strchr(s, '\0') - 1; |
| 349 | |
| 350 | while (s > target && isspace(s[0])) |
| 351 | --s; |
| 352 | s++; |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 353 | prev = *s; |
| 354 | *s = '\0'; |
| 355 | |
| 356 | ops->target.raw = strdup(target); |
| 357 | *s = prev; |
| 358 | |
| 359 | if (ops->target.raw == NULL) |
| 360 | goto out_free_source; |
| 361 | |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 362 | if (comment == NULL) |
| 363 | return 0; |
| 364 | |
| 365 | while (comment[0] != '\0' && isspace(comment[0])) |
| 366 | ++comment; |
| 367 | |
| 368 | comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name); |
| 369 | comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); |
| 370 | |
| 371 | return 0; |
| 372 | |
| 373 | out_free_source: |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 374 | zfree(&ops->source.raw); |
Arnaldo Carvalho de Melo | 6de783b | 2012-05-11 16:48:49 -0300 | [diff] [blame] | 375 | return -1; |
| 376 | } |
| 377 | |
| 378 | static int mov__scnprintf(struct ins *ins, char *bf, size_t size, |
| 379 | struct ins_operands *ops) |
| 380 | { |
| 381 | return scnprintf(bf, size, "%-6.6s %s,%s", ins->name, |
| 382 | ops->source.name ?: ops->source.raw, |
| 383 | ops->target.name ?: ops->target.raw); |
| 384 | } |
| 385 | |
| 386 | static struct ins_ops mov_ops = { |
| 387 | .parse = mov__parse, |
| 388 | .scnprintf = mov__scnprintf, |
| 389 | }; |
| 390 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 391 | static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map *map __maybe_unused) |
Arnaldo Carvalho de Melo | a43712c | 2012-05-11 17:21:09 -0300 | [diff] [blame] | 392 | { |
| 393 | char *target, *comment, *s, prev; |
| 394 | |
| 395 | target = s = ops->raw; |
| 396 | |
| 397 | while (s[0] != '\0' && !isspace(s[0])) |
| 398 | ++s; |
| 399 | prev = *s; |
| 400 | *s = '\0'; |
| 401 | |
| 402 | ops->target.raw = strdup(target); |
| 403 | *s = prev; |
| 404 | |
| 405 | if (ops->target.raw == NULL) |
| 406 | return -1; |
| 407 | |
| 408 | comment = strchr(s, '#'); |
| 409 | if (comment == NULL) |
| 410 | return 0; |
| 411 | |
| 412 | while (comment[0] != '\0' && isspace(comment[0])) |
| 413 | ++comment; |
| 414 | |
| 415 | comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static int dec__scnprintf(struct ins *ins, char *bf, size_t size, |
| 421 | struct ins_operands *ops) |
| 422 | { |
| 423 | return scnprintf(bf, size, "%-6.6s %s", ins->name, |
| 424 | ops->target.name ?: ops->target.raw); |
| 425 | } |
| 426 | |
| 427 | static struct ins_ops dec_ops = { |
| 428 | .parse = dec__parse, |
| 429 | .scnprintf = dec__scnprintf, |
| 430 | }; |
| 431 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 432 | static int nop__scnprintf(struct ins *ins __maybe_unused, char *bf, size_t size, |
| 433 | struct ins_operands *ops __maybe_unused) |
Arnaldo Carvalho de Melo | b9818e9 | 2012-05-07 18:57:02 -0300 | [diff] [blame] | 434 | { |
| 435 | return scnprintf(bf, size, "%-6.6s", "nop"); |
| 436 | } |
| 437 | |
| 438 | static struct ins_ops nop_ops = { |
| 439 | .scnprintf = nop__scnprintf, |
| 440 | }; |
| 441 | |
Naveen N. Rao | 6ef9492 | 2016-06-24 17:23:58 +0530 | [diff] [blame] | 442 | static struct ins_ops ret_ops = { |
| 443 | .scnprintf = ins__raw_scnprintf, |
| 444 | }; |
| 445 | |
| 446 | bool ins__is_ret(const struct ins *ins) |
| 447 | { |
| 448 | return ins->ops == &ret_ops; |
| 449 | } |
| 450 | |
Chris Ryder | 7e4c149 | 2016-05-19 17:59:46 +0100 | [diff] [blame] | 451 | static int ins__key_cmp(const void *name, const void *insp) |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 452 | { |
| 453 | const struct ins *ins = insp; |
| 454 | |
| 455 | return strcmp(name, ins->name); |
| 456 | } |
| 457 | |
Chris Ryder | 7e4c149 | 2016-05-19 17:59:46 +0100 | [diff] [blame] | 458 | static int ins__cmp(const void *a, const void *b) |
| 459 | { |
| 460 | const struct ins *ia = a; |
| 461 | const struct ins *ib = b; |
| 462 | |
| 463 | return strcmp(ia->name, ib->name); |
| 464 | } |
| 465 | |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 466 | static void ins__sort(struct arch *arch) |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 467 | { |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 468 | const int nmemb = arch->nr_instructions; |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 469 | |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 470 | qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); |
Chris Ryder | 7e4c149 | 2016-05-19 17:59:46 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Arnaldo Carvalho de Melo | 2a1ff81 | 2016-11-24 11:37:08 -0300 | [diff] [blame^] | 473 | static struct ins_ops *__ins__find(struct arch *arch, const char *name) |
Chris Ryder | 7e4c149 | 2016-05-19 17:59:46 +0100 | [diff] [blame] | 474 | { |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 475 | struct ins *ins; |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 476 | const int nmemb = arch->nr_instructions; |
Chris Ryder | 7e4c149 | 2016-05-19 17:59:46 +0100 | [diff] [blame] | 477 | |
Arnaldo Carvalho de Melo | 763d896 | 2016-11-17 12:31:51 -0300 | [diff] [blame] | 478 | if (!arch->sorted_instructions) { |
| 479 | ins__sort(arch); |
| 480 | arch->sorted_instructions = true; |
Chris Ryder | 7e4c149 | 2016-05-19 17:59:46 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 483 | ins = bsearch(name, arch->instructions, nmemb, sizeof(struct ins), ins__key_cmp); |
| 484 | return ins ? ins->ops : NULL; |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 485 | } |
| 486 | |
Arnaldo Carvalho de Melo | 2a1ff81 | 2016-11-24 11:37:08 -0300 | [diff] [blame^] | 487 | static struct ins_ops *ins__find(struct arch *arch, const char *name) |
| 488 | { |
| 489 | struct ins_ops *ops = __ins__find(arch, name); |
| 490 | |
| 491 | if (!ops && arch->associate_instruction_ops) |
| 492 | ops = arch->associate_instruction_ops(arch, name); |
| 493 | |
| 494 | return ops; |
| 495 | } |
| 496 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 497 | static int arch__key_cmp(const void *name, const void *archp) |
| 498 | { |
| 499 | const struct arch *arch = archp; |
| 500 | |
| 501 | return strcmp(name, arch->name); |
| 502 | } |
| 503 | |
| 504 | static int arch__cmp(const void *a, const void *b) |
| 505 | { |
| 506 | const struct arch *aa = a; |
| 507 | const struct arch *ab = b; |
| 508 | |
| 509 | return strcmp(aa->name, ab->name); |
| 510 | } |
| 511 | |
| 512 | static void arch__sort(void) |
| 513 | { |
| 514 | const int nmemb = ARRAY_SIZE(architectures); |
| 515 | |
| 516 | qsort(architectures, nmemb, sizeof(struct arch), arch__cmp); |
| 517 | } |
| 518 | |
| 519 | static struct arch *arch__find(const char *name) |
| 520 | { |
| 521 | const int nmemb = ARRAY_SIZE(architectures); |
| 522 | static bool sorted; |
| 523 | |
| 524 | if (!sorted) { |
| 525 | arch__sort(); |
| 526 | sorted = true; |
| 527 | } |
| 528 | |
| 529 | return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key_cmp); |
| 530 | } |
| 531 | |
Arnaldo Carvalho de Melo | d04b35f | 2011-11-11 22:17:32 -0200 | [diff] [blame] | 532 | int symbol__alloc_hist(struct symbol *sym) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 533 | { |
| 534 | struct annotation *notes = symbol__annotation(sym); |
Arnaldo Carvalho de Melo | 1b2e2df | 2012-04-19 10:57:06 -0300 | [diff] [blame] | 535 | const size_t size = symbol__size(sym); |
Cody Schafer | 8696329 | 2012-07-19 20:05:25 -0700 | [diff] [blame] | 536 | size_t sizeof_sym_hist; |
| 537 | |
| 538 | /* Check for overflow when calculating sizeof_sym_hist */ |
| 539 | if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(u64)) |
| 540 | return -1; |
| 541 | |
| 542 | sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64)); |
| 543 | |
| 544 | /* Check for overflow in zalloc argument */ |
| 545 | if (sizeof_sym_hist > (SIZE_MAX - sizeof(*notes->src)) |
| 546 | / symbol_conf.nr_events) |
| 547 | return -1; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 548 | |
Arnaldo Carvalho de Melo | d04b35f | 2011-11-11 22:17:32 -0200 | [diff] [blame] | 549 | notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 550 | if (notes->src == NULL) |
| 551 | return -1; |
| 552 | notes->src->sizeof_sym_hist = sizeof_sym_hist; |
Arnaldo Carvalho de Melo | d04b35f | 2011-11-11 22:17:32 -0200 | [diff] [blame] | 553 | notes->src->nr_histograms = symbol_conf.nr_events; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 554 | INIT_LIST_HEAD(¬es->src->source); |
| 555 | return 0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 556 | } |
| 557 | |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 558 | /* The cycles histogram is lazily allocated. */ |
| 559 | static int symbol__alloc_hist_cycles(struct symbol *sym) |
| 560 | { |
| 561 | struct annotation *notes = symbol__annotation(sym); |
| 562 | const size_t size = symbol__size(sym); |
| 563 | |
| 564 | notes->src->cycles_hist = calloc(size, sizeof(struct cyc_hist)); |
| 565 | if (notes->src->cycles_hist == NULL) |
| 566 | return -1; |
| 567 | return 0; |
| 568 | } |
| 569 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 570 | void symbol__annotate_zero_histograms(struct symbol *sym) |
| 571 | { |
| 572 | struct annotation *notes = symbol__annotation(sym); |
| 573 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 574 | pthread_mutex_lock(¬es->lock); |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 575 | if (notes->src != NULL) { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 576 | memset(notes->src->histograms, 0, |
| 577 | notes->src->nr_histograms * notes->src->sizeof_sym_hist); |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 578 | if (notes->src->cycles_hist) |
| 579 | memset(notes->src->cycles_hist, 0, |
| 580 | symbol__size(sym) * sizeof(struct cyc_hist)); |
| 581 | } |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 582 | pthread_mutex_unlock(¬es->lock); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 583 | } |
| 584 | |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 585 | static int __symbol__account_cycles(struct annotation *notes, |
| 586 | u64 start, |
| 587 | unsigned offset, unsigned cycles, |
| 588 | unsigned have_start) |
| 589 | { |
| 590 | struct cyc_hist *ch; |
| 591 | |
| 592 | ch = notes->src->cycles_hist; |
| 593 | /* |
| 594 | * For now we can only account one basic block per |
| 595 | * final jump. But multiple could be overlapping. |
| 596 | * Always account the longest one. So when |
| 597 | * a shorter one has been already seen throw it away. |
| 598 | * |
| 599 | * We separately always account the full cycles. |
| 600 | */ |
| 601 | ch[offset].num_aggr++; |
| 602 | ch[offset].cycles_aggr += cycles; |
| 603 | |
| 604 | if (!have_start && ch[offset].have_start) |
| 605 | return 0; |
| 606 | if (ch[offset].num) { |
| 607 | if (have_start && (!ch[offset].have_start || |
| 608 | ch[offset].start > start)) { |
| 609 | ch[offset].have_start = 0; |
| 610 | ch[offset].cycles = 0; |
| 611 | ch[offset].num = 0; |
| 612 | if (ch[offset].reset < 0xffff) |
| 613 | ch[offset].reset++; |
| 614 | } else if (have_start && |
| 615 | ch[offset].start < start) |
| 616 | return 0; |
| 617 | } |
| 618 | ch[offset].have_start = have_start; |
| 619 | ch[offset].start = start; |
| 620 | ch[offset].cycles += cycles; |
| 621 | ch[offset].num++; |
| 622 | return 0; |
| 623 | } |
| 624 | |
Arnaldo Carvalho de Melo | b66d8c0 | 2013-12-18 15:37:41 -0300 | [diff] [blame] | 625 | static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map, |
| 626 | struct annotation *notes, int evidx, u64 addr) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 627 | { |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 628 | unsigned offset; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 629 | struct sym_hist *h; |
| 630 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 631 | pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr)); |
| 632 | |
Arnaldo Carvalho de Melo | e3d006c | 2015-10-21 15:45:13 -0300 | [diff] [blame] | 633 | if (addr < sym->start || addr >= sym->end) { |
| 634 | pr_debug("%s(%d): ERANGE! sym->name=%s, start=%#" PRIx64 ", addr=%#" PRIx64 ", end=%#" PRIx64 "\n", |
| 635 | __func__, __LINE__, sym->name, sym->start, addr, sym->end); |
Arnaldo Carvalho de Melo | 31d68e7 | 2012-03-27 12:55:57 -0300 | [diff] [blame] | 636 | return -ERANGE; |
Arnaldo Carvalho de Melo | e3d006c | 2015-10-21 15:45:13 -0300 | [diff] [blame] | 637 | } |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 638 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 639 | offset = addr - sym->start; |
| 640 | h = annotation__histogram(notes, evidx); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 641 | h->sum++; |
| 642 | h->addr[offset]++; |
| 643 | |
| 644 | pr_debug3("%#" PRIx64 " %s: period++ [addr: %#" PRIx64 ", %#" PRIx64 |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 645 | ", evidx=%d] => %" PRIu64 "\n", sym->start, sym->name, |
| 646 | addr, addr - sym->start, evidx, h->addr[offset]); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 650 | static struct annotation *symbol__get_annotation(struct symbol *sym, bool cycles) |
Andi Kleen | 83be34a | 2015-05-27 10:51:46 -0700 | [diff] [blame] | 651 | { |
| 652 | struct annotation *notes = symbol__annotation(sym); |
| 653 | |
| 654 | if (notes->src == NULL) { |
| 655 | if (symbol__alloc_hist(sym) < 0) |
| 656 | return NULL; |
| 657 | } |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 658 | if (!notes->src->cycles_hist && cycles) { |
| 659 | if (symbol__alloc_hist_cycles(sym) < 0) |
| 660 | return NULL; |
| 661 | } |
Andi Kleen | 83be34a | 2015-05-27 10:51:46 -0700 | [diff] [blame] | 662 | return notes; |
| 663 | } |
| 664 | |
Arnaldo Carvalho de Melo | 44e8303 | 2013-12-18 17:12:24 -0300 | [diff] [blame] | 665 | static int symbol__inc_addr_samples(struct symbol *sym, struct map *map, |
| 666 | int evidx, u64 addr) |
Arnaldo Carvalho de Melo | b66d8c0 | 2013-12-18 15:37:41 -0300 | [diff] [blame] | 667 | { |
| 668 | struct annotation *notes; |
| 669 | |
Namhyung Kim | 48c65bd | 2014-02-20 10:32:53 +0900 | [diff] [blame] | 670 | if (sym == NULL) |
Arnaldo Carvalho de Melo | b66d8c0 | 2013-12-18 15:37:41 -0300 | [diff] [blame] | 671 | return 0; |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 672 | notes = symbol__get_annotation(sym, false); |
Andi Kleen | 83be34a | 2015-05-27 10:51:46 -0700 | [diff] [blame] | 673 | if (notes == NULL) |
| 674 | return -ENOMEM; |
Arnaldo Carvalho de Melo | b66d8c0 | 2013-12-18 15:37:41 -0300 | [diff] [blame] | 675 | return __symbol__inc_addr_samples(sym, map, notes, evidx, addr); |
| 676 | } |
| 677 | |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 678 | static int symbol__account_cycles(u64 addr, u64 start, |
| 679 | struct symbol *sym, unsigned cycles) |
| 680 | { |
| 681 | struct annotation *notes; |
| 682 | unsigned offset; |
| 683 | |
| 684 | if (sym == NULL) |
| 685 | return 0; |
| 686 | notes = symbol__get_annotation(sym, true); |
| 687 | if (notes == NULL) |
| 688 | return -ENOMEM; |
| 689 | if (addr < sym->start || addr >= sym->end) |
| 690 | return -ERANGE; |
| 691 | |
| 692 | if (start) { |
| 693 | if (start < sym->start || start >= sym->end) |
| 694 | return -ERANGE; |
| 695 | if (start >= addr) |
| 696 | start = 0; |
| 697 | } |
| 698 | offset = addr - sym->start; |
| 699 | return __symbol__account_cycles(notes, |
| 700 | start ? start - sym->start : 0, |
| 701 | offset, cycles, |
| 702 | !!start); |
| 703 | } |
| 704 | |
| 705 | int addr_map_symbol__account_cycles(struct addr_map_symbol *ams, |
| 706 | struct addr_map_symbol *start, |
| 707 | unsigned cycles) |
| 708 | { |
Adrian Hunter | 3d7245b | 2015-08-14 10:11:34 +0300 | [diff] [blame] | 709 | u64 saddr = 0; |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 710 | int err; |
| 711 | |
| 712 | if (!cycles) |
| 713 | return 0; |
| 714 | |
| 715 | /* |
| 716 | * Only set start when IPC can be computed. We can only |
| 717 | * compute it when the basic block is completely in a single |
| 718 | * function. |
| 719 | * Special case the case when the jump is elsewhere, but |
| 720 | * it starts on the function start. |
| 721 | */ |
| 722 | if (start && |
| 723 | (start->sym == ams->sym || |
| 724 | (ams->sym && |
| 725 | start->addr == ams->sym->start + ams->map->start))) |
| 726 | saddr = start->al_addr; |
| 727 | if (saddr == 0) |
Adrian Hunter | 3d7245b | 2015-08-14 10:11:34 +0300 | [diff] [blame] | 728 | pr_debug2("BB with bad start: addr %"PRIx64" start %"PRIx64" sym %"PRIx64" saddr %"PRIx64"\n", |
Andi Kleen | d495763 | 2015-07-18 08:24:48 -0700 | [diff] [blame] | 729 | ams->addr, |
| 730 | start ? start->addr : 0, |
| 731 | ams->sym ? ams->sym->start + ams->map->start : 0, |
| 732 | saddr); |
| 733 | err = symbol__account_cycles(ams->al_addr, saddr, ams->sym, cycles); |
| 734 | if (err) |
| 735 | pr_debug2("account_cycles failed %d\n", err); |
| 736 | return err; |
| 737 | } |
| 738 | |
Arnaldo Carvalho de Melo | 0f4e7a2 | 2013-12-18 16:48:29 -0300 | [diff] [blame] | 739 | int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx) |
| 740 | { |
| 741 | return symbol__inc_addr_samples(ams->sym, ams->map, evidx, ams->al_addr); |
| 742 | } |
| 743 | |
Arnaldo Carvalho de Melo | f626adf | 2013-12-18 17:10:15 -0300 | [diff] [blame] | 744 | int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip) |
| 745 | { |
| 746 | return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip); |
| 747 | } |
| 748 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 749 | static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arch, struct map *map) |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 750 | { |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 751 | dl->ins.ops = ins__find(arch, dl->ins.name); |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 752 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 753 | if (!dl->ins.ops) |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 754 | return; |
| 755 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 756 | if (dl->ins.ops->parse && dl->ins.ops->parse(arch, &dl->ops, map) < 0) |
| 757 | dl->ins.ops = NULL; |
Arnaldo Carvalho de Melo | 4f9d032 | 2012-04-18 13:58:34 -0300 | [diff] [blame] | 758 | } |
| 759 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 760 | static int disasm_line__parse(char *line, const char **namep, char **rawp) |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 761 | { |
| 762 | char *name = line, tmp; |
| 763 | |
| 764 | while (isspace(name[0])) |
| 765 | ++name; |
| 766 | |
| 767 | if (name[0] == '\0') |
| 768 | return -1; |
| 769 | |
| 770 | *rawp = name + 1; |
| 771 | |
| 772 | while ((*rawp)[0] != '\0' && !isspace((*rawp)[0])) |
| 773 | ++*rawp; |
| 774 | |
| 775 | tmp = (*rawp)[0]; |
| 776 | (*rawp)[0] = '\0'; |
| 777 | *namep = strdup(name); |
| 778 | |
| 779 | if (*namep == NULL) |
| 780 | goto out_free_name; |
| 781 | |
| 782 | (*rawp)[0] = tmp; |
| 783 | |
| 784 | if ((*rawp)[0] != '\0') { |
| 785 | (*rawp)++; |
| 786 | while (isspace((*rawp)[0])) |
| 787 | ++(*rawp); |
| 788 | } |
| 789 | |
| 790 | return 0; |
| 791 | |
| 792 | out_free_name: |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 793 | free((void *)namep); |
| 794 | *namep = NULL; |
Arnaldo Carvalho de Melo | 7a997fe | 2012-05-12 13:15:34 -0300 | [diff] [blame] | 795 | return -1; |
| 796 | } |
| 797 | |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 798 | static struct disasm_line *disasm_line__new(s64 offset, char *line, |
Arnaldo Carvalho de Melo | bff5c30 | 2016-09-19 17:18:16 -0300 | [diff] [blame] | 799 | size_t privsize, int line_nr, |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 800 | struct arch *arch, |
Arnaldo Carvalho de Melo | bff5c30 | 2016-09-19 17:18:16 -0300 | [diff] [blame] | 801 | struct map *map) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 802 | { |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 803 | struct disasm_line *dl = zalloc(sizeof(*dl) + privsize); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 804 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 805 | if (dl != NULL) { |
| 806 | dl->offset = offset; |
| 807 | dl->line = strdup(line); |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 808 | dl->line_nr = line_nr; |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 809 | if (dl->line == NULL) |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 810 | goto out_delete; |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 811 | |
| 812 | if (offset != -1) { |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 813 | if (disasm_line__parse(dl->line, &dl->ins.name, &dl->ops.raw) < 0) |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 814 | goto out_free_line; |
| 815 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 816 | disasm_line__init_ins(dl, arch, map); |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 817 | } |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 818 | } |
| 819 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 820 | return dl; |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 821 | |
| 822 | out_free_line: |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 823 | zfree(&dl->line); |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 824 | out_delete: |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 825 | free(dl); |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 826 | return NULL; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 827 | } |
| 828 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 829 | void disasm_line__free(struct disasm_line *dl) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 830 | { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 831 | zfree(&dl->line); |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 832 | if (dl->ins.ops && dl->ins.ops->free) |
| 833 | dl->ins.ops->free(&dl->ops); |
Arnaldo Carvalho de Melo | c46219ac | 2012-05-12 13:26:20 -0300 | [diff] [blame] | 834 | else |
| 835 | ins__delete(&dl->ops); |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 836 | free((void *)dl->ins.name); |
| 837 | dl->ins.name = NULL; |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 838 | free(dl); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 839 | } |
| 840 | |
Arnaldo Carvalho de Melo | 5417072 | 2012-05-07 18:54:16 -0300 | [diff] [blame] | 841 | int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw) |
| 842 | { |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 843 | if (raw || !dl->ins.ops) |
| 844 | return scnprintf(bf, size, "%-6.6s %s", dl->ins.name, dl->ops.raw); |
Arnaldo Carvalho de Melo | 5417072 | 2012-05-07 18:54:16 -0300 | [diff] [blame] | 845 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 846 | return ins__scnprintf(&dl->ins, bf, size, &dl->ops); |
Arnaldo Carvalho de Melo | 5417072 | 2012-05-07 18:54:16 -0300 | [diff] [blame] | 847 | } |
| 848 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 849 | static void disasm__add(struct list_head *head, struct disasm_line *line) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 850 | { |
| 851 | list_add_tail(&line->node, head); |
| 852 | } |
| 853 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 854 | struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 855 | { |
| 856 | list_for_each_entry_continue(pos, head, node) |
| 857 | if (pos->offset >= 0) |
| 858 | return pos; |
| 859 | |
| 860 | return NULL; |
| 861 | } |
| 862 | |
Namhyung Kim | e64aa75 | 2013-03-05 14:53:30 +0900 | [diff] [blame] | 863 | double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 864 | s64 end, const char **path, u64 *nr_samples) |
Namhyung Kim | e5ccf9f | 2013-03-05 14:53:23 +0900 | [diff] [blame] | 865 | { |
| 866 | struct source_line *src_line = notes->src->lines; |
Namhyung Kim | e5ccf9f | 2013-03-05 14:53:23 +0900 | [diff] [blame] | 867 | double percent = 0.0; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 868 | *nr_samples = 0; |
Namhyung Kim | e5ccf9f | 2013-03-05 14:53:23 +0900 | [diff] [blame] | 869 | |
Namhyung Kim | bd64fcb | 2013-03-05 14:53:24 +0900 | [diff] [blame] | 870 | if (src_line) { |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 871 | size_t sizeof_src_line = sizeof(*src_line) + |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 872 | sizeof(src_line->samples) * (src_line->nr_pcnt - 1); |
Namhyung Kim | e5ccf9f | 2013-03-05 14:53:23 +0900 | [diff] [blame] | 873 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 874 | while (offset < end) { |
| 875 | src_line = (void *)notes->src->lines + |
| 876 | (sizeof_src_line * offset); |
| 877 | |
| 878 | if (*path == NULL) |
| 879 | *path = src_line->path; |
| 880 | |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 881 | percent += src_line->samples[evidx].percent; |
| 882 | *nr_samples += src_line->samples[evidx].nr; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 883 | offset++; |
Namhyung Kim | bd64fcb | 2013-03-05 14:53:24 +0900 | [diff] [blame] | 884 | } |
| 885 | } else { |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 886 | struct sym_hist *h = annotation__histogram(notes, evidx); |
| 887 | unsigned int hits = 0; |
| 888 | |
Namhyung Kim | bd64fcb | 2013-03-05 14:53:24 +0900 | [diff] [blame] | 889 | while (offset < end) |
| 890 | hits += h->addr[offset++]; |
| 891 | |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 892 | if (h->sum) { |
| 893 | *nr_samples = hits; |
Namhyung Kim | bd64fcb | 2013-03-05 14:53:24 +0900 | [diff] [blame] | 894 | percent = 100.0 * hits / h->sum; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 895 | } |
Namhyung Kim | e5ccf9f | 2013-03-05 14:53:23 +0900 | [diff] [blame] | 896 | } |
| 897 | |
Namhyung Kim | e5ccf9f | 2013-03-05 14:53:23 +0900 | [diff] [blame] | 898 | return percent; |
| 899 | } |
| 900 | |
Peter Zijlstra | 70fbe05 | 2016-09-05 16:08:12 -0300 | [diff] [blame] | 901 | static const char *annotate__address_color(struct block_range *br) |
| 902 | { |
| 903 | double cov = block_range__coverage(br); |
| 904 | |
| 905 | if (cov >= 0) { |
| 906 | /* mark red for >75% coverage */ |
| 907 | if (cov > 0.75) |
| 908 | return PERF_COLOR_RED; |
| 909 | |
| 910 | /* mark dull for <1% coverage */ |
| 911 | if (cov < 0.01) |
| 912 | return PERF_COLOR_NORMAL; |
| 913 | } |
| 914 | |
| 915 | return PERF_COLOR_MAGENTA; |
| 916 | } |
| 917 | |
| 918 | static const char *annotate__asm_color(struct block_range *br) |
| 919 | { |
| 920 | double cov = block_range__coverage(br); |
| 921 | |
| 922 | if (cov >= 0) { |
| 923 | /* mark dull for <1% coverage */ |
| 924 | if (cov < 0.01) |
| 925 | return PERF_COLOR_NORMAL; |
| 926 | } |
| 927 | |
| 928 | return PERF_COLOR_BLUE; |
| 929 | } |
| 930 | |
| 931 | static void annotate__branch_printf(struct block_range *br, u64 addr) |
| 932 | { |
| 933 | bool emit_comment = true; |
| 934 | |
| 935 | if (!br) |
| 936 | return; |
| 937 | |
| 938 | #if 1 |
| 939 | if (br->is_target && br->start == addr) { |
| 940 | struct block_range *branch = br; |
| 941 | double p; |
| 942 | |
| 943 | /* |
| 944 | * Find matching branch to our target. |
| 945 | */ |
| 946 | while (!branch->is_branch) |
| 947 | branch = block_range__next(branch); |
| 948 | |
| 949 | p = 100 *(double)br->entry / branch->coverage; |
| 950 | |
| 951 | if (p > 0.1) { |
| 952 | if (emit_comment) { |
| 953 | emit_comment = false; |
| 954 | printf("\t#"); |
| 955 | } |
| 956 | |
| 957 | /* |
| 958 | * The percentage of coverage joined at this target in relation |
| 959 | * to the next branch. |
| 960 | */ |
| 961 | printf(" +%.2f%%", p); |
| 962 | } |
| 963 | } |
| 964 | #endif |
| 965 | if (br->is_branch && br->end == addr) { |
| 966 | double p = 100*(double)br->taken / br->coverage; |
| 967 | |
| 968 | if (p > 0.1) { |
| 969 | if (emit_comment) { |
| 970 | emit_comment = false; |
| 971 | printf("\t#"); |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | * The percentage of coverage leaving at this branch, and |
| 976 | * its prediction ratio. |
| 977 | */ |
| 978 | printf(" -%.2f%% (p:%.2f%%)", p, 100*(double)br->pred / br->taken); |
| 979 | } |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 984 | static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start, |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 985 | struct perf_evsel *evsel, u64 len, int min_pcnt, int printed, |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 986 | int max_lines, struct disasm_line *queue) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 987 | { |
| 988 | static const char *prev_line; |
| 989 | static const char *prev_color; |
| 990 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 991 | if (dl->offset != -1) { |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 992 | const char *path = NULL; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 993 | u64 nr_samples; |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 994 | double percent, max_percent = 0.0; |
| 995 | double *ppercents = &percent; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 996 | u64 *psamples = &nr_samples; |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 997 | int i, nr_percent = 1; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 998 | const char *color; |
| 999 | struct annotation *notes = symbol__annotation(sym); |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1000 | s64 offset = dl->offset; |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1001 | const u64 addr = start + offset; |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1002 | struct disasm_line *next; |
Peter Zijlstra | 70fbe05 | 2016-09-05 16:08:12 -0300 | [diff] [blame] | 1003 | struct block_range *br; |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1004 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1005 | next = disasm__get_next_ip_line(¬es->src->source, dl); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1006 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 1007 | if (perf_evsel__is_group_event(evsel)) { |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1008 | nr_percent = evsel->nr_members; |
| 1009 | ppercents = calloc(nr_percent, sizeof(double)); |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1010 | psamples = calloc(nr_percent, sizeof(u64)); |
| 1011 | if (ppercents == NULL || psamples == NULL) { |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1012 | return -1; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1013 | } |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | for (i = 0; i < nr_percent; i++) { |
| 1017 | percent = disasm__calc_percent(notes, |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1018 | notes->src->lines ? i : evsel->idx + i, |
| 1019 | offset, |
| 1020 | next ? next->offset : (s64) len, |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1021 | &path, &nr_samples); |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1022 | |
| 1023 | ppercents[i] = percent; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1024 | psamples[i] = nr_samples; |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1025 | if (percent > max_percent) |
| 1026 | max_percent = percent; |
| 1027 | } |
| 1028 | |
| 1029 | if (max_percent < min_pcnt) |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1030 | return -1; |
| 1031 | |
Arnaldo Carvalho de Melo | e3087b8 | 2011-02-08 15:01:39 -0200 | [diff] [blame] | 1032 | if (max_lines && printed >= max_lines) |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1033 | return 1; |
Arnaldo Carvalho de Melo | d040bd3 | 2011-02-05 15:37:31 -0200 | [diff] [blame] | 1034 | |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1035 | if (queue != NULL) { |
| 1036 | list_for_each_entry_from(queue, ¬es->src->source, node) { |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1037 | if (queue == dl) |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1038 | break; |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1039 | disasm_line__print(queue, sym, start, evsel, len, |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1040 | 0, 0, 1, NULL); |
| 1041 | } |
| 1042 | } |
| 1043 | |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1044 | color = get_percent_color(max_percent); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1045 | |
| 1046 | /* |
| 1047 | * Also color the filename and line if needed, with |
| 1048 | * the same color than the percentage. Don't print it |
| 1049 | * twice for close colored addr with the same filename:line |
| 1050 | */ |
| 1051 | if (path) { |
| 1052 | if (!prev_line || strcmp(prev_line, path) |
| 1053 | || color != prev_color) { |
| 1054 | color_fprintf(stdout, color, " %s", path); |
| 1055 | prev_line = path; |
| 1056 | prev_color = color; |
| 1057 | } |
| 1058 | } |
| 1059 | |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1060 | for (i = 0; i < nr_percent; i++) { |
| 1061 | percent = ppercents[i]; |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1062 | nr_samples = psamples[i]; |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1063 | color = get_percent_color(percent); |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1064 | |
| 1065 | if (symbol_conf.show_total_period) |
| 1066 | color_fprintf(stdout, color, " %7" PRIu64, |
| 1067 | nr_samples); |
| 1068 | else |
| 1069 | color_fprintf(stdout, color, " %7.2f", percent); |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1070 | } |
| 1071 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1072 | printf(" : "); |
Peter Zijlstra | 70fbe05 | 2016-09-05 16:08:12 -0300 | [diff] [blame] | 1073 | |
| 1074 | br = block_range__find(addr); |
| 1075 | color_fprintf(stdout, annotate__address_color(br), " %" PRIx64 ":", addr); |
| 1076 | color_fprintf(stdout, annotate__asm_color(br), "%s", dl->line); |
| 1077 | annotate__branch_printf(br, addr); |
| 1078 | printf("\n"); |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1079 | |
| 1080 | if (ppercents != &percent) |
| 1081 | free(ppercents); |
| 1082 | |
Martin Liška | 0c4a5bc | 2015-06-19 16:10:43 -0300 | [diff] [blame] | 1083 | if (psamples != &nr_samples) |
| 1084 | free(psamples); |
| 1085 | |
Arnaldo Carvalho de Melo | e3087b8 | 2011-02-08 15:01:39 -0200 | [diff] [blame] | 1086 | } else if (max_lines && printed >= max_lines) |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1087 | return 1; |
| 1088 | else { |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1089 | int width = 8; |
| 1090 | |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1091 | if (queue) |
| 1092 | return -1; |
| 1093 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 1094 | if (perf_evsel__is_group_event(evsel)) |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1095 | width *= evsel->nr_members; |
| 1096 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1097 | if (!*dl->line) |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1098 | printf(" %*s:\n", width, " "); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1099 | else |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1100 | printf(" %*s: %s\n", width, " ", dl->line); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1101 | } |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1102 | |
| 1103 | return 0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1104 | } |
| 1105 | |
Namhyung Kim | 3aec150 | 2013-03-05 14:53:22 +0900 | [diff] [blame] | 1106 | /* |
| 1107 | * symbol__parse_objdump_line() parses objdump output (with -d --no-show-raw) |
| 1108 | * which looks like following |
| 1109 | * |
| 1110 | * 0000000000415500 <_init>: |
| 1111 | * 415500: sub $0x8,%rsp |
| 1112 | * 415504: mov 0x2f5ad5(%rip),%rax # 70afe0 <_DYNAMIC+0x2f8> |
| 1113 | * 41550b: test %rax,%rax |
| 1114 | * 41550e: je 415515 <_init+0x15> |
| 1115 | * 415510: callq 416e70 <__gmon_start__@plt> |
| 1116 | * 415515: add $0x8,%rsp |
| 1117 | * 415519: retq |
| 1118 | * |
| 1119 | * it will be parsed and saved into struct disasm_line as |
| 1120 | * <offset> <name> <ops.raw> |
| 1121 | * |
| 1122 | * The offset will be a relative offset from the start of the symbol and -1 |
| 1123 | * means that it's not a disassembly line so should be treated differently. |
| 1124 | * The ops.raw part will be parsed further according to type of the instruction. |
| 1125 | */ |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1126 | static int symbol__parse_objdump_line(struct symbol *sym, struct map *map, |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1127 | struct arch *arch, |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1128 | FILE *file, size_t privsize, |
| 1129 | int *line_nr) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1130 | { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1131 | struct annotation *notes = symbol__annotation(sym); |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1132 | struct disasm_line *dl; |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1133 | char *line = NULL, *parsed_line, *tmp, *tmp2, *c; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1134 | size_t line_len; |
| 1135 | s64 line_ip, offset = -1; |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1136 | regmatch_t match[2]; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1137 | |
| 1138 | if (getline(&line, &line_len, file) < 0) |
| 1139 | return -1; |
| 1140 | |
| 1141 | if (!line) |
| 1142 | return -1; |
| 1143 | |
| 1144 | while (line_len != 0 && isspace(line[line_len - 1])) |
| 1145 | line[--line_len] = '\0'; |
| 1146 | |
| 1147 | c = strchr(line, '\n'); |
| 1148 | if (c) |
| 1149 | *c = 0; |
| 1150 | |
| 1151 | line_ip = -1; |
Namhyung Kim | a31b7cc | 2012-04-11 17:04:59 -0300 | [diff] [blame] | 1152 | parsed_line = line; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1153 | |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1154 | /* /filename:linenr ? Save line number and ignore. */ |
| 1155 | if (regexec(&file_lineno, line, 2, match, 0) == 0) { |
| 1156 | *line_nr = atoi(line + match[1].rm_so); |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1160 | /* |
| 1161 | * Strip leading spaces: |
| 1162 | */ |
| 1163 | tmp = line; |
| 1164 | while (*tmp) { |
| 1165 | if (*tmp != ' ') |
| 1166 | break; |
| 1167 | tmp++; |
| 1168 | } |
| 1169 | |
| 1170 | if (*tmp) { |
| 1171 | /* |
| 1172 | * Parse hexa addresses followed by ':' |
| 1173 | */ |
| 1174 | line_ip = strtoull(tmp, &tmp2, 16); |
| 1175 | if (*tmp2 != ':' || tmp == tmp2 || tmp2[1] == '\0') |
| 1176 | line_ip = -1; |
| 1177 | } |
| 1178 | |
| 1179 | if (line_ip != -1) { |
| 1180 | u64 start = map__rip_2objdump(map, sym->start), |
| 1181 | end = map__rip_2objdump(map, sym->end); |
| 1182 | |
| 1183 | offset = line_ip - start; |
Arnaldo Carvalho de Melo | 2c241bd | 2014-10-14 17:19:44 -0300 | [diff] [blame] | 1184 | if ((u64)line_ip < start || (u64)line_ip >= end) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1185 | offset = -1; |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1186 | else |
| 1187 | parsed_line = tmp2 + 1; |
Namhyung Kim | a31b7cc | 2012-04-11 17:04:59 -0300 | [diff] [blame] | 1188 | } |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1189 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1190 | dl = disasm_line__new(offset, parsed_line, privsize, *line_nr, arch, map); |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1191 | free(line); |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1192 | (*line_nr)++; |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1193 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1194 | if (dl == NULL) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1195 | return -1; |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1196 | |
Adrian Hunter | bbb7f84 | 2013-08-07 14:38:54 +0300 | [diff] [blame] | 1197 | if (dl->ops.target.offset == UINT64_MAX) |
| 1198 | dl->ops.target.offset = dl->ops.target.addr - |
| 1199 | map__rip_2objdump(map, sym->start); |
| 1200 | |
Adrian Hunter | 6e427ab | 2013-10-14 13:43:40 +0300 | [diff] [blame] | 1201 | /* kcore has no symbols, so add the call target name */ |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 1202 | if (dl->ins.ops && ins__is_call(&dl->ins) && !dl->ops.target.name) { |
Adrian Hunter | 6e427ab | 2013-10-14 13:43:40 +0300 | [diff] [blame] | 1203 | struct addr_map_symbol target = { |
| 1204 | .map = map, |
| 1205 | .addr = dl->ops.target.addr, |
| 1206 | }; |
Adrian Hunter | b178170 | 2013-08-07 14:38:57 +0300 | [diff] [blame] | 1207 | |
Arnaldo Carvalho de Melo | be39db9 | 2016-09-01 19:25:52 -0300 | [diff] [blame] | 1208 | if (!map_groups__find_ams(&target) && |
Adrian Hunter | 6e427ab | 2013-10-14 13:43:40 +0300 | [diff] [blame] | 1209 | target.sym->start == target.al_addr) |
| 1210 | dl->ops.target.name = strdup(target.sym->name); |
Adrian Hunter | b178170 | 2013-08-07 14:38:57 +0300 | [diff] [blame] | 1211 | } |
| 1212 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1213 | disasm__add(¬es->src->source, dl); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1218 | static __attribute__((constructor)) void symbol__init_regexpr(void) |
| 1219 | { |
| 1220 | regcomp(&file_lineno, "^/[^:]+:([0-9]+)", REG_EXTENDED); |
| 1221 | } |
| 1222 | |
Adrian Hunter | 484a5e7 | 2013-08-07 14:38:56 +0300 | [diff] [blame] | 1223 | static void delete_last_nop(struct symbol *sym) |
| 1224 | { |
| 1225 | struct annotation *notes = symbol__annotation(sym); |
| 1226 | struct list_head *list = ¬es->src->source; |
| 1227 | struct disasm_line *dl; |
| 1228 | |
| 1229 | while (!list_empty(list)) { |
| 1230 | dl = list_entry(list->prev, struct disasm_line, node); |
| 1231 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 1232 | if (dl->ins.ops) { |
| 1233 | if (dl->ins.ops != &nop_ops) |
Adrian Hunter | 484a5e7 | 2013-08-07 14:38:56 +0300 | [diff] [blame] | 1234 | return; |
| 1235 | } else { |
| 1236 | if (!strstr(dl->line, " nop ") && |
| 1237 | !strstr(dl->line, " nopl ") && |
| 1238 | !strstr(dl->line, " nopw ")) |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | list_del(&dl->node); |
| 1243 | disasm_line__free(dl); |
| 1244 | } |
| 1245 | } |
| 1246 | |
Arnaldo Carvalho de Melo | ee51d85 | 2016-07-29 16:27:18 -0300 | [diff] [blame] | 1247 | int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *map, |
| 1248 | int errnum, char *buf, size_t buflen) |
| 1249 | { |
| 1250 | struct dso *dso = map->dso; |
| 1251 | |
| 1252 | BUG_ON(buflen == 0); |
| 1253 | |
| 1254 | if (errnum >= 0) { |
| 1255 | str_error_r(errnum, buf, buflen); |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
| 1259 | switch (errnum) { |
| 1260 | case SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX: { |
| 1261 | char bf[SBUILD_ID_SIZE + 15] = " with build id "; |
| 1262 | char *build_id_msg = NULL; |
| 1263 | |
| 1264 | if (dso->has_build_id) { |
| 1265 | build_id__sprintf(dso->build_id, |
| 1266 | sizeof(dso->build_id), bf + 15); |
| 1267 | build_id_msg = bf; |
| 1268 | } |
| 1269 | scnprintf(buf, buflen, |
| 1270 | "No vmlinux file%s\nwas found in the path.\n\n" |
| 1271 | "Note that annotation using /proc/kcore requires CAP_SYS_RAWIO capability.\n\n" |
| 1272 | "Please use:\n\n" |
| 1273 | " perf buildid-cache -vu vmlinux\n\n" |
| 1274 | "or:\n\n" |
| 1275 | " --vmlinux vmlinux\n", build_id_msg ?: ""); |
| 1276 | } |
| 1277 | break; |
| 1278 | default: |
| 1279 | scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum); |
| 1280 | break; |
| 1281 | } |
| 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
Arnaldo Carvalho de Melo | 05ed3ac | 2016-08-09 15:32:53 -0300 | [diff] [blame] | 1286 | static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filename_size) |
| 1287 | { |
| 1288 | char linkname[PATH_MAX]; |
| 1289 | char *build_id_filename; |
| 1290 | |
| 1291 | if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && |
| 1292 | !dso__is_kcore(dso)) |
| 1293 | return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; |
| 1294 | |
| 1295 | build_id_filename = dso__build_id_filename(dso, NULL, 0); |
| 1296 | if (build_id_filename) { |
| 1297 | __symbol__join_symfs(filename, filename_size, build_id_filename); |
| 1298 | free(build_id_filename); |
| 1299 | } else { |
| 1300 | if (dso->has_build_id) |
| 1301 | return ENOMEM; |
| 1302 | goto fallback; |
| 1303 | } |
| 1304 | |
| 1305 | if (dso__is_kcore(dso) || |
| 1306 | readlink(filename, linkname, sizeof(linkname)) < 0 || |
| 1307 | strstr(linkname, DSO__NAME_KALLSYMS) || |
| 1308 | access(filename, R_OK)) { |
| 1309 | fallback: |
| 1310 | /* |
| 1311 | * If we don't have build-ids or the build-id file isn't in the |
| 1312 | * cache, or is just a kallsyms file, well, lets hope that this |
| 1313 | * DSO is the same as when 'perf record' ran. |
| 1314 | */ |
| 1315 | __symbol__join_symfs(filename, filename_size, dso->long_name); |
| 1316 | } |
| 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1321 | static const char *annotate__norm_arch(const char *arch_name) |
| 1322 | { |
| 1323 | struct utsname uts; |
| 1324 | |
| 1325 | if (!arch_name) { /* Assume we are annotating locally. */ |
| 1326 | if (uname(&uts) < 0) |
| 1327 | return NULL; |
| 1328 | arch_name = uts.machine; |
| 1329 | } |
| 1330 | return normalize_arch((char *)arch_name); |
| 1331 | } |
| 1332 | |
| 1333 | int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_name, size_t privsize) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1334 | { |
| 1335 | struct dso *dso = map->dso; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1336 | char command[PATH_MAX * 2]; |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1337 | struct arch *arch = NULL; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1338 | FILE *file; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1339 | char symfs_filename[PATH_MAX]; |
Adrian Hunter | afba19d | 2013-10-09 15:01:12 +0300 | [diff] [blame] | 1340 | struct kcore_extract kce; |
| 1341 | bool delete_extract = false; |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1342 | int stdout_fd[2]; |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1343 | int lineno = 0; |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1344 | int nline; |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1345 | pid_t pid; |
Arnaldo Carvalho de Melo | 05ed3ac | 2016-08-09 15:32:53 -0300 | [diff] [blame] | 1346 | int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename)); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1347 | |
Arnaldo Carvalho de Melo | 05ed3ac | 2016-08-09 15:32:53 -0300 | [diff] [blame] | 1348 | if (err) |
| 1349 | return err; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1350 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1351 | arch_name = annotate__norm_arch(arch_name); |
| 1352 | if (!arch_name) |
| 1353 | return -1; |
| 1354 | |
| 1355 | arch = arch__find(arch_name); |
| 1356 | if (arch == NULL) |
| 1357 | return -ENOTSUP; |
| 1358 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1359 | pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__, |
Arnaldo Carvalho de Melo | 3caee09 | 2016-08-09 15:16:37 -0300 | [diff] [blame] | 1360 | symfs_filename, sym->name, map->unmap_ip(map, sym->start), |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1361 | map->unmap_ip(map, sym->end)); |
| 1362 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1363 | pr_debug("annotating [%p] %30s : [%p] %30s\n", |
| 1364 | dso, dso->long_name, sym, sym->name); |
| 1365 | |
Adrian Hunter | afba19d | 2013-10-09 15:01:12 +0300 | [diff] [blame] | 1366 | if (dso__is_kcore(dso)) { |
| 1367 | kce.kcore_filename = symfs_filename; |
| 1368 | kce.addr = map__rip_2objdump(map, sym->start); |
| 1369 | kce.offs = sym->start; |
Arnaldo Carvalho de Melo | 2c241bd | 2014-10-14 17:19:44 -0300 | [diff] [blame] | 1370 | kce.len = sym->end - sym->start; |
Adrian Hunter | afba19d | 2013-10-09 15:01:12 +0300 | [diff] [blame] | 1371 | if (!kcore_extract__create(&kce)) { |
| 1372 | delete_extract = true; |
| 1373 | strlcpy(symfs_filename, kce.extract_filename, |
| 1374 | sizeof(symfs_filename)); |
Adrian Hunter | afba19d | 2013-10-09 15:01:12 +0300 | [diff] [blame] | 1375 | } |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1376 | } else if (dso__needs_decompress(dso)) { |
| 1377 | char tmp[PATH_MAX]; |
| 1378 | struct kmod_path m; |
| 1379 | int fd; |
| 1380 | bool ret; |
| 1381 | |
| 1382 | if (kmod_path__parse_ext(&m, symfs_filename)) |
Arnaldo Carvalho de Melo | 3caee09 | 2016-08-09 15:16:37 -0300 | [diff] [blame] | 1383 | goto out; |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1384 | |
| 1385 | snprintf(tmp, PATH_MAX, "/tmp/perf-kmod-XXXXXX"); |
| 1386 | |
| 1387 | fd = mkstemp(tmp); |
| 1388 | if (fd < 0) { |
| 1389 | free(m.ext); |
Arnaldo Carvalho de Melo | 3caee09 | 2016-08-09 15:16:37 -0300 | [diff] [blame] | 1390 | goto out; |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | ret = decompress_to_file(m.ext, symfs_filename, fd); |
| 1394 | |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1395 | if (ret) |
| 1396 | pr_err("Cannot decompress %s %s\n", m.ext, symfs_filename); |
| 1397 | |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1398 | free(m.ext); |
| 1399 | close(fd); |
| 1400 | |
| 1401 | if (!ret) |
Arnaldo Carvalho de Melo | 3caee09 | 2016-08-09 15:16:37 -0300 | [diff] [blame] | 1402 | goto out; |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1403 | |
| 1404 | strcpy(symfs_filename, tmp); |
Adrian Hunter | afba19d | 2013-10-09 15:01:12 +0300 | [diff] [blame] | 1405 | } |
| 1406 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1407 | snprintf(command, sizeof(command), |
Maciek Borzecki | 7a4ec93 | 2012-09-04 12:32:30 +0200 | [diff] [blame] | 1408 | "%s %s%s --start-address=0x%016" PRIx64 |
Stephane Eranian | 3e6a2a7 | 2011-05-17 17:32:07 +0200 | [diff] [blame] | 1409 | " --stop-address=0x%016" PRIx64 |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1410 | " -l -d %s %s -C %s 2>/dev/null|grep -v %s|expand", |
Maciek Borzecki | 7a4ec93 | 2012-09-04 12:32:30 +0200 | [diff] [blame] | 1411 | objdump_path ? objdump_path : "objdump", |
Andi Kleen | f69b64f | 2011-09-15 14:31:41 -0700 | [diff] [blame] | 1412 | disassembler_style ? "-M " : "", |
| 1413 | disassembler_style ? disassembler_style : "", |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1414 | map__rip_2objdump(map, sym->start), |
Arnaldo Carvalho de Melo | 2c241bd | 2014-10-14 17:19:44 -0300 | [diff] [blame] | 1415 | map__rip_2objdump(map, sym->end), |
Stephane Eranian | 3e6a2a7 | 2011-05-17 17:32:07 +0200 | [diff] [blame] | 1416 | symbol_conf.annotate_asm_raw ? "" : "--no-show-raw", |
| 1417 | symbol_conf.annotate_src ? "-S" : "", |
Arnaldo Carvalho de Melo | 3caee09 | 2016-08-09 15:16:37 -0300 | [diff] [blame] | 1418 | symfs_filename, symfs_filename); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1419 | |
| 1420 | pr_debug("Executing: %s\n", command); |
| 1421 | |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1422 | err = -1; |
| 1423 | if (pipe(stdout_fd) < 0) { |
| 1424 | pr_err("Failure creating the pipe to run %s\n", command); |
| 1425 | goto out_remove_tmp; |
| 1426 | } |
| 1427 | |
| 1428 | pid = fork(); |
| 1429 | if (pid < 0) { |
| 1430 | pr_err("Failure forking to run %s\n", command); |
| 1431 | goto out_close_stdout; |
| 1432 | } |
| 1433 | |
| 1434 | if (pid == 0) { |
| 1435 | close(stdout_fd[0]); |
| 1436 | dup2(stdout_fd[1], 1); |
| 1437 | close(stdout_fd[1]); |
| 1438 | execl("/bin/sh", "sh", "-c", command, NULL); |
| 1439 | perror(command); |
| 1440 | exit(-1); |
| 1441 | } |
| 1442 | |
| 1443 | close(stdout_fd[1]); |
| 1444 | |
| 1445 | file = fdopen(stdout_fd[0], "r"); |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1446 | if (!file) { |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1447 | pr_err("Failure creating FILE stream for %s\n", command); |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1448 | /* |
| 1449 | * If we were using debug info should retry with |
| 1450 | * original binary. |
| 1451 | */ |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1452 | goto out_remove_tmp; |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1453 | } |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1454 | |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1455 | nline = 0; |
| 1456 | while (!feof(file)) { |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1457 | if (symbol__parse_objdump_line(sym, map, arch, file, privsize, |
Andi Kleen | e592488 | 2014-11-12 18:05:26 -0800 | [diff] [blame] | 1458 | &lineno) < 0) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1459 | break; |
Andi Kleen | 62ec9b3 | 2015-11-05 19:06:07 -0800 | [diff] [blame] | 1460 | nline++; |
| 1461 | } |
| 1462 | |
| 1463 | if (nline == 0) |
| 1464 | pr_err("No output from %s\n", command); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1465 | |
Adrian Hunter | 484a5e7 | 2013-08-07 14:38:56 +0300 | [diff] [blame] | 1466 | /* |
| 1467 | * kallsyms does not have symbol sizes so there may a nop at the end. |
| 1468 | * Remove it. |
| 1469 | */ |
| 1470 | if (dso__is_kcore(dso)) |
| 1471 | delete_last_nop(sym); |
| 1472 | |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1473 | fclose(file); |
| 1474 | err = 0; |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1475 | out_remove_tmp: |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1476 | close(stdout_fd[0]); |
| 1477 | |
Jiri Olsa | 2c7da8c | 2015-03-02 12:56:12 -0500 | [diff] [blame] | 1478 | if (dso__needs_decompress(dso)) |
| 1479 | unlink(symfs_filename); |
Arnaldo Carvalho de Melo | 3caee09 | 2016-08-09 15:16:37 -0300 | [diff] [blame] | 1480 | |
Adrian Hunter | afba19d | 2013-10-09 15:01:12 +0300 | [diff] [blame] | 1481 | if (delete_extract) |
| 1482 | kcore_extract__delete(&kce); |
Arnaldo Carvalho de Melo | c12944f | 2016-08-09 14:56:13 -0300 | [diff] [blame] | 1483 | out: |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1484 | return err; |
Arnaldo Carvalho de Melo | 9955d0b | 2016-06-15 15:48:08 -0300 | [diff] [blame] | 1485 | |
| 1486 | out_close_stdout: |
| 1487 | close(stdout_fd[1]); |
| 1488 | goto out_remove_tmp; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | static void insert_source_line(struct rb_root *root, struct source_line *src_line) |
| 1492 | { |
| 1493 | struct source_line *iter; |
| 1494 | struct rb_node **p = &root->rb_node; |
| 1495 | struct rb_node *parent = NULL; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1496 | int i, ret; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1497 | |
| 1498 | while (*p != NULL) { |
| 1499 | parent = *p; |
| 1500 | iter = rb_entry(parent, struct source_line, node); |
| 1501 | |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1502 | ret = strcmp(iter->path, src_line->path); |
| 1503 | if (ret == 0) { |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1504 | for (i = 0; i < src_line->nr_pcnt; i++) |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1505 | iter->samples[i].percent_sum += src_line->samples[i].percent; |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1506 | return; |
| 1507 | } |
| 1508 | |
| 1509 | if (ret < 0) |
| 1510 | p = &(*p)->rb_left; |
| 1511 | else |
| 1512 | p = &(*p)->rb_right; |
| 1513 | } |
| 1514 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1515 | for (i = 0; i < src_line->nr_pcnt; i++) |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1516 | src_line->samples[i].percent_sum = src_line->samples[i].percent; |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1517 | |
| 1518 | rb_link_node(&src_line->node, parent, p); |
| 1519 | rb_insert_color(&src_line->node, root); |
| 1520 | } |
| 1521 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1522 | static int cmp_source_line(struct source_line *a, struct source_line *b) |
| 1523 | { |
| 1524 | int i; |
| 1525 | |
| 1526 | for (i = 0; i < a->nr_pcnt; i++) { |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1527 | if (a->samples[i].percent_sum == b->samples[i].percent_sum) |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1528 | continue; |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1529 | return a->samples[i].percent_sum > b->samples[i].percent_sum; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1535 | static void __resort_source_line(struct rb_root *root, struct source_line *src_line) |
| 1536 | { |
| 1537 | struct source_line *iter; |
| 1538 | struct rb_node **p = &root->rb_node; |
| 1539 | struct rb_node *parent = NULL; |
| 1540 | |
| 1541 | while (*p != NULL) { |
| 1542 | parent = *p; |
| 1543 | iter = rb_entry(parent, struct source_line, node); |
| 1544 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1545 | if (cmp_source_line(src_line, iter)) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1546 | p = &(*p)->rb_left; |
| 1547 | else |
| 1548 | p = &(*p)->rb_right; |
| 1549 | } |
| 1550 | |
| 1551 | rb_link_node(&src_line->node, parent, p); |
| 1552 | rb_insert_color(&src_line->node, root); |
| 1553 | } |
| 1554 | |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1555 | static void resort_source_line(struct rb_root *dest_root, struct rb_root *src_root) |
| 1556 | { |
| 1557 | struct source_line *src_line; |
| 1558 | struct rb_node *node; |
| 1559 | |
| 1560 | node = rb_first(src_root); |
| 1561 | while (node) { |
| 1562 | struct rb_node *next; |
| 1563 | |
| 1564 | src_line = rb_entry(node, struct source_line, node); |
| 1565 | next = rb_next(node); |
| 1566 | rb_erase(node, src_root); |
| 1567 | |
| 1568 | __resort_source_line(dest_root, src_line); |
| 1569 | node = next; |
| 1570 | } |
| 1571 | } |
| 1572 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1573 | static void symbol__free_source_line(struct symbol *sym, int len) |
| 1574 | { |
| 1575 | struct annotation *notes = symbol__annotation(sym); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1576 | struct source_line *src_line = notes->src->lines; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1577 | size_t sizeof_src_line; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1578 | int i; |
| 1579 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1580 | sizeof_src_line = sizeof(*src_line) + |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1581 | (sizeof(src_line->samples) * (src_line->nr_pcnt - 1)); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1582 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1583 | for (i = 0; i < len; i++) { |
Namhyung Kim | f048d54 | 2013-09-11 14:09:28 +0900 | [diff] [blame] | 1584 | free_srcline(src_line->path); |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1585 | src_line = (void *)src_line + sizeof_src_line; |
| 1586 | } |
| 1587 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 1588 | zfree(¬es->src->lines); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | /* Get the filename:line for the colored entries */ |
| 1592 | static int symbol__get_source_line(struct symbol *sym, struct map *map, |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1593 | struct perf_evsel *evsel, |
Namhyung Kim | 86c98ca | 2013-09-11 14:09:30 +0900 | [diff] [blame] | 1594 | struct rb_root *root, int len) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1595 | { |
| 1596 | u64 start; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1597 | int i, k; |
| 1598 | int evidx = evsel->idx; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1599 | struct source_line *src_line; |
| 1600 | struct annotation *notes = symbol__annotation(sym); |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1601 | struct sym_hist *h = annotation__histogram(notes, evidx); |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1602 | struct rb_root tmp_root = RB_ROOT; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1603 | int nr_pcnt = 1; |
| 1604 | u64 h_sum = h->sum; |
| 1605 | size_t sizeof_src_line = sizeof(struct source_line); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1606 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1607 | if (perf_evsel__is_group_event(evsel)) { |
| 1608 | for (i = 1; i < evsel->nr_members; i++) { |
| 1609 | h = annotation__histogram(notes, evidx + i); |
| 1610 | h_sum += h->sum; |
| 1611 | } |
| 1612 | nr_pcnt = evsel->nr_members; |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1613 | sizeof_src_line += (nr_pcnt - 1) * sizeof(src_line->samples); |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | if (!h_sum) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1617 | return 0; |
| 1618 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1619 | src_line = notes->src->lines = calloc(len, sizeof_src_line); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1620 | if (!notes->src->lines) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1621 | return -1; |
| 1622 | |
David Miller | f40a063 | 2012-03-25 16:28:12 -0400 | [diff] [blame] | 1623 | start = map__rip_2objdump(map, sym->start); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1624 | |
| 1625 | for (i = 0; i < len; i++) { |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1626 | u64 offset; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1627 | double percent_max = 0.0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1628 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1629 | src_line->nr_pcnt = nr_pcnt; |
| 1630 | |
| 1631 | for (k = 0; k < nr_pcnt; k++) { |
| 1632 | h = annotation__histogram(notes, evidx + k); |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1633 | src_line->samples[k].percent = 100.0 * h->addr[i] / h->sum; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1634 | |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1635 | if (src_line->samples[k].percent > percent_max) |
| 1636 | percent_max = src_line->samples[k].percent; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | if (percent_max <= 0.5) |
| 1640 | goto next; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1641 | |
| 1642 | offset = start + i; |
Andi Kleen | 85c116a | 2014-11-12 18:05:27 -0800 | [diff] [blame] | 1643 | src_line->path = get_srcline(map->dso, offset, NULL, false); |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1644 | insert_source_line(&tmp_root, src_line); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1645 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1646 | next: |
| 1647 | src_line = (void *)src_line + sizeof_src_line; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1648 | } |
| 1649 | |
Namhyung Kim | 4112796 | 2012-11-09 14:58:49 +0900 | [diff] [blame] | 1650 | resort_source_line(root, &tmp_root); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1651 | return 0; |
| 1652 | } |
| 1653 | |
| 1654 | static void print_summary(struct rb_root *root, const char *filename) |
| 1655 | { |
| 1656 | struct source_line *src_line; |
| 1657 | struct rb_node *node; |
| 1658 | |
| 1659 | printf("\nSorted summary for file %s\n", filename); |
| 1660 | printf("----------------------------------------------\n\n"); |
| 1661 | |
| 1662 | if (RB_EMPTY_ROOT(root)) { |
| 1663 | printf(" Nothing higher than %1.1f%%\n", MIN_GREEN); |
| 1664 | return; |
| 1665 | } |
| 1666 | |
| 1667 | node = rb_first(root); |
| 1668 | while (node) { |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1669 | double percent, percent_max = 0.0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1670 | const char *color; |
| 1671 | char *path; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1672 | int i; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1673 | |
| 1674 | src_line = rb_entry(node, struct source_line, node); |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1675 | for (i = 0; i < src_line->nr_pcnt; i++) { |
Arnaldo Carvalho de Melo | 276af92f | 2015-06-19 16:36:12 -0300 | [diff] [blame] | 1676 | percent = src_line->samples[i].percent_sum; |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1677 | color = get_percent_color(percent); |
| 1678 | color_fprintf(stdout, color, " %7.2f", percent); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1679 | |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1680 | if (percent > percent_max) |
| 1681 | percent_max = percent; |
| 1682 | } |
| 1683 | |
| 1684 | path = src_line->path; |
| 1685 | color = get_percent_color(percent_max); |
Namhyung Kim | f048d54 | 2013-09-11 14:09:28 +0900 | [diff] [blame] | 1686 | color_fprintf(stdout, color, " %s\n", path); |
Namhyung Kim | 1491c22 | 2013-03-05 14:53:28 +0900 | [diff] [blame] | 1687 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1688 | node = rb_next(node); |
| 1689 | } |
| 1690 | } |
| 1691 | |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1692 | static void symbol__annotate_hits(struct symbol *sym, struct perf_evsel *evsel) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1693 | { |
| 1694 | struct annotation *notes = symbol__annotation(sym); |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1695 | struct sym_hist *h = annotation__histogram(notes, evsel->idx); |
Arnaldo Carvalho de Melo | 1b2e2df | 2012-04-19 10:57:06 -0300 | [diff] [blame] | 1696 | u64 len = symbol__size(sym), offset; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1697 | |
| 1698 | for (offset = 0; offset < len; ++offset) |
| 1699 | if (h->addr[offset] != 0) |
| 1700 | printf("%*" PRIx64 ": %" PRIu64 "\n", BITS_PER_LONG / 2, |
| 1701 | sym->start + offset, h->addr[offset]); |
| 1702 | printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum); |
| 1703 | } |
| 1704 | |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1705 | int symbol__annotate_printf(struct symbol *sym, struct map *map, |
| 1706 | struct perf_evsel *evsel, bool full_paths, |
| 1707 | int min_pcnt, int max_lines, int context) |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1708 | { |
| 1709 | struct dso *dso = map->dso; |
David Ahern | bfd14b9 | 2012-09-08 09:06:50 -0600 | [diff] [blame] | 1710 | char *filename; |
| 1711 | const char *d_filename; |
Arnaldo Carvalho de Melo | 9cdbadce | 2014-03-18 11:50:21 -0300 | [diff] [blame] | 1712 | const char *evsel_name = perf_evsel__name(evsel); |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1713 | struct annotation *notes = symbol__annotation(sym); |
Peter Zijlstra (Intel) | 135cce1 | 2016-06-30 10:29:55 +0200 | [diff] [blame] | 1714 | struct sym_hist *h = annotation__histogram(notes, evsel->idx); |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1715 | struct disasm_line *pos, *queue = NULL; |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1716 | u64 start = map__rip_2objdump(map, sym->start); |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1717 | int printed = 2, queue_len = 0; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1718 | int more = 0; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1719 | u64 len; |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1720 | int width = 8; |
Peter Zijlstra (Intel) | 53dd9b5 | 2016-06-30 09:17:26 -0300 | [diff] [blame] | 1721 | int graph_dotted_len; |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1722 | |
David Ahern | bfd14b9 | 2012-09-08 09:06:50 -0600 | [diff] [blame] | 1723 | filename = strdup(dso->long_name); |
| 1724 | if (!filename) |
| 1725 | return -ENOMEM; |
| 1726 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1727 | if (full_paths) |
| 1728 | d_filename = filename; |
| 1729 | else |
| 1730 | d_filename = basename(filename); |
| 1731 | |
Arnaldo Carvalho de Melo | 1b2e2df | 2012-04-19 10:57:06 -0300 | [diff] [blame] | 1732 | len = symbol__size(sym); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1733 | |
Namhyung Kim | 759ff49 | 2013-03-05 14:53:26 +0900 | [diff] [blame] | 1734 | if (perf_evsel__is_group_event(evsel)) |
Namhyung Kim | b1dd443 | 2013-03-05 14:53:25 +0900 | [diff] [blame] | 1735 | width *= evsel->nr_members; |
| 1736 | |
Peter Zijlstra (Intel) | 135cce1 | 2016-06-30 10:29:55 +0200 | [diff] [blame] | 1737 | graph_dotted_len = printf(" %-*.*s| Source code & Disassembly of %s for %s (%" PRIu64 " samples)\n", |
| 1738 | width, width, "Percent", d_filename, evsel_name, h->sum); |
Arnaldo Carvalho de Melo | 9cdbadce | 2014-03-18 11:50:21 -0300 | [diff] [blame] | 1739 | |
Peter Zijlstra (Intel) | 53dd9b5 | 2016-06-30 09:17:26 -0300 | [diff] [blame] | 1740 | printf("%-*.*s----\n", |
Arnaldo Carvalho de Melo | 9cdbadce | 2014-03-18 11:50:21 -0300 | [diff] [blame] | 1741 | graph_dotted_len, graph_dotted_len, graph_dotted_line); |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1742 | |
| 1743 | if (verbose) |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1744 | symbol__annotate_hits(sym, evsel); |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1745 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1746 | list_for_each_entry(pos, ¬es->src->source, node) { |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1747 | if (context && queue == NULL) { |
| 1748 | queue = pos; |
| 1749 | queue_len = 0; |
| 1750 | } |
| 1751 | |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1752 | switch (disasm_line__print(pos, sym, start, evsel, len, |
Arnaldo Carvalho de Melo | 058b4cc | 2012-04-02 12:59:01 -0300 | [diff] [blame] | 1753 | min_pcnt, printed, max_lines, |
| 1754 | queue)) { |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1755 | case 0: |
| 1756 | ++printed; |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1757 | if (context) { |
| 1758 | printed += queue_len; |
| 1759 | queue = NULL; |
| 1760 | queue_len = 0; |
| 1761 | } |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1762 | break; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1763 | case 1: |
| 1764 | /* filtered by max_lines */ |
| 1765 | ++more; |
| 1766 | break; |
| 1767 | case -1: |
| 1768 | default: |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1769 | /* |
| 1770 | * Filtered by min_pcnt or non IP lines when |
| 1771 | * context != 0 |
| 1772 | */ |
| 1773 | if (!context) |
| 1774 | break; |
| 1775 | if (queue_len == context) |
| 1776 | queue = list_entry(queue->node.next, typeof(*queue), node); |
| 1777 | else |
| 1778 | ++queue_len; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1779 | break; |
| 1780 | } |
| 1781 | } |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1782 | |
David Ahern | bfd14b9 | 2012-09-08 09:06:50 -0600 | [diff] [blame] | 1783 | free(filename); |
| 1784 | |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1785 | return more; |
| 1786 | } |
| 1787 | |
| 1788 | void symbol__annotate_zero_histogram(struct symbol *sym, int evidx) |
| 1789 | { |
| 1790 | struct annotation *notes = symbol__annotation(sym); |
| 1791 | struct sym_hist *h = annotation__histogram(notes, evidx); |
| 1792 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1793 | memset(h, 0, notes->src->sizeof_sym_hist); |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1794 | } |
| 1795 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1796 | void symbol__annotate_decay_histogram(struct symbol *sym, int evidx) |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1797 | { |
| 1798 | struct annotation *notes = symbol__annotation(sym); |
| 1799 | struct sym_hist *h = annotation__histogram(notes, evidx); |
Arnaldo Carvalho de Melo | 1b2e2df | 2012-04-19 10:57:06 -0300 | [diff] [blame] | 1800 | int len = symbol__size(sym), offset; |
Arnaldo Carvalho de Melo | 3653246 | 2011-02-06 14:54:44 -0200 | [diff] [blame] | 1801 | |
| 1802 | h->sum = 0; |
Arnaldo Carvalho de Melo | 8b84a56 | 2012-04-05 16:15:59 -0300 | [diff] [blame] | 1803 | for (offset = 0; offset < len; ++offset) { |
| 1804 | h->addr[offset] = h->addr[offset] * 7 / 8; |
| 1805 | h->sum += h->addr[offset]; |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1806 | } |
| 1807 | } |
| 1808 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1809 | void disasm__purge(struct list_head *head) |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1810 | { |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1811 | struct disasm_line *pos, *n; |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1812 | |
| 1813 | list_for_each_entry_safe(pos, n, head, node) { |
| 1814 | list_del(&pos->node); |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1815 | disasm_line__free(pos); |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 1819 | static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp) |
| 1820 | { |
| 1821 | size_t printed; |
| 1822 | |
| 1823 | if (dl->offset == -1) |
| 1824 | return fprintf(fp, "%s\n", dl->line); |
| 1825 | |
Arnaldo Carvalho de Melo | 75b4920 | 2016-11-24 11:16:06 -0300 | [diff] [blame] | 1826 | printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->ins.name); |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 1827 | |
Arnaldo Carvalho de Melo | c7e6ead | 2012-04-20 14:38:46 -0300 | [diff] [blame] | 1828 | if (dl->ops.raw[0] != '\0') { |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 1829 | printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ", |
Arnaldo Carvalho de Melo | c7e6ead | 2012-04-20 14:38:46 -0300 | [diff] [blame] | 1830 | dl->ops.raw); |
Arnaldo Carvalho de Melo | 5145418 | 2012-04-15 15:52:18 -0300 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | return printed + fprintf(fp, "\n"); |
| 1834 | } |
| 1835 | |
| 1836 | size_t disasm__fprintf(struct list_head *head, FILE *fp) |
| 1837 | { |
| 1838 | struct disasm_line *pos; |
| 1839 | size_t printed = 0; |
| 1840 | |
| 1841 | list_for_each_entry(pos, head, node) |
| 1842 | printed += disasm_line__fprintf(pos, fp); |
| 1843 | |
| 1844 | return printed; |
| 1845 | } |
| 1846 | |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1847 | int symbol__tty_annotate(struct symbol *sym, struct map *map, |
| 1848 | struct perf_evsel *evsel, bool print_lines, |
| 1849 | bool full_paths, int min_pcnt, int max_lines) |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1850 | { |
| 1851 | struct dso *dso = map->dso; |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1852 | struct rb_root source_line = RB_ROOT; |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1853 | u64 len; |
| 1854 | |
Arnaldo Carvalho de Melo | 786c1b5 | 2016-11-16 15:39:50 -0300 | [diff] [blame] | 1855 | if (symbol__disassemble(sym, map, perf_evsel__env_arch(evsel), 0) < 0) |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1856 | return -1; |
| 1857 | |
Arnaldo Carvalho de Melo | 1b2e2df | 2012-04-19 10:57:06 -0300 | [diff] [blame] | 1858 | len = symbol__size(sym); |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1859 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1860 | if (print_lines) { |
Michael Petlan | 4a4c03c | 2015-11-09 16:33:31 +0100 | [diff] [blame] | 1861 | srcline_full_filename = full_paths; |
Namhyung Kim | 86c98ca | 2013-09-11 14:09:30 +0900 | [diff] [blame] | 1862 | symbol__get_source_line(sym, map, evsel, &source_line, len); |
| 1863 | print_summary(&source_line, dso->long_name); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1864 | } |
| 1865 | |
Namhyung Kim | db8fd07 | 2013-03-05 14:53:21 +0900 | [diff] [blame] | 1866 | symbol__annotate_printf(sym, map, evsel, full_paths, |
Arnaldo Carvalho de Melo | d5e3d74 | 2011-02-08 15:29:25 -0200 | [diff] [blame] | 1867 | min_pcnt, max_lines, 0); |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1868 | if (print_lines) |
| 1869 | symbol__free_source_line(sym, len); |
| 1870 | |
Arnaldo Carvalho de Melo | 29ed6e7 | 2012-04-15 15:24:39 -0300 | [diff] [blame] | 1871 | disasm__purge(&symbol__annotation(sym)->src->source); |
Arnaldo Carvalho de Melo | f1e2701 | 2011-02-05 18:51:38 -0200 | [diff] [blame] | 1872 | |
Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1873 | return 0; |
| 1874 | } |
Arnaldo Carvalho de Melo | f626adf | 2013-12-18 17:10:15 -0300 | [diff] [blame] | 1875 | |
Namhyung Kim | 48c65bd | 2014-02-20 10:32:53 +0900 | [diff] [blame] | 1876 | bool ui__has_annotation(void) |
| 1877 | { |
Jiri Olsa | 2e0453a | 2016-05-03 13:54:44 +0200 | [diff] [blame] | 1878 | return use_browser == 1 && perf_hpp_list.sym; |
Namhyung Kim | 48c65bd | 2014-02-20 10:32:53 +0900 | [diff] [blame] | 1879 | } |