2 This file is part of SXEmacs
4 SXEmacs is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 SXEmacs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Synched up with: Not in FSF. */
24 /* This file used to include debugging hooks for malloc(), back when we
25 shipped our own copy of gmalloc.c. Now we just use the system malloc, and
26 this file has code to debug GCPROs. */
28 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)
30 /* Note: There is no more input blocking in XEmacs */
32 block_type, unblock_type, totally_type,
33 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, gcpro5_type,
37 struct block_input_history_struct {
44 typedef struct block_input_history_struct block_input_history;
46 #endif /* DEBUG_INPUT_BLOCKING || DEBUG_GCPRO */
48 #ifdef DEBUG_INPUT_BLOCKING
52 #define BLHISTLIMIT 1000
54 block_input_history blhist[BLHISTLIMIT];
56 note_block_input(char *file, int line)
58 note_block(file, line, block_type);
59 if (interrupt_input_blocked > 2)
63 note_unblock_input(char *file, int line)
65 note_block(file, line, unblock_type);
68 note_totally_unblocked(char *file, int line)
70 note_block(file, line, totally_type);
73 note_block(char *file, int line, blocktype type)
75 blhist[blhistptr].file = file;
76 blhist[blhistptr].line = line;
77 blhist[blhistptr].type = type;
78 blhist[blhistptr].value = interrupt_input_blocked;
81 if (blhistptr >= BLHISTLIMIT)
85 #endif /* DEBUG_INPUT_BLOCKING */
90 #define GCPROHISTLIMIT 1000
91 block_input_history gcprohist[GCPROHISTLIMIT];
93 static void log_gcpro(char *file, int line, struct gcpro *value, blocktype type)
95 if (type == ungcpro_type) {
96 if (value == gcprolist)
100 if (value == gcprolist->next)
102 if (!gcprolist->next)
104 if (value == gcprolist->next->next)
106 if (!gcprolist->next->next)
108 if (value == gcprolist->next->next->next)
110 if (!gcprolist->next->next->next)
112 if (value == gcprolist->next->next->next->next)
117 gcprohist[gcprohistptr].file = file;
118 gcprohist[gcprohistptr].line = line;
119 gcprohist[gcprohistptr].type = type;
120 gcprohist[gcprohistptr].value = (int)value;
122 if (gcprohistptr >= GCPROHISTLIMIT)
126 void debug_gcpro1(char *file, int line, struct gcpro *gcpro1, Lisp_Object * var)
128 gcpro1->next = gcprolist;
132 log_gcpro(file, line, gcpro1, gcpro1_type);
136 debug_gcpro2(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
137 Lisp_Object * var1, Lisp_Object * var2)
139 gcpro1->next = gcprolist;
142 gcpro2->next = gcpro1;
146 log_gcpro(file, line, gcpro2, gcpro2_type);
150 debug_gcpro3(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
151 struct gcpro *gcpro3, Lisp_Object * var1, Lisp_Object * var2,
154 gcpro1->next = gcprolist;
157 gcpro2->next = gcpro1;
160 gcpro3->next = gcpro2;
164 log_gcpro(file, line, gcpro3, gcpro3_type);
168 debug_gcpro4(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
169 struct gcpro *gcpro3, struct gcpro *gcpro4, Lisp_Object * var1,
170 Lisp_Object * var2, Lisp_Object * var3, Lisp_Object * var4)
172 log_gcpro(file, line, gcpro4, gcpro4_type);
173 gcpro1->next = gcprolist;
176 gcpro2->next = gcpro1;
179 gcpro3->next = gcpro2;
182 gcpro4->next = gcpro3;
189 debug_gcpro5(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
190 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
191 Lisp_Object * var1, Lisp_Object * var2, Lisp_Object * var3,
192 Lisp_Object * var4, Lisp_Object * var5)
194 log_gcpro(file, line, gcpro5, gcpro5_type);
195 gcpro1->next = gcprolist;
198 gcpro2->next = gcpro1;
201 gcpro3->next = gcpro2;
204 gcpro4->next = gcpro3;
207 gcpro5->next = gcpro4;
214 debug_gcpro6(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
215 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
216 struct gcpro *gcpro6,
217 Lisp_Object * var1, Lisp_Object * var2, Lisp_Object * var3,
218 Lisp_Object * var4, Lisp_Object * var5, Lisp_Object * var6)
220 log_gcpro(file, line, gcpro5, gcpro5_type);
221 gcpro1->next = gcprolist;
224 gcpro2->next = gcpro1;
227 gcpro3->next = gcpro2;
230 gcpro4->next = gcpro3;
233 gcpro5->next = gcpro4;
236 gcpro6->next = gcpro5;
243 debug_gcpro7(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
244 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
245 struct gcpro *gcpro6, struct gcpro *gcpro7,
246 Lisp_Object * var1, Lisp_Object * var2, Lisp_Object * var3,
247 Lisp_Object * var4, Lisp_Object * var5, Lisp_Object * var6,
250 log_gcpro(file, line, gcpro5, gcpro5_type);
251 gcpro1->next = gcprolist;
254 gcpro2->next = gcpro1;
257 gcpro3->next = gcpro2;
260 gcpro4->next = gcpro3;
263 gcpro5->next = gcpro4;
266 gcpro6->next = gcpro5;
269 gcpro7->next = gcpro6;
276 debug_gcpro8(char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
277 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
278 struct gcpro *gcpro6, struct gcpro *gcpro7, struct gcpro *gcpro8,
279 Lisp_Object * var1, Lisp_Object * var2, Lisp_Object * var3,
280 Lisp_Object * var4, Lisp_Object * var5, Lisp_Object * var6,
281 Lisp_Object * var7, Lisp_Object * var8)
283 log_gcpro(file, line, gcpro5, gcpro5_type);
284 gcpro1->next = gcprolist;
287 gcpro2->next = gcpro1;
290 gcpro3->next = gcpro2;
293 gcpro4->next = gcpro3;
296 gcpro5->next = gcpro4;
299 gcpro6->next = gcpro5;
302 gcpro7->next = gcpro6;
305 gcpro8->next = gcpro7;
311 void debug_ungcpro(char *file, int line, struct gcpro *gcpro1)
313 log_gcpro(file, line, gcpro1, ungcpro_type);
314 gcprolist = gcpro1->next;
317 /* To be called from the debugger */
318 void show_gcprohist(void);
319 void show_gcprohist(void)
322 for (i = 0, j = gcprohistptr; i < GCPROHISTLIMIT; i++, j++) {
323 if (j >= GCPROHISTLIMIT)
325 printf("%3d %s %d %s 0x%x\n",
326 j, gcprohist[j].file, gcprohist[j].line,
327 (gcprohist[j].type ==
328 gcpro1_type ? "GCPRO1" : gcprohist[j].
330 gcpro2_type ? "GCPRO2" : gcprohist[j].
332 gcpro3_type ? "GCPRO3" : gcprohist[j].
334 gcpro4_type ? "GCPRO4" : gcprohist[j].
336 gcpro5_type ? "GCPRO5" : gcprohist[j].
338 ungcpro_type ? "UNGCPRO" : "???"), gcprohist[j].value);
343 #endif /* DEBUG_GCPRO */