aboutsummaryrefslogtreecommitdiff
path: root/filter.h
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-03-31 02:00:00 +0200
committerPetr Machata <pmachata@redhat.com>2012-04-19 01:35:44 +0200
commit1bbfbc6c6a7b7706bf4e8bf152d7ffc28453c3bd (patch)
tree2ea948384c010f7a56f0978807b9e749851a77de /filter.h
parent6a7997de9eabf9b0c6e32309ca08870198eb864b (diff)
downloadltrace-1bbfbc6c6a7b7706bf4e8bf152d7ffc28453c3bd.tar.gz
Add glob.c/.h, filter.c/.h
- these should be useful when implementing filtering expressions
Diffstat (limited to 'filter.h')
-rw-r--r--filter.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/filter.h b/filter.h
new file mode 100644
index 0000000..23ca382
--- /dev/null
+++ b/filter.h
@@ -0,0 +1,94 @@
+/*
+ * 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 name. */
+ FLM_NAME,
+ /* 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 based on LIBNAME_RE is owned and
+ * destroyed by MATCHER. */
+void filter_lib_matcher_name_init(struct filter_lib_matcher *matcher,
+ regex_t libname_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, struct library_symbol *sym);
+
+#endif /* FILTER_H */