liblttng-ust \
liblttng-ust-ctl \
liblttng-ust-fork \
+ liblttng-ust-libc \
tests
if BUILD_JNI_INTERFACE
- tests
Various test programs
- - liblttng-ust-malloc
- An example library that can be LD_PRELOAD'ed to instrument calls to malloc()
- in any program without need to recompile it.
+ - liblttng-ust-libc
+ An example library that can be LD_PRELOAD'ed to instrument some
+ calls to libc (currently malloc() and free()) in any program without
+ need to recompile it.
- liblttng-ust-fork
A library that is LD_PRELOAD'ed, and that hijacks calls to several system
AM_CONDITIONAL([BUILD_JNI_INTERFACE], [test "x$jni_interface" = "xyes"])
#currently disabled.
- #liblttng-ust-malloc/Makefile
#tests/hello2/Makefile
#tests/basic/Makefile
#tests/simple_include/Makefile
liblttng-ust-ctl/Makefile
liblttng-ust-fork/Makefile
liblttng-ust-java/Makefile
+ liblttng-ust-libc/Makefile
tests/Makefile
tests/hello/Makefile
tests/hello.cxx/Makefile
--- /dev/null
+AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_CFLAGS = -fno-strict-aliasing
+
+lib_LTLIBRARIES = liblttng-ust-libc.la
+liblttng_ust_libc_la_SOURCES = lttng-ust-malloc.c
+liblttng_ust_libc_la_LIBADD = -ldl
+
+noinst_SCRIPTS = run
+EXTRA_DIST = run
--- /dev/null
+liblttng-ust-libc is used for instrumenting some calls to libc in a
+program, without need for recompiling it.
+
+This library defines a malloc() function that is instrumented with a
+tracepoint. It also calls the libc malloc afterwards. When loaded with
+LD_PRELOAD, it replaces the libc malloc() function, in effect
+instrumenting all calls to malloc(). The same is performed for free().
+
+See the "run" script for a usage example.
--- /dev/null
+/*
+ * Copyright (C) 2009 Pierre-Marc Fournier
+ * Copyright (C) 2011 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
+ * 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 _GNU_SOURCE
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#define TRACEPOINT_DEFINE
+#define TRACEPOINT_CREATE_PROBES
+#include "ust_libc.h"
+
+void *malloc(size_t size)
+{
+ static void *(*plibc_malloc)(size_t size) = NULL;
+ void *retval;
+
+ if (plibc_malloc == NULL) {
+ plibc_malloc = dlsym(RTLD_NEXT, "malloc");
+ if (plibc_malloc == NULL) {
+ fprintf(stderr, "mallocwrap: unable to find malloc\n");
+ return NULL;
+ }
+ }
+ retval = plibc_malloc(size);
+ tracepoint(ust_libc, malloc, size, retval);
+ return retval;
+}
+
+void free(void *ptr)
+{
+ static void *(*plibc_free)(void *ptr) = NULL;
+
+ if (plibc_free == NULL) {
+ plibc_free = dlsym(RTLD_NEXT, "free");
+ if (plibc_free == NULL) {
+ fprintf(stderr, "mallocwrap: unable to find free\n");
+ return;
+ }
+ }
+ tracepoint(ust_libc, free, ptr);
+ plibc_free(ptr);
+}
--- /dev/null
+#!/bin/sh
+
+LD_VERBOSE=1 LD_PRELOAD=.libs/liblttng-ust-libc.so $1
--- /dev/null
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER ust_libc
+
+#if !defined(_TRACEPOINT_UST_LIBC_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_UST_LIBC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose, provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(ust_libc, malloc,
+ TP_ARGS(size_t, size, void *, ptr),
+ TP_FIELDS(
+ ctf_integer(size_t, size, size)
+ ctf_integer_hex(unsigned long, ptr, (unsigned long) ptr)
+ )
+)
+
+TRACEPOINT_EVENT(ust_libc, free,
+ TP_ARGS(void *, ptr),
+ TP_FIELDS(
+ ctf_integer_hex(unsigned long, ptr, (unsigned long) ptr)
+ )
+)
+
+#endif /* _TRACEPOINT_UST_LIBC_H */
+
+#undef TRACEPOINT_INCLUDE_FILE
+#define TRACEPOINT_INCLUDE_FILE ./ust_libc.h
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
+++ /dev/null
-AM_CPPFLAGS = -I$(top_srcdir)/include
-AM_CFLAGS = -fno-strict-aliasing
-
-lib_LTLIBRARIES = liblttng-ust-malloc.la
-liblttng_ust_malloc_la_SOURCES = mallocwrap.c
-liblttng_ust_malloc_la_LIBADD = -ldl
-
-noinst_SCRIPTS = run
-EXTRA_DIST = run
+++ /dev/null
-libustinstr-malloc is used for instrumenting calls to malloc(3) in a program,
-without need for recompiling it.
-
-libustinstr-malloc defines a malloc() function that is instrumented with a
-marker. It also calls the libc malloc afterwards. When loaded with LD_PRELOAD,
-it replaces the libc malloc() function, in effect instrumenting all calls to
-malloc().
-
-See the "run" script for a usage example.
+++ /dev/null
-/*
- * Copyright (C) 2009 Pierre-Marc Fournier
- *
- * 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 _GNU_SOURCE
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <ust/marker.h>
-
-void *malloc(size_t size)
-{
- static void *(*plibc_malloc)(size_t size) = NULL;
- void *retval;
-
- if (plibc_malloc == NULL) {
- plibc_malloc = dlsym(RTLD_NEXT, "malloc");
- if (plibc_malloc == NULL) {
- fprintf(stderr, "mallocwrap: unable to find malloc\n");
- return NULL;
- }
- }
-
- retval = plibc_malloc(size);
-
- ust_marker(malloc, "size %d ptr %p", (int)size, retval);
-
- return retval;
-}
-
-void free(void *ptr)
-{
- static void *(*plibc_free)(void *ptr) = NULL;
-
- if (plibc_free == NULL) {
- plibc_free = dlsym(RTLD_NEXT, "free");
- if (plibc_free == NULL) {
- fprintf(stderr, "mallocwrap: unable to find free\n");
- return;
- }
- }
-
- ust_marker(free, "ptr %p", ptr);
-
- plibc_free(ptr);
-}
-
-UST_MARKER_LIB
+++ /dev/null
-#!/bin/sh
-
-LD_VERBOSE=1 LD_LIBRARY_PATH=.:../libust/.libs:../../liburcu LD_PRELOAD=liburcu.so:libust.so:.libs/libmallocwrap.so $1
}
}
+static
+void lib_disable_tracepoints(struct tracepoint * const *begin,
+ struct tracepoint * const *end)
+{
+ struct tracepoint * const *iter;
+
+ for (iter = begin; iter < end; iter++) {
+ if (!*iter)
+ continue; /* skip dummy */
+ disable_tracepoint(*iter);
+ }
+
+}
+
int tracepoint_register_lib(struct tracepoint * const *tracepoints_start,
int tracepoints_count)
{
int tracepoint_unregister_lib(struct tracepoint * const *tracepoints_start)
{
struct tracepoint_lib *lib;
+ int tracepoints_count;
ust_lock();
cds_list_for_each_entry(lib, &libs, list) {
if (lib->tracepoints_start == tracepoints_start) {
struct tracepoint_lib *lib2free = lib;
+
cds_list_del(&lib->list);
+ tracepoints_count = lib->tracepoints_count;
free(lib2free);
- break;
+ goto found;
}
}
+ goto end;
+found:
+ /*
+ * Force tracepoint disarm for all tracepoints of this lib.
+ * This takes care of destructor of library that would leave a
+ * LD_PRELOAD wrapper override function enabled for tracing, but
+ * the session teardown would not be able to reach the
+ * tracepoint anymore to disable it.
+ */
+ lib_disable_tracepoints(tracepoints_start,
+ tracepoints_start + tracepoints_count);
+ DBG("just unregistered a tracepoints section from %p",
+ tracepoints_start);
+end:
ust_unlock();
-
return 0;
}