annotate.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. #include "../../util/util.h"
  2. #include "../browser.h"
  3. #include "../helpline.h"
  4. #include "../libslang.h"
  5. #include "../ui.h"
  6. #include "../util.h"
  7. #include "../../util/annotate.h"
  8. #include "../../util/hist.h"
  9. #include "../../util/sort.h"
  10. #include "../../util/symbol.h"
  11. #include <pthread.h>
  12. #include <newt.h>
  13. struct browser_disasm_line {
  14. struct rb_node rb_node;
  15. double percent;
  16. u32 idx;
  17. int idx_asm;
  18. bool jump_target;
  19. };
  20. struct annotate_browser {
  21. struct ui_browser b;
  22. struct rb_root entries;
  23. struct rb_node *curr_hot;
  24. struct disasm_line *selection;
  25. struct disasm_line **offsets;
  26. u64 start;
  27. int nr_asm_entries;
  28. int nr_entries;
  29. bool hide_src_code;
  30. bool use_offset;
  31. bool searching_backwards;
  32. u8 offset_width;
  33. char search_bf[128];
  34. };
  35. static inline struct browser_disasm_line *disasm_line__browser(struct disasm_line *dl)
  36. {
  37. return (struct browser_disasm_line *)(dl + 1);
  38. }
  39. static bool disasm_line__filter(struct ui_browser *browser, void *entry)
  40. {
  41. struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
  42. if (ab->hide_src_code) {
  43. struct disasm_line *dl = list_entry(entry, struct disasm_line, node);
  44. return dl->offset == -1;
  45. }
  46. return false;
  47. }
  48. static void annotate_browser__write(struct ui_browser *self, void *entry, int row)
  49. {
  50. struct annotate_browser *ab = container_of(self, struct annotate_browser, b);
  51. struct disasm_line *dl = list_entry(entry, struct disasm_line, node);
  52. struct browser_disasm_line *bdl = disasm_line__browser(dl);
  53. bool current_entry = ui_browser__is_current_entry(self, row);
  54. bool change_color = (!ab->hide_src_code &&
  55. (!current_entry || (self->use_navkeypressed &&
  56. !self->navkeypressed)));
  57. int width = self->width;
  58. if (dl->offset != -1) {
  59. ui_browser__set_percent_color(self, bdl->percent, current_entry);
  60. slsmg_printf(" %7.2f ", bdl->percent);
  61. } else {
  62. ui_browser__set_percent_color(self, 0, current_entry);
  63. slsmg_write_nstring(" ", 9);
  64. }
  65. SLsmg_set_char_set(1);
  66. SLsmg_write_char(SLSMG_VLINE_CHAR);
  67. SLsmg_set_char_set(0);
  68. SLsmg_write_char(' ');
  69. /* The scroll bar isn't being used */
  70. if (!self->navkeypressed)
  71. width += 1;
  72. if (dl->offset != -1 && change_color)
  73. ui_browser__set_color(self, HE_COLORSET_CODE);
  74. if (!*dl->line)
  75. slsmg_write_nstring(" ", width - 10);
  76. else if (dl->offset == -1)
  77. slsmg_write_nstring(dl->line, width - 10);
  78. else {
  79. char bf[256];
  80. u64 addr = dl->offset;
  81. int printed, color = -1;
  82. if (!ab->use_offset)
  83. addr += ab->start;
  84. if (!ab->use_offset) {
  85. printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ":", addr);
  86. } else {
  87. if (bdl->jump_target) {
  88. printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ":",
  89. ab->offset_width, addr);
  90. } else {
  91. printed = scnprintf(bf, sizeof(bf), "%*s ",
  92. ab->offset_width, " ");
  93. }
  94. }
  95. if (change_color)
  96. color = ui_browser__set_color(self, HE_COLORSET_ADDR);
  97. slsmg_write_nstring(bf, printed);
  98. if (change_color)
  99. ui_browser__set_color(self, color);
  100. if (dl->ins && dl->ins->ops->scnprintf) {
  101. if (ins__is_jump(dl->ins)) {
  102. bool fwd = dl->ops.target > (u64)dl->offset;
  103. SLsmg_set_char_set(1);
  104. SLsmg_write_char(fwd ? SLSMG_DARROW_CHAR :
  105. SLSMG_UARROW_CHAR);
  106. SLsmg_set_char_set(0);
  107. SLsmg_write_char(' ');
  108. } else {
  109. slsmg_write_nstring(" ", 2);
  110. }
  111. dl->ins->ops->scnprintf(dl->ins, bf, sizeof(bf), &dl->ops,
  112. !ab->use_offset);
  113. } else {
  114. if (strcmp(dl->name, "retq")) {
  115. slsmg_write_nstring(" ", 2);
  116. } else {
  117. SLsmg_set_char_set(1);
  118. SLsmg_write_char(SLSMG_LARROW_CHAR);
  119. SLsmg_set_char_set(0);
  120. SLsmg_write_char(' ');
  121. }
  122. scnprintf(bf, sizeof(bf), "%-6.6s %s", dl->name, dl->ops.raw);
  123. }
  124. slsmg_write_nstring(bf, width - 12 - printed);
  125. }
  126. if (current_entry)
  127. ab->selection = dl;
  128. }
  129. static double disasm_line__calc_percent(struct disasm_line *dl, struct symbol *sym, int evidx)
  130. {
  131. double percent = 0.0;
  132. if (dl->offset != -1) {
  133. int len = sym->end - sym->start;
  134. unsigned int hits = 0;
  135. struct annotation *notes = symbol__annotation(sym);
  136. struct source_line *src_line = notes->src->lines;
  137. struct sym_hist *h = annotation__histogram(notes, evidx);
  138. s64 offset = dl->offset;
  139. struct disasm_line *next;
  140. next = disasm__get_next_ip_line(&notes->src->source, dl);
  141. while (offset < (s64)len &&
  142. (next == NULL || offset < next->offset)) {
  143. if (src_line) {
  144. percent += src_line[offset].percent;
  145. } else
  146. hits += h->addr[offset];
  147. ++offset;
  148. }
  149. /*
  150. * If the percentage wasn't already calculated in
  151. * symbol__get_source_line, do it now:
  152. */
  153. if (src_line == NULL && h->sum)
  154. percent = 100.0 * hits / h->sum;
  155. }
  156. return percent;
  157. }
  158. static void disasm_rb_tree__insert(struct rb_root *root, struct browser_disasm_line *bdl)
  159. {
  160. struct rb_node **p = &root->rb_node;
  161. struct rb_node *parent = NULL;
  162. struct browser_disasm_line *l;
  163. while (*p != NULL) {
  164. parent = *p;
  165. l = rb_entry(parent, struct browser_disasm_line, rb_node);
  166. if (bdl->percent < l->percent)
  167. p = &(*p)->rb_left;
  168. else
  169. p = &(*p)->rb_right;
  170. }
  171. rb_link_node(&bdl->rb_node, parent, p);
  172. rb_insert_color(&bdl->rb_node, root);
  173. }
  174. static void annotate_browser__set_top(struct annotate_browser *self,
  175. struct disasm_line *pos, u32 idx)
  176. {
  177. unsigned back;
  178. ui_browser__refresh_dimensions(&self->b);
  179. back = self->b.height / 2;
  180. self->b.top_idx = self->b.index = idx;
  181. while (self->b.top_idx != 0 && back != 0) {
  182. pos = list_entry(pos->node.prev, struct disasm_line, node);
  183. if (disasm_line__filter(&self->b, &pos->node))
  184. continue;
  185. --self->b.top_idx;
  186. --back;
  187. }
  188. self->b.top = pos;
  189. self->b.navkeypressed = true;
  190. }
  191. static void annotate_browser__set_rb_top(struct annotate_browser *browser,
  192. struct rb_node *nd)
  193. {
  194. struct browser_disasm_line *bpos;
  195. struct disasm_line *pos;
  196. bpos = rb_entry(nd, struct browser_disasm_line, rb_node);
  197. pos = ((struct disasm_line *)bpos) - 1;
  198. annotate_browser__set_top(browser, pos, bpos->idx);
  199. browser->curr_hot = nd;
  200. }
  201. static void annotate_browser__calc_percent(struct annotate_browser *browser,
  202. int evidx)
  203. {
  204. struct map_symbol *ms = browser->b.priv;
  205. struct symbol *sym = ms->sym;
  206. struct annotation *notes = symbol__annotation(sym);
  207. struct disasm_line *pos;
  208. browser->entries = RB_ROOT;
  209. pthread_mutex_lock(&notes->lock);
  210. list_for_each_entry(pos, &notes->src->source, node) {
  211. struct browser_disasm_line *bpos = disasm_line__browser(pos);
  212. bpos->percent = disasm_line__calc_percent(pos, sym, evidx);
  213. if (bpos->percent < 0.01) {
  214. RB_CLEAR_NODE(&bpos->rb_node);
  215. continue;
  216. }
  217. disasm_rb_tree__insert(&browser->entries, bpos);
  218. }
  219. pthread_mutex_unlock(&notes->lock);
  220. browser->curr_hot = rb_last(&browser->entries);
  221. }
  222. static bool annotate_browser__toggle_source(struct annotate_browser *browser)
  223. {
  224. struct disasm_line *dl;
  225. struct browser_disasm_line *bdl;
  226. off_t offset = browser->b.index - browser->b.top_idx;
  227. browser->b.seek(&browser->b, offset, SEEK_CUR);
  228. dl = list_entry(browser->b.top, struct disasm_line, node);
  229. bdl = disasm_line__browser(dl);
  230. if (browser->hide_src_code) {
  231. if (bdl->idx_asm < offset)
  232. offset = bdl->idx;
  233. browser->b.nr_entries = browser->nr_entries;
  234. browser->hide_src_code = false;
  235. browser->b.seek(&browser->b, -offset, SEEK_CUR);
  236. browser->b.top_idx = bdl->idx - offset;
  237. browser->b.index = bdl->idx;
  238. } else {
  239. if (bdl->idx_asm < 0) {
  240. ui_helpline__puts("Only available for assembly lines.");
  241. browser->b.seek(&browser->b, -offset, SEEK_CUR);
  242. return false;
  243. }
  244. if (bdl->idx_asm < offset)
  245. offset = bdl->idx_asm;
  246. browser->b.nr_entries = browser->nr_asm_entries;
  247. browser->hide_src_code = true;
  248. browser->b.seek(&browser->b, -offset, SEEK_CUR);
  249. browser->b.top_idx = bdl->idx_asm - offset;
  250. browser->b.index = bdl->idx_asm;
  251. }
  252. return true;
  253. }
  254. static bool annotate_browser__callq(struct annotate_browser *browser,
  255. int evidx, void (*timer)(void *arg),
  256. void *arg, int delay_secs)
  257. {
  258. struct map_symbol *ms = browser->b.priv;
  259. struct disasm_line *dl = browser->selection;
  260. struct symbol *sym = ms->sym;
  261. struct annotation *notes;
  262. struct symbol *target;
  263. u64 ip;
  264. if (!ins__is_call(dl->ins))
  265. return false;
  266. ip = ms->map->map_ip(ms->map, dl->ops.target);
  267. target = map__find_symbol(ms->map, ip, NULL);
  268. if (target == NULL) {
  269. ui_helpline__puts("The called function was not found.");
  270. return true;
  271. }
  272. notes = symbol__annotation(target);
  273. pthread_mutex_lock(&notes->lock);
  274. if (notes->src == NULL && symbol__alloc_hist(target) < 0) {
  275. pthread_mutex_unlock(&notes->lock);
  276. ui__warning("Not enough memory for annotating '%s' symbol!\n",
  277. target->name);
  278. return true;
  279. }
  280. pthread_mutex_unlock(&notes->lock);
  281. symbol__tui_annotate(target, ms->map, evidx, timer, arg, delay_secs);
  282. ui_browser__show_title(&browser->b, sym->name);
  283. return true;
  284. }
  285. static
  286. struct disasm_line *annotate_browser__find_offset(struct annotate_browser *browser,
  287. s64 offset, s64 *idx)
  288. {
  289. struct map_symbol *ms = browser->b.priv;
  290. struct symbol *sym = ms->sym;
  291. struct annotation *notes = symbol__annotation(sym);
  292. struct disasm_line *pos;
  293. *idx = 0;
  294. list_for_each_entry(pos, &notes->src->source, node) {
  295. if (pos->offset == offset)
  296. return pos;
  297. if (!disasm_line__filter(&browser->b, &pos->node))
  298. ++*idx;
  299. }
  300. return NULL;
  301. }
  302. static bool annotate_browser__jump(struct annotate_browser *browser)
  303. {
  304. struct disasm_line *dl = browser->selection;
  305. s64 idx;
  306. if (!ins__is_jump(dl->ins))
  307. return false;
  308. dl = annotate_browser__find_offset(browser, dl->ops.target, &idx);
  309. if (dl == NULL) {
  310. ui_helpline__puts("Invallid jump offset");
  311. return true;
  312. }
  313. annotate_browser__set_top(browser, dl, idx);
  314. return true;
  315. }
  316. static
  317. struct disasm_line *annotate_browser__find_string(struct annotate_browser *browser,
  318. char *s, s64 *idx)
  319. {
  320. struct map_symbol *ms = browser->b.priv;
  321. struct symbol *sym = ms->sym;
  322. struct annotation *notes = symbol__annotation(sym);
  323. struct disasm_line *pos = browser->selection;
  324. *idx = browser->b.index;
  325. list_for_each_entry_continue(pos, &notes->src->source, node) {
  326. if (disasm_line__filter(&browser->b, &pos->node))
  327. continue;
  328. ++*idx;
  329. if (pos->line && strstr(pos->line, s) != NULL)
  330. return pos;
  331. }
  332. return NULL;
  333. }
  334. static bool __annotate_browser__search(struct annotate_browser *browser)
  335. {
  336. struct disasm_line *dl;
  337. s64 idx;
  338. dl = annotate_browser__find_string(browser, browser->search_bf, &idx);
  339. if (dl == NULL) {
  340. ui_helpline__puts("String not found!");
  341. return false;
  342. }
  343. annotate_browser__set_top(browser, dl, idx);
  344. browser->searching_backwards = false;
  345. return true;
  346. }
  347. static
  348. struct disasm_line *annotate_browser__find_string_reverse(struct annotate_browser *browser,
  349. char *s, s64 *idx)
  350. {
  351. struct map_symbol *ms = browser->b.priv;
  352. struct symbol *sym = ms->sym;
  353. struct annotation *notes = symbol__annotation(sym);
  354. struct disasm_line *pos = browser->selection;
  355. *idx = browser->b.index;
  356. list_for_each_entry_continue_reverse(pos, &notes->src->source, node) {
  357. if (disasm_line__filter(&browser->b, &pos->node))
  358. continue;
  359. --*idx;
  360. if (pos->line && strstr(pos->line, s) != NULL)
  361. return pos;
  362. }
  363. return NULL;
  364. }
  365. static bool __annotate_browser__search_reverse(struct annotate_browser *browser)
  366. {
  367. struct disasm_line *dl;
  368. s64 idx;
  369. dl = annotate_browser__find_string_reverse(browser, browser->search_bf, &idx);
  370. if (dl == NULL) {
  371. ui_helpline__puts("String not found!");
  372. return false;
  373. }
  374. annotate_browser__set_top(browser, dl, idx);
  375. browser->searching_backwards = true;
  376. return true;
  377. }
  378. static bool annotate_browser__search_window(struct annotate_browser *browser,
  379. int delay_secs)
  380. {
  381. if (ui_browser__input_window("Search", "String: ", browser->search_bf,
  382. "ENTER: OK, ESC: Cancel",
  383. delay_secs * 2) != K_ENTER ||
  384. !*browser->search_bf)
  385. return false;
  386. return true;
  387. }
  388. static bool annotate_browser__search(struct annotate_browser *browser, int delay_secs)
  389. {
  390. if (annotate_browser__search_window(browser, delay_secs))
  391. return __annotate_browser__search(browser);
  392. return false;
  393. }
  394. static bool annotate_browser__continue_search(struct annotate_browser *browser,
  395. int delay_secs)
  396. {
  397. if (!*browser->search_bf)
  398. return annotate_browser__search(browser, delay_secs);
  399. return __annotate_browser__search(browser);
  400. }
  401. static bool annotate_browser__search_reverse(struct annotate_browser *browser,
  402. int delay_secs)
  403. {
  404. if (annotate_browser__search_window(browser, delay_secs))
  405. return __annotate_browser__search_reverse(browser);
  406. return false;
  407. }
  408. static
  409. bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
  410. int delay_secs)
  411. {
  412. if (!*browser->search_bf)
  413. return annotate_browser__search_reverse(browser, delay_secs);
  414. return __annotate_browser__search_reverse(browser);
  415. }
  416. static int annotate_browser__run(struct annotate_browser *self, int evidx,
  417. void(*timer)(void *arg),
  418. void *arg, int delay_secs)
  419. {
  420. struct rb_node *nd = NULL;
  421. struct map_symbol *ms = self->b.priv;
  422. struct symbol *sym = ms->sym;
  423. const char *help = "<-/ESC: Exit, TAB/shift+TAB: Cycle hot lines, "
  424. "H: Go to hottest line, ->/ENTER: Line action, "
  425. "O: Toggle offset view, "
  426. "S: Toggle source code view";
  427. int key;
  428. if (ui_browser__show(&self->b, sym->name, help) < 0)
  429. return -1;
  430. annotate_browser__calc_percent(self, evidx);
  431. if (self->curr_hot) {
  432. annotate_browser__set_rb_top(self, self->curr_hot);
  433. self->b.navkeypressed = false;
  434. }
  435. nd = self->curr_hot;
  436. while (1) {
  437. key = ui_browser__run(&self->b, delay_secs);
  438. if (delay_secs != 0) {
  439. annotate_browser__calc_percent(self, evidx);
  440. /*
  441. * Current line focus got out of the list of most active
  442. * lines, NULL it so that if TAB|UNTAB is pressed, we
  443. * move to curr_hot (current hottest line).
  444. */
  445. if (nd != NULL && RB_EMPTY_NODE(nd))
  446. nd = NULL;
  447. }
  448. switch (key) {
  449. case K_TIMER:
  450. if (timer != NULL)
  451. timer(arg);
  452. if (delay_secs != 0)
  453. symbol__annotate_decay_histogram(sym, evidx);
  454. continue;
  455. case K_TAB:
  456. if (nd != NULL) {
  457. nd = rb_prev(nd);
  458. if (nd == NULL)
  459. nd = rb_last(&self->entries);
  460. } else
  461. nd = self->curr_hot;
  462. break;
  463. case K_UNTAB:
  464. if (nd != NULL)
  465. nd = rb_next(nd);
  466. if (nd == NULL)
  467. nd = rb_first(&self->entries);
  468. else
  469. nd = self->curr_hot;
  470. break;
  471. case 'H':
  472. case 'h':
  473. nd = self->curr_hot;
  474. break;
  475. case 'S':
  476. case 's':
  477. if (annotate_browser__toggle_source(self))
  478. ui_helpline__puts(help);
  479. continue;
  480. case 'O':
  481. case 'o':
  482. self->use_offset = !self->use_offset;
  483. continue;
  484. case '/':
  485. if (annotate_browser__search(self, delay_secs)) {
  486. show_help:
  487. ui_helpline__puts(help);
  488. }
  489. continue;
  490. case 'n':
  491. if (self->searching_backwards ?
  492. annotate_browser__continue_search_reverse(self, delay_secs) :
  493. annotate_browser__continue_search(self, delay_secs))
  494. goto show_help;
  495. continue;
  496. case '?':
  497. if (annotate_browser__search_reverse(self, delay_secs))
  498. goto show_help;
  499. continue;
  500. case K_ENTER:
  501. case K_RIGHT:
  502. if (self->selection == NULL)
  503. ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org");
  504. else if (self->selection->offset == -1)
  505. ui_helpline__puts("Actions are only available for assembly lines.");
  506. else if (!self->selection->ins) {
  507. if (strcmp(self->selection->name, "retq"))
  508. goto show_sup_ins;
  509. goto out;
  510. } else if (!(annotate_browser__jump(self) ||
  511. annotate_browser__callq(self, evidx, timer, arg, delay_secs))) {
  512. show_sup_ins:
  513. ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions.");
  514. }
  515. continue;
  516. case K_LEFT:
  517. case K_ESC:
  518. case 'q':
  519. case CTRL('c'):
  520. goto out;
  521. default:
  522. continue;
  523. }
  524. if (nd != NULL)
  525. annotate_browser__set_rb_top(self, nd);
  526. }
  527. out:
  528. ui_browser__hide(&self->b);
  529. return key;
  530. }
  531. int hist_entry__tui_annotate(struct hist_entry *he, int evidx,
  532. void(*timer)(void *arg), void *arg, int delay_secs)
  533. {
  534. return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx,
  535. timer, arg, delay_secs);
  536. }
  537. static void annotate_browser__mark_jump_targets(struct annotate_browser *browser,
  538. size_t size)
  539. {
  540. u64 offset;
  541. for (offset = 0; offset < size; ++offset) {
  542. struct disasm_line *dl = browser->offsets[offset], *dlt;
  543. struct browser_disasm_line *bdlt;
  544. if (!dl || !dl->ins || !ins__is_jump(dl->ins))
  545. continue;
  546. if (dl->ops.target >= size) {
  547. ui__error("jump to after symbol!\n"
  548. "size: %zx, jump target: %" PRIx64,
  549. size, dl->ops.target);
  550. continue;
  551. }
  552. dlt = browser->offsets[dl->ops.target];
  553. bdlt = disasm_line__browser(dlt);
  554. bdlt->jump_target = true;
  555. }
  556. }
  557. int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
  558. void(*timer)(void *arg), void *arg,
  559. int delay_secs)
  560. {
  561. struct disasm_line *pos, *n;
  562. struct annotation *notes;
  563. const size_t size = symbol__size(sym);
  564. struct map_symbol ms = {
  565. .map = map,
  566. .sym = sym,
  567. };
  568. struct annotate_browser browser = {
  569. .b = {
  570. .refresh = ui_browser__list_head_refresh,
  571. .seek = ui_browser__list_head_seek,
  572. .write = annotate_browser__write,
  573. .filter = disasm_line__filter,
  574. .priv = &ms,
  575. .use_navkeypressed = true,
  576. },
  577. .use_offset = true,
  578. };
  579. int ret = -1;
  580. if (sym == NULL)
  581. return -1;
  582. if (map->dso->annotate_warned)
  583. return -1;
  584. browser.offsets = zalloc(size * sizeof(struct disasm_line *));
  585. if (browser.offsets == NULL) {
  586. ui__error("Not enough memory!");
  587. return -1;
  588. }
  589. if (symbol__annotate(sym, map, sizeof(struct browser_disasm_line)) < 0) {
  590. ui__error("%s", ui_helpline__last_msg);
  591. goto out_free_offsets;
  592. }
  593. ui_helpline__push("Press <- or ESC to exit");
  594. notes = symbol__annotation(sym);
  595. browser.start = map__rip_2objdump(map, sym->start);
  596. list_for_each_entry(pos, &notes->src->source, node) {
  597. struct browser_disasm_line *bpos;
  598. size_t line_len = strlen(pos->line);
  599. if (browser.b.width < line_len)
  600. browser.b.width = line_len;
  601. bpos = disasm_line__browser(pos);
  602. bpos->idx = browser.nr_entries++;
  603. if (pos->offset != -1) {
  604. bpos->idx_asm = browser.nr_asm_entries++;
  605. /*
  606. * FIXME: short term bandaid to cope with assembly
  607. * routines that comes with labels in the same column
  608. * as the address in objdump, sigh.
  609. *
  610. * E.g. copy_user_generic_unrolled
  611. */
  612. if (pos->offset < (s64)size)
  613. browser.offsets[pos->offset] = pos;
  614. } else
  615. bpos->idx_asm = -1;
  616. }
  617. annotate_browser__mark_jump_targets(&browser, size);
  618. browser.offset_width = hex_width(size);
  619. browser.b.nr_entries = browser.nr_entries;
  620. browser.b.entries = &notes->src->source,
  621. browser.b.width += 18; /* Percentage */
  622. ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs);
  623. list_for_each_entry_safe(pos, n, &notes->src->source, node) {
  624. list_del(&pos->node);
  625. disasm_line__free(pos);
  626. }
  627. out_free_offsets:
  628. free(browser.offsets);
  629. return ret;
  630. }