Making sure to not double-examine the same DWARF CU
[platform/upstream/ltrace.git] / proc.c
diff --git a/proc.c b/proc.c
index 49c0b93..5385510 100644 (file)
--- a/proc.c
+++ b/proc.c
@@ -37,7 +37,6 @@
 #include "proc.h"
 #include "value_dict.h"
 #include "dwarf_prototypes.h"
-#include "filter.h"
 
 #ifndef OS_HAVE_PROCESS_DATA
 int
@@ -176,6 +175,7 @@ process_bare_init(struct process *proc, const char *filename,
 
 #if defined(HAVE_LIBDW)
        proc->dwfl = NULL; /* Initialize for leader only on first library.  */
+       proc->should_attach_dwfl = 1; /* should try to attach the DWFL data */
 #endif /* defined(HAVE_LIBDW) */
 
        return 0;
@@ -895,6 +895,7 @@ proc_add_library(struct process *proc, struct library *lib)
 
 #if defined(HAVE_LIBDW)
        Dwfl *dwfl = NULL;
+       Dwfl_Module *dwfl_module = NULL;
 
        /* Setup module tracking for libdwfl unwinding.  */
        struct process *leader = proc->leader;
@@ -907,31 +908,33 @@ proc_add_library(struct process *proc, struct library *lib)
                dwfl = dwfl_begin(&proc_callbacks);
                if (dwfl == NULL)
                        fprintf(stderr,
-                                       "Couldn't initialize libdwfl unwinding "
-                                       "for process %d: %s\n", leader->pid,
-                                       dwfl_errmsg (-1));
+                               "Couldn't initialize libdwfl unwinding "
+                               "for process %d: %s\n", leader->pid,
+                               dwfl_errmsg (-1));
        }
 
        if (dwfl != NULL) {
                dwfl_report_begin_add(dwfl);
-               if (dwfl_report_elf(dwfl, lib->soname,
-                                                       lib->pathname, -1,
-                                                       (GElf_Addr) lib->base,
-                                                       false) == NULL)
+               dwfl_module =
+                       dwfl_report_elf(dwfl, lib->soname,
+                                       lib->pathname, -1,
+                                       (GElf_Addr) lib->base,
+                                       false);
+               if (dwfl_module == NULL)
                        fprintf(stderr,
-                                       "dwfl_report_elf %s@%p (%s) %d: %s\n",
-                                       lib->soname, lib->base, lib->pathname,
-                                       proc->pid, dwfl_errmsg (-1));
+                               "dwfl_report_elf %s@%p (%s) %d: %s\n",
+                               lib->soname, lib->base, lib->pathname,
+                               proc->pid, dwfl_errmsg (-1));
+
                dwfl_report_end(dwfl, NULL, NULL);
 
                if (options.bt_depth > 0) {
-                       if (leader->dwfl == NULL) {
+                       if (proc->should_attach_dwfl) {
                                int r = dwfl_linux_proc_attach(dwfl,
                                                               leader->pid,
                                                               true);
-                               if (r == 0)
-                                       leader->dwfl = dwfl;
-                               else {
+                               proc->should_attach_dwfl = 0;
+                               if (r != 0) {
                                        const char *msg;
                                        dwfl_end(dwfl);
                                        if (r < 0)
@@ -939,21 +942,16 @@ proc_add_library(struct process *proc, struct library *lib)
                                        else
                                                msg = strerror(r);
                                        fprintf(stderr, "Couldn't initialize "
-                                               "libdwfl (for unwinding, prototype import) for "
-                                               "process %d: %s\n",
+                                               "libdwfl (unwinding, prototype "
+                                               "import) for process %d: %s\n",
                                                leader->pid, msg);
                                }
                        }
                }
        }
 
-       if( dwfl != NULL &&
-               ( filter_matches_library(options.plt_filter,    lib ) ||
-                 filter_matches_library(options.static_filter, lib ) ||
-                 filter_matches_library(options.export_filter, lib ) ) )
-       {
-               import_DWARF_prototypes( lib->protolib, lib, dwfl );
-       }
+       lib->dwfl_module = dwfl_module;
+       leader->dwfl = dwfl;
 
 #endif /* defined(HAVE_LIBDW) */