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