@@ -19,6 +19,16 @@ struct browser_disasm_line {
1919 int jump_sources ;
2020};
2121
22+ static struct annotate_browser_opt {
23+ bool hide_src_code ,
24+ use_offset ,
25+ jump_arrows ,
26+ show_nr_jumps ;
27+ } annotate_browser__opts = {
28+ .use_offset = true,
29+ .jump_arrows = true,
30+ };
31+
2232struct annotate_browser {
2333 struct ui_browser b ;
2434 struct rb_root entries ;
@@ -30,10 +40,6 @@ struct annotate_browser {
3040 int nr_entries ;
3141 int max_jump_sources ;
3242 int nr_jumps ;
33- bool hide_src_code ;
34- bool use_offset ;
35- bool jump_arrows ;
36- bool show_nr_jumps ;
3743 bool searching_backwards ;
3844 u8 addr_width ;
3945 u8 jumps_width ;
@@ -48,11 +54,9 @@ static inline struct browser_disasm_line *disasm_line__browser(struct disasm_lin
4854 return (struct browser_disasm_line * )(dl + 1 );
4955}
5056
51- static bool disasm_line__filter (struct ui_browser * browser , void * entry )
57+ static bool disasm_line__filter (struct ui_browser * browser __used , void * entry )
5258{
53- struct annotate_browser * ab = container_of (browser , struct annotate_browser , b );
54-
55- if (ab -> hide_src_code ) {
59+ if (annotate_browser__opts .hide_src_code ) {
5660 struct disasm_line * dl = list_entry (entry , struct disasm_line , node );
5761 return dl -> offset == -1 ;
5862 }
@@ -85,7 +89,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
8589 struct disasm_line * dl = list_entry (entry , struct disasm_line , node );
8690 struct browser_disasm_line * bdl = disasm_line__browser (dl );
8791 bool current_entry = ui_browser__is_current_entry (self , row );
88- bool change_color = (!ab -> hide_src_code &&
92+ bool change_color = (!annotate_browser__opts . hide_src_code &&
8993 (!current_entry || (self -> use_navkeypressed &&
9094 !self -> navkeypressed )));
9195 int width = self -> width , printed ;
@@ -116,14 +120,14 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
116120 u64 addr = dl -> offset ;
117121 int color = -1 ;
118122
119- if (!ab -> use_offset )
123+ if (!annotate_browser__opts . use_offset )
120124 addr += ab -> start ;
121125
122- if (!ab -> use_offset ) {
126+ if (!annotate_browser__opts . use_offset ) {
123127 printed = scnprintf (bf , sizeof (bf ), "%" PRIx64 ": " , addr );
124128 } else {
125129 if (bdl -> jump_sources ) {
126- if (ab -> show_nr_jumps ) {
130+ if (annotate_browser__opts . show_nr_jumps ) {
127131 int prev ;
128132 printed = scnprintf (bf , sizeof (bf ), "%*d " ,
129133 ab -> jumps_width ,
@@ -169,7 +173,7 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
169173 }
170174 }
171175
172- disasm_line__scnprintf (dl , bf , sizeof (bf ), !ab -> use_offset );
176+ disasm_line__scnprintf (dl , bf , sizeof (bf ), !annotate_browser__opts . use_offset );
173177 slsmg_write_nstring (bf , width - 10 - printed );
174178 }
175179
@@ -184,7 +188,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
184188 struct browser_disasm_line * btarget , * bcursor ;
185189 unsigned int from , to ;
186190
187- if (!cursor -> ins || !ins__is_jump (cursor -> ins ) ||
191+ if (!cursor || ! cursor -> ins || !ins__is_jump (cursor -> ins ) ||
188192 !disasm_line__has_offset (cursor ))
189193 return ;
190194
@@ -195,7 +199,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
195199 bcursor = disasm_line__browser (cursor );
196200 btarget = disasm_line__browser (target );
197201
198- if (ab -> hide_src_code ) {
202+ if (annotate_browser__opts . hide_src_code ) {
199203 from = bcursor -> idx_asm ;
200204 to = btarget -> idx_asm ;
201205 } else {
@@ -209,10 +213,9 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
209213
210214static unsigned int annotate_browser__refresh (struct ui_browser * browser )
211215{
212- struct annotate_browser * ab = container_of (browser , struct annotate_browser , b );
213216 int ret = ui_browser__list_head_refresh (browser );
214217
215- if (ab -> jump_arrows )
218+ if (annotate_browser__opts . jump_arrows )
216219 annotate_browser__draw_current_jump (browser );
217220
218221 ui_browser__set_color (browser , HE_COLORSET_NORMAL );
@@ -305,7 +308,7 @@ static void annotate_browser__set_rb_top(struct annotate_browser *browser,
305308 bpos = rb_entry (nd , struct browser_disasm_line , rb_node );
306309 pos = ((struct disasm_line * )bpos ) - 1 ;
307310 idx = bpos -> idx ;
308- if (browser -> hide_src_code )
311+ if (annotate_browser__opts . hide_src_code )
309312 idx = bpos -> idx_asm ;
310313 annotate_browser__set_top (browser , pos , idx );
311314 browser -> curr_hot = nd ;
@@ -347,12 +350,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
347350 dl = list_entry (browser -> b .top , struct disasm_line , node );
348351 bdl = disasm_line__browser (dl );
349352
350- if (browser -> hide_src_code ) {
353+ if (annotate_browser__opts . hide_src_code ) {
351354 if (bdl -> idx_asm < offset )
352355 offset = bdl -> idx ;
353356
354357 browser -> b .nr_entries = browser -> nr_entries ;
355- browser -> hide_src_code = false;
358+ annotate_browser__opts . hide_src_code = false;
356359 browser -> b .seek (& browser -> b , - offset , SEEK_CUR );
357360 browser -> b .top_idx = bdl -> idx - offset ;
358361 browser -> b .index = bdl -> idx ;
@@ -367,7 +370,7 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
367370 offset = bdl -> idx_asm ;
368371
369372 browser -> b .nr_entries = browser -> nr_asm_entries ;
370- browser -> hide_src_code = true;
373+ annotate_browser__opts . hide_src_code = true;
371374 browser -> b .seek (& browser -> b , - offset , SEEK_CUR );
372375 browser -> b .top_idx = bdl -> idx_asm - offset ;
373376 browser -> b .index = bdl -> idx_asm ;
@@ -376,6 +379,12 @@ static bool annotate_browser__toggle_source(struct annotate_browser *browser)
376379 return true;
377380}
378381
382+ static void annotate_browser__init_asm_mode (struct annotate_browser * browser )
383+ {
384+ ui_browser__reset_index (& browser -> b );
385+ browser -> b .nr_entries = browser -> nr_asm_entries ;
386+ }
387+
379388static bool annotate_browser__callq (struct annotate_browser * browser ,
380389 int evidx , void (* timer )(void * arg ),
381390 void * arg , int delay_secs )
@@ -578,6 +587,19 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
578587 return __annotate_browser__search_reverse (browser );
579588}
580589
590+ static void annotate_browser__update_addr_width (struct annotate_browser * browser )
591+ {
592+ if (annotate_browser__opts .use_offset )
593+ browser -> target_width = browser -> min_addr_width ;
594+ else
595+ browser -> target_width = browser -> max_addr_width ;
596+
597+ browser -> addr_width = browser -> target_width ;
598+
599+ if (annotate_browser__opts .show_nr_jumps )
600+ browser -> addr_width += browser -> jumps_width + 1 ;
601+ }
602+
581603static int annotate_browser__run (struct annotate_browser * self , int evidx ,
582604 void (* timer )(void * arg ),
583605 void * arg , int delay_secs )
@@ -663,22 +685,16 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
663685 ui_helpline__puts (help );
664686 continue ;
665687 case 'o' :
666- self -> use_offset = !self -> use_offset ;
667- if (self -> use_offset )
668- self -> target_width = self -> min_addr_width ;
669- else
670- self -> target_width = self -> max_addr_width ;
671- update_addr_width :
672- self -> addr_width = self -> target_width ;
673- if (self -> show_nr_jumps )
674- self -> addr_width += self -> jumps_width + 1 ;
688+ annotate_browser__opts .use_offset = !annotate_browser__opts .use_offset ;
689+ annotate_browser__update_addr_width (self );
675690 continue ;
676691 case 'j' :
677- self -> jump_arrows = !self -> jump_arrows ;
692+ annotate_browser__opts . jump_arrows = !annotate_browser__opts . jump_arrows ;
678693 continue ;
679694 case 'J' :
680- self -> show_nr_jumps = !self -> show_nr_jumps ;
681- goto update_addr_width ;
695+ annotate_browser__opts .show_nr_jumps = !annotate_browser__opts .show_nr_jumps ;
696+ annotate_browser__update_addr_width (self );
697+ continue ;
682698 case '/' :
683699 if (annotate_browser__search (self , delay_secs )) {
684700show_help :
@@ -695,6 +711,17 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
695711 if (annotate_browser__search_reverse (self , delay_secs ))
696712 goto show_help ;
697713 continue ;
714+ case 'D' : {
715+ static int seq ;
716+ ui_helpline__pop ();
717+ ui_helpline__fpush ("%d: nr_ent=%d, height=%d, idx=%d, top_idx=%d, nr_asm_entries=%d" ,
718+ seq ++ , self -> b .nr_entries ,
719+ self -> b .height ,
720+ self -> b .index ,
721+ self -> b .top_idx ,
722+ self -> nr_asm_entries );
723+ }
724+ continue ;
698725 case K_ENTER :
699726 case K_RIGHT :
700727 if (self -> selection == NULL )
@@ -801,8 +828,6 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
801828 .priv = & ms ,
802829 .use_navkeypressed = true,
803830 },
804- .use_offset = true,
805- .jump_arrows = true,
806831 };
807832 int ret = -1 ;
808833
@@ -859,6 +884,12 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
859884 browser .b .nr_entries = browser .nr_entries ;
860885 browser .b .entries = & notes -> src -> source ,
861886 browser .b .width += 18 ; /* Percentage */
887+
888+ if (annotate_browser__opts .hide_src_code )
889+ annotate_browser__init_asm_mode (& browser );
890+
891+ annotate_browser__update_addr_width (& browser );
892+
862893 ret = annotate_browser__run (& browser , evidx , timer , arg , delay_secs );
863894 list_for_each_entry_safe (pos , n , & notes -> src -> source , node ) {
864895 list_del (& pos -> node );
0 commit comments