Replace readdir_r with readdir
[platform/upstream/ltrace.git] / filter.h
1 /*
2  * This file is part of ltrace.
3  * Copyright (C) 2012 Petr Machata, Red Hat Inc.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  */
20
21 /* This file contains declarations and types for working with symbol
22  * filters.  */
23
24 #ifndef FILTER_H
25 #define FILTER_H
26
27 #include <sys/types.h>
28 #include <regex.h>
29
30 #include "forward.h"
31
32 enum filter_lib_matcher_type {
33         /* Match by soname.  */
34         FLM_SONAME,
35         /* Match by path name.  */
36         FLM_PATHNAME,
37         /* Match main binary.  */
38         FLM_MAIN,
39 };
40
41 struct filter_lib_matcher {
42         enum filter_lib_matcher_type type;
43         regex_t libname_re;
44 };
45
46 enum filter_rule_type {
47         FR_ADD,
48         FR_SUBTRACT,
49 };
50
51 struct filter_rule {
52         struct filter_rule *next;
53         struct filter_lib_matcher *lib_matcher;
54         regex_t symbol_re; /* Regex for matching symbol name.  */
55         enum filter_rule_type type;
56 };
57
58 struct filter {
59         struct filter *next;
60         struct filter_rule *rules;
61 };
62
63 void filter_init(struct filter *filt);
64 void filter_destroy(struct filter *filt);
65
66 /* Both SYMBOL_RE and MATCHER are owned and destroyed by RULE.  */
67 void filter_rule_init(struct filter_rule *rule, enum filter_rule_type type,
68                       struct filter_lib_matcher *matcher,
69                       regex_t symbol_re);
70
71 void filter_rule_destroy(struct filter_rule *rule);
72
73 /* RULE is added to FILT and owned and destroyed by it.  */
74 void filter_add_rule(struct filter *filt, struct filter_rule *rule);
75
76 /* Create a matcher that matches library name.  RE is owned and
77  * destroyed by MATCHER.  TYPE shall be FLM_SONAME or
78  * FLM_PATHNAME.  */
79 void filter_lib_matcher_name_init(struct filter_lib_matcher *matcher,
80                                   enum filter_lib_matcher_type type,
81                                   regex_t re);
82
83 /* Create a matcher that matches main binary.  */
84 void filter_lib_matcher_main_init(struct filter_lib_matcher *matcher);
85
86 void filter_lib_matcher_destroy(struct filter_lib_matcher *matcher);
87
88 /* Ask whether FILTER might match a symbol in LIB.  0 if no, non-0 if
89  * yes.  Note that positive answer doesn't mean that anything will
90  * actually be matched, just that potentially it could.  */
91 int filter_matches_library(struct filter *filt, struct library *lib);
92
93 /* Ask whether FILTER matches this symbol.  Returns 0 if it doesn't,
94  * or non-0 value if it does.  */
95 int filter_matches_symbol(struct filter *filt, const char *sym_name,
96                           struct library *lib);
97
98 #endif /* FILTER_H */