annotate.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  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 "ui/ui.h"
  11. #include "sort.h"
  12. #include "build-id.h"
  13. #include "color.h"
  14. #include "cache.h"
  15. #include "symbol.h"
  16. #include "debug.h"
  17. #include "annotate.h"
  18. #include "evsel.h"
  19. #include <pthread.h>
  20. #include <linux/bitops.h>
  21. const char *disassembler_style;
  22. const char *objdump_path;
  23. static struct ins *ins__find(const char *name);
  24. static int disasm_line__parse(char *line, char **namep, char **rawp);
  25. static void ins__delete(struct ins_operands *ops)
  26. {
  27. zfree(&ops->source.raw);
  28. zfree(&ops->source.name);
  29. zfree(&ops->target.raw);
  30. zfree(&ops->target.name);
  31. }
  32. static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size,
  33. struct ins_operands *ops)
  34. {
  35. return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->raw);
  36. }
  37. int ins__scnprintf(struct ins *ins, char *bf, size_t size,
  38. struct ins_operands *ops)
  39. {
  40. if (ins->ops->scnprintf)
  41. return ins->ops->scnprintf(ins, bf, size, ops);
  42. return ins__raw_scnprintf(ins, bf, size, ops);
  43. }
  44. static int call__parse(struct ins_operands *ops)
  45. {
  46. char *endptr, *tok, *name;
  47. ops->target.addr = strtoull(ops->raw, &endptr, 16);
  48. name = strchr(endptr, '<');
  49. if (name == NULL)
  50. goto indirect_call;
  51. name++;
  52. tok = strchr(name, '>');
  53. if (tok == NULL)
  54. return -1;
  55. *tok = '\0';
  56. ops->target.name = strdup(name);
  57. *tok = '>';
  58. return ops->target.name == NULL ? -1 : 0;
  59. indirect_call:
  60. tok = strchr(endptr, '(');
  61. if (tok != NULL) {
  62. ops->target.addr = 0;
  63. return 0;
  64. }
  65. tok = strchr(endptr, '*');
  66. if (tok == NULL)
  67. return -1;
  68. ops->target.addr = strtoull(tok + 1, NULL, 16);
  69. return 0;
  70. }
  71. static int call__scnprintf(struct ins *ins, char *bf, size_t size,
  72. struct ins_operands *ops)
  73. {
  74. if (ops->target.name)
  75. return scnprintf(bf, size, "%-6.6s %s", ins->name, ops->target.name);
  76. if (ops->target.addr == 0)
  77. return ins__raw_scnprintf(ins, bf, size, ops);
  78. return scnprintf(bf, size, "%-6.6s *%" PRIx64, ins->name, ops->target.addr);
  79. }
  80. static struct ins_ops call_ops = {
  81. .parse = call__parse,
  82. .scnprintf = call__scnprintf,
  83. };
  84. bool ins__is_call(const struct ins *ins)
  85. {
  86. return ins->ops == &call_ops;
  87. }
  88. static int jump__parse(struct ins_operands *ops)
  89. {
  90. const char *s = strchr(ops->raw, '+');
  91. ops->target.addr = strtoull(ops->raw, NULL, 16);
  92. if (s++ != NULL)
  93. ops->target.offset = strtoull(s, NULL, 16);
  94. else
  95. ops->target.offset = UINT64_MAX;
  96. return 0;
  97. }
  98. static int jump__scnprintf(struct ins *ins, char *bf, size_t size,
  99. struct ins_operands *ops)
  100. {
  101. return scnprintf(bf, size, "%-6.6s %" PRIx64, ins->name, ops->target.offset);
  102. }
  103. static struct ins_ops jump_ops = {
  104. .parse = jump__parse,
  105. .scnprintf = jump__scnprintf,
  106. };
  107. bool ins__is_jump(const struct ins *ins)
  108. {
  109. return ins->ops == &jump_ops;
  110. }
  111. static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep)
  112. {
  113. char *endptr, *name, *t;
  114. if (strstr(raw, "(%rip)") == NULL)
  115. return 0;
  116. *addrp = strtoull(comment, &endptr, 16);
  117. name = strchr(endptr, '<');
  118. if (name == NULL)
  119. return -1;
  120. name++;
  121. t = strchr(name, '>');
  122. if (t == NULL)
  123. return 0;
  124. *t = '\0';
  125. *namep = strdup(name);
  126. *t = '>';
  127. return 0;
  128. }
  129. static int lock__parse(struct ins_operands *ops)
  130. {
  131. char *name;
  132. ops->locked.ops = zalloc(sizeof(*ops->locked.ops));
  133. if (ops->locked.ops == NULL)
  134. return 0;
  135. if (disasm_line__parse(ops->raw, &name, &ops->locked.ops->raw) < 0)
  136. goto out_free_ops;
  137. ops->locked.ins = ins__find(name);
  138. if (ops->locked.ins == NULL)
  139. goto out_free_ops;
  140. if (!ops->locked.ins->ops)
  141. return 0;
  142. if (ops->locked.ins->ops->parse)
  143. ops->locked.ins->ops->parse(ops->locked.ops);
  144. return 0;
  145. out_free_ops:
  146. zfree(&ops->locked.ops);
  147. return 0;
  148. }
  149. static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
  150. struct ins_operands *ops)
  151. {
  152. int printed;
  153. if (ops->locked.ins == NULL)
  154. return ins__raw_scnprintf(ins, bf, size, ops);
  155. printed = scnprintf(bf, size, "%-6.6s ", ins->name);
  156. return printed + ins__scnprintf(ops->locked.ins, bf + printed,
  157. size - printed, ops->locked.ops);
  158. }
  159. static void lock__delete(struct ins_operands *ops)
  160. {
  161. zfree(&ops->locked.ops);
  162. zfree(&ops->target.raw);
  163. zfree(&ops->target.name);
  164. }
  165. static struct ins_ops lock_ops = {
  166. .free = lock__delete,
  167. .parse = lock__parse,
  168. .scnprintf = lock__scnprintf,
  169. };
  170. static int mov__parse(struct ins_operands *ops)
  171. {
  172. char *s = strchr(ops->raw, ','), *target, *comment, prev;
  173. if (s == NULL)
  174. return -1;
  175. *s = '\0';
  176. ops->source.raw = strdup(ops->raw);
  177. *s = ',';
  178. if (ops->source.raw == NULL)
  179. return -1;
  180. target = ++s;
  181. while (s[0] != '\0' && !isspace(s[0]))
  182. ++s;
  183. prev = *s;
  184. *s = '\0';
  185. ops->target.raw = strdup(target);
  186. *s = prev;
  187. if (ops->target.raw == NULL)
  188. goto out_free_source;
  189. comment = strchr(s, '#');
  190. if (comment == NULL)
  191. return 0;
  192. while (comment[0] != '\0' && isspace(comment[0]))
  193. ++comment;
  194. comment__symbol(ops->source.raw, comment, &ops->source.addr, &ops->source.name);
  195. comment__symbol(ops->target.raw, comment, &ops->target.addr, &ops->target.name);
  196. return 0;
  197. out_free_source:
  198. zfree(&ops->source.raw);
  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. static 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)
  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. zfree(namep);
  448. return -1;
  449. }
  450. static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
  451. {
  452. struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);
  453. if (dl != NULL) {
  454. dl->offset = offset;
  455. dl->line = strdup(line);
  456. if (dl->line == NULL)
  457. goto out_delete;
  458. if (offset != -1) {
  459. if (disasm_line__parse(dl->line, &dl->name, &dl->ops.raw) < 0)
  460. goto out_free_line;
  461. disasm_line__init_ins(dl);
  462. }
  463. }
  464. return dl;
  465. out_free_line:
  466. zfree(&dl->line);
  467. out_delete:
  468. free(dl);
  469. return NULL;
  470. }
  471. void disasm_line__free(struct disasm_line *dl)
  472. {
  473. zfree(&dl->line);
  474. zfree(&dl->name);
  475. if (dl->ins && dl->ins->ops->free)
  476. dl->ins->ops->free(&dl->ops);
  477. else
  478. ins__delete(&dl->ops);
  479. free(dl);
  480. }
  481. int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw)
  482. {
  483. if (raw || !dl->ins)
  484. return scnprintf(bf, size, "%-6.6s %s", dl->name, dl->ops.raw);
  485. return ins__scnprintf(dl->ins, bf, size, &dl->ops);
  486. }
  487. static void disasm__add(struct list_head *head, struct disasm_line *line)
  488. {
  489. list_add_tail(&line->node, head);
  490. }
  491. struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos)
  492. {
  493. list_for_each_entry_continue(pos, head, node)
  494. if (pos->offset >= 0)
  495. return pos;
  496. return NULL;
  497. }
  498. double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
  499. s64 end, const char **path)
  500. {
  501. struct source_line *src_line = notes->src->lines;
  502. double percent = 0.0;
  503. if (src_line) {
  504. size_t sizeof_src_line = sizeof(*src_line) +
  505. sizeof(src_line->p) * (src_line->nr_pcnt - 1);
  506. while (offset < end) {
  507. src_line = (void *)notes->src->lines +
  508. (sizeof_src_line * offset);
  509. if (*path == NULL)
  510. *path = src_line->path;
  511. percent += src_line->p[evidx].percent;
  512. offset++;
  513. }
  514. } else {
  515. struct sym_hist *h = annotation__histogram(notes, evidx);
  516. unsigned int hits = 0;
  517. while (offset < end)
  518. hits += h->addr[offset++];
  519. if (h->sum)
  520. percent = 100.0 * hits / h->sum;
  521. }
  522. return percent;
  523. }
  524. static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 start,
  525. struct perf_evsel *evsel, u64 len, int min_pcnt, int printed,
  526. int max_lines, struct disasm_line *queue)
  527. {
  528. static const char *prev_line;
  529. static const char *prev_color;
  530. if (dl->offset != -1) {
  531. const char *path = NULL;
  532. double percent, max_percent = 0.0;
  533. double *ppercents = &percent;
  534. int i, nr_percent = 1;
  535. const char *color;
  536. struct annotation *notes = symbol__annotation(sym);
  537. s64 offset = dl->offset;
  538. const u64 addr = start + offset;
  539. struct disasm_line *next;
  540. next = disasm__get_next_ip_line(&notes->src->source, dl);
  541. if (perf_evsel__is_group_event(evsel)) {
  542. nr_percent = evsel->nr_members;
  543. ppercents = calloc(nr_percent, sizeof(double));
  544. if (ppercents == NULL)
  545. return -1;
  546. }
  547. for (i = 0; i < nr_percent; i++) {
  548. percent = disasm__calc_percent(notes,
  549. notes->src->lines ? i : evsel->idx + i,
  550. offset,
  551. next ? next->offset : (s64) len,
  552. &path);
  553. ppercents[i] = percent;
  554. if (percent > max_percent)
  555. max_percent = percent;
  556. }
  557. if (max_percent < min_pcnt)
  558. return -1;
  559. if (max_lines && printed >= max_lines)
  560. return 1;
  561. if (queue != NULL) {
  562. list_for_each_entry_from(queue, &notes->src->source, node) {
  563. if (queue == dl)
  564. break;
  565. disasm_line__print(queue, sym, start, evsel, len,
  566. 0, 0, 1, NULL);
  567. }
  568. }
  569. color = get_percent_color(max_percent);
  570. /*
  571. * Also color the filename and line if needed, with
  572. * the same color than the percentage. Don't print it
  573. * twice for close colored addr with the same filename:line
  574. */
  575. if (path) {
  576. if (!prev_line || strcmp(prev_line, path)
  577. || color != prev_color) {
  578. color_fprintf(stdout, color, " %s", path);
  579. prev_line = path;
  580. prev_color = color;
  581. }
  582. }
  583. for (i = 0; i < nr_percent; i++) {
  584. percent = ppercents[i];
  585. color = get_percent_color(percent);
  586. color_fprintf(stdout, color, " %7.2f", percent);
  587. }
  588. printf(" : ");
  589. color_fprintf(stdout, PERF_COLOR_MAGENTA, " %" PRIx64 ":", addr);
  590. color_fprintf(stdout, PERF_COLOR_BLUE, "%s\n", dl->line);
  591. if (ppercents != &percent)
  592. free(ppercents);
  593. } else if (max_lines && printed >= max_lines)
  594. return 1;
  595. else {
  596. int width = 8;
  597. if (queue)
  598. return -1;
  599. if (perf_evsel__is_group_event(evsel))
  600. width *= evsel->nr_members;
  601. if (!*dl->line)
  602. printf(" %*s:\n", width, " ");
  603. else
  604. printf(" %*s: %s\n", width, " ", dl->line);
  605. }
  606. return 0;
  607. }
  608. /*
  609. * symbol__parse_objdump_line() parses objdump output (with -d --no-show-raw)
  610. * which looks like following
  611. *
  612. * 0000000000415500 <_init>:
  613. * 415500: sub $0x8,%rsp
  614. * 415504: mov 0x2f5ad5(%rip),%rax # 70afe0 <_DYNAMIC+0x2f8>
  615. * 41550b: test %rax,%rax
  616. * 41550e: je 415515 <_init+0x15>
  617. * 415510: callq 416e70 <__gmon_start__@plt>
  618. * 415515: add $0x8,%rsp
  619. * 415519: retq
  620. *
  621. * it will be parsed and saved into struct disasm_line as
  622. * <offset> <name> <ops.raw>
  623. *
  624. * The offset will be a relative offset from the start of the symbol and -1
  625. * means that it's not a disassembly line so should be treated differently.
  626. * The ops.raw part will be parsed further according to type of the instruction.
  627. */
  628. static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
  629. FILE *file, size_t privsize)
  630. {
  631. struct annotation *notes = symbol__annotation(sym);
  632. struct disasm_line *dl;
  633. char *line = NULL, *parsed_line, *tmp, *tmp2, *c;
  634. size_t line_len;
  635. s64 line_ip, offset = -1;
  636. if (getline(&line, &line_len, file) < 0)
  637. return -1;
  638. if (!line)
  639. return -1;
  640. while (line_len != 0 && isspace(line[line_len - 1]))
  641. line[--line_len] = '\0';
  642. c = strchr(line, '\n');
  643. if (c)
  644. *c = 0;
  645. line_ip = -1;
  646. parsed_line = line;
  647. /*
  648. * Strip leading spaces:
  649. */
  650. tmp = line;
  651. while (*tmp) {
  652. if (*tmp != ' ')
  653. break;
  654. tmp++;
  655. }
  656. if (*tmp) {
  657. /*
  658. * Parse hexa addresses followed by ':'
  659. */
  660. line_ip = strtoull(tmp, &tmp2, 16);
  661. if (*tmp2 != ':' || tmp == tmp2 || tmp2[1] == '\0')
  662. line_ip = -1;
  663. }
  664. if (line_ip != -1) {
  665. u64 start = map__rip_2objdump(map, sym->start),
  666. end = map__rip_2objdump(map, sym->end);
  667. offset = line_ip - start;
  668. if ((u64)line_ip < start || (u64)line_ip > end)
  669. offset = -1;
  670. else
  671. parsed_line = tmp2 + 1;
  672. }
  673. dl = disasm_line__new(offset, parsed_line, privsize);
  674. free(line);
  675. if (dl == NULL)
  676. return -1;
  677. if (dl->ops.target.offset == UINT64_MAX)
  678. dl->ops.target.offset = dl->ops.target.addr -
  679. map__rip_2objdump(map, sym->start);
  680. /* kcore has no symbols, so add the call target name */
  681. if (dl->ins && ins__is_call(dl->ins) && !dl->ops.target.name) {
  682. struct addr_map_symbol target = {
  683. .map = map,
  684. .addr = dl->ops.target.addr,
  685. };
  686. if (!map_groups__find_ams(&target, NULL) &&
  687. target.sym->start == target.al_addr)
  688. dl->ops.target.name = strdup(target.sym->name);
  689. }
  690. disasm__add(&notes->src->source, dl);
  691. return 0;
  692. }
  693. static void delete_last_nop(struct symbol *sym)
  694. {
  695. struct annotation *notes = symbol__annotation(sym);
  696. struct list_head *list = &notes->src->source;
  697. struct disasm_line *dl;
  698. while (!list_empty(list)) {
  699. dl = list_entry(list->prev, struct disasm_line, node);
  700. if (dl->ins && dl->ins->ops) {
  701. if (dl->ins->ops != &nop_ops)
  702. return;
  703. } else {
  704. if (!strstr(dl->line, " nop ") &&
  705. !strstr(dl->line, " nopl ") &&
  706. !strstr(dl->line, " nopw "))
  707. return;
  708. }
  709. list_del(&dl->node);
  710. disasm_line__free(dl);
  711. }
  712. }
  713. int symbol__annotate(struct symbol *sym, struct map *map, size_t privsize)
  714. {
  715. struct dso *dso = map->dso;
  716. char *filename = dso__build_id_filename(dso, NULL, 0);
  717. bool free_filename = true;
  718. char command[PATH_MAX * 2];
  719. FILE *file;
  720. int err = 0;
  721. char symfs_filename[PATH_MAX];
  722. struct kcore_extract kce;
  723. bool delete_extract = false;
  724. if (filename) {
  725. snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
  726. symbol_conf.symfs, filename);
  727. }
  728. if (filename == NULL) {
  729. if (dso->has_build_id) {
  730. pr_err("Can't annotate %s: not enough memory\n",
  731. sym->name);
  732. return -ENOMEM;
  733. }
  734. goto fallback;
  735. } else if (readlink(symfs_filename, command, sizeof(command)) < 0 ||
  736. strstr(command, "[kernel.kallsyms]") ||
  737. access(symfs_filename, R_OK)) {
  738. free(filename);
  739. fallback:
  740. /*
  741. * If we don't have build-ids or the build-id file isn't in the
  742. * cache, or is just a kallsyms file, well, lets hope that this
  743. * DSO is the same as when 'perf record' ran.
  744. */
  745. filename = (char *)dso->long_name;
  746. snprintf(symfs_filename, sizeof(symfs_filename), "%s%s",
  747. symbol_conf.symfs, filename);
  748. free_filename = false;
  749. }
  750. if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
  751. !dso__is_kcore(dso)) {
  752. char bf[BUILD_ID_SIZE * 2 + 16] = " with build id ";
  753. char *build_id_msg = NULL;
  754. if (dso->annotate_warned)
  755. goto out_free_filename;
  756. if (dso->has_build_id) {
  757. build_id__sprintf(dso->build_id,
  758. sizeof(dso->build_id), bf + 15);
  759. build_id_msg = bf;
  760. }
  761. err = -ENOENT;
  762. dso->annotate_warned = 1;
  763. pr_err("Can't annotate %s:\n\n"
  764. "No vmlinux file%s\nwas found in the path.\n\n"
  765. "Please use:\n\n"
  766. " perf buildid-cache -vu vmlinux\n\n"
  767. "or:\n\n"
  768. " --vmlinux vmlinux\n",
  769. sym->name, build_id_msg ?: "");
  770. goto out_free_filename;
  771. }
  772. pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
  773. filename, sym->name, map->unmap_ip(map, sym->start),
  774. map->unmap_ip(map, sym->end));
  775. pr_debug("annotating [%p] %30s : [%p] %30s\n",
  776. dso, dso->long_name, sym, sym->name);
  777. if (dso__is_kcore(dso)) {
  778. kce.kcore_filename = symfs_filename;
  779. kce.addr = map__rip_2objdump(map, sym->start);
  780. kce.offs = sym->start;
  781. kce.len = sym->end + 1 - sym->start;
  782. if (!kcore_extract__create(&kce)) {
  783. delete_extract = true;
  784. strlcpy(symfs_filename, kce.extract_filename,
  785. sizeof(symfs_filename));
  786. if (free_filename) {
  787. free(filename);
  788. free_filename = false;
  789. }
  790. filename = symfs_filename;
  791. }
  792. }
  793. snprintf(command, sizeof(command),
  794. "%s %s%s --start-address=0x%016" PRIx64
  795. " --stop-address=0x%016" PRIx64
  796. " -d %s %s -C %s 2>/dev/null|grep -v %s|expand",
  797. objdump_path ? objdump_path : "objdump",
  798. disassembler_style ? "-M " : "",
  799. disassembler_style ? disassembler_style : "",
  800. map__rip_2objdump(map, sym->start),
  801. map__rip_2objdump(map, sym->end+1),
  802. symbol_conf.annotate_asm_raw ? "" : "--no-show-raw",
  803. symbol_conf.annotate_src ? "-S" : "",
  804. symfs_filename, filename);
  805. pr_debug("Executing: %s\n", command);
  806. file = popen(command, "r");
  807. if (!file)
  808. goto out_free_filename;
  809. while (!feof(file))
  810. if (symbol__parse_objdump_line(sym, map, file, privsize) < 0)
  811. break;
  812. /*
  813. * kallsyms does not have symbol sizes so there may a nop at the end.
  814. * Remove it.
  815. */
  816. if (dso__is_kcore(dso))
  817. delete_last_nop(sym);
  818. pclose(file);
  819. out_free_filename:
  820. if (delete_extract)
  821. kcore_extract__delete(&kce);
  822. if (free_filename)
  823. free(filename);
  824. return err;
  825. }
  826. static void insert_source_line(struct rb_root *root, struct source_line *src_line)
  827. {
  828. struct source_line *iter;
  829. struct rb_node **p = &root->rb_node;
  830. struct rb_node *parent = NULL;
  831. int i, ret;
  832. while (*p != NULL) {
  833. parent = *p;
  834. iter = rb_entry(parent, struct source_line, node);
  835. ret = strcmp(iter->path, src_line->path);
  836. if (ret == 0) {
  837. for (i = 0; i < src_line->nr_pcnt; i++)
  838. iter->p[i].percent_sum += src_line->p[i].percent;
  839. return;
  840. }
  841. if (ret < 0)
  842. p = &(*p)->rb_left;
  843. else
  844. p = &(*p)->rb_right;
  845. }
  846. for (i = 0; i < src_line->nr_pcnt; i++)
  847. src_line->p[i].percent_sum = src_line->p[i].percent;
  848. rb_link_node(&src_line->node, parent, p);
  849. rb_insert_color(&src_line->node, root);
  850. }
  851. static int cmp_source_line(struct source_line *a, struct source_line *b)
  852. {
  853. int i;
  854. for (i = 0; i < a->nr_pcnt; i++) {
  855. if (a->p[i].percent_sum == b->p[i].percent_sum)
  856. continue;
  857. return a->p[i].percent_sum > b->p[i].percent_sum;
  858. }
  859. return 0;
  860. }
  861. static void __resort_source_line(struct rb_root *root, struct source_line *src_line)
  862. {
  863. struct source_line *iter;
  864. struct rb_node **p = &root->rb_node;
  865. struct rb_node *parent = NULL;
  866. while (*p != NULL) {
  867. parent = *p;
  868. iter = rb_entry(parent, struct source_line, node);
  869. if (cmp_source_line(src_line, iter))
  870. p = &(*p)->rb_left;
  871. else
  872. p = &(*p)->rb_right;
  873. }
  874. rb_link_node(&src_line->node, parent, p);
  875. rb_insert_color(&src_line->node, root);
  876. }
  877. static void resort_source_line(struct rb_root *dest_root, struct rb_root *src_root)
  878. {
  879. struct source_line *src_line;
  880. struct rb_node *node;
  881. node = rb_first(src_root);
  882. while (node) {
  883. struct rb_node *next;
  884. src_line = rb_entry(node, struct source_line, node);
  885. next = rb_next(node);
  886. rb_erase(node, src_root);
  887. __resort_source_line(dest_root, src_line);
  888. node = next;
  889. }
  890. }
  891. static void symbol__free_source_line(struct symbol *sym, int len)
  892. {
  893. struct annotation *notes = symbol__annotation(sym);
  894. struct source_line *src_line = notes->src->lines;
  895. size_t sizeof_src_line;
  896. int i;
  897. sizeof_src_line = sizeof(*src_line) +
  898. (sizeof(src_line->p) * (src_line->nr_pcnt - 1));
  899. for (i = 0; i < len; i++) {
  900. free_srcline(src_line->path);
  901. src_line = (void *)src_line + sizeof_src_line;
  902. }
  903. zfree(&notes->src->lines);
  904. }
  905. /* Get the filename:line for the colored entries */
  906. static int symbol__get_source_line(struct symbol *sym, struct map *map,
  907. struct perf_evsel *evsel,
  908. struct rb_root *root, int len)
  909. {
  910. u64 start;
  911. int i, k;
  912. int evidx = evsel->idx;
  913. struct source_line *src_line;
  914. struct annotation *notes = symbol__annotation(sym);
  915. struct sym_hist *h = annotation__histogram(notes, evidx);
  916. struct rb_root tmp_root = RB_ROOT;
  917. int nr_pcnt = 1;
  918. u64 h_sum = h->sum;
  919. size_t sizeof_src_line = sizeof(struct source_line);
  920. if (perf_evsel__is_group_event(evsel)) {
  921. for (i = 1; i < evsel->nr_members; i++) {
  922. h = annotation__histogram(notes, evidx + i);
  923. h_sum += h->sum;
  924. }
  925. nr_pcnt = evsel->nr_members;
  926. sizeof_src_line += (nr_pcnt - 1) * sizeof(src_line->p);
  927. }
  928. if (!h_sum)
  929. return 0;
  930. src_line = notes->src->lines = calloc(len, sizeof_src_line);
  931. if (!notes->src->lines)
  932. return -1;
  933. start = map__rip_2objdump(map, sym->start);
  934. for (i = 0; i < len; i++) {
  935. u64 offset;
  936. double percent_max = 0.0;
  937. src_line->nr_pcnt = nr_pcnt;
  938. for (k = 0; k < nr_pcnt; k++) {
  939. h = annotation__histogram(notes, evidx + k);
  940. src_line->p[k].percent = 100.0 * h->addr[i] / h->sum;
  941. if (src_line->p[k].percent > percent_max)
  942. percent_max = src_line->p[k].percent;
  943. }
  944. if (percent_max <= 0.5)
  945. goto next;
  946. offset = start + i;
  947. src_line->path = get_srcline(map->dso, offset);
  948. insert_source_line(&tmp_root, src_line);
  949. next:
  950. src_line = (void *)src_line + sizeof_src_line;
  951. }
  952. resort_source_line(root, &tmp_root);
  953. return 0;
  954. }
  955. static void print_summary(struct rb_root *root, const char *filename)
  956. {
  957. struct source_line *src_line;
  958. struct rb_node *node;
  959. printf("\nSorted summary for file %s\n", filename);
  960. printf("----------------------------------------------\n\n");
  961. if (RB_EMPTY_ROOT(root)) {
  962. printf(" Nothing higher than %1.1f%%\n", MIN_GREEN);
  963. return;
  964. }
  965. node = rb_first(root);
  966. while (node) {
  967. double percent, percent_max = 0.0;
  968. const char *color;
  969. char *path;
  970. int i;
  971. src_line = rb_entry(node, struct source_line, node);
  972. for (i = 0; i < src_line->nr_pcnt; i++) {
  973. percent = src_line->p[i].percent_sum;
  974. color = get_percent_color(percent);
  975. color_fprintf(stdout, color, " %7.2f", percent);
  976. if (percent > percent_max)
  977. percent_max = percent;
  978. }
  979. path = src_line->path;
  980. color = get_percent_color(percent_max);
  981. color_fprintf(stdout, color, " %s\n", path);
  982. node = rb_next(node);
  983. }
  984. }
  985. static void symbol__annotate_hits(struct symbol *sym, struct perf_evsel *evsel)
  986. {
  987. struct annotation *notes = symbol__annotation(sym);
  988. struct sym_hist *h = annotation__histogram(notes, evsel->idx);
  989. u64 len = symbol__size(sym), offset;
  990. for (offset = 0; offset < len; ++offset)
  991. if (h->addr[offset] != 0)
  992. printf("%*" PRIx64 ": %" PRIu64 "\n", BITS_PER_LONG / 2,
  993. sym->start + offset, h->addr[offset]);
  994. printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
  995. }
  996. int symbol__annotate_printf(struct symbol *sym, struct map *map,
  997. struct perf_evsel *evsel, bool full_paths,
  998. int min_pcnt, int max_lines, int context)
  999. {
  1000. struct dso *dso = map->dso;
  1001. char *filename;
  1002. const char *d_filename;
  1003. const char *evsel_name = perf_evsel__name(evsel);
  1004. struct annotation *notes = symbol__annotation(sym);
  1005. struct disasm_line *pos, *queue = NULL;
  1006. u64 start = map__rip_2objdump(map, sym->start);
  1007. int printed = 2, queue_len = 0;
  1008. int more = 0;
  1009. u64 len;
  1010. int width = 8;
  1011. int namelen, evsel_name_len, graph_dotted_len;
  1012. filename = strdup(dso->long_name);
  1013. if (!filename)
  1014. return -ENOMEM;
  1015. if (full_paths)
  1016. d_filename = filename;
  1017. else
  1018. d_filename = basename(filename);
  1019. len = symbol__size(sym);
  1020. namelen = strlen(d_filename);
  1021. evsel_name_len = strlen(evsel_name);
  1022. if (perf_evsel__is_group_event(evsel))
  1023. width *= evsel->nr_members;
  1024. printf(" %-*.*s| Source code & Disassembly of %s for %s\n",
  1025. width, width, "Percent", d_filename, evsel_name);
  1026. graph_dotted_len = width + namelen + evsel_name_len;
  1027. printf("-%-*.*s-----------------------------------------\n",
  1028. graph_dotted_len, graph_dotted_len, graph_dotted_line);
  1029. if (verbose)
  1030. symbol__annotate_hits(sym, evsel);
  1031. list_for_each_entry(pos, &notes->src->source, node) {
  1032. if (context && queue == NULL) {
  1033. queue = pos;
  1034. queue_len = 0;
  1035. }
  1036. switch (disasm_line__print(pos, sym, start, evsel, len,
  1037. min_pcnt, printed, max_lines,
  1038. queue)) {
  1039. case 0:
  1040. ++printed;
  1041. if (context) {
  1042. printed += queue_len;
  1043. queue = NULL;
  1044. queue_len = 0;
  1045. }
  1046. break;
  1047. case 1:
  1048. /* filtered by max_lines */
  1049. ++more;
  1050. break;
  1051. case -1:
  1052. default:
  1053. /*
  1054. * Filtered by min_pcnt or non IP lines when
  1055. * context != 0
  1056. */
  1057. if (!context)
  1058. break;
  1059. if (queue_len == context)
  1060. queue = list_entry(queue->node.next, typeof(*queue), node);
  1061. else
  1062. ++queue_len;
  1063. break;
  1064. }
  1065. }
  1066. free(filename);
  1067. return more;
  1068. }
  1069. void symbol__annotate_zero_histogram(struct symbol *sym, int evidx)
  1070. {
  1071. struct annotation *notes = symbol__annotation(sym);
  1072. struct sym_hist *h = annotation__histogram(notes, evidx);
  1073. memset(h, 0, notes->src->sizeof_sym_hist);
  1074. }
  1075. void symbol__annotate_decay_histogram(struct symbol *sym, int evidx)
  1076. {
  1077. struct annotation *notes = symbol__annotation(sym);
  1078. struct sym_hist *h = annotation__histogram(notes, evidx);
  1079. int len = symbol__size(sym), offset;
  1080. h->sum = 0;
  1081. for (offset = 0; offset < len; ++offset) {
  1082. h->addr[offset] = h->addr[offset] * 7 / 8;
  1083. h->sum += h->addr[offset];
  1084. }
  1085. }
  1086. void disasm__purge(struct list_head *head)
  1087. {
  1088. struct disasm_line *pos, *n;
  1089. list_for_each_entry_safe(pos, n, head, node) {
  1090. list_del(&pos->node);
  1091. disasm_line__free(pos);
  1092. }
  1093. }
  1094. static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
  1095. {
  1096. size_t printed;
  1097. if (dl->offset == -1)
  1098. return fprintf(fp, "%s\n", dl->line);
  1099. printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name);
  1100. if (dl->ops.raw[0] != '\0') {
  1101. printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
  1102. dl->ops.raw);
  1103. }
  1104. return printed + fprintf(fp, "\n");
  1105. }
  1106. size_t disasm__fprintf(struct list_head *head, FILE *fp)
  1107. {
  1108. struct disasm_line *pos;
  1109. size_t printed = 0;
  1110. list_for_each_entry(pos, head, node)
  1111. printed += disasm_line__fprintf(pos, fp);
  1112. return printed;
  1113. }
  1114. int symbol__tty_annotate(struct symbol *sym, struct map *map,
  1115. struct perf_evsel *evsel, bool print_lines,
  1116. bool full_paths, int min_pcnt, int max_lines)
  1117. {
  1118. struct dso *dso = map->dso;
  1119. struct rb_root source_line = RB_ROOT;
  1120. u64 len;
  1121. if (symbol__annotate(sym, map, 0) < 0)
  1122. return -1;
  1123. len = symbol__size(sym);
  1124. if (print_lines) {
  1125. symbol__get_source_line(sym, map, evsel, &source_line, len);
  1126. print_summary(&source_line, dso->long_name);
  1127. }
  1128. symbol__annotate_printf(sym, map, evsel, full_paths,
  1129. min_pcnt, max_lines, 0);
  1130. if (print_lines)
  1131. symbol__free_source_line(sym, len);
  1132. disasm__purge(&symbol__annotation(sym)->src->source);
  1133. return 0;
  1134. }
  1135. int hist_entry__annotate(struct hist_entry *he, size_t privsize)
  1136. {
  1137. return symbol__annotate(he->ms.sym, he->ms.map, privsize);
  1138. }
  1139. bool ui__has_annotation(void)
  1140. {
  1141. return use_browser == 1 && sort__has_sym;
  1142. }