File: filter.h

package info (click to toggle)
ltrace 0.7.3-4
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,908 kB
  • ctags: 2,421
  • sloc: ansic: 22,862; sh: 10,956; exp: 1,498; makefile: 375; cpp: 196; awk: 88; asm: 40; perl: 24
file content (99 lines) | stat: -rw-r--r-- 2,989 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * This file is part of ltrace.
 * Copyright (C) 2012 Petr Machata, Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

/* This file contains declarations and types for working with symbol
 * filters.  */

#ifndef FILTER_H
#define FILTER_H

#include <sys/types.h>
#include <regex.h>

struct library;
struct library_symbol;

enum filter_lib_matcher_type {
	/* Match by soname.  */
	FLM_SONAME,
	/* Match by path name.  */
	FLM_PATHNAME,
	/* Match main binary.  */
	FLM_MAIN,
};

struct filter_lib_matcher {
	enum filter_lib_matcher_type type;
	regex_t libname_re;
};

enum filter_rule_type {
	FR_ADD,
	FR_SUBTRACT,
};

struct filter_rule {
	struct filter_rule *next;
	struct filter_lib_matcher *lib_matcher;
	regex_t symbol_re; /* Regex for matching symbol name.  */
	enum filter_rule_type type;
};

struct filter {
	struct filter *next;
	struct filter_rule *rules;
};

void filter_init(struct filter *filt);
void filter_destroy(struct filter *filt);

/* Both SYMBOL_RE and MATCHER are owned and destroyed by RULE.  */
void filter_rule_init(struct filter_rule *rule, enum filter_rule_type type,
		      struct filter_lib_matcher *matcher,
		      regex_t symbol_re);

void filter_rule_destroy(struct filter_rule *rule);

/* RULE is added to FILT and owned and destroyed by it.  */
void filter_add_rule(struct filter *filt, struct filter_rule *rule);

/* Create a matcher that matches library name.  RE is owned and
 * destroyed by MATCHER.  TYPE shall be FLM_SONAME or
 * FLM_PATHNAME.  */
void filter_lib_matcher_name_init(struct filter_lib_matcher *matcher,
				  enum filter_lib_matcher_type type,
				  regex_t re);

/* Create a matcher that matches main binary.  */
void filter_lib_matcher_main_init(struct filter_lib_matcher *matcher);

void filter_lib_matcher_destroy(struct filter_lib_matcher *matcher);

/* Ask whether FILTER might match a symbol in LIB.  0 if no, non-0 if
 * yes.  Note that positive answer doesn't mean that anything will
 * actually be matched, just that potentially it could.  */
int filter_matches_library(struct filter *filt, struct library *lib);

/* Ask whether FILTER matches this symbol.  Returns 0 if it doesn't,
 * or non-0 value if it does.  */
int filter_matches_symbol(struct filter *filt, const char *sym_name,
			  struct library *lib);

#endif /* FILTER_H */