If -l is requested, keep latent PLT entries

That is, if a PLT entry doesn't match plt_filter, keep it around as latent
in case a library implementing this name is mapped in.
diff --git a/ChangeLog b/ChangeLog
index 772ea4e..8157273 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-09-28  Petr Machata  <pmachata@redhat.com>
+
+	* ltrace-elf.c (mark_chain_latent): New function.
+	(populate_plt): New argument LATENT_PLTS.
+	(ltelf_read_library): Update calls to populate_plt.
+
 2012-09-27  Petr Machata  <pmachata@redhat.com>
 
 	* ltrace-elf.c (populate_this_symtab): New argument NAMES.
diff --git a/ltrace-elf.c b/ltrace-elf.c
index efa989f..e20c2de 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -543,9 +543,19 @@
 }
 #endif
 
+static void
+mark_chain_latent(struct library_symbol *libsym)
+{
+	for (; libsym != NULL; libsym = libsym->next) {
+		debug(DEBUG_FUNCTION, "marking %s latent", libsym->name);
+		libsym->latent = 1;
+	}
+}
+
 static int
 populate_plt(struct Process *proc, const char *filename,
-	     struct ltelf *lte, struct library *lib)
+	     struct ltelf *lte, struct library *lib,
+	     int latent_plts)
 {
 	size_t i;
 	for (i = 0; i < lte->relplt_count; ++i) {
@@ -557,7 +567,12 @@
 
 		char const *name = lte->dynstr + sym.st_name;
 
-		if (!filter_matches_symbol(options.plt_filter, name, lib))
+		/* If the symbol wasn't matched, reject it, unless we
+		 * need to keep latent PLT breakpoints for tracing
+		 * exports.  */
+		int matched = filter_matches_symbol(options.plt_filter,
+						    name, lib);
+		if (!matched && !latent_plts)
 			continue;
 
 		struct library_symbol *libsym = NULL;
@@ -571,8 +586,14 @@
 				return -1;
 			/* fall-through */
 		case plt_ok:
-			if (libsym != NULL)
+			if (libsym != NULL) {
+				/* If we are adding those symbols just
+				 * for tracing exports, mark them all
+				 * latent.  */
+				if (!matched)
+					mark_chain_latent(libsym);
 				library_add_symbol(lib, libsym);
+			}
 		}
 	}
 	return 0;
@@ -851,7 +872,8 @@
 
 	int plts = filter_matches_library(options.plt_filter, lib);
 	if ((plts || options.export_filter != NULL)
-	    && populate_plt(proc, filename, &lte, lib) < 0)
+	    && populate_plt(proc, filename, &lte, lib,
+			    options.export_filter != NULL) < 0)
 		goto fail;
 
 	int exports = filter_matches_library(options.export_filter, lib);