annotate.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. #include "util.h"
  10. #include "build-id.h"
  11. #include "color.h"
  12. #include "cache.h"
  13. #include "symbol.h"
  14. #include "debug.h"
  15. #include "annotate.h"
  16. #include <pthread.h>
  17. const char *disassembler_style;
  18. static int call_ops__parse_target(const char *operands, u64 *target)
  19. {
  20. *target = strtoull(operands, NULL, 16);
  21. return 0;
  22. }
  23. static struct ins_ops call_ops = {
  24. .parse_target = call_ops__parse_target,
  25. };
  26. bool ins__is_call(const struct ins *ins)
  27. {
  28. return ins->ops == &call_ops;
  29. }
  30. static int jump_ops__parse_target(const char *operands, u64 *target)
  31. {
  32. const char *s = strchr(operands, '+');
  33. if (s++ == NULL)
  34. return -1;
  35. *target = strtoll(s, NULL, 16);
  36. return 0;
  37. }
  38. static struct ins_ops jump_ops = {
  39. .parse_target = jump_ops__parse_target,
  40. };
  41. bool ins__is_jump(const struct ins *ins)
  42. {
  43. return ins->ops == &jump_ops;
  44. }
  45. /*
  46. * Must be sorted by name!
  47. */
  48. static struct ins instructions[] = {
  49. { .name = "call", .ops = &call_ops, },
  50. { .name = "callq", .ops = &call_ops, },
  51. { .name = "ja", .ops = &jump_ops, },
  52. { .name = "je", .ops = &jump_ops, },
  53. { .name = "jmp", .ops = &jump_ops, },
  54. { .name = "jmpq", .ops = &jump_ops, },
  55. { .name = "jne", .ops = &jump_ops, },
  56. { .name = "js", .ops = &jump_ops, },
  57. };
  58. static int ins__cmp(const void *name, const void *insp)
  59. {
  60. const struct ins *ins = insp;
  61. return strcmp(name, ins->name);
  62. }
  63. static struct ins *ins__find(const char *name)
  64. {
  65. const int nmemb = ARRAY_SIZE(instructions);
  66. return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__cmp);
  67. }
  68. int symbol__annotate_init(struct map *map __used, struct symbol *sym)
  69. {
  70. struct annotation *notes = symbol__annotation(sym);
  71. pthread_mutex_init(&notes->lock, NULL);
  72. return 0;
  73. }
  74. int symbol__alloc_hist(struct symbol *sym)
  75. {
  76. struct annotation *notes = symbol__annotation(sym);
  77. const size_t size = sym->end - sym->start + 1;
  78. size_t sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64));
  79. notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist);
  80. if (notes->src == NULL)
  81. return -1;
  82. notes->src->sizeof_sym_hist = sizeof_sym_hist;
  83. notes->src->nr_histograms = symbol_conf.nr_events;
  84. INIT_LIST_HEAD(&notes->src->source);
  85. return 0;
  86. }
  87. void symbol__annotate_zero_histograms(struct symbol *sym)
  88. {
  89. struct annotation *notes = symbol__annotation(sym);
  90. pthread_mutex_lock(&notes->lock);
  91. if (notes->src != NULL)
  92. memset(notes->src->histograms, 0,
  93. notes->src->nr_histograms * notes->src->sizeof_sym_hist);
  94. pthread_mutex_unlock(&notes->lock);
  95. }
  96. int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
  97. int evidx, u64 addr)
  98. {
  99. unsigned offset;
  100. struct annotation *notes;
  101. struct sym_hist *h;
  102. notes = symbol__annotation(sym);
  103. if (notes->src == NULL)
  104. return -ENOMEM;
  105. pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
  106. if (addr < sym->start || addr > sym->end)
  107. return -ERANGE;
  108. offset = addr - sym->start;
  109. h = annotation__histogram(notes, evidx);
  110. h->sum++;
  111. h->addr[offset]++;
  112. pr_debug3("%#" PRIx64 " %s: period++ [addr: %#" PRIx64 ", %#" PRIx64
  113. ", evidx=%d] => %" PRIu64 "\n", sym->start, sym->name,
  114. addr, addr - sym->start, evidx, h->addr[offset]);
  115. return 0;
  116. }
  117. static void disasm_line__init_ins(struct disasm_line *dl)
  118. {
  119. dl->ins = ins__find(dl->name);
  120. if (dl->ins == NULL)
  121. return;
  122. if (!dl->ins->ops)
  123. return;
  124. if (dl->ins->ops->parse_target)
  125. dl->ins->ops->parse_target(dl->operands, &dl->target);
  126. }
  127. static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
  128. {
  129. struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);
  130. if (dl != NULL) {
  131. dl->offset = offset;
  132. dl->line = strdup(line);
  133. if (dl->line == NULL)
  134. goto out_delete;
  135. if (offset != -1) {
  136. char *name = dl->line, tmp;
  137. while (isspace(name[0]))
  138. ++name;
  139. if (name[0] == '\0')
  140. goto out_delete;
  141. dl->operands = name + 1;
  142. while (dl->operands[0] != '\0' &&
  143. !isspace(dl->operands[0]))
  144. ++dl->operands;
  145. tmp = dl->operands[0];
  146. dl->operands[0] = '\0';
  147. dl->name = strdup(name);
  148. if (dl->name == NULL)
  149. goto out_free_line;
  150. dl->operands[0] = tmp;
  151. if (dl->operands[0] != '\0') {
  152. dl->operands++;
  153. while (isspace(dl->operands[0]))
  154. ++dl->operands;
  155. }
  156. disasm_line__init_ins(dl);
  157. }
  158. }
  159. return dl;
  160. out_free_line:
  161. free(dl->line);
  162. out_delete:
  163. free(dl);
  164. return NULL;
  165. }
  166. void disasm_line__free(struct disasm_line *dl)
  167. {
  168. free(dl->line);
  169. free(dl->name);
  170. free(dl);
  171. }
  172. static void disasm__add(struct list_head *head, struct disasm_line *line)
  173. {
  174. list_add_tail(&line->node, head);
  175. }
  176. struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos)
  177. {
  178. list_for_each_entry_continue(pos, head, node)
  179. if (pos->offset >= 0)
  180. return pos;
  181. return NULL;
  182. }
  183. static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start,
  184. int evidx, u64 len, int min_pcnt, int printed,
  185. int max_lines, struct disasm_line *queue)
  186. {
  187. static const char *prev_line;
  188. static const char *prev_color;
  189. if (dl->offset != -1) {
  190. const char *path = NULL;
  191. unsigned int hits = 0;
  192. double percent = 0.0;
  193. const char *color;
  194. struct annotation *notes = symbol__annotation(sym);
  195. struct source_line *src_line = notes->src->lines;
  196. struct sym_hist *h = annotation__histogram(notes, evidx);
  197. s64 offset = dl->offset;
  198. const u64 addr = start + offset;
  199. struct disasm_line *next;
  200. next = disasm__get_next_ip_line(&notes->src->source, dl);
  201. while (offset < (s64)len &&
  202. (next == NULL || offset < next->offset)) {
  203. if (src_line) {
  204. if (path == NULL)
  205. path = src_line[offset].path;
  206. percent += src_line[offset].percent;
  207. } else
  208. hits += h->addr[offset];
  209. ++offset;
  210. }
  211. if (src_line == NULL && h->sum)
  212. percent = 100.0 * hits / h->sum;
  213. if (percent < min_pcnt)
  214. return -1;
  215. if (max_lines && printed >= max_lines)
  216. return 1;
  217. if (queue != NULL) {
  218. list_for_each_entry_from(queue, &notes->src->source, node) {
  219. if (queue == dl)
  220. break;
  221. disasm_line__print(queue, sym, start, evidx, len,
  222. 0, 0, 1, NULL);
  223. }
  224. }
  225. color = get_percent_color(percent);
  226. /*
  227. * Also color the filename and line if needed, with
  228. * the same color than the percentage. Don't print it
  229. * twice for close colored addr with the same filename:line
  230. */
  231. if (path) {
  232. if (!prev_line || strcmp(prev_line, path)
  233. || color != prev_color) {
  234. color_fprintf(stdout, color, " %s", path);
  235. prev_line = path;
  236. prev_color = color;
  237. }
  238. }
  239. color_fprintf(stdout, color, " %7.2f", percent);
  240. printf(" : ");
  241. color_fprintf(stdout, PERF_COLOR_MAGENTA, " %" PRIx64 ":", addr);
  242. color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", dl->line);
  243. } else if (max_lines && printed >= max_lines)
  244. return 1;
  245. else {
  246. if (queue)
  247. return -1;
  248. if (!*dl->line)
  249. printf(" :\n");
  250. else
  251. printf(" : %s\n", dl->line);
  252. }
  253. return 0;
  254. }
  255. static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
  256. FILE *file, size_t privsize)
  257. {
  258. struct annotation *notes = symbol__annotation(sym);
  259. struct disasm_line *dl;
  260. char *line = NULL, *parsed_line, *tmp, *tmp2, *c;
  261. size_t line_len;
  262. s64 line_ip, offset = -1;
  263. if (getline(&line, &line_len, file) < 0)
  264. return -1;
  265. if (!line)
  266. return -1;
  267. while (line_len != 0 && isspace(line[line_len - 1]))
  268. line[--line_len] = '\0';
  269. c = strchr(line, '\n');
  270. if (c)
  271. *c = 0;
  272. line_ip = -1;
  273. parsed_line = line;
  274. /*
  275. * Strip leading spaces:
  276. */
  277. tmp = line;
  278. while (*tmp) {
  279. if (*tmp != ' ')
  280. break;
  281. tmp++;
  282. }
  283. if (*tmp) {
  284. /*
  285. * Parse hexa addresses followed by ':'
  286. */
  287. line_ip = strtoull(tmp, &tmp2, 16);
  288. if (*tmp2 != ':' || tmp == tmp2 || tmp2[1] == '\0')
  289. line_ip = -1;
  290. }
  291. if (line_ip != -1) {
  292. u64 start = map__rip_2objdump(map, sym->start),
  293. end = map__rip_2objdump(map, sym->end);
  294. offset = line_ip - start;
  295. if (offset < 0 || (u64)line_ip > end)
  296. offset = -1;
  297. else
  298. parsed_line = tmp2 + 1;
  299. }
  300. dl = disasm_line__new(offset, parsed_line, privsize);
  301. free(line);
  302. if (dl == NULL)
  303. return -1;
  304. disasm__add(&notes->src->source, dl);
  305. return 0;
  306. }
  307. int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
  308. {
  309. struct dso *dso = map->dso;
  310. char *filename = dso__build_id_filename(dso, NULL, 0);
  311. bool free_filename = true;
  312. char command[PATH_MAX * 2];
  313. FILE *file;
  314. int err = 0;
  315. char symfs_filename[PATH_MAX];
  316. if (filename) {
  317. snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
  318. symbol_conf.symfs, filename);
  319. }
  320. if (filename == NULL) {
  321. if (dso->has_build_id) {
  322. pr_err("Can't annotate %s: not enough memory\n",
  323. sym->name);
  324. return -ENOMEM;
  325. }
  326. goto fallback;
  327. } else if (readlink(symfs_filename, command, sizeof(command)) < 0 ||
  328. strstr(command, "[kernel.kallsyms]") ||
  329. access(symfs_filename, R_OK)) {
  330. free(filename);
  331. fallback:
  332. /*
  333. * If we don't have build-ids or the build-id file isn't in the
  334. * cache, or is just a kallsyms file, well, lets hope that this
  335. * DSO is the same as when 'perf record' ran.
  336. */
  337. filename = dso->long_name;
  338. snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
  339. symbol_conf.symfs, filename);
  340. free_filename = false;
  341. }
  342. if (dso->symtab_type == SYMTAB__KALLSYMS) {
  343. char bf[BUILD_ID_SIZE * 2 + 16] = " with build id ";
  344. char *build_id_msg = NULL;
  345. if (dso->annotate_warned)
  346. goto out_free_filename;
  347. if (dso->has_build_id) {
  348. build_id__sprintf(dso->build_id,
  349. sizeof(dso->build_id), bf + 15);
  350. build_id_msg = bf;
  351. }
  352. err = -ENOENT;
  353. dso->annotate_warned = 1;
  354. pr_err("Can't annotate %s:\n\n"
  355. "No vmlinux file%s\nwas found in the path.\n\n"
  356. "Please use:\n\n"
  357. " perf buildid-cache -av vmlinux\n\n"
  358. "or:\n\n"
  359. " --vmlinux vmlinux\n",
  360. sym->name, build_id_msg ?: "");
  361. goto out_free_filename;
  362. }
  363. pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
  364. filename, sym->name, map->unmap_ip(map, sym->start),
  365. map->unmap_ip(map, sym->end));
  366. pr_debug("annotating [%p] %30s : [%p] %30s\n",
  367. dso, dso->long_name, sym, sym->name);
  368. snprintf(command, sizeof(command),
  369. "objdump %s%s --start-address=0x%016" PRIx64
  370. " --stop-address=0x%016" PRIx64
  371. " -d %s %s -C %s|grep -v %s|expand",
  372. disassembler_style ? "-M " : "",
  373. disassembler_style ? disassembler_style : "",
  374. map__rip_2objdump(map, sym->start),
  375. map__rip_2objdump(map, sym->end+1),
  376. symbol_conf.annotate_asm_raw ? "" : "--no-show-raw",
  377. symbol_conf.annotate_src ? "-S" : "",
  378. symfs_filename, filename);
  379. pr_debug("Executing: %s\n", command);
  380. file = popen(command, "r");
  381. if (!file)
  382. goto out_free_filename;
  383. while (!feof(file))
  384. if (symbol__parse_objdump_line(sym, map, file, privsize) < 0)
  385. break;
  386. pclose(file);
  387. out_free_filename:
  388. if (free_filename)
  389. free(filename);
  390. return err;
  391. }
  392. static void insert_source_line(struct rb_root *root, struct source_line *src_line)
  393. {
  394. struct source_line *iter;
  395. struct rb_node **p = &root->rb_node;
  396. struct rb_node *parent = NULL;
  397. while (*p != NULL) {
  398. parent = *p;
  399. iter = rb_entry(parent, struct source_line, node);
  400. if (src_line->percent > iter->percent)
  401. p = &(*p)->rb_left;
  402. else
  403. p = &(*p)->rb_right;
  404. }
  405. rb_link_node(&src_line->node, parent, p);
  406. rb_insert_color(&src_line->node, root);
  407. }
  408. static void symbol__free_source_line(struct symbol *sym, int len)
  409. {
  410. struct annotation *notes = symbol__annotation(sym);
  411. struct source_line *src_line = notes->src->lines;
  412. int i;
  413. for (i = 0; i < len; i++)
  414. free(src_line[i].path);
  415. free(src_line);
  416. notes->src->lines = NULL;
  417. }
  418. /* Get the filename:line for the colored entries */
  419. static int symbol__get_source_line(struct symbol *sym, struct map *map,
  420. int evidx, struct rb_root *root, int len,
  421. const char *filename)
  422. {
  423. u64 start;
  424. int i;
  425. char cmd[PATH_MAX * 2];
  426. struct source_line *src_line;
  427. struct annotation *notes = symbol__annotation(sym);
  428. struct sym_hist *h = annotation__histogram(notes, evidx);
  429. if (!h->sum)
  430. return 0;
  431. src_line = notes->src->lines = calloc(len, sizeof(struct source_line));
  432. if (!notes->src->lines)
  433. return -1;
  434. start = map__rip_2objdump(map, sym->start);
  435. for (i = 0; i < len; i++) {
  436. char *path = NULL;
  437. size_t line_len;
  438. u64 offset;
  439. FILE *fp;
  440. src_line[i].percent = 100.0 * h->addr[i] / h->sum;
  441. if (src_line[i].percent <= 0.5)
  442. continue;
  443. offset = start + i;
  444. sprintf(cmd, "addr2line -e %s %016" PRIx64, filename, offset);
  445. fp = popen(cmd, "r");
  446. if (!fp)
  447. continue;
  448. if (getline(&path, &line_len, fp) < 0 || !line_len)
  449. goto next;
  450. src_line[i].path = malloc(sizeof(char) * line_len + 1);
  451. if (!src_line[i].path)
  452. goto next;
  453. strcpy(src_line[i].path, path);
  454. insert_source_line(root, &src_line[i]);
  455. next:
  456. pclose(fp);
  457. }
  458. return 0;
  459. }
  460. static void print_summary(struct rb_root *root, const char *filename)
  461. {
  462. struct source_line *src_line;
  463. struct rb_node *node;
  464. printf("\nSorted summary for file %s\n", filename);
  465. printf("----------------------------------------------\n\n");
  466. if (RB_EMPTY_ROOT(root)) {
  467. printf(" Nothing higher than %1.1f%%\n", MIN_GREEN);
  468. return;
  469. }
  470. node = rb_first(root);
  471. while (node) {
  472. double percent;
  473. const char *color;
  474. char *path;
  475. src_line = rb_entry(node, struct source_line, node);
  476. percent = src_line->percent;
  477. color = get_percent_color(percent);
  478. path = src_line->path;
  479. color_fprintf(stdout, color, " %7.2f %s", percent, path);
  480. node = rb_next(node);
  481. }
  482. }
  483. static void symbol__annotate_hits(struct symbol *sym, int evidx)
  484. {
  485. struct annotation *notes = symbol__annotation(sym);
  486. struct sym_hist *h = annotation__histogram(notes, evidx);
  487. u64 len = sym->end - sym->start, offset;
  488. for (offset = 0; offset < len; ++offset)
  489. if (h->addr[offset] != 0)
  490. printf("%*" PRIx64 ": %" PRIu64 "\n", BITS_PER_LONG / 2,
  491. sym->start + offset, h->addr[offset]);
  492. printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
  493. }
  494. int symbol__annotate_printf(struct symbol *sym, struct map *map, int evidx,
  495. bool full_paths, int min_pcnt, int max_lines,
  496. int context)
  497. {
  498. struct dso *dso = map->dso;
  499. const char *filename = dso->long_name, *d_filename;
  500. struct annotation *notes = symbol__annotation(sym);
  501. struct disasm_line *pos, *queue = NULL;
  502. u64 start = map__rip_2objdump(map, sym->start);
  503. int printed = 2, queue_len = 0;
  504. int more = 0;
  505. u64 len;
  506. if (full_paths)
  507. d_filename = filename;
  508. else
  509. d_filename = basename(filename);
  510. len = sym->end - sym->start;
  511. printf(" Percent | Source code & Disassembly of %s\n", d_filename);
  512. printf("------------------------------------------------\n");
  513. if (verbose)
  514. symbol__annotate_hits(sym, evidx);
  515. list_for_each_entry(pos, &notes->src->source, node) {
  516. if (context && queue == NULL) {
  517. queue = pos;
  518. queue_len = 0;
  519. }
  520. switch (disasm_line__print(pos, sym, start, evidx, len,
  521. min_pcnt, printed, max_lines,
  522. queue)) {
  523. case 0:
  524. ++printed;
  525. if (context) {
  526. printed += queue_len;
  527. queue = NULL;
  528. queue_len = 0;
  529. }
  530. break;
  531. case 1:
  532. /* filtered by max_lines */
  533. ++more;
  534. break;
  535. case -1:
  536. default:
  537. /*
  538. * Filtered by min_pcnt or non IP lines when
  539. * context != 0
  540. */
  541. if (!context)
  542. break;
  543. if (queue_len == context)
  544. queue = list_entry(queue->node.next, typeof(*queue), node);
  545. else
  546. ++queue_len;
  547. break;
  548. }
  549. }
  550. return more;
  551. }
  552. void symbol__annotate_zero_histogram(struct symbol *sym, int evidx)
  553. {
  554. struct annotation *notes = symbol__annotation(sym);
  555. struct sym_hist *h = annotation__histogram(notes, evidx);
  556. memset(h, 0, notes->src->sizeof_sym_hist);
  557. }
  558. void symbol__annotate_decay_histogram(struct symbol *sym, int evidx)
  559. {
  560. struct annotation *notes = symbol__annotation(sym);
  561. struct sym_hist *h = annotation__histogram(notes, evidx);
  562. int len = sym->end - sym->start, offset;
  563. h->sum = 0;
  564. for (offset = 0; offset < len; ++offset) {
  565. h->addr[offset] = h->addr[offset] * 7 / 8;
  566. h->sum += h->addr[offset];
  567. }
  568. }
  569. void disasm__purge(struct list_head *head)
  570. {
  571. struct disasm_line *pos, *n;
  572. list_for_each_entry_safe(pos, n, head, node) {
  573. list_del(&pos->node);
  574. disasm_line__free(pos);
  575. }
  576. }
  577. static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
  578. {
  579. size_t printed;
  580. if (dl->offset == -1)
  581. return fprintf(fp, "%s\n", dl->line);
  582. printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name);
  583. if (dl->operands[0] != '\0') {
  584. printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
  585. dl->operands);
  586. }
  587. return printed + fprintf(fp, "\n");
  588. }
  589. size_t disasm__fprintf(struct list_head *head, FILE *fp)
  590. {
  591. struct disasm_line *pos;
  592. size_t printed = 0;
  593. list_for_each_entry(pos, head, node)
  594. printed += disasm_line__fprintf(pos, fp);
  595. return printed;
  596. }
  597. int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
  598. bool print_lines, bool full_paths, int min_pcnt,
  599. int max_lines)
  600. {
  601. struct dso *dso = map->dso;
  602. const char *filename = dso->long_name;
  603. struct rb_root source_line = RB_ROOT;
  604. u64 len;
  605. if (symbol__annotate(sym, map, 0) < 0)
  606. return -1;
  607. len = sym->end - sym->start;
  608. if (print_lines) {
  609. symbol__get_source_line(sym, map, evidx, &source_line,
  610. len, filename);
  611. print_summary(&source_line, filename);
  612. }
  613. symbol__annotate_printf(sym, map, evidx, full_paths,
  614. min_pcnt, max_lines, 0);
  615. if (print_lines)
  616. symbol__free_source_line(sym, len);
  617. disasm__purge(&symbol__annotation(sym)->src->source);
  618. return 0;
  619. }