Main Page   Class Hierarchy   Compound List   File List   Compound Members  

mdebug.h

00001 /***************************************************************************
00002  *   This file is part of the MagiC++ library.                             *
00003  *                                                                         *
00004  *   Copyright (C) 1998-2001 Marko Grönroos <magi@iki.fi>                  *
00005  *                                                                         *
00006  ***************************************************************************
00007  *                                                                         *
00008  *  This library is free software; you can redistribute it and/or          *
00009  *  modify it under the terms of the GNU Library General Public            *
00010  *  License as published by the Free Software Foundation; either           *
00011  *  version 2 of the License, or (at your option) any later version.       *
00012  *                                                                         *
00013  *  This library is distributed in the hope that it will be useful,        *
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
00016  *  Library General Public License for more details.                       *
00017  *                                                                         *
00018  *  You should have received a copy of the GNU Library General Public      *
00019  *  License along with this library; see the file COPYING.LIB.  If         *
00020  *  not, write to the Free Software Foundation, Inc., 59 Temple Place      *
00021  *  - Suite 330, Boston, MA 02111-1307, USA.                               *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #ifndef __DEBUG_H__
00026 #define __DEBUG_H__
00027 
00028 #include "mconfig.h"
00029 
00030 
00031 
00033 //                                                                           //
00034 //     ___                                                                   //
00035 //     |  \   ___  |                           ___   ___            ____     //
00036 //     |   | /   ) |---  |   |  ___     |/|/|  ___| |   \ |/\  __  (         //
00037 //     |   | |---  |   ) |   | (   \    | | | (   | |     |   /  \  \__      //
00038 //     |__/   \__  |__/   \__!  ---/    | | |  \__|  \__/ |   \__/ ____)     //
00039 //                              __/                                          //
00041 
00042 #ifndef NODEBUG
00043 
00044 #define TRACELINE {fprintf (dbgout, "File:%s, Line#%d %s\n", __FILE__, __LINE__, __FUNCTION__); fflush (dbgout);}
00045 #define TRACE(expr) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr); fprintf (dbgout, "\n"); fflush (dbgout);}
00046 #define TRACE1(expr,par1) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1); fprintf (dbgout, "\n"); fflush (dbgout);}
00047 #define TRACE2(expr,par1,par2) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1, par2); fprintf (dbgout, "\n"); fflush (dbgout);}
00048 #define TRACE3(expr,par1,par2,par3) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1, par2, par3); fprintf (dbgout, "\n"); fflush (dbgout);}
00049 #define TRACE4(expr,par1,par2,par3,par4) {fprintf (dbgout, "File:%s, Line#%d %s: ", __FILE__, __LINE__, __FUNCTION__); fprintf (dbgout, expr, par1, par2, par3, par4); fprintf (dbgout, "\n"); fflush (dbgout);}
00050 
00051 // ASSERT is not available under Qt, which also defines it. Clever.
00052 #ifndef QT_VERSION
00053 #define ASSERT(expr) {if (!(expr)) assertwith (__FILE__, __LINE__, __FUNCTION__, #expr);}
00054 #endif
00055 
00056 #define ASSERTWITH(expr,message) {if (!(expr)) assertwith (__FILE__, __LINE__, __FUNCTION__, #expr, message);}
00057 #define PRE(expr) ASSERTWITH(expr, "Violation of precondition");
00058 #define POST(expr) ASSERTWITH(expr, "Violation of postcondition");
00059 
00060 #else
00061 
00062 #define TRACELINE
00063 #define ASSERT(expr)
00064 #define ASSERTWITH(expr,message)
00065 #define PRE(expr)
00066 #define POST(expr)
00067 #define TRACE(msg) {}
00068 #define TRACE1(msg,p1) {}
00069 #define TRACE2(msg,p1,p2) {}
00070 #define TRACE3(msg,p1,p2,p3) {}
00071 #define TRACE4(msg,p1,p2,p3,p4) {}
00072 #endif
00073 
00074 
00075 
00077 //                                                                           //
00078 //     |   |                                   |                             //
00079 //     |\ /|  ___                              |  ___  |                     //
00080 //     | V | /   ) |/|/|  __  |/\ \   |     ---| /   ) |---  |   |  ___      //
00081 //     | | | |---  | | | /  \ |    \  |    (   | |---  |   ) |   | (   \     //
00082 //     |   |  \__  | | | \__/ |     \_/     ---|  \__  |__/   \__!  ---/     //
00083 //                                 \_/                              __/      //
00085 
00086 // Define may memory debugging extensions, unless disabled in config.h
00087 #ifndef DISABLE_ALL_MEMORY_DEBUGGING
00088 
00089 //#define new DEBUG_NEW
00090 #define DEBUG_NEW new(__FILE__,__LINE__,__FUNCTION__)
00091 #ifdef new
00092 #undef new
00093 #define new_UNDEFD
00094 #define renew(p,ns) _renew (p,ns,__FILE__,__LINE__,__FUNCTION__)
00095 #else
00096 #define renew realloc
00097 #warning "Renew is realloc"
00098 #endif
00099 
00100 extern void* operator new[] (size_t size, const char* filen, int lineno, const char* funcn);
00101 extern void* operator new (size_t size, const char* filen, int lineno, const char* funcn);
00102 extern void operator delete (void* p);
00103 extern void list_allocations (int number=100, FILE* out=stderr);
00104 extern void* _renew (void* p, size_t newsize, const char* filen, int lineno, const char* funcn);
00105 extern "C" void newComment (const char* comment);
00106 
00107 #ifdef new_UNDEFD
00108 #define new DEBUG_NEW
00109 #undef new_UNDEFD
00110 #endif
00111 
00112 struct mallocinfostr {
00113     char            startsym[6];
00114     int             size;
00115     const char*     filename;
00116     int             lineno;
00117     const char*     funcname;
00118     char*           newcomment;
00119     bool            renewed;
00120     bool            isObject;
00121     mallocinfostr*  next;
00122     mallocinfostr*  prev;
00123 
00124     // This is required to corrent double-allocation word frame shift,
00125     // which results in BUS ERROR when writing to a double reference
00126     char            padding[4];
00127 };
00128 
00129 extern mallocinfostr* lastmalloced;     // The last malloced memory block
00130 extern int dbgnewmalloced;              // Total amount of memory malloced
00131 
00132 #else // DISABLE_ALL_MEMORY_DEBUGGING
00133 // Some dummy function definitions
00134 
00135 #include <stdlib.h>
00136 
00137 inline void* _renew (void* p, size_t newsize, const char* filen, int lineno, const char* funcn) {
00138     return realloc (p, newsize);
00139 }
00140 #define renew(p,ns) _renew (p,ns,__FILE__,__LINE__,__FUNCTION__)
00141 
00142 inline void newComment (const char* comment) {}
00143 
00144 #endif // DISABLE_ALL_MEMORY_DEBUGGING
00145 
00146 #endif

Generated at Tue Dec 4 19:53:25 2001 for MagiC++ by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001