0
|
1 /* This file is part of XEmacs.
|
|
2
|
|
3 XEmacs is free software; you can redistribute it and/or modify it
|
|
4 under the terms of the GNU General Public License as published by the
|
|
5 Free Software Foundation; either version 2, or (at your option) any
|
|
6 later version.
|
|
7
|
|
8 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
11 for more details.
|
|
12
|
|
13 You should have received a copy of the GNU General Public License
|
|
14 along with XEmacs; see the file COPYING. If not, write to
|
|
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
16 Boston, MA 02111-1307, USA. */
|
|
17
|
|
18 /* Synched up with: Not in FSF. */
|
|
19
|
|
20 /* Debugging hooks for malloc. */
|
|
21
|
|
22 /* These hooks work with gmalloc to catch allocation errors.
|
|
23 In particular, the following is trapped:
|
|
24
|
|
25 * Freeing the same pointer twice.
|
|
26 * Trying to free a pointer not returned by malloc.
|
|
27 * Trying to realloc a pointer not returned by malloc.
|
|
28
|
|
29 In addition, every word of every block freed is set to
|
|
30 0xdeadbeef. This causes many uses of freed storage to be
|
|
31 trapped or recognized.
|
|
32
|
|
33 When you use this, the storage used by the last FREE_QUEUE_LIMIT
|
|
34 calls to free() is not recycled. When you call free for the Nth
|
|
35 time, the (N - FREE_QUEUE_LIMIT)'th block is actually recycled.
|
|
36
|
|
37 For these last FREE_QUEUE_LIMIT calls to free() a backtrace is
|
|
38 saved showing where it was called from. The function
|
|
39 find_backtrace() is provided here to be called from GDB with a
|
|
40 pointer (such as would be passed to free()) as argument, e.g.
|
|
41 (gdb) p/a *find_backtrace (0x234000). If SAVE_ARGS is defined,
|
|
42 the first three arguments to each function are saved as well as the
|
|
43 return addresses.
|
|
44
|
|
45 If UNMAPPED_FREE is defined, instead of setting every word of freed
|
|
46 storage to 0xdeadbeef, every call to malloc goes on its own page(s).
|
|
47 When free() is called, the block is read and write protected. This
|
|
48 is very useful when debugging, since it usually generates a bus error
|
|
49 when the deadbeef hack might only cause some garbage to be printed.
|
|
50 However, this is too slow for everyday use, since it takes an enormous
|
|
51 number of pages.
|
|
52
|
|
53
|
|
54 Some other features that would be useful are:
|
|
55
|
|
56 * Checking for storage leaks.
|
|
57 This could be done by a GC-like facility that would scan the data
|
|
58 segment looking for pointers to allocated storage and tell you
|
|
59 about those that are no longer referenced. This could be invoked
|
|
60 at any time. Another possibility is to report on what allocated
|
|
61 storage is still in use when the process is exited. Typically
|
|
62 there will be a large amount, so this might not be very useful.
|
|
63 */
|
|
64
|
|
65 #if defined (EMACS_BTL) && defined (sun4) && !defined (__lucid)
|
|
66 /* currently only works in this configuration */
|
|
67 # define SAVE_STACK
|
|
68 #endif
|
|
69
|
|
70 #ifdef emacs
|
|
71 #ifdef SAVE_STACK
|
|
72 #include "cadillac-btl.h"
|
|
73 #endif
|
|
74 #include <config.h>
|
|
75 #include "lisp.h"
|
|
76 #else
|
|
77 void *malloc (unsigned long);
|
|
78 #endif
|
|
79
|
|
80 #include <stdio.h>
|
|
81
|
|
82 #include "hash.h"
|
|
83
|
|
84 #ifdef UNMAPPED_FREE
|
|
85 #include <sys/mman.h>
|
|
86 #include <sys/param.h>
|
|
87 #define ROUND_UP_TO_PAGE(i) (((i) + PAGEOFFSET) & PAGEMASK)
|
|
88 #endif
|
|
89
|
|
90 #include <sys/types.h>
|
|
91
|
|
92 /* System function prototypes don't belong in C source files */
|
|
93 /* extern void free (void *); */
|
|
94
|
|
95 c_hashtable pointer_table;
|
|
96
|
|
97 extern void (*__free_hook) (void *);
|
|
98 extern void *(*__malloc_hook) (unsigned long);
|
|
99
|
|
100 static void *check_malloc (unsigned long);
|
|
101
|
|
102 typedef void (*fun_ptr) ();
|
|
103
|
|
104 #ifdef SAVE_STACK
|
|
105 #define FREE_QUEUE_LIMIT 1000
|
|
106 #else
|
|
107 /* free_queue is not too useful without backtrace logging */
|
|
108 #define FREE_QUEUE_LIMIT 1
|
|
109 #endif
|
|
110 #define TRACE_LIMIT 20
|
|
111
|
|
112 typedef struct {
|
|
113 fun_ptr return_pc;
|
|
114 #ifdef SAVE_ARGS
|
|
115 void *arg[3];
|
|
116 #endif
|
|
117 } fun_entry;
|
|
118
|
|
119 typedef struct {
|
|
120 void *address;
|
|
121 unsigned long length;
|
|
122 #ifdef SAVE_STACK
|
|
123 fun_entry backtrace[TRACE_LIMIT];
|
|
124 #endif
|
|
125 } free_queue_entry;
|
|
126
|
|
127 free_queue_entry free_queue[FREE_QUEUE_LIMIT];
|
|
128
|
|
129 int current_free;
|
|
130
|
|
131 #ifdef SAVE_STACK
|
|
132 static void
|
|
133 init_frame (FRAME *fptr)
|
|
134 {
|
|
135 FRAME tmp_frame;
|
|
136
|
|
137 #ifdef sparc
|
|
138 /* Do the system trap ST_FLUSH_WINDOWS */
|
|
139 asm ("ta 3");
|
|
140 asm ("st %sp, [%i0+0]");
|
|
141 asm ("st %fp, [%i0+4]");
|
|
142 #endif
|
|
143
|
|
144 fptr->pc = (char *) init_frame;
|
|
145 tmp_frame = *fptr;
|
|
146
|
|
147 PREVIOUS_FRAME (tmp_frame);
|
|
148
|
|
149 *fptr = tmp_frame;
|
|
150 return;
|
|
151 }
|
|
152
|
|
153 #ifdef SAVE_ARGS
|
|
154 static void *
|
|
155 frame_arg (FRAME *fptr, int index)
|
|
156 {
|
|
157 return ((void *) FRAME_ARG(*fptr, index));
|
|
158 }
|
|
159 #endif
|
|
160
|
|
161 static void
|
|
162 save_backtrace (FRAME *current_frame_ptr, fun_entry *table)
|
|
163 {
|
|
164 int i = 0;
|
|
165 #ifdef SAVE_ARGS
|
|
166 int j;
|
|
167 #endif
|
|
168 FRAME current_frame = *current_frame_ptr;
|
|
169
|
|
170 /* Get up and out of free() */
|
|
171 PREVIOUS_FRAME (current_frame);
|
|
172
|
|
173 /* now do the basic loop adding data until there is no more */
|
|
174 while (PREVIOUS_FRAME (current_frame) && i < TRACE_LIMIT)
|
|
175 {
|
|
176 table[i].return_pc = (void (*)())FRAME_PC (current_frame);
|
|
177 #ifdef SAVE_ARGS
|
|
178 for (j = 0; j < 3; j++)
|
|
179 table[i].arg[j] = frame_arg (¤t_frame, j);
|
|
180 #endif
|
|
181 i++;
|
|
182 }
|
|
183 memset (&table[i], 0, sizeof (fun_entry) * (TRACE_LIMIT - i));
|
|
184 }
|
|
185
|
|
186 free_queue_entry *
|
|
187 find_backtrace (void *ptr)
|
|
188 {
|
|
189 int i;
|
|
190
|
|
191 for (i = 0; i < FREE_QUEUE_LIMIT; i++)
|
|
192 if (free_queue[i].address == ptr)
|
|
193 return &free_queue[i];
|
|
194
|
|
195 return 0;
|
|
196 }
|
|
197 #endif /* SAVE_STACK */
|
|
198
|
|
199 int strict_free_check;
|
|
200
|
|
201 static void
|
|
202 check_free (void *ptr)
|
|
203 {
|
|
204 #ifdef SAVE_STACK
|
|
205 FRAME start_frame;
|
185
|
206
|
0
|
207 init_frame (&start_frame);
|
|
208 #endif
|
|
209
|
|
210 __free_hook = 0;
|
|
211 __malloc_hook = 0;
|
|
212 if (!pointer_table)
|
|
213 pointer_table = make_hashtable (max (100, FREE_QUEUE_LIMIT * 2));
|
|
214 if (ptr != 0)
|
|
215 {
|
|
216 long size;
|
|
217 #ifdef UNMAPPED_FREE
|
|
218 unsigned long rounded_up_size;
|
|
219 #endif
|
|
220
|
185
|
221 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table,
|
|
222 (void **) &size);
|
0
|
223
|
|
224 if (!present)
|
233
|
225 {
|
0
|
226 /* This can only happen if you try to free something that didn't
|
|
227 come from malloc */
|
|
228 if (strict_free_check)
|
|
229 abort ();
|
|
230 else
|
|
231 {
|
|
232 __free_hook = check_free;
|
|
233 __malloc_hook = check_malloc;
|
|
234 goto end;
|
|
235 }
|
233
|
236 }
|
0
|
237
|
|
238 if (size < 0)
|
233
|
239 {
|
0
|
240 /* This happens when you free twice */
|
|
241 if (strict_free_check)
|
|
242 abort ();
|
|
243 else
|
|
244 {
|
|
245 __free_hook = check_free;
|
|
246 __malloc_hook = check_malloc;
|
|
247 goto end;
|
|
248 }
|
233
|
249 }
|
0
|
250 puthash (ptr, (void *)-size, pointer_table);
|
|
251 #ifdef UNMAPPED_FREE
|
|
252 /* Round up size to an even number of pages. */
|
|
253 rounded_up_size = ROUND_UP_TO_PAGE (size);
|
|
254 /* Protect the pages freed from all access */
|
|
255 if (strict_free_check)
|
|
256 mprotect (ptr, rounded_up_size, PROT_NONE);
|
|
257 #else
|
|
258 /* Set every word in the block to 0xdeadbeef */
|
|
259 if (strict_free_check)
|
|
260 {
|
|
261 unsigned long long_length = (size + (sizeof (long) - 1))
|
|
262 / sizeof (long);
|
|
263 unsigned long i;
|
|
264
|
|
265 for (i = 0; i < long_length; i++)
|
|
266 ((unsigned long *) ptr)[i] = 0xdeadbeef;
|
|
267 }
|
|
268 #endif
|
|
269 free_queue[current_free].address = ptr;
|
|
270 free_queue[current_free].length = size;
|
|
271 #ifdef SAVE_STACK
|
|
272 save_backtrace (&start_frame,
|
|
273 free_queue[current_free].backtrace);
|
|
274 #endif
|
|
275 current_free++;
|
|
276 if (current_free >= FREE_QUEUE_LIMIT)
|
|
277 current_free = 0;
|
|
278 /* Really free this if there's something there */
|
|
279 {
|
|
280 void *old = free_queue[current_free].address;
|
|
281
|
|
282 if (old)
|
|
283 {
|
|
284 #ifdef UNMAPPED_FREE
|
|
285 unsigned long old_len = free_queue[current_free].length;
|
|
286
|
|
287 mprotect (old, old_len, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
288 #endif
|
|
289 free (old);
|
|
290 remhash (old, pointer_table);
|
|
291 }
|
|
292 }
|
|
293 }
|
|
294 __free_hook = check_free;
|
|
295 __malloc_hook = check_malloc;
|
|
296
|
|
297 end:
|
|
298 return;
|
185
|
299 }
|
0
|
300
|
|
301 static void *
|
|
302 check_malloc (unsigned long size)
|
|
303 {
|
|
304 unsigned long rounded_up_size;
|
|
305 void *result;
|
|
306
|
|
307 __free_hook = 0;
|
|
308 __malloc_hook = 0;
|
|
309 if (size == 0)
|
|
310 {
|
|
311 result = 0;
|
|
312 goto end;
|
|
313 }
|
|
314 #ifdef UNMAPPED_FREE
|
|
315 /* Round up to an even number of pages. */
|
|
316 rounded_up_size = ROUND_UP_TO_PAGE (size);
|
|
317 #else
|
|
318 rounded_up_size = size;
|
|
319 #endif
|
|
320 result = malloc (rounded_up_size);
|
|
321 if (!pointer_table)
|
|
322 pointer_table = make_hashtable (FREE_QUEUE_LIMIT * 2);
|
|
323 puthash (result, (void *)size, pointer_table);
|
|
324 __free_hook = check_free;
|
|
325 __malloc_hook = check_malloc;
|
|
326 end:
|
|
327 return result;
|
|
328 }
|
|
329
|
|
330 extern void *(*__realloc_hook) (void *, unsigned long);
|
|
331
|
|
332 #ifdef MIN
|
|
333 #undef MIN
|
|
334 #endif
|
|
335 #define MIN(A, B) ((A) < (B) ? (A) : (B))
|
|
336
|
|
337 /* Don't optimize realloc */
|
|
338
|
|
339 static void *
|
|
340 check_realloc (void * ptr, unsigned long size)
|
|
341 {
|
|
342 EMACS_INT present;
|
|
343 unsigned long old_size;
|
|
344 void *result = malloc (size);
|
185
|
345
|
|
346 present = (EMACS_INT) gethash (ptr, pointer_table, (void **) &old_size);
|
0
|
347 if (!present)
|
|
348 /* This can only happen by reallocing a pointer that didn't
|
|
349 come from malloc. */
|
|
350 abort ();
|
|
351 if (result == 0)
|
|
352 goto end;
|
|
353 memcpy (result, ptr, MIN (size, old_size));
|
|
354 free (ptr);
|
|
355 end:
|
|
356 return result;
|
|
357 }
|
|
358
|
185
|
359 void enable_strict_free_check (void);
|
0
|
360 void
|
|
361 enable_strict_free_check (void)
|
|
362 {
|
|
363 strict_free_check = 1;
|
|
364 }
|
|
365
|
185
|
366 void disable_strict_free_check (void);
|
0
|
367 void
|
|
368 disable_strict_free_check (void)
|
|
369 {
|
|
370 strict_free_check = 0;
|
|
371 }
|
|
372
|
|
373 /* Note: All BLOCK_INPUT stuff removed from this file because it's
|
|
374 completely gone in XEmacs */
|
|
375
|
|
376 static void *
|
|
377 block_input_malloc (unsigned long size);
|
|
378
|
|
379 static void
|
|
380 block_input_free (void* ptr)
|
|
381 {
|
|
382 __free_hook = 0;
|
|
383 __malloc_hook = 0;
|
|
384 free (ptr);
|
|
385 __free_hook = block_input_free;
|
|
386 __malloc_hook = block_input_malloc;
|
|
387 }
|
|
388
|
|
389 static void *
|
|
390 block_input_malloc (unsigned long size)
|
|
391 {
|
|
392 void* result;
|
|
393 __free_hook = 0;
|
|
394 __malloc_hook = 0;
|
|
395 result = malloc (size);
|
|
396 __free_hook = block_input_free;
|
|
397 __malloc_hook = block_input_malloc;
|
|
398 return result;
|
|
399 }
|
|
400
|
|
401
|
|
402 static void *
|
|
403 block_input_realloc (void* ptr, unsigned long size)
|
|
404 {
|
|
405 void* result;
|
|
406 __free_hook = 0;
|
|
407 __malloc_hook = 0;
|
|
408 __realloc_hook = 0;
|
|
409 result = realloc (ptr, size);
|
|
410 __free_hook = block_input_free;
|
|
411 __malloc_hook = block_input_malloc;
|
|
412 __realloc_hook = block_input_realloc;
|
|
413 return result;
|
|
414 }
|
|
415
|
|
416 #ifdef emacs
|
|
417
|
|
418 void disable_free_hook (void);
|
|
419 void
|
|
420 disable_free_hook (void)
|
|
421 {
|
|
422 __free_hook = block_input_free;
|
|
423 __malloc_hook = block_input_malloc;
|
|
424 __realloc_hook = block_input_realloc;
|
|
425 }
|
|
426
|
|
427 void
|
|
428 init_free_hook (void)
|
|
429 {
|
|
430 __free_hook = check_free;
|
|
431 __malloc_hook = check_malloc;
|
|
432 __realloc_hook = check_realloc;
|
|
433 current_free = 0;
|
|
434 strict_free_check = 1;
|
|
435 }
|
|
436
|
|
437 void really_free_one_entry (void *, int, int *);
|
|
438
|
20
|
439 DEFUN ("really-free", Freally_free, 0, 1, "P", /*
|
0
|
440 Actually free the storage held by the free() debug hook.
|
|
441 A no-op if the free hook is disabled.
|
20
|
442 */
|
|
443 (arg))
|
0
|
444 {
|
|
445 int count[2];
|
|
446 Lisp_Object lisp_count[2];
|
|
447
|
|
448 if ((__free_hook != 0) && pointer_table)
|
|
449 {
|
|
450 count[0] = 0;
|
|
451 count[1] = 0;
|
|
452 __free_hook = 0;
|
185
|
453 maphash ((maphash_function)really_free_one_entry,
|
0
|
454 pointer_table, (void *)&count);
|
|
455 memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT);
|
|
456 current_free = 0;
|
|
457 __free_hook = check_free;
|
|
458 XSETINT (lisp_count[0], count[0]);
|
|
459 XSETINT (lisp_count[1], count[1]);
|
|
460 return Fcons (lisp_count[0], lisp_count[1]);
|
|
461 }
|
|
462 else
|
|
463 return Fcons (make_int (0), make_int (0));
|
|
464 }
|
|
465
|
|
466 void
|
|
467 really_free_one_entry (void *key, int contents, int *countp)
|
|
468 {
|
|
469 if (contents < 0)
|
|
470 {
|
|
471 free (key);
|
|
472 #ifdef UNMAPPED_FREE
|
|
473 mprotect (key, -contents, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
474 #endif
|
|
475 remhash (key, pointer_table);
|
|
476 countp[0]++;
|
|
477 countp[1] += -contents;
|
|
478 }
|
|
479 }
|
|
480
|
|
481 void
|
|
482 syms_of_free_hook (void)
|
|
483 {
|
20
|
484 DEFSUBR (Freally_free);
|
0
|
485 }
|
|
486
|
|
487 #else
|
|
488 void (*__free_hook)() = check_free;
|
|
489 void *(*__malloc_hook)() = check_malloc;
|
|
490 void *(*__realloc_hook)() = check_realloc;
|
|
491 #endif
|
|
492
|
|
493
|
|
494 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)
|
|
495
|
|
496 /* Note: There is no more input blocking in XEmacs */
|
|
497 typedef enum {
|
|
498 block_type, unblock_type, totally_type,
|
|
499 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, ungcpro_type
|
|
500 } blocktype;
|
|
501
|
185
|
502 struct block_input_history_struct
|
|
503 {
|
0
|
504 char *file;
|
|
505 int line;
|
|
506 blocktype type;
|
|
507 int value;
|
|
508 #ifdef SAVE_STACK
|
|
509 fun_entry backtrace[TRACE_LIMIT];
|
|
510 #endif
|
|
511 };
|
|
512
|
|
513 typedef struct block_input_history_struct block_input_history;
|
|
514
|
|
515 #endif
|
|
516
|
|
517 #ifdef DEBUG_INPUT_BLOCKING
|
|
518
|
|
519 int blhistptr;
|
|
520
|
|
521 #define BLHISTLIMIT 1000
|
|
522
|
|
523 block_input_history blhist[BLHISTLIMIT];
|
|
524
|
|
525 note_block_input (char *file, int line)
|
|
526 {
|
|
527 note_block (file, line, block_type);
|
|
528 if (interrupt_input_blocked > 2) abort();
|
|
529 }
|
|
530
|
|
531 note_unblock_input (char* file, int line)
|
|
532 {
|
|
533 note_block (file, line, unblock_type);
|
|
534 }
|
|
535
|
|
536 note_totally_unblocked (char* file, int line)
|
|
537 {
|
|
538 note_block (file, line, totally_type);
|
|
539 }
|
|
540
|
|
541 note_block (char *file, int line, blocktype type)
|
|
542 {
|
|
543 #ifdef SAVE_STACK
|
|
544 FRAME start_frame;
|
|
545
|
|
546 init_frame (&start_frame);
|
|
547 #endif
|
185
|
548
|
0
|
549 blhist[blhistptr].file = file;
|
|
550 blhist[blhistptr].line = line;
|
|
551 blhist[blhistptr].type = type;
|
|
552 blhist[blhistptr].value = interrupt_input_blocked;
|
|
553
|
|
554 #ifdef SAVE_STACK
|
|
555 save_backtrace (&start_frame,
|
|
556 blhist[blhistptr].backtrace);
|
|
557 #endif
|
|
558
|
|
559 blhistptr++;
|
|
560 if (blhistptr >= BLHISTLIMIT)
|
|
561 blhistptr = 0;
|
|
562 }
|
|
563
|
|
564 #endif
|
|
565
|
|
566
|
|
567 #ifdef DEBUG_GCPRO
|
|
568
|
|
569 int gcprohistptr;
|
|
570 #define GCPROHISTLIMIT 1000
|
|
571 block_input_history gcprohist[GCPROHISTLIMIT];
|
|
572
|
|
573 static void
|
|
574 log_gcpro (char *file, int line, struct gcpro *value, blocktype type)
|
|
575 {
|
|
576 FRAME start_frame;
|
|
577
|
|
578 if (type == ungcpro_type)
|
|
579 {
|
|
580 if (value == gcprolist) goto OK;
|
|
581 if (! gcprolist) abort ();
|
|
582 if (value == gcprolist->next) goto OK;
|
|
583 if (! gcprolist->next) abort ();
|
|
584 if (value == gcprolist->next->next) goto OK;
|
|
585 if (! gcprolist->next->next) abort ();
|
|
586 if (value == gcprolist->next->next->next) goto OK;
|
|
587 abort ();
|
|
588 OK:;
|
|
589 }
|
|
590 #ifdef SAVE_STACK
|
|
591 init_frame (&start_frame);
|
|
592 #endif
|
|
593 gcprohist[gcprohistptr].file = file;
|
|
594 gcprohist[gcprohistptr].line = line;
|
|
595 gcprohist[gcprohistptr].type = type;
|
|
596 gcprohist[gcprohistptr].value = (int) value;
|
|
597 #ifdef SAVE_STACK
|
|
598 save_backtrace (&start_frame, gcprohist[gcprohistptr].backtrace);
|
|
599 #endif
|
|
600 gcprohistptr++;
|
|
601 if (gcprohistptr >= GCPROHISTLIMIT)
|
|
602 gcprohistptr = 0;
|
|
603 }
|
|
604
|
|
605 void
|
|
606 debug_gcpro1 (char *file, int line, struct gcpro *gcpro1, Lisp_Object *var)
|
|
607 {
|
|
608 gcpro1->next = gcprolist; gcpro1->var = var; gcpro1->nvars = 1;
|
|
609 gcprolist = gcpro1;
|
|
610 log_gcpro (file, line, gcpro1, gcpro1_type);
|
|
611 }
|
|
612
|
|
613 void
|
|
614 debug_gcpro2 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
615 Lisp_Object *var1, Lisp_Object *var2)
|
|
616 {
|
|
617 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
618 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
619 gcprolist = gcpro2;
|
|
620 log_gcpro (file, line, gcpro2, gcpro2_type);
|
|
621 }
|
|
622
|
|
623 void
|
|
624 debug_gcpro3 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
625 struct gcpro *gcpro3, Lisp_Object *var1, Lisp_Object *var2,
|
|
626 Lisp_Object *var3)
|
|
627 {
|
|
628 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
629 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
630 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
631 gcprolist = gcpro3;
|
|
632 log_gcpro (file, line, gcpro3, gcpro3_type);
|
|
633 }
|
|
634
|
|
635 void
|
|
636 debug_gcpro4 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
637 struct gcpro *gcpro3, struct gcpro *gcpro4, Lisp_Object *var1,
|
|
638 Lisp_Object *var2, Lisp_Object *var3, Lisp_Object *var4)
|
|
639 {
|
|
640 log_gcpro (file, line, gcpro4, gcpro4_type);
|
|
641 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
642 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
643 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
644 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
|
|
645 gcprolist = gcpro4;
|
|
646 }
|
|
647
|
|
648 void
|
|
649 debug_gcpro5 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
650 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
|
|
651 Lisp_Object *var1, Lisp_Object *var2, Lisp_Object *var3,
|
|
652 Lisp_Object *var4, Lisp_Object *var5)
|
|
653 {
|
|
654 log_gcpro (file, line, gcpro5, gcpro5_type);
|
|
655 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
656 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
657 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
658 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
|
|
659 gcpro5->next = gcpro4; gcpro5->var = var5; gcpro5->nvars = 1;
|
|
660 gcprolist = gcpro5;
|
|
661 }
|
|
662
|
|
663 void
|
|
664 debug_ungcpro (char *file, int line, struct gcpro *gcpro1)
|
|
665 {
|
|
666 log_gcpro (file, line, gcpro1, ungcpro_type);
|
|
667 gcprolist = gcpro1->next;
|
|
668 }
|
|
669
|
|
670 void
|
|
671 show_gcprohist (void)
|
|
672 {
|
|
673 int i, j;
|
|
674 for (i = 0, j = gcprohistptr;
|
|
675 i < GCPROHISTLIMIT;
|
|
676 i++, j++)
|
|
677 {
|
|
678 if (j >= GCPROHISTLIMIT)
|
|
679 j = 0;
|
|
680 printf ("%3d %s %d %s 0x%x\n",
|
|
681 j, gcprohist[j].file, gcprohist[j].line,
|
|
682 (gcprohist[j].type == gcpro1_type ? "GCPRO1" :
|
|
683 gcprohist[j].type == gcpro2_type ? "GCPRO2" :
|
|
684 gcprohist[j].type == gcpro3_type ? "GCPRO3" :
|
|
685 gcprohist[j].type == gcpro4_type ? "GCPRO4" :
|
|
686 gcprohist[j].type == ungcpro_type ? "UNGCPRO" : "???"),
|
|
687 gcprohist[j].value);
|
|
688 }
|
|
689 fflush (stdout);
|
|
690 }
|
|
691
|
|
692 #endif
|