annotate.c 18 KB

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