annotate.c 33 KB

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