Fix bugs in filter code, enable filtering according to -e setting
diff --git a/options.c b/options.c
index d77fbd0..4f026ea 100644
--- a/options.c
+++ b/options.c
@@ -208,7 +208,7 @@
 	}
 
 	regex_t lib_re;
-	status = (lib_re_p ? regcomp : globcomp)(&lib_re, sym, 0);
+	status = (lib_re_p ? regcomp : globcomp)(&lib_re, lib, 0);
 	if (status != 0) {
 		char buf[100];
 		regerror(status, &lib_re, buf, sizeof buf);
@@ -220,6 +220,7 @@
 
 	filter_lib_matcher_name_init(matcher, lib_re);
 	filter_rule_init(rule, type, matcher, symbol_re);
+	filter_add_rule(filt, rule);
 }
 
 static int
@@ -382,7 +383,7 @@
 }
 
 static void
-parse_chain(struct options_t *options, const char *expr)
+parse_filter_chain(struct options_t *options, const char *expr)
 {
 	char *str = strdup(expr);
 	if (str == NULL) {
@@ -471,7 +472,7 @@
 			break;
 
 		case 'e':
-			parse_chain(&options, optarg);
+			parse_filter_chain(&options, optarg);
 			break;
 
 		case 'f':
@@ -627,6 +628,9 @@
 		opt_F = egg;
 	}
 
+	if (options.filter == NULL)
+		parse_filter_chain(&options, "*");
+
 	if (!opt_p && argc < 1) {
 		fprintf(stderr, "%s: too few arguments\n", progname);
 		err_usage();
diff --git a/proc.c b/proc.c
index 46d7b7c..8fc4cae 100644
--- a/proc.c
+++ b/proc.c
@@ -16,6 +16,7 @@
 #include "common.h"
 #include "breakpoint.h"
 #include "proc.h"
+#include "filter.h"
 
 static int
 process_bare_init(struct Process *proc, const char *filename, pid_t pid)
@@ -485,9 +486,9 @@
 breakpoint_for_symbol(struct library_symbol *libsym, void *data)
 {
 	struct Process *proc = data;
-	fprintf(stderr, "  %s@%p\n", libsym->name, libsym->enter_addr);
 
-	if (insert_breakpoint(proc, libsym->enter_addr, libsym) == NULL)
+	if (filter_matches_symbol(options.filter, libsym)
+	    && insert_breakpoint(proc, libsym->enter_addr, libsym) == NULL)
 		return CBS_STOP;
 
 	return CBS_CONT;
@@ -502,6 +503,9 @@
 	fprintf(stderr, "=== Added library %s@%p to %d:\n",
 		lib->name, lib->base, proc->pid);
 
+	if (!filter_matches_library(options.filter, lib))
+		return;
+
 	struct library_symbol *libsym = NULL;
 	while ((libsym = library_each_symbol(lib, libsym, breakpoint_for_symbol,
 					     proc)) != NULL)