From 9663b5af151ba5433d1670c55923ab1ebcbb9c50 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 19 Sep 2011 15:48:52 +0100 Subject: [PATCH 1/9] Add support for inserting (a subset of) Valgrind client requests 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 | 47 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletions(-) create mode 100644 dbus/dbus-valgrind-internal.h diff --git a/configure.ac b/configure.ac index 10575df..2a8ee49 100644 --- a/configure.ac +++ b/configure.ac @@ -1133,6 +1133,20 @@ fi AC_SUBST([NETWORK_libs]) +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 LIBDBUS_LIBS="$THREAD_LIBS $NETWORK_libs" AC_SUBST([LIBDBUS_LIBS]) diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 3c44ae4..ff618a1 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -4,6 +4,7 @@ configdir=$(sysconfdir)/dbus-1 AM_CPPFLAGS = \ -I$(top_builddir) \ -I$(top_srcdir) \ + $(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..4c972c5 --- /dev/null +++ b/dbus/dbus-valgrind-internal.h @@ -0,0 +1,47 @@ +/* -*- 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.6.3