Add library load/unload tracking events
[deliverable/lttng-ust.git] / liblttng-ust-dl / lttng-ust-dl.c
index d6b807149861415e30212a5ca72100dfef8db4c7..81b5bec470ad91dda754776220b9f5bb9435cf3d 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2013  Paul Woegerer <paul.woegerer@mentor.com>
  * Copyright (C) 2015  Antoine Busque <abusque@efficios.com>
+ * Copyright (C) 2016  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,9 +18,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
-#define _LGPL_SOURCE
 #define _GNU_SOURCE
-
+#define _LGPL_SOURCE
 #include <limits.h>
 #include <stdio.h>
 #include <sys/types.h>
@@ -27,6 +27,8 @@
 
 #include <lttng/ust-dlfcn.h>
 #include <lttng/ust-elf.h>
+#include <lttng/ust-events.h>
+#include <helper.h>
 #include "usterr-signal-safe.h"
 
 /* Include link.h last else it conflicts with ust-dlfcn. */
@@ -70,9 +72,9 @@ void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip)
        char resolved_path[PATH_MAX];
        struct lttng_ust_elf *elf;
        uint64_t memsz;
-       uint8_t *build_id;
+       uint8_t *build_id = NULL;
        size_t build_id_len;
-       char *dbg_file;
+       char *dbg_file = NULL;
        uint32_t crc;
        int has_build_id = 0, has_debug_link = 0;
        int ret;
@@ -104,21 +106,22 @@ void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip)
        }
 
        tracepoint(lttng_ust_dl, dlopen,
-               ip, so_base, resolved_path, memsz);
+               ip, so_base, resolved_path, memsz,
+               has_build_id, has_debug_link);
 
        if (has_build_id) {
                tracepoint(lttng_ust_dl, build_id,
                        ip, so_base, build_id, build_id_len);
-               free(build_id);
        }
 
        if (has_debug_link) {
                tracepoint(lttng_ust_dl, debug_link,
                        ip, so_base, dbg_file, crc);
-               free(dbg_file);
        }
 
 end:
+       free(dbg_file);
+       free(build_id);
        lttng_ust_elf_destroy(elf);
        return;
 }
@@ -134,27 +137,30 @@ void *dlopen(const char *filename, int flag)
 
                ret = dlinfo(handle, RTLD_DI_LINKMAP, &p);
                if (ret != -1 && p != NULL && p->l_addr != 0) {
-                       lttng_ust_dl_dlopen((void *) p->l_addr, p->l_name,
-                               __builtin_return_address(0));
+                       lttng_ust_dl_dlopen((void *) p->l_addr,
+                               p->l_name,
+                               LTTNG_UST_CALLER_IP());
                }
        }
-
+       lttng_ust_dl_update(LTTNG_UST_CALLER_IP());
        return handle;
 }
 
 int dlclose(void *handle)
 {
-       if (__tracepoint_ptrs_registered && handle) {
+       int ret;
+
+       if (__tracepoint_ptrs_registered) {
                struct link_map *p = NULL;
-               int ret;
 
                ret = dlinfo(handle, RTLD_DI_LINKMAP, &p);
                if (ret != -1 && p != NULL && p->l_addr != 0) {
                        tracepoint(lttng_ust_dl, dlclose,
-                               __builtin_return_address(0),
+                               LTTNG_UST_CALLER_IP(),
                                (void *) p->l_addr);
                }
        }
-
-       return _lttng_ust_dl_libc_dlclose(handle);
+       ret = _lttng_ust_dl_libc_dlclose(handle);
+       lttng_ust_dl_update(LTTNG_UST_CALLER_IP());
+       return ret;
 }
This page took 0.026484 seconds and 5 git commands to generate.