65c575a92835bab3fc8ed4ed612d6593de517455
[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 struct library;
31 struct library_symbol;
32
33 enum filter_lib_matcher_type {
34         /* Match by soname.  */
35         FLM_SONAME,
36         /* Match by path name.  */
37         FLM_PATHNAME,
38         /* Match main binary.  */
39         FLM_MAIN,
40 };
41
42 struct filter_lib_matcher {
43         enum filter_lib_matcher_type type;
44         regex_t libname_re;
45 };
46
47 enum filter_rule_type {
48         FR_ADD,
49         FR_SUBTRACT,
50 };
51
52 struct filter_rule {
53         struct filter_rule *next;
54         struct filter_lib_matcher *lib_matcher;
55         regex_t symbol_re; /* Regex for matching symbol name.  */
56         enum filter_rule_type type;
57 };
58
59 struct filter {
60         struct filter *next;
61         struct filter_rule *rules;
62 };
63
64 void filter_init(struct filter *filt);
65 void filter_destroy(struct filter *filt);
66
67 /* Both SYMBOL_RE and MATCHER are owned and destroyed by RULE.  */
68 void filter_rule_init(struct filter_rule *rule, enum filter_rule_type type,
69                       struct filter_lib_matcher *matcher,
70                       regex_t symbol_re);
71
72 void filter_rule_destroy(struct filter_rule *rule);
73
74 /* RULE is added to FILT and owned and destroyed by it.  */
75 void filter_add_rule(struct filter *filt, struct filter_rule *rule);
76
77 /* Create a matcher that matches library name.  RE is owned and
78  * destroyed by MATCHER.  TYPE shall be FLM_SONAME or
79  * FLM_PATHNAME.  */
80 void filter_lib_matcher_name_init(struct filter_lib_matcher *matcher,
81                                   enum filter_lib_matcher_type type,
82                                   regex_t re);
83
84 /* Create a matcher that matches main binary.  */
85 void filter_lib_matcher_main_init(struct filter_lib_matcher *matcher);
86
87 void filter_lib_matcher_destroy(struct filter_lib_matcher *matcher);
88
89 /* Ask whether FILTER might match a symbol in LIB.  0 if no, non-0 if
90  * yes.  Note that positive answer doesn't mean that anything will
91  * actually be matched, just that potentially it could.  */
92 int filter_matches_library(struct filter *filt, struct library *lib);
93
94 /* Ask whether FILTER matches this symbol.  Returns 0 if it doesn't,
95  * or non-0 value if it does.  */
96 int filter_matches_symbol(struct filter *filt, const char *sym_name,
97                           struct library *lib);
98
99 #endif /* FILTER_H */