GCS  0.2.3
gu_dbug.h
1 /******************************************************************************
2  * *
3  * N O T I C E *
4  * *
5  * Copyright Abandoned, 1987, Fred Fish *
6  * *
7  * *
8  * This previously copyrighted work has been placed into the public *
9  * domain by the author and may be freely used for any purpose, *
10  * private or commercial. *
11  * *
12  * Because of the number of inquiries I was receiving about the use *
13  * of this product in commercially developed works I have decided to *
14  * simply make it public domain to further its unrestricted use. I *
15  * specifically would be most happy to see this material become a *
16  * part of the standard Unix distributions by AT&T and the Berkeley *
17  * Computer Science Research Group, and a standard part of the GNU *
18  * system from the Free Software Foundation. *
19  * *
20  * I would appreciate it, as a courtesy, if this notice is left in *
21  * all copies and derivative works. Thank you. *
22  * *
23  * The author makes no warranty of any kind with respect to this *
24  * product and explicitly disclaims any implied warranties of mer- *
25  * chantability or fitness for any particular purpose. *
26  * *
27  ******************************************************************************
28  */
29 
30 
31 /*
32  * FILE
33  *
34  * dbug.c runtime support routines for dbug package
35  *
36  * SCCS
37  *
38  * @(#)dbug.c 1.25 7/25/89
39  *
40  * DESCRIPTION
41  *
42  * These are the runtime support routines for the dbug package.
43  * The dbug package has two main components; the user include
44  * file containing various macro definitions, and the runtime
45  * support routines which are called from the macro expansions.
46  *
47  * Externally visible functions in the runtime support module
48  * use the naming convention pattern "_db_xx...xx_", thus
49  * they are unlikely to collide with user defined function names.
50  *
51  * AUTHOR(S)
52  *
53  * Fred Fish (base code)
54  * Enhanced Software Technologies, Tempe, AZ
55  * asuvax!mcdphx!estinc!fnf
56  *
57  * Binayak Banerjee (profiling enhancements)
58  * seismo!bpa!sjuvax!bbanerje
59  *
60  * Michael Widenius:
61  * DBUG_DUMP - To dump a pice of memory.
62  * PUSH_FLAG "O" - To be used instead of "o" if we don't
63  * want flushing (for slow systems)
64  * PUSH_FLAG "A" - as 'O', but we will append to the out file instead
65  * of creating a new one.
66  * Check of malloc on entry/exit (option "S")
67  *
68  * Alexey Yurchenko:
69  * Renamed global symbols for use with galera project to avoid
70  * collisions with other software (notably MySQL)
71  *
72  * $Id: gu_dbug.h 2745 2012-03-17 00:00:23Z alex $
73  */
74 
75 #ifndef _dbug_h
76 #define _dbug_h
77 
78 #include <stdio.h>
79 #include <sys/types.h>
80 
81 typedef unsigned int uint;
82 typedef unsigned long ulong;
83 
84 #define THREAD 1
85 
86 #ifdef __cplusplus
87 extern "C"
88 {
89 #endif
90 
91  extern char _gu_dig_vec[];
92  extern FILE* _gu_db_fp_;
93 
94 #define GU_DBUG_FILE _gu_db_fp_
95 
96 #if defined(GU_DBUG_ON) && !defined(_lint)
97  extern int _gu_db_on_;
98  extern int _gu_no_db_;
99  extern char* _gu_db_process_;
100  extern int _gu_db_keyword_(const char* keyword);
101  extern void _gu_db_setjmp_ (void);
102  extern void _gu_db_longjmp_(void);
103  extern void _gu_db_push_ (const char* control);
104  extern void _gu_db_pop_ (void);
105  extern void _gu_db_enter_ (const char* _func_,
106  const char* _file_,
107  uint _line_,
108  const char** _sfunc_,
109  const char** _sfile_,
110  uint* _slevel_,
111  char***);
112  extern void _gu_db_return_ (uint _line_,
113  const char** _sfunc_,
114  const char** _sfile_,
115  uint* _slevel_);
116  extern void _gu_db_pargs_ (uint _line_,
117  const char* keyword);
118  extern void _gu_db_doprnt_ (const char* format,
119  ...);
120  extern void _gu_db_dump_ (uint _line_,
121  const char *keyword,
122  const char *memory,
123  uint length);
124  extern void _gu_db_lock_file (void);
125  extern void _gu_db_unlock_file(void);
126 
127 
128 #define GU_DBUG_ENTER(a) \
129  const char *_gu_db_func_, *_gu_db_file_; \
130  uint _gu_db_level_; \
131  char **_gu_db_framep_; \
132  _gu_db_enter_ (a, __FILE__, __LINE__, &_gu_db_func_, &_gu_db_file_, \
133  &_gu_db_level_, &_gu_db_framep_)
134 
135 #define GU_DBUG_LEAVE \
136  (_gu_db_return_ (__LINE__, &_gu_db_func_, &_gu_db_file_, \
137  &_gu_db_level_))
138 
139 #define GU_DBUG_RETURN(a1) {GU_DBUG_LEAVE; return(a1);}
140 #define GU_DBUG_VOID_RETURN {GU_DBUG_LEAVE; return; }
141 
142 #define GU_DBUG_EXECUTE(keyword,a1) \
143  {if (_gu_db_on_) {if (_gu_db_keyword_ (keyword)) { a1 }}}
144 
145 #define GU_DBUG_PRINT(keyword,arglist) \
146  {if (_gu_db_on_) {_gu_db_pargs_(__LINE__,keyword); \
147  _gu_db_doprnt_ arglist;}}
148 
149 #define GU_DBUG_PUSH(a1) _gu_db_push_ (a1)
150 #define GU_DBUG_POP() _gu_db_pop_ ()
151 #define GU_DBUG_PROCESS(a1) (_gu_db_process_ = a1)
152 #define GU_DBUG_SETJMP(a1) (_gu_db_setjmp_ (), setjmp (a1))
153 #define GU_DBUG_LONGJMP(a1,a2) (_gu_db_longjmp_ (), longjmp (a1, a2))
154 
155 #define GU_DBUG_DUMP(keyword,a1,a2)\
156  {if (_gu_db_on_) {_gu_db_dump_(__LINE__,keyword,a1,a2);}}
157 
158 #define GU_DBUG_IN_USE (_gu_db_fp_ && _gu_db_fp_ != stderr)
159 #define GU_DEBUGGER_OFF _no_gu_db_=1;_gu_db_on_=0;
160 #define GU_DEBUGGER_ON _no_gu_db_=0
161 #define GU_DBUG_my_pthread_mutex_lock_FILE { _gu_db_lock_file(); }
162 #define GU_DBUG_my_pthread_mutex_unlock_FILE { _gu_db_unlock_file(); }
163 #define GU_DBUG_ASSERT(A) assert(A)
164 
165 #else /* No debugger */
166 
167 #define GU_DBUG_ENTER(a1)
168 #define GU_DBUG_RETURN(a1) return(a1)
169 #define GU_DBUG_VOID_RETURN return
170 #define GU_DBUG_EXECUTE(keyword,a1) {}
171 #define GU_DBUG_PRINT(keyword,arglist) {}
172 #define GU_DBUG_PUSH(a1) {}
173 #define GU_DBUG_POP() {}
174 #define GU_DBUG_PROCESS(a1) {}
175 #define GU_DBUG_SETJMP setjmp
176 #define GU_DBUG_LONGJMP longjmp
177 #define GU_DBUG_DUMP(keyword,a1,a2) {}
178 #define GU_DBUG_IN_USE 0
179 #define GU_DEBUGGER_OFF
180 #define GU_DEBUGGER_ON
181 #define GU_DBUG_my_pthread_mutex_lock_FILE
182 #define GU_DBUG_my_pthread_mutex_unlock_FILE
183 #define GU_DBUG_ASSERT(A) {}
184 #endif
185 #ifdef __cplusplus
186 }
187 #endif
188 #endif