annotate.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  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 "evsel.h"
  17. #include <pthread.h>
  18. #include <linux/bitops.h>
  19. const char *disassembler_style;
  20. const char *objdump_path;
  21. static struct ins *ins__find(const char *name);
  22. static int disasm_line__parse(char *line, char **namep, char **rawp);
  23. static void ins__delete(struct ins_operands *ops)
  24. {
  25. free(ops->source.raw);
  26. free(ops->source.name);
  27. free(ops->target.raw);
  28. free(ops->target.name);
  29. }
  30. static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
  31. struct ins_operands *ops)
  32. {
  33. return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);
  34. }
  35. int ins__scnprintf(struct ins *ins, char *bf, size_t size,
  36. struct ins_operands *ops)
  37. {
  38. if (ins->ops->scnprintf)
  39. return ins->ops->scnprintf(ins, bf, size, ops);
  40. return ins__raw_scnprintf(ins, bf, size, ops);
  41. }
  42. static int call__parse(struct ins_operands *ops)
  43. {
  44. char *endptr, *tok, *name;
  45. ops->target.addr = strtoull(ops->raw, &endptr, 16);
  46. name = strchr(endptr, '<');
  47. if (name == NULL)
  48. goto indirect_call;
  49. name++;
  50. tok = strchr(name, '>');
  51. if (tok == NULL)
  52. return -1;
  53. *tok = '\0';
  54. ops->target.name = strdup(name);
  55. *tok = '>';
  56. return ops->target.name == NULL ? -1 : 0;
  57. indirect_call:
  58. tok = strchr(endptr, '(');
  59. if (tok != NULL) {
  60. ops->target.addr = 0;
  61. return 0;
  62. }
  63. tok = strchr(endptr, '*');
  64. if (tok == NULL)
  65. return -1;
  66. ops->target.addr = strtoull(tok + 1, NULL, 16);
  67. return 0;
  68. }
  69. static int call__scnprintf(struct ins *ins, char *bf, size_t size,
  70. struct ins_operands *ops)
  71. {
  72. if (ops->target.name)
  73. return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->target.name);
  74. if (ops->target.addr == 0)
  75. return ins__raw_scnprintf(ins, bf, size, ops);
  76. return scnprintf(bf, size, "%-6.6s *%" PRIx64, ins->name, ops->target.addr);
  77. }
  78. static struct ins_ops call_ops = {
  79. .parse = call__parse,
  80. .scnprintf = call__scnprintf,
  81. };
  82. bool ins__is_call(const struct ins *ins)
  83. {
  84. return ins->ops == &call_ops;
  85. }
  86. static int jump__parse(struct ins_operands *ops)
  87. {
  88. const char *s = strchr(ops->raw, '+');
  89. ops->target.addr = strtoull(ops->raw, NULL, 16);
  90. if (s++ != NULL)
  91. ops->target.offset = strtoull(s, NULL, 16);
  92. else
  93. ops->target.offset = UINT64_MAX;
  94. return 0;
  95. }
  96. static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
  97. struct ins_operands *ops)
  98. {
  99. return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset);
  100. }
  101. static struct ins_ops jump_ops = {
  102. .parse = jump__parse,
  103. .scnprintf = jump__scnprintf,
  104. };
  105. bool ins__is_jump(const struct ins *ins)
  106. {
  107. return ins->ops == &jump_ops;
  108. }
  109. static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep)
  110. {
  111. char *endptr, *name, *t;
  112. if (strstr(raw, "(%rip)") == NULL)
  113. return 0;
  114. *addrp = strtoull(comment, &endptr, 16);
  115. name = strchr(endptr, '<');
  116. if (name == NULL)
  117. return -1;
  118. name++;
  119. t = strchr(name, '>');
  120. if (t == NULL)
  121. return 0;
  122. *t = '\0';
  123. *namep = strdup(name);
  124. *t = '>';
  125. return 0;
  126. }
  127. static int lock__parse(struct ins_operands *ops)
  128. {
  129. char *name;
  130. ops->locked.ops = zalloc(sizeof(*ops->locked.ops));
  131. if (ops->locked.ops == NULL)
  132. return 0;
  133. if (disasm_line__parse(ops->raw, &name, &ops->locked.ops->raw) < 0)
  134. goto out_free_ops;
  135. ops->locked.ins = ins__find(name);
  136. if (ops->locked.ins == NULL)
  137. goto out_free_ops;
  138. if (!ops->locked.ins->ops)
  139. return 0;
  140. if (ops->locked.ins->ops->parse)
  141. ops->locked.ins->ops->parse(ops->locked.ops);
  142. return 0;
  143. out_free_ops:
  144. free(ops->locked.ops);
  145. ops->locked.ops = NULL;
  146. return 0;
  147. }
  148. static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
  149. struct ins_operands *ops)
  150. {
  151. int printed;
  152. if (ops->locked.ins == NULL)
  153. return ins__raw_scnprintf(ins, bf, size, ops);
  154. printed = scnprintf(bf, size, "%-6.6s ", ins->name);
  155. return printed + ins__scnprintf(ops->locked.ins, bf + printed,
  156. size - printed, ops->locked.ops);
  157. }
  158. static void lock__delete(struct ins_operands *ops)
  159. {
  160. free(ops->locked.ops);
  161. free(ops->target.raw);
  162. free(ops->target.name);
  163. }
  164. static struct ins_ops lock_ops = {
  165. .free = lock__delete,
  166. .parse = lock__parse,
  167. .scnprintf = lock__scnprintf,
  168. };
  169. static int mov__parse(struct ins_operands *ops)
  170. {
  171. char *s = strchr(ops->raw, ','), *target, *comment, prev;
  172. if (s == NULL)
  173. return -1;
  174. *s = '\0';
  175. ops->source.raw = strdup(ops->raw);
  176. *s = ',';
  177. if (ops->source.raw == NULL)
  178. return -1;
  179. target = ++s;
  180. while (s[0] != '\0' && !isspace(s[0]))
  181. ++s;
  182. prev = *s;
  183. *s = '\0';
  184. ops->target.raw = strdup(target);
  185. *s = prev;
  186. if (ops->target.raw == NULL)
  187. goto out_free_source;
  188. comment = strchr(s, '#');
  189. if (comment == NULL)
  190. return 0;
  191. while (comment[0] != '\0' && isspace(comment[0]))
  192. ++comment;
  193. comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name);
  194. comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
  195. return 0;
  196. out_free_source:
  197. free(ops->source.raw);
  198. ops->source.raw = NULL;
  199. return -1;
  200. }
  201. static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
  202. struct ins_operands *ops)
  203. {
  204. return scnprintf(bf, size, "%-6.6s %s,%s", ins->name,
  205. ops->source.name ?: ops->source.raw,
  206. ops->target.name ?: ops->target.raw);
  207. }
  208. static struct ins_ops mov_ops = {
  209. .parse = mov__parse,
  210. .scnprintf = mov__scnprintf,
  211. };
  212. static int dec__parse(struct ins_operands *ops)
  213. {
  214. char *target, *comment, *s, prev;
  215. target = s = ops->raw;
  216. while (s[0] != '\0' && !isspace(s[0]))
  217. ++s;
  218. prev = *s;
  219. *s = '\0';
  220. ops->target.raw = strdup(target);
  221. *s = prev;
  222. if (ops->target.raw == NULL)
  223. return -1;
  224. comment = strchr(s, '#');
  225. if (comment == NULL)
  226. return 0;
  227. while (comment[0] != '\0' && isspace(comment[0]))
  228. ++comment;
  229. comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
  230. return 0;
  231. }
  232. static int dec__scnprintf(struct ins *ins, char *bf, size_t size,
  233. struct ins_operands *ops)
  234. {
  235. return scnprintf(bf, size, "%-6.6s %s", ins->name,
  236. ops->target.name ?: ops->target.raw);
  237. }
  238. static struct ins_ops dec_ops = {
  239. .parse = dec__parse,
  240. .scnprintf = dec__scnprintf,
  241. };
  242. static int nop__scnprintf(struct ins *ins __maybe_unused, char *bf, size_t size,
  243. struct ins_operands *ops __maybe_unused)
  244. {
  245. return scnprintf(bf, size, "%-6.6s", "nop");
  246. }
  247. static struct ins_ops nop_ops = {
  248. .scnprintf = nop__scnprintf,
  249. };
  250. /*
  251. * Must be sorted by name!
  252. */
  253. static struct ins instructions[] = {
  254. { .name = "add", .ops = &mov_ops, },
  255. { .name = "addl", .ops = &mov_ops, },
  256. { .name = "addq", .ops = &mov_ops, },
  257. { .name = "addw", .ops = &mov_ops, },
  258. { .name = "and", .ops = &mov_ops, },
  259. { .name = "bts", .ops = &mov_ops, },
  260. { .name = "call", .ops = &call_ops, },
  261. { .name = "callq", .ops = &call_ops, },
  262. { .name = "cmp", .ops = &mov_ops, },
  263. { .name = "cmpb", .ops = &mov_ops, },
  264. { .name = "cmpl", .ops = &mov_ops, },
  265. { .name = "cmpq", .ops = &mov_ops, },
  266. { .name = "cmpw", .ops = &mov_ops, },
  267. { .name = "cmpxch", .ops = &mov_ops, },
  268. { .name = "dec", .ops = &dec_ops, },
  269. { .name = "decl", .ops = &dec_ops, },
  270. { .name = "imul", .ops = &mov_ops, },
  271. { .name = "inc", .ops = &dec_ops, },
  272. { .name = "incl", .ops = &dec_ops, },
  273. { .name = "ja", .ops = &jump_ops, },
  274. { .name = "jae", .ops = &jump_ops, },
  275. { .name = "jb", .ops = &jump_ops, },
  276. { .name = "jbe", .ops = &jump_ops, },
  277. { .name = "jc", .ops = &jump_ops, },
  278. { .name = "jcxz", .ops = &jump_ops, },
  279. { .name = "je", .ops = &jump_ops, },
  280. { .name = "jecxz", .ops = &jump_ops, },
  281. { .name = "jg", .ops = &jump_ops, },
  282. { .name = "jge", .ops = &jump_ops, },
  283. { .name = "jl", .ops = &jump_ops, },
  284. { .name = "jle", .ops = &jump_ops, },
  285. { .name = "jmp", .ops = &jump_ops, },
  286. { .name = "jmpq", .ops = &jump_ops, },
  287. { .name = "jna", .ops = &jump_ops, },
  288. { .name = "jnae", .ops = &jump_ops, },
  289. { .name = "jnb", .ops = &jump_ops, },
  290. { .name = "jnbe", .ops = &jump_ops, },
  291. { .name = "jnc", .ops = &jump_ops, },
  292. { .name = "jne", .ops = &jump_ops, },
  293. { .name = "jng", .ops = &jump_ops, },
  294. { .name = "jnge", .ops = &jump_ops, },
  295. { .name = "jnl", .ops = &jump_ops, },
  296. { .name = "jnle", .ops = &jump_ops, },
  297. { .name = "jno", .ops = &jump_ops, },
  298. { .name = "jnp", .ops = &jump_ops, },
  299. { .name = "jns", .ops = &jump_ops, },
  300. { .name = "jnz", .ops = &jump_ops, },
  301. { .name = "jo", .ops = &jump_ops, },
  302. { .name = "jp", .ops = &jump_ops, },
  303. { .name = "jpe", .ops = &jump_ops, },
  304. { .name = "jpo", .ops = &jump_ops, },
  305. { .name = "jrcxz", .ops = &jump_ops, },
  306. { .name = "js", .ops = &jump_ops, },
  307. { .name = "jz", .ops = &jump_ops, },
  308. { .name = "lea", .ops = &mov_ops, },
  309. { .name = "lock", .ops = &lock_ops, },
  310. { .name = "mov", .ops = &mov_ops, },
  311. { .name = "movb", .ops = &mov_ops, },
  312. { .name = "movdqa",.ops = &mov_ops, },
  313. { .name = "movl", .ops = &mov_ops, },
  314. { .name = "movq", .ops = &mov_ops, },
  315. { .name = "movslq", .ops = &mov_ops, },
  316. { .name = "movzbl", .ops = &mov_ops, },
  317. { .name = "movzwl", .ops = &mov_ops, },
  318. { .name = "nop", .ops = &nop_ops, },
  319. { .name = "nopl", .ops = &nop_ops, },
  320. { .name = "nopw", .ops = &nop_ops, },
  321. { .name = "or", .ops = &mov_ops, },
  322. { .name = "orl", .ops = &mov_ops, },
  323. { .name = "test", .ops = &mov_ops, },
  324. { .name = "testb", .ops = &mov_ops, },
  325. { .name = "testl", .ops = &mov_ops, },
  326. { .name = "xadd", .ops = &mov_ops, },
  327. { .name = "xbeginl", .ops = &jump_ops, },
  328. { .name = "xbeginq", .ops = &jump_ops, },
  329. };
  330. static int ins__cmp(const void *name, const void *insp)
  331. {
  332. const struct ins *ins = insp;
  333. return strcmp(name, ins->name);
  334. }
  335. static struct ins *ins__find(const char *name)
  336. {
  337. const int nmemb = ARRAY_SIZE(instructions);
  338. return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__cmp);
  339. }
  340. int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym)
  341. {
  342. struct annotation *notes = symbol__annotation(sym);
  343. pthread_mutex_init(&notes->lock, NULL);
  344. return 0;
  345. }
  346. int symbol__alloc_hist(struct symbol *sym)
  347. {
  348. struct annotation *notes = symbol__annotation(sym);
  349. const size_t size = symbol__size(sym);
  350. size_t sizeof_sym_hist;
  351. /* Check for overflow when calculating sizeof_sym_hist */
  352. if (size > (SIZE_MAX - sizeof(struct sym_hist)) / sizeof(u64))
  353. return -1;
  354. sizeof_sym_hist = (sizeof(struct sym_hist) + size * sizeof(u64));
  355. /* Check for overflow in zalloc argument */
  356. if (sizeof_sym_hist > (SIZE_MAX - sizeof(*notes->src))
  357. / symbol_conf.nr_events)
  358. return -1;
  359. notes->src = zalloc(sizeof(*notes->src) + symbol_conf.nr_events * sizeof_sym_hist);
  360. if (notes->src == NULL)
  361. return -1;
  362. notes->src->sizeof_sym_hist = sizeof_sym_hist;
  363. notes->src->nr_histograms = symbol_conf.nr_events;
  364. INIT_LIST_HEAD(&notes->src->source);
  365. return 0;
  366. }
  367. void symbol__annotate_zero_histograms(struct symbol *sym)
  368. {
  369. struct annotation *notes = symbol__annotation(sym);
  370. pthread_mutex_lock(&notes->lock);
  371. if (notes->src != NULL)
  372. memset(notes->src->histograms, 0,
  373. notes->src->nr_histograms * notes->src->sizeof_sym_hist);
  374. pthread_mutex_unlock(&notes->lock);
  375. }
  376. static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map,
  377. struct annotation *notes, int evidx, u64 addr)
  378. {
  379. unsigned offset;
  380. struct sym_hist *h;
  381. pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
  382. if (addr < sym->start || addr > sym->end)
  383. return -ERANGE;
  384. offset = addr - sym->start;
  385. h = annotation__histogram(notes, evidx);
  386. h->sum++;
  387. h->addr[offset]++;
  388. pr_debug3("%#" PRIx64 " %s: period++ [addr: %#" PRIx64 ", %#" PRIx64
  389. ", evidx=%d] => %" PRIu64 "\n", sym->start, sym->name,
  390. addr, addr - sym->start, evidx, h->addr[offset]);
  391. return 0;
  392. }
  393. int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
  394. int evidx, u64 addr)
  395. {
  396. struct annotation *notes;
  397. if (sym == NULL || use_browser != 1 || !sort__has_sym)
  398. return 0;
  399. notes = symbol__annotation(sym);
  400. if (notes->src == NULL) {
  401. if (symbol__alloc_hist(sym) < 0)
  402. return -ENOMEM;
  403. }
  404. return __symbol__inc_addr_samples(sym, map, notes, evidx, addr);
  405. }
  406. int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx)
  407. {
  408. return symbol__inc_addr_samples(ams->sym, ams->map, evidx, ams->al_addr);
  409. }
  410. int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
  411. {
  412. return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
  413. }
  414. static void disasm_line__init_ins(struct disasm_line *dl)
  415. {
  416. dl->ins = ins__find(dl->name);
  417. if (dl->ins == NULL)
  418. return;
  419. if (!dl->ins->ops)
  420. return;
  421. if (dl->ins->ops->parse)
  422. dl->ins->ops->parse(&dl->ops);
  423. }
  424. static int disasm_line__parse(char *line, char **namep, char **rawp)
  425. {
  426. char *name = line, tmp;
  427. while (isspace(name[0]))
  428. ++name;
  429. if (name[0] == '\0')
  430. return -1;
  431. *rawp = name + 1;
  432. while ((*rawp)[0] != '\0' && !isspace((*rawp)[0]))
  433. ++*rawp;
  434. tmp = (*rawp)[0];
  435. (*rawp)[0] = '\0';
  436. *namep = strdup(name);
  437. if (*namep == NULL)
  438. goto out_free_name;
  439. (*rawp)[0] = tmp;
  440. if ((*rawp)[0] != '\0') {
  441. (*rawp)++;
  442. while (isspace((*rawp)[0]))
  443. ++(*rawp);
  444. }
  445. return 0;
  446. out_free_name:
  447. free(*namep);
  448. *namep = NULL;
  449. return -1;
  450. }
  451. static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
  452. {
  453. struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);
  454. if (dl != NULL) {
  455. dl->offset = offset;
  456. dl->line = strdup(line);
  457. if (dl->line == NULL)
  458. goto out_delete;
  459. if (offset != -1) {
  460. if (disasm_line__parse(dl->line, &dl->name, &dl->ops.raw) < 0)
  461. goto out_free_line;
  462. disasm_line__init_ins(dl);
  463. }
  464. }
  465. return dl;
  466. out_free_line:
  467. free(dl->line);
  468. out_delete:
  469. free(dl);
  470. return NULL;
  471. }
  472. void disasm_line__free(struct disasm_line *dl)
  473. {
  474. free(dl->line);
  475. free(dl->name);
  476. if (dl->ins && dl->ins->ops->free)
  477. dl->ins->ops->free(&dl->ops);
  478. else
  479. ins__delete(&dl->ops);
  480. free(dl);
  481. }
  482. int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw)
  483. {
  484. if (raw || !dl->ins)
  485. return scnprintf(bf, size, "%-6.6s %s", dl->name, dl->ops.raw);
  486. return ins__scnprintf(dl->ins, bf, size, &dl->ops);
  487. }
  488. static void disasm__add(struct list_head *head, struct disasm_line *line)
  489. {
  490. list_add_tail(&line->node, head);
  491. }
  492. struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos)
  493. {
  494. list_for_each_entry_continue(pos, head, node)
  495. if (pos->offset >= 0)
  496. return pos;
  497. return NULL;
  498. }
  499. double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
  500. s64 end, const char **path)
  501. {
  502. struct source_line *src_line = notes->src->lines;
  503. double percent = 0.0;
  504. if (src_line) {
  505. size_t sizeof_src_line = sizeof(*src_line) +
  506. sizeof(src_line->p) * (src_line->nr_pcnt - 1);
  507. while (offset < end) {
  508. src_line = (void *)notes->src->lines +
  509. (sizeof_src_line * offset);
  510. if (*path == NULL)
  511. *path = src_line->path;
  512. percent += src_line->p[evidx].percent;
  513. offset++;
  514. }
  515. } else {
  516. struct sym_hist *h = annotation__histogram(notes, evidx);
  517. unsigned int hits = 0;
  518. while (offset < end)
  519. hits += h->addr[offset++];
  520. if (h->sum)
  521. percent = 100.0 * hits / h->sum;
  522. }
  523. return percent;
  524. }
  525. static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start,
  526. struct perf_evsel *evsel, u64 len, int min_pcnt, int printed,
  527. int max_lines, struct disasm_line *queue)
  528. {
  529. static const char *prev_line;
  530. static const char *prev_color;
  531. if (dl->offset != -1) {
  532. const char *path = NULL;
  533. double percent, max_percent = 0.0;
  534. double *ppercents = &percent;
  535. int i, nr_percent = 1;
  536. const char *color;
  537. struct annotation *notes = symbol__annotation(sym);
  538. s64 offset = dl->offset;
  539. const u64 addr = start + offset;
  540. struct disasm_line *next;
  541. next = disasm__get_next_ip_line(&notes->src->source, dl);
  542. if (perf_evsel__is_group_event(evsel)) {
  543. nr_percent = evsel->nr_members;
  544. ppercents = calloc(nr_percent, sizeof(double));
  545. if (ppercents == NULL)
  546. return -1;
  547. }
  548. for (i = 0; i < nr_percent; i++) {
  549. percent = disasm__calc_percent(notes,
  550. notes->src->lines ? i : evsel->idx + i,
  551. offset,
  552. next ? next->offset : (s64) len,
  553. &path);
  554. ppercents[i] = percent;
  555. if (percent > max_percent)
  556. max_percent = percent;
  557. }
  558. if (max_percent < min_pcnt)
  559. return -1;
  560. if (max_lines && printed >= max_lines)
  561. return 1;
  562. if (queue != NULL) {
  563. list_for_each_entry_from(queue, &notes->src->source, node) {
  564. if (queue == dl)
  565. break;
  566. disasm_line__print(queue, sym, start, evsel, len,
  567. 0, 0, 1, NULL);
  568. }
  569. }
  570. color = get_percent_color(max_percent);
  571. /*
  572. * Also color the filename and line if needed, with
  573. * the same color than the percentage. Don't print it
  574. * twice for close colored addr with the same filename:line
  575. */
  576. if (path) {
  577. if (!prev_line || strcmp(prev_line, path)
  578. || color != prev_color) {
  579. color_fprintf(stdout, color, " %s", path);
  580. prev_line = path;
  581. prev_color = color;
  582. }
  583. }
  584. for (i = 0; i < nr_percent; i++) {
  585. percent = ppercents[i];
  586. color = get_percent_color(percent);
  587. color_fprintf(stdout, color, " %7.2f", percent);
  588. }
  589. printf(" : ");
  590. color_fprintf(stdout, PERF_COLOR_MAGENTA, " %" PRIx64 ":", addr);
  591. color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", dl->line);
  592. if (ppercents != &percent)
  593. free(ppercents);
  594. } else if (max_lines && printed >= max_lines)
  595. return 1;
  596. else {
  597. int width = 8;
  598. if (queue)
  599. return -1;
  600. if (perf_evsel__is_group_event(evsel))
  601. width *= evsel->nr_members;
  602. if (!*dl->line)
  603. printf(" %*s:\n", width, " ");
  604. else
  605. printf(" %*s: %s\n", width, " ", dl->line);
  606. }
  607. return 0;
  608. }
  609. /*
  610. * symbol__parse_objdump_line() parses objdump output (with -d --no-show-raw)
  611. * which looks like following
  612. *
  613. * 0000000000415500 <_init>:
  614. * 415500: sub $0x8,%rsp
  615. * 415504: mov 0x2f5ad5(%rip),%rax # 70afe0 <_DYNAMIC+0x2f8>
  616. * 41550b: test %rax,%rax
  617. * 41550e: je 415515 <_init+0x15>
  618. * 415510: callq 416e70 <__gmon_start__@plt>
  619. * 415515: add $0x8,%rsp
  620. * 415519: retq
  621. *
  622. * it will be parsed and saved into struct disasm_line as
  623. * <offset> <name> <ops.raw>
  624. *
  625. * The offset will be a relative offset from the start of the symbol and -1
  626. * means that it's not a disassembly line so should be treated differently.
  627. * The ops.raw part will be parsed further according to type of the instruction.
  628. */
  629. static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
  630. FILE *file, size_t privsize)
  631. {
  632. struct annotation *notes = symbol__annotation(sym);
  633. struct disasm_line *dl;
  634. char *line = NULL, *parsed_line, *tmp, *tmp2, *c;
  635. size_t line_len;
  636. s64 line_ip, offset = -1;
  637. if (getline(&line, &line_len, file) < 0)
  638. return -1;
  639. if (!line)
  640. return -1;
  641. while (line_len != 0 && isspace(line[line_len - 1]))
  642. line[--line_len] = '\0';
  643. c = strchr(line, '\n');
  644. if (c)
  645. *c = 0;
  646. line_ip = -1;
  647. parsed_line = line;
  648. /*
  649. * Strip leading spaces:
  650. */
  651. tmp = line;
  652. while (*tmp) {
  653. if (*tmp != ' ')
  654. break;
  655. tmp++;
  656. }
  657. if (*tmp) {
  658. /*
  659. * Parse hexa addresses followed by ':'
  660. */
  661. line_ip = strtoull(tmp, &tmp2, 16);
  662. if (*tmp2 != ':' || tmp == tmp2 || tmp2[1] == '\0')
  663. line_ip = -1;
  664. }
  665. if (line_ip != -1) {
  666. u64 start = map__rip_2objdump(map, sym->start),
  667. end = map__rip_2objdump(map, sym->end);
  668. offset = line_ip - start;
  669. if ((u64)line_ip < start || (u64)line_ip > end)
  670. offset = -1;
  671. else
  672. parsed_line = tmp2 + 1;
  673. }
  674. dl = disasm_line__new(offset, parsed_line, privsize);
  675. free(line);
  676. if (dl == NULL)
  677. return -1;
  678. if (dl->ops.target.offset == UINT64_MAX)
  679. dl->ops.target.offset = dl->ops.target.addr -
  680. map__rip_2objdump(map, sym->start);
  681. /* kcore has no symbols, so add the call target name */
  682. if (dl->ins && ins__is_call(dl->ins) && !dl->ops.target.name) {
  683. struct addr_map_symbol target = {
  684. .map = map,
  685. .addr = dl->ops.target.addr,
  686. };
  687. if (!map_groups__find_ams(&target, NULL) &&
  688. target.sym->start == target.al_addr)
  689. dl->ops.target.name = strdup(target.sym->name);
  690. }
  691. disasm__add(&notes->src->source, dl);
  692. return 0;
  693. }
  694. static void delete_last_nop(struct symbol *sym)
  695. {
  696. struct annotation *notes = symbol__annotation(sym);
  697. struct list_head *list = &notes->src->source;
  698. struct disasm_line *dl;
  699. while (!list_empty(list)) {
  700. dl = list_entry(list->prev, struct disasm_line, node);
  701. if (dl->ins && dl->ins->ops) {
  702. if (dl->ins->ops != &nop_ops)
  703. return;
  704. } else {
  705. if (!strstr(dl->line, " nop ") &&
  706. !strstr(dl->line, " nopl ") &&
  707. !strstr(dl->line, " nopw "))
  708. return;
  709. }
  710. list_del(&dl->node);
  711. disasm_line__free(dl);
  712. }
  713. }
  714. int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
  715. {
  716. struct dso *dso = map->dso;
  717. char *filename = dso__build_id_filename(dso, NULL, 0);
  718. bool free_filename = true;
  719. char command[PATH_MAX * 2];
  720. FILE *file;
  721. int err = 0;
  722. char symfs_filename[PATH_MAX];
  723. struct kcore_extract kce;
  724. bool delete_extract = false;
  725. if (filename) {
  726. snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
  727. symbol_conf.symfs, filename);
  728. }
  729. if (filename == NULL) {
  730. if (dso->has_build_id) {
  731. pr_err("Can't annotate %s: not enough memory\n",
  732. sym->name);
  733. return -ENOMEM;
  734. }
  735. goto fallback;
  736. } else if (readlink(symfs_filename, command, sizeof(command)) < 0 ||
  737. strstr(command, "[kernel.kallsyms]") ||
  738. access(symfs_filename, R_OK)) {
  739. free(filename);
  740. fallback:
  741. /*
  742. * If we don't have build-ids or the build-id file isn't in the
  743. * cache, or is just a kallsyms file, well, lets hope that this
  744. * DSO is the same as when 'perf record' ran.
  745. */
  746. filename = (char *)dso->long_name;
  747. snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
  748. symbol_conf.symfs, filename);
  749. free_filename = false;
  750. }
  751. if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
  752. !dso__is_kcore(dso)) {
  753. char bf[BUILD_ID_SIZE * 2 + 16] = " with build id ";
  754. char *build_id_msg = NULL;
  755. if (dso->annotate_warned)
  756. goto out_free_filename;
  757. if (dso->has_build_id) {
  758. build_id__sprintf(dso->build_id,
  759. sizeof(dso->build_id), bf + 15);
  760. build_id_msg = bf;
  761. }
  762. err = -ENOENT;
  763. dso->annotate_warned = 1;
  764. pr_err("Can't annotate %s:\n\n"
  765. "No vmlinux file%s\nwas found in the path.\n\n"
  766. "Please use:\n\n"
  767. " perf buildid-cache -vu vmlinux\n\n"
  768. "or:\n\n"
  769. " --vmlinux vmlinux\n",
  770. sym->name, build_id_msg ?: "");
  771. goto out_free_filename;
  772. }
  773. pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
  774. filename, sym->name, map->unmap_ip(map, sym->start),
  775. map->unmap_ip(map, sym->end));
  776. pr_debug("annotating [%p] %30s : [%p] %30s\n",
  777. dso, dso->long_name, sym, sym->name);
  778. if (dso__is_kcore(dso)) {
  779. kce.kcore_filename = symfs_filename;
  780. kce.addr = map__rip_2objdump(map, sym->start);
  781. kce.offs = sym->start;
  782. kce.len = sym->end + 1 - sym->start;
  783. if (!kcore_extract__create(&kce)) {
  784. delete_extract = true;
  785. strlcpy(symfs_filename, kce.extract_filename,
  786. sizeof(symfs_filename));
  787. if (free_filename) {
  788. free(filename);
  789. free_filename = false;
  790. }
  791. filename = symfs_filename;
  792. }
  793. }
  794. snprintf(command, sizeof(command),
  795. "%s %s%s --start-address=0x%016" PRIx64
  796. " --stop-address=0x%016" PRIx64
  797. " -d %s %s -C %s 2>/dev/null|grep -v %s|expand",
  798. objdump_path ? objdump_path : "objdump",
  799. disassembler_style ? "-M " : "",
  800. disassembler_style ? disassembler_style : "",
  801. map__rip_2objdump(map, sym->start),
  802. map__rip_2objdump(map, sym->end+1),
  803. symbol_conf.annotate_asm_raw ? "" : "--no-show-raw",
  804. symbol_conf.annotate_src ? "-S" : "",
  805. symfs_filename, filename);
  806. pr_debug("Executing: %s\n", command);
  807. file = popen(command, "r");
  808. if (!file)
  809. goto out_free_filename;
  810. while (!feof(file))
  811. if (symbol__parse_objdump_line(sym, map, file, privsize) < 0)
  812. break;
  813. /*
  814. * kallsyms does not have symbol sizes so there may a nop at the end.
  815. * Remove it.
  816. */
  817. if (dso__is_kcore(dso))
  818. delete_last_nop(sym);
  819. pclose(file);
  820. out_free_filename:
  821. if (delete_extract)
  822. kcore_extract__delete(&kce);
  823. if (free_filename)
  824. free(filename);
  825. return err;
  826. }
  827. static void insert_source_line(struct rb_root *root, struct source_line *src_line)
  828. {
  829. struct source_line *iter;
  830. struct rb_node **p = &root->rb_node;
  831. struct rb_node *parent = NULL;
  832. int i, ret;
  833. while (*p != NULL) {
  834. parent = *p;
  835. iter = rb_entry(parent, struct source_line, node);
  836. ret = strcmp(iter->path, src_line->path);
  837. if (ret == 0) {
  838. for (i = 0; i < src_line->nr_pcnt; i++)
  839. iter->p[i].percent_sum += src_line->p[i].percent;
  840. return;
  841. }
  842. if (ret < 0)
  843. p = &(*p)->rb_left;
  844. else
  845. p = &(*p)->rb_right;
  846. }
  847. for (i = 0; i < src_line->nr_pcnt; i++)
  848. src_line->p[i].percent_sum = src_line->p[i].percent;
  849. rb_link_node(&src_line->node, parent, p);
  850. rb_insert_color(&src_line->node, root);
  851. }
  852. static int cmp_source_line(struct source_line *a, struct source_line *b)
  853. {
  854. int i;
  855. for (i = 0; i < a->nr_pcnt; i++) {
  856. if (a->p[i].percent_sum == b->p[i].percent_sum)
  857. continue;
  858. return a->p[i].percent_sum > b->p[i].percent_sum;
  859. }
  860. return 0;
  861. }
  862. static void __resort_source_line(struct rb_root *root, struct source_line *src_line)
  863. {
  864. struct source_line *iter;
  865. struct rb_node **p = &root->rb_node;
  866. struct rb_node *parent = NULL;
  867. while (*p != NULL) {
  868. parent = *p;
  869. iter = rb_entry(parent, struct source_line, node);
  870. if (cmp_source_line(src_line, iter))
  871. p = &(*p)->rb_left;
  872. else
  873. p = &(*p)->rb_right;
  874. }
  875. rb_link_node(&src_line->node, parent, p);
  876. rb_insert_color(&src_line->node, root);
  877. }
  878. static void resort_source_line(struct rb_root *dest_root, struct rb_root *src_root)
  879. {
  880. struct source_line *src_line;
  881. struct rb_node *node;
  882. node = rb_first(src_root);
  883. while (node) {
  884. struct rb_node *next;
  885. src_line = rb_entry(node, struct source_line, node);
  886. next = rb_next(node);
  887. rb_erase(node, src_root);
  888. __resort_source_line(dest_root, src_line);
  889. node = next;
  890. }
  891. }
  892. static void symbol__free_source_line(struct symbol *sym, int len)
  893. {
  894. struct annotation *notes = symbol__annotation(sym);
  895. struct source_line *src_line = notes->src->lines;
  896. size_t sizeof_src_line;
  897. int i;
  898. sizeof_src_line = sizeof(*src_line) +
  899. (sizeof(src_line->p) * (src_line->nr_pcnt - 1));
  900. for (i = 0; i < len; i++) {
  901. free_srcline(src_line->path);
  902. src_line = (void *)src_line + sizeof_src_line;
  903. }
  904. free(notes->src->lines);
  905. notes->src->lines = NULL;
  906. }
  907. /* Get the filename:line for the colored entries */
  908. static int symbol__get_source_line(struct symbol *sym, struct map *map,
  909. struct perf_evsel *evsel,
  910. struct rb_root *root, int len)
  911. {
  912. u64 start;
  913. int i, k;
  914. int evidx = evsel->idx;
  915. struct source_line *src_line;
  916. struct annotation *notes = symbol__annotation(sym);
  917. struct sym_hist *h = annotation__histogram(notes, evidx);
  918. struct rb_root tmp_root = RB_ROOT;
  919. int nr_pcnt = 1;
  920. u64 h_sum = h->sum;
  921. size_t sizeof_src_line = sizeof(struct source_line);
  922. if (perf_evsel__is_group_event(evsel)) {
  923. for (i = 1; i < evsel->nr_members; i++) {
  924. h = annotation__histogram(notes, evidx + i);
  925. h_sum += h->sum;
  926. }
  927. nr_pcnt = evsel->nr_members;
  928. sizeof_src_line += (nr_pcnt - 1) * sizeof(src_line->p);
  929. }
  930. if (!h_sum)
  931. return 0;
  932. src_line = notes->src->lines = calloc(len, sizeof_src_line);
  933. if (!notes->src->lines)
  934. return -1;
  935. start = map__rip_2objdump(map, sym->start);
  936. for (i = 0; i < len; i++) {
  937. u64 offset;
  938. double percent_max = 0.0;
  939. src_line->nr_pcnt = nr_pcnt;
  940. for (k = 0; k < nr_pcnt; k++) {
  941. h = annotation__histogram(notes, evidx + k);
  942. src_line->p[k].percent = 100.0 * h->addr[i] / h->sum;
  943. if (src_line->p[k].percent > percent_max)
  944. percent_max = src_line->p[k].percent;
  945. }
  946. if (percent_max <= 0.5)
  947. goto next;
  948. offset = start + i;
  949. src_line->path = get_srcline(map->dso, offset);
  950. insert_source_line(&tmp_root, src_line);
  951. next:
  952. src_line = (void *)src_line + sizeof_src_line;
  953. }
  954. resort_source_line(root, &tmp_root);
  955. return 0;
  956. }
  957. static void print_summary(struct rb_root *root, const char *filename)
  958. {
  959. struct source_line *src_line;
  960. struct rb_node *node;
  961. printf("\nSorted summary for file %s\n", filename);
  962. printf("----------------------------------------------\n\n");
  963. if (RB_EMPTY_ROOT(root)) {
  964. printf(" Nothing higher than %1.1f%%\n", MIN_GREEN);
  965. return;
  966. }
  967. node = rb_first(root);
  968. while (node) {
  969. double percent, percent_max = 0.0;
  970. const char *color;
  971. char *path;
  972. int i;
  973. src_line = rb_entry(node, struct source_line, node);
  974. for (i = 0; i < src_line->nr_pcnt; i++) {
  975. percent = src_line->p[i].percent_sum;
  976. color = get_percent_color(percent);
  977. color_fprintf(stdout, color, " %7.2f", percent);
  978. if (percent > percent_max)
  979. percent_max = percent;
  980. }
  981. path = src_line->path;
  982. color = get_percent_color(percent_max);
  983. color_fprintf(stdout, color, " %s\n", path);
  984. node = rb_next(node);
  985. }
  986. }
  987. static void symbol__annotate_hits(struct symbol *sym, struct perf_evsel *evsel)
  988. {
  989. struct annotation *notes = symbol__annotation(sym);
  990. struct sym_hist *h = annotation__histogram(notes, evsel->idx);
  991. u64 len = symbol__size(sym), offset;
  992. for (offset = 0; offset < len; ++offset)
  993. if (h->addr[offset] != 0)
  994. printf("%*" PRIx64 ": %" PRIu64 "\n", BITS_PER_LONG / 2,
  995. sym->start + offset, h->addr[offset]);
  996. printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
  997. }
  998. int symbol__annotate_printf(struct symbol *sym, struct map *map,
  999. struct perf_evsel *evsel, bool full_paths,
  1000. int min_pcnt, int max_lines, int context)
  1001. {
  1002. struct dso *dso = map->dso;
  1003. char *filename;
  1004. const char *d_filename;
  1005. struct annotation *notes = symbol__annotation(sym);
  1006. struct disasm_line *pos, *queue = NULL;
  1007. u64 start = map__rip_2objdump(map, sym->start);
  1008. int printed = 2, queue_len = 0;
  1009. int more = 0;
  1010. u64 len;
  1011. int width = 8;
  1012. int namelen;
  1013. filename = strdup(dso->long_name);
  1014. if (!filename)
  1015. return -ENOMEM;
  1016. if (full_paths)
  1017. d_filename = filename;
  1018. else
  1019. d_filename = basename(filename);
  1020. len = symbol__size(sym);
  1021. namelen = strlen(d_filename);
  1022. if (perf_evsel__is_group_event(evsel))
  1023. width *= evsel->nr_members;
  1024. printf(" %-*.*s| Source code & Disassembly of %s\n",
  1025. width, width, "Percent", d_filename);
  1026. printf("-%-*.*s-------------------------------------\n",
  1027. width+namelen, width+namelen, graph_dotted_line);
  1028. if (verbose)
  1029. symbol__annotate_hits(sym, evsel);
  1030. list_for_each_entry(pos, &notes->src->source, node) {
  1031. if (context && queue == NULL) {
  1032. queue = pos;
  1033. queue_len = 0;
  1034. }
  1035. switch (disasm_line__print(pos, sym, start, evsel, len,
  1036. min_pcnt, printed, max_lines,
  1037. queue)) {
  1038. case 0:
  1039. ++printed;
  1040. if (context) {
  1041. printed += queue_len;
  1042. queue = NULL;
  1043. queue_len = 0;
  1044. }
  1045. break;
  1046. case 1:
  1047. /* filtered by max_lines */
  1048. ++more;
  1049. break;
  1050. case -1:
  1051. default:
  1052. /*
  1053. * Filtered by min_pcnt or non IP lines when
  1054. * context != 0
  1055. */
  1056. if (!context)
  1057. break;
  1058. if (queue_len == context)
  1059. queue = list_entry(queue->node.next, typeof(*queue), node);
  1060. else
  1061. ++queue_len;
  1062. break;
  1063. }
  1064. }
  1065. free(filename);
  1066. return more;
  1067. }
  1068. void symbol__annotate_zero_histogram(struct symbol *sym, int evidx)
  1069. {
  1070. struct annotation *notes = symbol__annotation(sym);
  1071. struct sym_hist *h = annotation__histogram(notes, evidx);
  1072. memset(h, 0, notes->src->sizeof_sym_hist);
  1073. }
  1074. void symbol__annotate_decay_histogram(struct symbol *sym, int evidx)
  1075. {
  1076. struct annotation *notes = symbol__annotation(sym);
  1077. struct sym_hist *h = annotation__histogram(notes, evidx);
  1078. int len = symbol__size(sym), offset;
  1079. h->sum = 0;
  1080. for (offset = 0; offset < len; ++offset) {
  1081. h->addr[offset] = h->addr[offset] * 7 / 8;
  1082. h->sum += h->addr[offset];
  1083. }
  1084. }
  1085. void disasm__purge(struct list_head *head)
  1086. {
  1087. struct disasm_line *pos, *n;
  1088. list_for_each_entry_safe(pos, n, head, node) {
  1089. list_del(&pos->node);
  1090. disasm_line__free(pos);
  1091. }
  1092. }
  1093. static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
  1094. {
  1095. size_t printed;
  1096. if (dl->offset == -1)
  1097. return fprintf(fp, "%s\n", dl->line);
  1098. printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name);
  1099. if (dl->ops.raw[0] != '\0') {
  1100. printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
  1101. dl->ops.raw);
  1102. }
  1103. return printed + fprintf(fp, "\n");
  1104. }
  1105. size_t disasm__fprintf(struct list_head *head, FILE *fp)
  1106. {
  1107. struct disasm_line *pos;
  1108. size_t printed = 0;
  1109. list_for_each_entry(pos, head, node)
  1110. printed += disasm_line__fprintf(pos, fp);
  1111. return printed;
  1112. }
  1113. int symbol__tty_annotate(struct symbol *sym, struct map *map,
  1114. struct perf_evsel *evsel, bool print_lines,
  1115. bool full_paths, int min_pcnt, int max_lines)
  1116. {
  1117. struct dso *dso = map->dso;
  1118. struct rb_root source_line = RB_ROOT;
  1119. u64 len;
  1120. if (symbol__annotate(sym, map, 0) < 0)
  1121. return -1;
  1122. len = symbol__size(sym);
  1123. if (print_lines) {
  1124. symbol__get_source_line(sym, map, evsel, &source_line, len);
  1125. print_summary(&source_line, dso->long_name);
  1126. }
  1127. symbol__annotate_printf(sym, map, evsel, full_paths,
  1128. min_pcnt, max_lines, 0);
  1129. if (print_lines)
  1130. symbol__free_source_line(sym, len);
  1131. disasm__purge(&symbol__annotation(sym)->src->source);
  1132. return 0;
  1133. }
  1134. int hist_entry__annotate(struct hist_entry *he, size_t privsize)
  1135. {
  1136. return symbol__annotate(he->ms.sym, he->ms.map, privsize);
  1137. }