3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
valgrind.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_VALGRIND_HH
25#define DUMUX_VALGRIND_HH
26
27#if ! HAVE_VALGRIND
28namespace Valgrind
29{
30bool boolBlubb(bool value) { return value; }
31void voidBlubb() { }
32
33#define SetUndefined(t) voidBlubb()
34#define SetDefined(t) voidBlubb()
35#define CheckDefined(t) boolBlubb(true)
36#define SetNoAccess(t) voidBlubb()
37#define Running() boolBlubb(false)
38}
39#else
40
41#include <valgrind/memcheck.h>
42
43namespace Valgrind
44{
49inline bool Running()
50{
51#if !defined NDEBUG && HAVE_VALGRIND
52 return RUNNING_ON_VALGRIND;
53#else
54 return false;
55#endif
56}
57
58
71template <class T>
72inline bool CheckDefined(const T &value)
73{
74#if !defined NDEBUG && HAVE_VALGRIND
75 unsigned int tmp = VALGRIND_CHECK_MEM_IS_DEFINED(&value, sizeof(T));
76 return tmp == 0;
77#else
78 return true;
79#endif
80}
81
82template <class T>
83inline bool CheckDefined(const T *value, int size)
84{
85#if !defined NDEBUG && HAVE_VALGRIND
86 unsigned int tmp = VALGRIND_CHECK_MEM_IS_DEFINED(value, size*sizeof(T));
87 return tmp == 0;
88#else
89 return true;
90#endif
91}
92
101template <class T>
102inline void SetUndefined(const T &value)
103{
104#if !defined NDEBUG && HAVE_VALGRIND
105 VALGRIND_MAKE_MEM_UNDEFINED(&value, sizeof(T));
106#endif
107}
108
109template <class T>
110inline void SetUndefined(const T *value, int size)
111{
112#if !defined NDEBUG && HAVE_VALGRIND
113 VALGRIND_MAKE_MEM_UNDEFINED(value, size*sizeof(T));
114#endif
115}
116
125template <class T>
126inline void SetDefined(const T &value)
127{
128#if !defined NDEBUG && HAVE_VALGRIND
129 VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(T));
130#endif
131}
132
133template <class T>
134inline void SetDefined(const T *value, int n)
135{
136#if !defined NDEBUG && HAVE_VALGRIND
137 VALGRIND_MAKE_MEM_DEFINED(value, n*sizeof(T));
138#endif
139}
140
149template <class T>
150inline void SetNoAccess(const T &value)
151{
152#if !defined NDEBUG && HAVE_VALGRIND
153 VALGRIND_MAKE_MEM_NOACCESS(&value, sizeof(T));
154#endif
155}
156
157template <class T>
158inline void SetNoAccess(const T *value, int n)
159{
160#if !defined NDEBUG && HAVE_VALGRIND
161 VALGRIND_MAKE_MEM_NOACCESS(value, n*sizeof(T));
162#endif
163}
164
165} // end namespace Valgrind
166
167#endif // HAVE_VALGRIND
168
169#endif // DUMUX_VALGRIND_HH
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition: valgrind.hh:72
bool Running()
Returns whether the program is running under Valgrind or not.
Definition: valgrind.hh:49
void SetDefined(const T &value)
Make the memory on which an object resides defined.
Definition: valgrind.hh:126
void SetUndefined(const T &value)
Make the memory on which an object resides undefined.
Definition: valgrind.hh:102
void SetNoAccess(const T &value)
Make valgrind complain if an object's memory is accessed.
Definition: valgrind.hh:150
Definition: valgrind.hh:44