@@ -605,7 +605,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
605605 target_ms .map = ms -> map ;
606606 target_ms .sym = dl -> ops .target .sym ;
607607 annotation__unlock (notes );
608- __hist_entry__tui_annotate (browser -> he , & target_ms , evsel , hbt );
608+ __hist_entry__tui_annotate (browser -> he , & target_ms , evsel , hbt , NO_ADDR );
609609
610610 /*
611611 * The annotate_browser above changed the title with the target function
@@ -852,6 +852,16 @@ static void annotate_browser__debuginfo_warning(struct annotate_browser *browser
852852 }
853853}
854854
855+ static s64 annotate_browser__curr_hot_offset (struct annotate_browser * browser )
856+ {
857+ struct annotation_line * al = NULL ;
858+
859+ if (browser -> curr_hot )
860+ al = rb_entry (browser -> curr_hot , struct annotation_line , rb_node );
861+
862+ return al ? al -> offset : 0 ;
863+ }
864+
855865static int annotate_browser__run (struct annotate_browser * browser ,
856866 struct evsel * evsel ,
857867 struct hist_browser_timer * hbt )
@@ -873,6 +883,11 @@ static int annotate_browser__run(struct annotate_browser *browser,
873883
874884 annotate_browser__calc_percent (browser , evsel );
875885
886+ if (browser -> selection != NULL ) {
887+ browser -> curr_hot = & browser -> selection -> rb_node ;
888+ browser -> b .use_navkeypressed = false;
889+ }
890+
876891 if (browser -> curr_hot ) {
877892 annotate_browser__set_rb_top (browser , browser -> curr_hot );
878893 browser -> b .navkeypressed = false;
@@ -969,8 +984,19 @@ static int annotate_browser__run(struct annotate_browser *browser,
969984 nd = browser -> curr_hot ;
970985 break ;
971986 case 's' :
987+ struct annotation_line * al = NULL ;
988+ s64 offset = annotate_browser__curr_hot_offset (browser );
989+
972990 if (annotate_browser__toggle_source (browser , evsel ))
973991 ui_helpline__puts (help );
992+
993+ /* Update the annotation browser's rb_tree, and reset the nd */
994+ annotate_browser__calc_percent (browser , evsel );
995+ /* Try to find the same asm line as before */
996+ al = annotated_source__get_line (notes -> src , offset );
997+ browser -> curr_hot = al ? & al -> rb_node : NULL ;
998+ nd = browser -> curr_hot ;
999+
9741000 annotate__scnprintf_title (hists , title , sizeof (title ));
9751001 annotate_browser__show (browser , title , help );
9761002 continue ;
@@ -1106,19 +1132,19 @@ static int annotate_browser__run(struct annotate_browser *browser,
11061132}
11071133
11081134int hist_entry__tui_annotate (struct hist_entry * he , struct evsel * evsel ,
1109- struct hist_browser_timer * hbt )
1135+ struct hist_browser_timer * hbt , u64 al_addr )
11101136{
11111137 /* reset abort key so that it can get Ctrl-C as a key */
11121138 SLang_reset_tty ();
11131139 SLang_init_tty (0 , 0 , 0 );
11141140 SLtty_set_suspend_state (true);
11151141
1116- return __hist_entry__tui_annotate (he , & he -> ms , evsel , hbt );
1142+ return __hist_entry__tui_annotate (he , & he -> ms , evsel , hbt , al_addr );
11171143}
11181144
11191145int __hist_entry__tui_annotate (struct hist_entry * he , struct map_symbol * ms ,
11201146 struct evsel * evsel ,
1121- struct hist_browser_timer * hbt )
1147+ struct hist_browser_timer * hbt , u64 al_addr )
11221148{
11231149 struct symbol * sym = ms -> sym ;
11241150 struct annotation * notes = symbol__annotation (sym );
@@ -1188,6 +1214,20 @@ int __hist_entry__tui_annotate(struct hist_entry *he, struct map_symbol *ms,
11881214 if (annotate_opts .hide_src_code )
11891215 ui_browser__init_asm_mode (& browser .b );
11901216
1217+ /*
1218+ * If al_addr is set, it means that there should be a line
1219+ * intentionally selected, not based on the percentages
1220+ * which caculated by the event sampling. In this case, we
1221+ * convey this information into the browser selection, where
1222+ * the selection in other cases should be empty.
1223+ */
1224+ if (al_addr != NO_ADDR ) {
1225+ struct annotation_line * al = annotated_source__get_line (notes -> src ,
1226+ al_addr - sym -> start );
1227+
1228+ browser .selection = al ;
1229+ }
1230+
11911231 ret = annotate_browser__run (& browser , evsel , hbt );
11921232
11931233 debuginfo__delete (browser .dbg );
0 commit comments