From 804d140b1c28dfc2340475b15a93171142d58035 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 12 May 2011 15:06:55 +0100 Subject: [PATCH 1/7] Add support for inserting (a subset of) Valgrind client requests Usage: ./configure --without-valgrind (equivalent to the default) ./configure --with-valgrind ./configure --with-valgrind="-I /opt/valgrind/include" If valgrind support is disabled, we define stub versions of the Valgrind client requests I plan to use, so the actual code doesn't need #ifdef hell. --- configure.ac | 14 ++++++++++++ dbus/Makefile.am | 4 ++- dbus/dbus-valgrind-internal.h | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletions(-) create mode 100644 dbus/dbus-valgrind-internal.h diff --git a/configure.ac b/configure.ac index 940bfae..f53a643 100644 --- a/configure.ac +++ b/configure.ac @@ -1040,6 +1040,20 @@ if test x$dbus_win = xyes ; then fi fi +AC_ARG_WITH([valgrind], + [AS_HELP_STRING([--with-valgrind], + [Add instrumentation to help valgrind to understand our allocator])], + [], + [with_valgrind=no]) + +if test x$with_valgrind != xno; then + PKG_CHECK_MODULES([VALGRIND], [valgrind >= 3.6]) + AC_DEFINE([WITH_VALGRIND], [1], [Define to add Valgrind instrumentation]) +fi + +AC_SUBST([VALGRIND_CFLAGS]) +AC_SUBST([VALGRIND_LIBS]) + #### Set up final flags DBUS_CLIENT_CFLAGS= DBUS_CLIENT_LIBS="$THREAD_LIBS $NETWORK_libs" diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 2e6ca1d..21c6a44 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -3,6 +3,7 @@ configdir=$(sysconfdir)/dbus-1 INCLUDES = -I$(top_builddir) -I$(top_srcdir) \ $(DBUS_CLIENT_CFLAGS) \ + $(VALGRIND_CFLAGS) \ -DDBUS_COMPILATION \ -DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\" \ -DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\" \ @@ -218,7 +219,8 @@ DBUS_SHARED_SOURCES= \ dbus-string-private.h \ $(DBUS_SHARED_arch_sources) \ dbus-sysdeps.c \ - dbus-sysdeps.h + dbus-sysdeps.h \ + dbus-valgrind-internal.h ### source code that is generic utility functionality used ### by the bus daemon or test apps, but is NOT included diff --git a/dbus/dbus-valgrind-internal.h b/dbus/dbus-valgrind-internal.h new file mode 100644 index 0000000..59e5a22 --- /dev/null +++ b/dbus/dbus-valgrind-internal.h @@ -0,0 +1,46 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* dbus-valgrind-internal.h - valgrind glue + * + * Copyright © 2011 Nokia Corporation + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef DBUS_VALGRIND_INTERNAL_H +#define DBUS_VALGRIND_INTERNAL_H + +#include "config.h" +#include "dbus-internals.h" + +#ifdef WITH_VALGRIND +# include +# include +#else +# define VALGRIND_CREATE_MEMPOOL(_1, _2, _3) /* nothing */ +# define VALGRIND_DESTROY_MEMPOOL(_1) /* nothing */ +# define VALGRIND_MEMPOOL_ALLOC(_1, _2, _3) /* nothing */ +# define VALGRIND_MEMPOOL_FREE(_1, _2) /* nothing */ +# define VALGRIND_MAKE_MEM_UNDEFINED(_1, _2) (0) + +# define VALGRIND_PRINTF(...) (0) +# define VALGRIND_PRINTF_BACKTRACE(...) (0) + +# define RUNNING_ON_VALGRIND 0 +#endif /* WITH_VALGRIND */ + +#endif /* header guard */ -- 1.7.5.1