@@ -384,10 +384,17 @@ static bool match_pattern_module(char *pathname)
384
384
return ret ;
385
385
}
386
386
387
- static bool match_pattern_list (struct uftrace_mmap * map , char * soname , char * sym_name )
387
+ /**
388
+ * match_pattern_list - match a symbol name against a pattern list
389
+ * @map - memory map of the symbol
390
+ * @soname - name of the module
391
+ * @sym_name - name of the symbol
392
+ * @return - -1 if match negative, 1 if match positive, 0 if no match
393
+ */
394
+ static int match_pattern_list (struct uftrace_mmap * map , char * soname , char * sym_name )
388
395
{
389
396
struct patt_list * pl ;
390
- bool ret = false ;
397
+ int ret = 0 ;
391
398
char * libname = basename (map -> libname );
392
399
393
400
list_for_each_entry (pl , & patterns , list ) {
@@ -398,7 +405,7 @@ static bool match_pattern_list(struct uftrace_mmap *map, char *soname, char *sym
398
405
continue ;
399
406
400
407
if (match_filter_pattern (& pl -> patt , sym_name ))
401
- ret = pl -> positive ;
408
+ ret = pl -> positive ? 1 : -1 ;
402
409
}
403
410
404
411
return ret ;
@@ -410,7 +417,6 @@ static void parse_pattern_list(char *patch_funcs, char *def_mod, enum uftrace_pa
410
417
char * name ;
411
418
int j ;
412
419
struct patt_list * pl ;
413
- bool all_negative = true;
414
420
415
421
strv_split (& funcs , patch_funcs , ";" );
416
422
@@ -421,10 +427,8 @@ static void parse_pattern_list(char *patch_funcs, char *def_mod, enum uftrace_pa
421
427
422
428
if (name [0 ] == '!' )
423
429
name ++ ;
424
- else {
430
+ else
425
431
pl -> positive = true;
426
- all_negative = false;
427
- }
428
432
429
433
delim = strchr (name , '@' );
430
434
if (delim == NULL ) {
@@ -439,20 +443,6 @@ static void parse_pattern_list(char *patch_funcs, char *def_mod, enum uftrace_pa
439
443
list_add_tail (& pl -> list , & patterns );
440
444
}
441
445
442
- /* prepend match-all pattern, if all patterns are negative */
443
- if (all_negative ) {
444
- pl = xzalloc (sizeof (* pl ));
445
- pl -> positive = true;
446
- pl -> module = xstrdup (def_mod );
447
-
448
- if (ptype == PATT_REGEX )
449
- init_filter_pattern (ptype , & pl -> patt , "." );
450
- else
451
- init_filter_pattern (PATT_GLOB , & pl -> patt , "*" );
452
-
453
- list_add (& pl -> list , & patterns );
454
- }
455
-
456
446
strv_free (& funcs );
457
447
}
458
448
@@ -487,12 +477,6 @@ static bool skip_sym(struct uftrace_symbol *sym, struct mcount_dynamic_info *mdi
487
477
if (sym -> type != ST_LOCAL_FUNC && sym -> type != ST_GLOBAL_FUNC && sym -> type != ST_WEAK_FUNC )
488
478
return true;
489
479
490
- if (!match_pattern_list (map , soname , sym -> name )) {
491
- if (mcount_unpatch_func (mdi , sym , & disasm ) == 0 )
492
- stats .unpatch ++ ;
493
- return true;
494
- }
495
-
496
480
return false;
497
481
}
498
482
@@ -559,6 +543,7 @@ static void patch_normal_func_matched(struct mcount_dynamic_info *mdi, struct uf
559
543
unsigned i ;
560
544
struct uftrace_symbol * sym ;
561
545
bool found = false;
546
+ int match ;
562
547
char * soname = get_soname (map -> libname );
563
548
564
549
symtab = & map -> mod -> symtab ;
@@ -568,9 +553,15 @@ static void patch_normal_func_matched(struct mcount_dynamic_info *mdi, struct uf
568
553
569
554
if (skip_sym (sym , mdi , map , soname ))
570
555
continue ;
571
-
572
556
found = true;
573
- mcount_patch_func_with_stats (mdi , sym );
557
+
558
+ match = match_pattern_list (map , soname , sym -> name );
559
+ if (!match )
560
+ continue ;
561
+ else if (match == 1 )
562
+ mcount_patch_func_with_stats (mdi , sym );
563
+ else
564
+ mcount_unpatch_func (mdi , sym , NULL );
574
565
}
575
566
576
567
if (!found )
@@ -846,27 +837,27 @@ TEST_CASE(dynamic_pattern_list)
846
837
pr_dbg ("check simple match with default module\n" );
847
838
parse_pattern_list ("abc;!def" , "main" , PATT_SIMPLE );
848
839
849
- TEST_EQ (match_pattern_list (main_map , NULL , "abc" ), true );
850
- TEST_EQ (match_pattern_list (main_map , NULL , "def" ), false );
851
- TEST_EQ (match_pattern_list (other_map , NULL , "xyz" ), false );
840
+ TEST_EQ (match_pattern_list (main_map , NULL , "abc" ), 1 );
841
+ TEST_EQ (match_pattern_list (main_map , NULL , "def" ), -1 );
842
+ TEST_EQ (match_pattern_list (other_map , NULL , "xyz" ), 0 );
852
843
853
844
release_pattern_list ();
854
845
855
846
pr_dbg ("check negative regex match with default module\n" );
856
847
parse_pattern_list ("!^a" , "main" , PATT_REGEX );
857
848
858
- TEST_EQ (match_pattern_list (main_map , NULL , "abc" ), false );
859
- TEST_EQ (match_pattern_list (main_map , NULL , "def" ), true );
860
- TEST_EQ (match_pattern_list (other_map , NULL , "xyz" ), false );
849
+ TEST_EQ (match_pattern_list (main_map , NULL , "abc" ), -1 );
850
+ TEST_EQ (match_pattern_list (main_map , NULL , "def" ), 0 );
851
+ TEST_EQ (match_pattern_list (other_map , NULL , "xyz" ), 0 );
861
852
862
853
release_pattern_list ();
863
854
864
855
pr_dbg ("check wildcard match with other module\n" );
865
856
parse_pattern_list ("*@other" , "main" , PATT_GLOB );
866
857
867
- TEST_EQ (match_pattern_list (main_map , NULL , "abc" ), false );
868
- TEST_EQ (match_pattern_list (main_map , NULL , "def" ), false );
869
- TEST_EQ (match_pattern_list (other_map , NULL , "xyz" ), true );
858
+ TEST_EQ (match_pattern_list (main_map , NULL , "abc" ), 0 );
859
+ TEST_EQ (match_pattern_list (main_map , NULL , "def" ), 0 );
860
+ TEST_EQ (match_pattern_list (other_map , NULL , "xyz" ), 1 );
870
861
871
862
release_pattern_list ();
872
863
0 commit comments