Back to index

tetex-bin  3.0
debug.h
Go to the documentation of this file.
00001 /* debug.h: Runtime tracing.
00002 
00003 Copyright (C) 1993, 94, 95, 96 Karl Berry.
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Library General Public
00007 License as published by the Free Software Foundation; either
00008 version 2 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Library General Public License for more details.
00014 
00015 You should have received a copy of the GNU Library General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00018 
00019 #ifndef KPATHSEA_DEBUG_H
00020 #define KPATHSEA_DEBUG_H
00021 
00022 /* If NO_DEBUG is defined (not recommended), skip all this.  */
00023 #ifndef NO_DEBUG
00024 
00025 #include <kpathsea/c-proto.h>
00026 #include <kpathsea/c-std.h>
00027 #include <kpathsea/types.h>
00028 
00029 #if defined(WIN32)
00030 #if defined(_DEBUG)
00031 /* This was needed at some time for catching errors in pdftex. */
00032 #include <crtdbg.h>
00033 #define  SET_CRT_DEBUG_FIELD(a) \
00034             _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
00035 #define  CLEAR_CRT_DEBUG_FIELD(a) \
00036             _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
00037 #define  SETUP_CRTDBG \
00038    { _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );    \
00039      _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );  \
00040      _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );   \
00041      _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT ); \
00042      _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );  \
00043      _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );\
00044    }
00045 #else /* ! _DEBUG */
00046 #define SET_CRT_DEBUG_FIELD(a) 
00047 #define CLEAR_CRT_DEBUG_FIELD(a)
00048 #define SETUP_CRTDBG
00049 #endif /* _DEBUG */
00050 #endif /* WIN32 */
00051 
00052 /* OK, we'll have tracing support.  */
00053 #define KPSE_DEBUG
00054 
00055 /* Bit vector defining what we should trace.  */
00056 extern KPSEDLL unsigned kpathsea_debug;
00057 
00058 /* Set a bit.  */
00059 #define KPSE_DEBUG_SET(bit) kpathsea_debug |= 1 << (bit)
00060 
00061 /* Test if a bit is on.  */
00062 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit)))
00063 
00064 #define KPSE_DEBUG_STAT 0          /* stat calls */
00065 #define KPSE_DEBUG_HASH 1          /* hash lookups */
00066 #define KPSE_DEBUG_FOPEN 2         /* fopen/fclose calls */
00067 #define KPSE_DEBUG_PATHS 3         /* search path initializations */
00068 #define KPSE_DEBUG_EXPAND 4        /* path element expansion */
00069 #define KPSE_DEBUG_SEARCH 5        /* searches */
00070 #define KPSE_DEBUG_VARS 6          /* variable values */
00071 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
00072 
00073 /* A printf for the debugging.  */
00074 #define DEBUGF_START() do { fputs ("kdebug:", stderr)
00075 #define DEBUGF_END()        fflush (stderr); } while (0)
00076 
00077 #define DEBUGF(str)                                            \
00078   DEBUGF_START (); fputs (str, stderr); DEBUGF_END ()
00079 #define DEBUGF1(str, e1)                                       \
00080   DEBUGF_START (); fprintf (stderr, str, e1); DEBUGF_END ()
00081 #define DEBUGF2(str, e1, e2)                                          \
00082   DEBUGF_START (); fprintf (stderr, str, e1, e2); DEBUGF_END ()
00083 #define DEBUGF3(str, e1, e2, e3)                               \
00084   DEBUGF_START (); fprintf (stderr, str, e1, e2, e3); DEBUGF_END ()
00085 #define DEBUGF4(str, e1, e2, e3, e4)                                  \
00086   DEBUGF_START (); fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END ()
00087 
00088 #undef fopen
00089 #define fopen kpse_fopen_trace
00090 extern KPSEDLL FILE *fopen P2H(const_string filename, const_string mode);
00091 #undef fclose
00092 #define fclose kpse_fclose_trace
00093 extern KPSEDLL int fclose P1H(FILE *);
00094 
00095 #endif /* not NO_DEBUG */
00096 
00097 #endif /* not KPATHSEA_DEBUG_H */