annotate.c 32 KB

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