Integrate base-address statedump into lttng-ust
authorPaul Woegerer <paul_woegerer@mentor.com>
Thu, 28 Nov 2013 12:26:52 +0000 (13:26 +0100)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 28 Nov 2013 15:32:53 +0000 (16:32 +0100)
Signed-off-by: Paul Woegerer <paul_woegerer@mentor.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 files changed:
Makefile.am
liblttng-ust-baddr/Makefile.am
liblttng-ust-baddr/lttng-ust-baddr.c
liblttng-ust-baddr/lttng-ust-baddr.h [new file with mode: 0644]
liblttng-ust-baddr/ust_baddr.c [deleted file]
liblttng-ust-baddr/ust_baddr.h [deleted file]
liblttng-ust-dl/Makefile.am
liblttng-ust-dl/ust_baddr.c [new file with mode: 0644]
liblttng-ust-dl/ust_baddr.h [new file with mode: 0644]
liblttng-ust-dl/ustdl.c
liblttng-ust/Makefile.am
liblttng-ust/lttng-ust-comm.c

index 10b54cb4191805f99a9489aa6e638daaeb3c65ca..6fab95641fab971faf950728300ddae5cadedc3b 100644 (file)
@@ -1,10 +1,9 @@
 ACLOCAL_AMFLAGS = -I config
 
-SUBDIRS = . include snprintf libringbuffer liblttng-ust-comm \
+SUBDIRS = . include snprintf libringbuffer liblttng-ust-comm liblttng-ust-baddr \
                liblttng-ust \
                liblttng-ust-ctl \
                liblttng-ust-fork \
-               liblttng-ust-baddr \
                liblttng-ust-dl \
                liblttng-ust-libc-wrapper \
                liblttng-ust-cyg-profile \
index 0d3cf28911d68c0eb8302729e2b4fdf298bf2a57..cdbc0c1ef0a728795005154d8e937aa9a4062d46 100644 (file)
@@ -1,20 +1,9 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
-lib_LTLIBRARIES = liblttng-ust-baddr.la
+noinst_LTLIBRARIES = liblttng-ust-baddr.la
+
 liblttng_ust_baddr_la_SOURCES = \
        lttng-ust-baddr.c \
-       ust_baddr.c \
-       ust_baddr.h \
        ust_baddr_statedump.c \
        ust_baddr_statedump.h
-liblttng_ust_baddr_la_LIBADD = \
-       -L$(top_builddir)/liblttng-ust/.libs \
-       -llttng-ust
-
-if LTTNG_UST_BUILD_WITH_LIBDL
-liblttng_ust_baddr_la_LIBADD += -ldl
-endif
-if LTTNG_UST_BUILD_WITH_LIBC_DL
-liblttng_ust_baddr_la_LIBADD += -lc
-endif
index a8569656bce804de5ea1369012ba42b3a4b0d19d..841223349a146e3c5f1d821dab92c5abc20bfecb 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include "usterr.h"
 
+#include "lttng-ust-baddr.h"
+
 #define TRACEPOINT_DEFINE
-#include "ust_baddr.h"
 #include "ust_baddr_statedump.h"
 
-int
-lttng_ust_push_baddr(void *so_base, const char *so_name)
-{
-       char resolved_path[PATH_MAX];
-       struct stat sostat;
-
-       if (!realpath(so_name, resolved_path)) {
-               ERR("could not resolve path '%s'", so_name);
-               return 0;
-       }
-
-       if (stat(resolved_path, &sostat)) {
-               ERR("could not access file status for %s", resolved_path);
-               return 0;
-       }
-
-       tracepoint(ust_baddr, push,
-               so_base, resolved_path, sostat.st_size, sostat.st_mtime);
-       return 0;
-}
-
-int
-lttng_ust_pop_baddr(void *so_base)
-{
-       tracepoint(ust_baddr, pop, so_base);
-       return 0;
-}
-
 static int
 extract_soinfo_events(struct dl_phdr_info *info, size_t size, void *data)
 {
diff --git a/liblttng-ust-baddr/lttng-ust-baddr.h b/liblttng-ust-baddr/lttng-ust-baddr.h
new file mode 100644 (file)
index 0000000..d338541
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef LTTNG_UST_BADDR_H
+#define LTTNG_UST_BADDR_H
+
+/*
+ * Copyright (C) 2013  Paul Woegerer <paul_woegerer@mentor.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <lttng/ust-events.h>
+
+int lttng_ust_baddr_statedump(struct lttng_session *session);
+
+#endif /* LTTNG_UST_BADDR_H */
diff --git a/liblttng-ust-baddr/ust_baddr.c b/liblttng-ust-baddr/ust_baddr.c
deleted file mode 100644 (file)
index bfbb7bf..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (C) 2013  Paul Woegerer <paul_woegerer@mentor.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
- */
-
-#define TRACEPOINT_CREATE_PROBES
-#include "ust_baddr.h"
diff --git a/liblttng-ust-baddr/ust_baddr.h b/liblttng-ust-baddr/ust_baddr.h
deleted file mode 100644 (file)
index 2c757f7..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#undef TRACEPOINT_PROVIDER
-#define TRACEPOINT_PROVIDER ust_baddr
-
-#if !defined(_TRACEPOINT_UST_BADDR_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
-#define _TRACEPOINT_UST_BADDR_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Copyright (C) 2013  Paul Woegerer <paul_woegerer@mentor.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <stdint.h>
-#include <unistd.h>
-
-#define LTTNG_UST_BADDR_PROVIDER
-#include <lttng/tracepoint.h>
-
-TRACEPOINT_EVENT(ust_baddr, push,
-       TP_ARGS(void *, baddr, const char*, sopath, int64_t, size, int64_t, mtime),
-       TP_FIELDS(
-               ctf_integer_hex(void *, baddr, baddr)
-               ctf_string(sopath, sopath)
-               ctf_integer(int64_t, size, size)
-               ctf_integer(int64_t, mtime, mtime)
-       )
-)
-
-TRACEPOINT_EVENT(ust_baddr, pop,
-       TP_ARGS(void *, baddr),
-       TP_FIELDS(
-               ctf_integer_hex(void *, baddr, baddr)
-       )
-)
-
-#endif /* _TRACEPOINT_UST_BADDR_H */
-
-#undef TRACEPOINT_INCLUDE
-#define TRACEPOINT_INCLUDE "./ust_baddr.h"
-
-/* This part must be outside ifdef protection */
-#include <lttng/tracepoint-event.h>
-
-#ifdef __cplusplus
-}
-#endif
index c408fddb35f10845d503a08c02e6dbc67c862d03..352f1452f92fe87a5a95b051704d09c68c4c1f62 100644 (file)
@@ -2,7 +2,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
 AM_CFLAGS = -fno-strict-aliasing
 
 lib_LTLIBRARIES = liblttng-ust-dl.la
-liblttng_ust_dl_la_SOURCES = ustdl.c
+liblttng_ust_dl_la_SOURCES = \
+       ustdl.c \
+       ust_baddr.c \
+       ust_baddr.h
 liblttng_ust_dl_la_LIBADD = \
        $(top_builddir)/liblttng-ust/liblttng-ust.la
 
diff --git a/liblttng-ust-dl/ust_baddr.c b/liblttng-ust-dl/ust_baddr.c
new file mode 100644 (file)
index 0000000..bfbb7bf
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2013  Paul Woegerer <paul_woegerer@mentor.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_baddr.h"
diff --git a/liblttng-ust-dl/ust_baddr.h b/liblttng-ust-dl/ust_baddr.h
new file mode 100644 (file)
index 0000000..2c757f7
--- /dev/null
@@ -0,0 +1,66 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_baddr
+
+#if !defined(_TRACEPOINT_UST_BADDR_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_BADDR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2013  Paul Woegerer <paul_woegerer@mentor.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <unistd.h>
+
+#define LTTNG_UST_BADDR_PROVIDER
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_baddr, push,
+       TP_ARGS(void *, baddr, const char*, sopath, int64_t, size, int64_t, mtime),
+       TP_FIELDS(
+               ctf_integer_hex(void *, baddr, baddr)
+               ctf_string(sopath, sopath)
+               ctf_integer(int64_t, size, size)
+               ctf_integer(int64_t, mtime, mtime)
+       )
+)
+
+TRACEPOINT_EVENT(ust_baddr, pop,
+       TP_ARGS(void *, baddr),
+       TP_FIELDS(
+               ctf_integer_hex(void *, baddr, baddr)
+       )
+)
+
+#endif /* _TRACEPOINT_UST_BADDR_H */
+
+#undef TRACEPOINT_INCLUDE
+#define TRACEPOINT_INCLUDE "./ust_baddr.h"
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
index 8baf9ee3ca2f58ab84bc0a8a8fcc55bfda2c4e25..dbde8b7fedd9976d7f4f28619c58d0c16afe3e3c 100644 (file)
@@ -22,6 +22,9 @@
 #include <link.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <signal.h>
 #include <sched.h>
 #include <stdarg.h>
 #include <lttng/ust-compiler.h>
 #include <lttng/ust.h>
 
+#define TRACEPOINT_DEFINE
+#include "ust_baddr.h"
+
 static void *(*__lttng_ust_plibc_dlopen)(const char *filename, int flag);
 static int (*__lttng_ust_plibc_dlclose)(void *handle);
-static void *__lttng_ust_baddr_handle;
 
 static
 void *_lttng_ust_dl_libc_dlopen(const char *filename, int flag)
@@ -61,53 +66,24 @@ int _lttng_ust_dl_libc_dlclose(void *handle)
 }
 
 static
-void *lttng_ust_baddr_handle(void)
+void lttng_ust_baddr_push(void *so_base, const char *so_name)
 {
-       if (!__lttng_ust_baddr_handle) {
-               __lttng_ust_baddr_handle = _lttng_ust_dl_libc_dlopen(
-                       "liblttng-ust-baddr.so.0", RTLD_NOW | RTLD_GLOBAL);
-               if (__lttng_ust_baddr_handle == NULL)
-                       fprintf(stderr, "%s\n", dlerror());
-       }
-       return __lttng_ust_baddr_handle;
-}
+       char resolved_path[PATH_MAX];
+       struct stat sostat;
 
-static
-int lttng_ust_baddr_push(void *so_base, const char *so_name)
-{
-       static int
-       (*lttng_ust_baddr_push_fn)(void *so_base, const char *so_name);
-       if (!lttng_ust_baddr_push_fn) {
-               void *baddr_handle = lttng_ust_baddr_handle();
-               if (baddr_handle) {
-                       lttng_ust_baddr_push_fn = dlsym(baddr_handle,
-                               "lttng_ust_push_baddr");
-                       if (lttng_ust_baddr_push_fn == NULL)
-                               fprintf(stderr, "%s\n", dlerror());
-               }
-               if (!lttng_ust_baddr_push_fn)
-                       return -1;
+       if (!realpath(so_name, resolved_path)) {
+               ERR("could not resolve path '%s'", so_name);
+               return;
        }
-       return lttng_ust_baddr_push_fn(so_base, so_name);
-}
 
-static
-int lttng_ust_baddr_pop(void *so_base)
-{
-       static int
-       (*lttng_ust_baddr_pop_fn)(void *so_base);
-       if (!lttng_ust_baddr_pop_fn) {
-               void *baddr_handle = lttng_ust_baddr_handle();
-               if (baddr_handle) {
-                       lttng_ust_baddr_pop_fn = dlsym(baddr_handle,
-                               "lttng_ust_pop_baddr");
-                       if (lttng_ust_baddr_pop_fn == NULL)
-                               fprintf(stderr, "%s\n", dlerror());
-               }
-               if (!lttng_ust_baddr_pop_fn)
-                       return -1;
+       if (stat(resolved_path, &sostat)) {
+               ERR("could not access file status for %s", resolved_path);
+               return;
        }
-       return lttng_ust_baddr_pop_fn(so_base);
+
+       tracepoint(ust_baddr, push,
+               so_base, resolved_path, sostat.st_size, sostat.st_mtime);
+       return;
 }
 
 void *dlopen(const char *filename, int flag)
@@ -128,19 +104,7 @@ int dlclose(void *handle)
                struct link_map *p = NULL;
                if (dlinfo(handle, RTLD_DI_LINKMAP, &p) != -1 && p != NULL
                                && p->l_addr != 0)
-                       lttng_ust_baddr_pop((void *) p->l_addr);
+                       tracepoint(ust_baddr, pop, (void *) p->l_addr);
        }
        return _lttng_ust_dl_libc_dlclose(handle);
 }
-
-static void __attribute__((destructor))
-lttng_ust_baddr_handle_fini(void);
-static void
-lttng_ust_baddr_handle_fini(void)
-{
-       if (__lttng_ust_baddr_handle) {
-               int ret = _lttng_ust_dl_libc_dlclose(__lttng_ust_baddr_handle);
-               if (ret)
-                       fprintf(stderr, "%s\n", dlerror());
-       }
-}
index a33331391eb59662092009c1df1ea30c76705b15..f00fe45fdf10e536b05608d6cb70402648673066 100644 (file)
@@ -69,6 +69,7 @@ liblttng_ust_la_LIBADD = \
        -lurcu-cds \
        $(top_builddir)/snprintf/libustsnprintf.la \
        $(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la \
+       $(top_builddir)/liblttng-ust-baddr/liblttng-ust-baddr.la \
        liblttng-ust-tracepoint.la \
        liblttng-ust-runtime.la liblttng-ust-support.la
 
index 77d8e3fcb3564de19100b0a50c080ecba5ba2ad4..2d3766f1326ff407351e3d41088d2d5c0aacf094 100644 (file)
@@ -52,6 +52,7 @@
 #include "lttng-tracer-core.h"
 #include "compat.h"
 #include "../libringbuffer/tlsfixup.h"
+#include "../liblttng-ust-baddr/lttng-ust-baddr.h"
 
 /*
  * Has lttng ust comm constructor been called ?
@@ -183,7 +184,6 @@ static const char *cmd_name_mapping[] = {
 
 static const char *str_timeout;
 static int got_timeout_env;
-static void *ust_baddr_handle;
 
 extern void lttng_ring_buffer_client_overwrite_init(void);
 extern void lttng_ring_buffer_client_overwrite_rt_init(void);
@@ -242,39 +242,6 @@ void print_cmd(int cmd, int handle)
                lttng_ust_obj_get_name(handle), handle);
 }
 
-static
-void *lttng_ust_baddr_handle(void)
-{
-       if (!ust_baddr_handle) {
-               ust_baddr_handle = dlopen(
-                       "liblttng-ust-baddr.so.0", RTLD_NOW | RTLD_GLOBAL);
-               if (ust_baddr_handle == NULL)
-                       ERR("%s", dlerror());
-       }
-       return ust_baddr_handle;
-}
-
-static
-int lttng_ust_baddr_statedump(struct lttng_session *session)
-{
-       static
-       int (*lttng_ust_baddr_init_fn)(struct lttng_session *);
-
-       if (!lttng_ust_baddr_init_fn) {
-               void *baddr_handle = lttng_ust_baddr_handle();
-               if (baddr_handle) {
-                       lttng_ust_baddr_init_fn = dlsym(baddr_handle,
-                               "lttng_ust_baddr_statedump");
-                       if (lttng_ust_baddr_init_fn == NULL)
-                               ERR("%s", dlerror());
-               }
-               if (!lttng_ust_baddr_init_fn)
-                       return -1;
-       }
-
-       return lttng_ust_baddr_init_fn(session);
-}
-
 static
 int setup_local_apps(void)
 {
@@ -1247,8 +1214,9 @@ restart:
                        if (ret) {
                                ERR("Error handling message for %s socket", sock_info->name);
                        } else {
-                               struct lttng_session *session =
-                                       sock_info->session_enabled;
+                               struct lttng_session *session;
+
+                               session = sock_info->session_enabled;
                                if (session) {
                                        sock_info->session_enabled = NULL;
                                        lttng_ust_baddr_statedump(session);
@@ -1489,12 +1457,6 @@ void __attribute__((destructor)) lttng_ust_exit(void)
         * cleanup the threads if there are stalled in a syscall.
         */
        lttng_ust_cleanup(1);
-
-       if (ust_baddr_handle) {
-               int ret = dlclose(ust_baddr_handle);
-               if (ret)
-                       ERR("%s", dlerror());
-       }
 }
 
 /*
This page took 0.033587 seconds and 4 git commands to generate.