Fix bug in `expr_clone`
[platform/upstream/ltrace.git] / proc.c
diff --git a/proc.c b/proc.c
index 5385510..bf2a172 100644 (file)
--- a/proc.c
+++ b/proc.c
 #include "options.h"
 #include "proc.h"
 #include "value_dict.h"
-#include "dwarf_prototypes.h"
+
+#if defined(HAVE_LIBDW)
+# include "dwarf_prototypes.h"
+#endif /* defined(HAVE_LIBDW) */
 
 #ifndef OS_HAVE_PROCESS_DATA
 int
@@ -867,20 +870,43 @@ proc_activate_delayed_symbol(struct process *proc,
        return breakpoint_for_symbol(libsym, proc);
 }
 
+
+struct activate_latent_in_context
+{
+       struct process *proc;
+       struct library_exported_names *exported_names;
+};
+static enum callback_status
+activate_latent_in_cb(struct library_symbol *libsym, void *data)
+{
+       struct activate_latent_in_context *ctx =
+               (struct activate_latent_in_context*)data;
+
+       if (libsym->latent &&
+           library_exported_names_contains(ctx->exported_names,
+                                           libsym->name) != 0)
+               proc_activate_latent_symbol(ctx->proc, libsym);
+
+       return CBS_CONT;
+}
+
 static enum callback_status
 activate_latent_in(struct process *proc, struct library *lib, void *data)
 {
-       struct library_exported_name *exported;
-       for (exported = data; exported != NULL; exported = exported->next) {
-               struct library_symbol *libsym = NULL;
-               while ((libsym = library_each_symbol(lib, libsym,
-                                                    library_symbol_named_cb,
-                                                    (void *)exported->name))
-                      != NULL)
-                       if (libsym->latent
-                           && proc_activate_latent_symbol(proc, libsym) < 0)
-                               return CBS_FAIL;
-       }
+       struct library_symbol *libsym = NULL;
+
+       struct library_exported_names *exported_names =
+               (struct library_exported_names*)data;
+
+       struct activate_latent_in_context ctx =
+               {.proc = proc,
+                .exported_names = exported_names};
+
+       if (library_each_symbol(lib, libsym,
+                               activate_latent_in_cb,
+                               &ctx) != NULL)
+               return CBS_FAIL;
+
        return CBS_CONT;
 }
 
@@ -964,15 +990,19 @@ proc_add_library(struct process *proc, struct library *lib)
                        "Couldn't insert breakpoint for %s to %d: %s.\n",
                        libsym->name, proc->pid, strerror(errno));
 
-       /* Look through export list of the new library and compare it
-        * with latent symbols of all libraries (including this
-        * library itself).  */
-       struct library *lib2 = NULL;
-       while ((lib2 = proc_each_library(proc, lib2, activate_latent_in,
-                                        lib->exported_names)) != NULL)
-               fprintf(stderr,
-                       "Couldn't activate latent symbols for %s in %d: %s.\n",
-                       lib2->soname, proc->pid, strerror(errno));
+       if (lib->should_activate_latent != 0) {
+               /* Look through export list of the new library and compare it
+                * with latent symbols of all libraries (including this
+                * library itself).  */
+               struct library *lib2 = NULL;
+
+               while ((lib2 = proc_each_library(proc, lib2, activate_latent_in,
+                                                &lib->exported_names)) != NULL)
+                       fprintf(stderr,
+                               "Couldn't activate latent symbols "
+                               "for %s in %d: %s.\n",
+                               lib2->soname, proc->pid, strerror(errno));
+       }
 }
 
 int