1 /* debug.h: runtime tracing.
3 Copyright 1993, 1994, 1995, 1996, 2008 Karl Berry.
4 Copyright 1999, 2005 Olaf Weber.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library 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 GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this library; if not, see <http://www.gnu.org/licenses/>. */
19 #ifndef KPATHSEA_DEBUG_H
20 #define KPATHSEA_DEBUG_H
22 /* If NO_DEBUG is defined (not recommended), skip all this. */
25 #include <kpathsea/c-proto.h>
26 #include <kpathsea/c-std.h>
27 #include <kpathsea/types.h>
31 /* This was needed at some time for catching errors in pdftex. */
33 #define SET_CRT_DEBUG_FIELD(a) \
34 _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
35 #define CLEAR_CRT_DEBUG_FIELD(a) \
36 _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
37 #define SETUP_CRTDBG \
38 { _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); \
39 _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT ); \
40 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); \
41 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT ); \
42 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); \
43 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );\
46 #define SET_CRT_DEBUG_FIELD(a)
47 #define CLEAR_CRT_DEBUG_FIELD(a)
52 /* OK, we'll have tracing support. */
55 /* Bit vector defining what we should trace. */
56 extern KPSEDLL unsigned kpathsea_debug;
59 #define KPSE_DEBUG_SET(bit) kpathsea_debug |= 1 << (bit)
61 /* Test if a bit is on. */
62 #define KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit)))
64 #define KPSE_DEBUG_STAT 0 /* stat calls */
65 #define KPSE_DEBUG_HASH 1 /* hash lookups */
66 #define KPSE_DEBUG_FOPEN 2 /* fopen/fclose calls */
67 #define KPSE_DEBUG_PATHS 3 /* search path initializations */
68 #define KPSE_DEBUG_EXPAND 4 /* path element expansion */
69 #define KPSE_DEBUG_SEARCH 5 /* searches */
70 #define KPSE_DEBUG_VARS 6 /* variable values */
71 #define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
73 /* A printf for the debugging. */
74 #define DEBUGF_START() do { fputs ("kdebug:", stderr)
75 #define DEBUGF_END() fflush (stderr); } while (0)
78 DEBUGF_START (); fputs (str, stderr); DEBUGF_END ()
79 #define DEBUGF1(str, e1) \
80 DEBUGF_START (); fprintf (stderr, str, e1); DEBUGF_END ()
81 #define DEBUGF2(str, e1, e2) \
82 DEBUGF_START (); fprintf (stderr, str, e1, e2); DEBUGF_END ()
83 #define DEBUGF3(str, e1, e2, e3) \
84 DEBUGF_START (); fprintf (stderr, str, e1, e2, e3); DEBUGF_END ()
85 #define DEBUGF4(str, e1, e2, e3, e4) \
86 DEBUGF_START (); fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END ()
89 #define fopen kpse_fopen_trace
90 extern KPSEDLL FILE *fopen P2H(const_string filename, const_string mode);
92 #define fclose kpse_fclose_trace
93 extern KPSEDLL int fclose P1H(FILE *);
95 #endif /* not NO_DEBUG */
97 #endif /* not KPATHSEA_DEBUG_H */