annotate.c 18 KB

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