@@ -21,6 +21,8 @@ struct annotate_browser {
21
21
int nr_entries ;
22
22
bool hide_src_code ;
23
23
bool use_offset ;
24
+ bool searching_backwards ;
25
+ char search_bf [128 ];
24
26
};
25
27
26
28
struct objdump_line_rb_node {
@@ -176,6 +178,7 @@ static void annotate_browser__set_top(struct annotate_browser *self,
176
178
}
177
179
178
180
self -> b .top = pos ;
181
+ self -> b .navkeypressed = true;
179
182
}
180
183
181
184
static void annotate_browser__set_rb_top (struct annotate_browser * browser ,
@@ -354,6 +357,132 @@ static bool annotate_browser__jump(struct annotate_browser *browser)
354
357
return true;
355
358
}
356
359
360
+ static struct objdump_line *
361
+ annotate_browser__find_string (struct annotate_browser * browser ,
362
+ char * s , s64 * idx )
363
+ {
364
+ struct map_symbol * ms = browser -> b .priv ;
365
+ struct symbol * sym = ms -> sym ;
366
+ struct annotation * notes = symbol__annotation (sym );
367
+ struct objdump_line * pos = browser -> selection ;
368
+
369
+ * idx = browser -> b .index ;
370
+ list_for_each_entry_continue (pos , & notes -> src -> source , node ) {
371
+ if (objdump_line__filter (& browser -> b , & pos -> node ))
372
+ continue ;
373
+
374
+ ++ * idx ;
375
+
376
+ if (pos -> line && strstr (pos -> line , s ) != NULL )
377
+ return pos ;
378
+ }
379
+
380
+ return NULL ;
381
+ }
382
+
383
+ static bool __annotate_browser__search (struct annotate_browser * browser )
384
+ {
385
+ struct objdump_line * line ;
386
+ s64 idx ;
387
+
388
+ line = annotate_browser__find_string (browser , browser -> search_bf , & idx );
389
+ if (line == NULL ) {
390
+ ui_helpline__puts ("String not found!" );
391
+ return false;
392
+ }
393
+
394
+ annotate_browser__set_top (browser , line , idx );
395
+ browser -> searching_backwards = false;
396
+ return true;
397
+ }
398
+
399
+ static struct objdump_line *
400
+ annotate_browser__find_string_reverse (struct annotate_browser * browser ,
401
+ char * s , s64 * idx )
402
+ {
403
+ struct map_symbol * ms = browser -> b .priv ;
404
+ struct symbol * sym = ms -> sym ;
405
+ struct annotation * notes = symbol__annotation (sym );
406
+ struct objdump_line * pos = browser -> selection ;
407
+
408
+ * idx = browser -> b .index ;
409
+ list_for_each_entry_continue_reverse (pos , & notes -> src -> source , node ) {
410
+ if (objdump_line__filter (& browser -> b , & pos -> node ))
411
+ continue ;
412
+
413
+ -- * idx ;
414
+
415
+ if (pos -> line && strstr (pos -> line , s ) != NULL )
416
+ return pos ;
417
+ }
418
+
419
+ return NULL ;
420
+ }
421
+
422
+ static bool __annotate_browser__search_reverse (struct annotate_browser * browser )
423
+ {
424
+ struct objdump_line * line ;
425
+ s64 idx ;
426
+
427
+ line = annotate_browser__find_string_reverse (browser , browser -> search_bf , & idx );
428
+ if (line == NULL ) {
429
+ ui_helpline__puts ("String not found!" );
430
+ return false;
431
+ }
432
+
433
+ annotate_browser__set_top (browser , line , idx );
434
+ browser -> searching_backwards = true;
435
+ return true;
436
+ }
437
+
438
+ static bool annotate_browser__search_window (struct annotate_browser * browser ,
439
+ int delay_secs )
440
+ {
441
+ if (ui_browser__input_window ("Search" , "String: " , browser -> search_bf ,
442
+ "ENTER: OK, ESC: Cancel" ,
443
+ delay_secs * 2 ) != K_ENTER ||
444
+ !* browser -> search_bf )
445
+ return false;
446
+
447
+ return true;
448
+ }
449
+
450
+ static bool annotate_browser__search (struct annotate_browser * browser , int delay_secs )
451
+ {
452
+ if (annotate_browser__search_window (browser , delay_secs ))
453
+ return __annotate_browser__search (browser );
454
+
455
+ return false;
456
+ }
457
+
458
+ static bool annotate_browser__continue_search (struct annotate_browser * browser ,
459
+ int delay_secs )
460
+ {
461
+ if (!* browser -> search_bf )
462
+ return annotate_browser__search (browser , delay_secs );
463
+
464
+ return __annotate_browser__search (browser );
465
+ }
466
+
467
+ static bool annotate_browser__search_reverse (struct annotate_browser * browser ,
468
+ int delay_secs )
469
+ {
470
+ if (annotate_browser__search_window (browser , delay_secs ))
471
+ return __annotate_browser__search_reverse (browser );
472
+
473
+ return false;
474
+ }
475
+
476
+ static
477
+ bool annotate_browser__continue_search_reverse (struct annotate_browser * browser ,
478
+ int delay_secs )
479
+ {
480
+ if (!* browser -> search_bf )
481
+ return annotate_browser__search_reverse (browser , delay_secs );
482
+
483
+ return __annotate_browser__search_reverse (browser );
484
+ }
485
+
357
486
static int annotate_browser__run (struct annotate_browser * self , int evidx ,
358
487
void (* timer )(void * arg ),
359
488
void * arg , int delay_secs )
@@ -372,8 +501,10 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
372
501
373
502
annotate_browser__calc_percent (self , evidx );
374
503
375
- if (self -> curr_hot )
504
+ if (self -> curr_hot ) {
376
505
annotate_browser__set_rb_top (self , self -> curr_hot );
506
+ self -> b .navkeypressed = false;
507
+ }
377
508
378
509
nd = self -> curr_hot ;
379
510
@@ -428,6 +559,22 @@ static int annotate_browser__run(struct annotate_browser *self, int evidx,
428
559
case 'o' :
429
560
self -> use_offset = !self -> use_offset ;
430
561
continue ;
562
+ case '/' :
563
+ if (annotate_browser__search (self , delay_secs )) {
564
+ show_help :
565
+ ui_helpline__puts (help );
566
+ }
567
+ continue ;
568
+ case 'n' :
569
+ if (self -> searching_backwards ?
570
+ annotate_browser__continue_search_reverse (self , delay_secs ) :
571
+ annotate_browser__continue_search (self , delay_secs ))
572
+ goto show_help ;
573
+ continue ;
574
+ case '?' :
575
+ if (annotate_browser__search_reverse (self , delay_secs ))
576
+ goto show_help ;
577
+ continue ;
431
578
case K_ENTER :
432
579
case K_RIGHT :
433
580
if (self -> selection == NULL )
0 commit comments