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