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
|
267
|
80 #if !defined(HAVE_LIBMCHECK)
|
0
|
81 #include <stdio.h>
|
|
82
|
|
83 #include "hash.h"
|
|
84
|
|
85 #ifdef UNMAPPED_FREE
|
|
86 #include <sys/mman.h>
|
|
87 #include <sys/param.h>
|
|
88 #define ROUND_UP_TO_PAGE(i) (((i) + PAGEOFFSET) & PAGEMASK)
|
|
89 #endif
|
|
90
|
|
91 #include <sys/types.h>
|
|
92
|
|
93 /* System function prototypes don't belong in C source files */
|
|
94 /* extern void free (void *); */
|
|
95
|
|
96 c_hashtable pointer_table;
|
|
97
|
|
98 extern void (*__free_hook) (void *);
|
|
99 extern void *(*__malloc_hook) (unsigned long);
|
|
100
|
|
101 static void *check_malloc (unsigned long);
|
|
102
|
|
103 typedef void (*fun_ptr) ();
|
|
104
|
|
105 #ifdef SAVE_STACK
|
|
106 #define FREE_QUEUE_LIMIT 1000
|
|
107 #else
|
|
108 /* free_queue is not too useful without backtrace logging */
|
|
109 #define FREE_QUEUE_LIMIT 1
|
|
110 #endif
|
|
111 #define TRACE_LIMIT 20
|
|
112
|
|
113 typedef struct {
|
|
114 fun_ptr return_pc;
|
|
115 #ifdef SAVE_ARGS
|
|
116 void *arg[3];
|
|
117 #endif
|
|
118 } fun_entry;
|
|
119
|
|
120 typedef struct {
|
|
121 void *address;
|
|
122 unsigned long length;
|
|
123 #ifdef SAVE_STACK
|
|
124 fun_entry backtrace[TRACE_LIMIT];
|
|
125 #endif
|
|
126 } free_queue_entry;
|
|
127
|
|
128 free_queue_entry free_queue[FREE_QUEUE_LIMIT];
|
|
129
|
|
130 int current_free;
|
|
131
|
|
132 #ifdef SAVE_STACK
|
|
133 static void
|
|
134 init_frame (FRAME *fptr)
|
|
135 {
|
|
136 FRAME tmp_frame;
|
|
137
|
|
138 #ifdef sparc
|
|
139 /* Do the system trap ST_FLUSH_WINDOWS */
|
|
140 asm ("ta 3");
|
|
141 asm ("st %sp, [%i0+0]");
|
|
142 asm ("st %fp, [%i0+4]");
|
|
143 #endif
|
|
144
|
|
145 fptr->pc = (char *) init_frame;
|
|
146 tmp_frame = *fptr;
|
|
147
|
|
148 PREVIOUS_FRAME (tmp_frame);
|
|
149
|
|
150 *fptr = tmp_frame;
|
|
151 return;
|
|
152 }
|
|
153
|
|
154 #ifdef SAVE_ARGS
|
|
155 static void *
|
|
156 frame_arg (FRAME *fptr, int index)
|
|
157 {
|
|
158 return ((void *) FRAME_ARG(*fptr, index));
|
|
159 }
|
|
160 #endif
|
|
161
|
|
162 static void
|
|
163 save_backtrace (FRAME *current_frame_ptr, fun_entry *table)
|
|
164 {
|
|
165 int i = 0;
|
|
166 #ifdef SAVE_ARGS
|
|
167 int j;
|
|
168 #endif
|
|
169 FRAME current_frame = *current_frame_ptr;
|
|
170
|
|
171 /* Get up and out of free() */
|
|
172 PREVIOUS_FRAME (current_frame);
|
|
173
|
|
174 /* now do the basic loop adding data until there is no more */
|
|
175 while (PREVIOUS_FRAME (current_frame) && i < TRACE_LIMIT)
|
|
176 {
|
|
177 table[i].return_pc = (void (*)())FRAME_PC (current_frame);
|
|
178 #ifdef SAVE_ARGS
|
|
179 for (j = 0; j < 3; j++)
|
|
180 table[i].arg[j] = frame_arg (¤t_frame, j);
|
|
181 #endif
|
|
182 i++;
|
|
183 }
|
|
184 memset (&table[i], 0, sizeof (fun_entry) * (TRACE_LIMIT - i));
|
|
185 }
|
|
186
|
|
187 free_queue_entry *
|
|
188 find_backtrace (void *ptr)
|
|
189 {
|
|
190 int i;
|
|
191
|
|
192 for (i = 0; i < FREE_QUEUE_LIMIT; i++)
|
|
193 if (free_queue[i].address == ptr)
|
|
194 return &free_queue[i];
|
|
195
|
|
196 return 0;
|
|
197 }
|
|
198 #endif /* SAVE_STACK */
|
|
199
|
|
200 int strict_free_check;
|
|
201
|
|
202 static void
|
|
203 check_free (void *ptr)
|
|
204 {
|
|
205 #ifdef SAVE_STACK
|
|
206 FRAME start_frame;
|
185
|
207
|
0
|
208 init_frame (&start_frame);
|
|
209 #endif
|
|
210
|
|
211 __free_hook = 0;
|
|
212 __malloc_hook = 0;
|
|
213 if (!pointer_table)
|
|
214 pointer_table = make_hashtable (max (100, FREE_QUEUE_LIMIT * 2));
|
|
215 if (ptr != 0)
|
|
216 {
|
|
217 long size;
|
|
218 #ifdef UNMAPPED_FREE
|
|
219 unsigned long rounded_up_size;
|
|
220 #endif
|
|
221
|
185
|
222 EMACS_INT present = (EMACS_INT) gethash (ptr, pointer_table,
|
|
223 (void **) &size);
|
0
|
224
|
|
225 if (!present)
|
233
|
226 {
|
0
|
227 /* This can only happen if you try to free something that didn't
|
|
228 come from malloc */
|
267
|
229 #if 1
|
|
230 /* I originally wrote: "There's really no need to drop core."
|
|
231 I have seen the error of my ways. -slb */
|
|
232 if (strict_free_check)
|
|
233 {
|
|
234 abort ();
|
|
235 }
|
|
236 #endif
|
|
237 printf("Freeing unmalloc'ed memory at %p\n", ptr);
|
|
238 __free_hook = check_free;
|
|
239 __malloc_hook = check_malloc;
|
|
240 goto end;
|
233
|
241 }
|
0
|
242
|
|
243 if (size < 0)
|
233
|
244 {
|
267
|
245 /* This happens when you free twice */
|
|
246 #if 1
|
|
247 /* See above comment. */
|
|
248 if (strict_free_check)
|
|
249 {
|
|
250 abort ();
|
|
251 }
|
|
252 #endif
|
|
253 printf("Freeing %p twice\n", ptr);
|
|
254 __free_hook = check_free;
|
|
255 __malloc_hook = check_malloc;
|
|
256 goto end;
|
233
|
257 }
|
267
|
258
|
0
|
259 puthash (ptr, (void *)-size, pointer_table);
|
|
260 #ifdef UNMAPPED_FREE
|
|
261 /* Round up size to an even number of pages. */
|
|
262 rounded_up_size = ROUND_UP_TO_PAGE (size);
|
|
263 /* Protect the pages freed from all access */
|
|
264 if (strict_free_check)
|
|
265 mprotect (ptr, rounded_up_size, PROT_NONE);
|
|
266 #else
|
|
267 /* Set every word in the block to 0xdeadbeef */
|
|
268 if (strict_free_check)
|
|
269 {
|
|
270 unsigned long long_length = (size + (sizeof (long) - 1))
|
|
271 / sizeof (long);
|
|
272 unsigned long i;
|
|
273
|
|
274 for (i = 0; i < long_length; i++)
|
|
275 ((unsigned long *) ptr)[i] = 0xdeadbeef;
|
|
276 }
|
|
277 #endif
|
|
278 free_queue[current_free].address = ptr;
|
|
279 free_queue[current_free].length = size;
|
|
280 #ifdef SAVE_STACK
|
|
281 save_backtrace (&start_frame,
|
|
282 free_queue[current_free].backtrace);
|
|
283 #endif
|
|
284 current_free++;
|
|
285 if (current_free >= FREE_QUEUE_LIMIT)
|
|
286 current_free = 0;
|
|
287 /* Really free this if there's something there */
|
|
288 {
|
|
289 void *old = free_queue[current_free].address;
|
|
290
|
|
291 if (old)
|
|
292 {
|
|
293 #ifdef UNMAPPED_FREE
|
|
294 unsigned long old_len = free_queue[current_free].length;
|
|
295
|
|
296 mprotect (old, old_len, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
297 #endif
|
|
298 free (old);
|
|
299 remhash (old, pointer_table);
|
|
300 }
|
|
301 }
|
|
302 }
|
|
303 __free_hook = check_free;
|
|
304 __malloc_hook = check_malloc;
|
|
305
|
|
306 end:
|
|
307 return;
|
185
|
308 }
|
0
|
309
|
|
310 static void *
|
|
311 check_malloc (unsigned long size)
|
|
312 {
|
|
313 unsigned long rounded_up_size;
|
|
314 void *result;
|
|
315
|
|
316 __free_hook = 0;
|
|
317 __malloc_hook = 0;
|
|
318 if (size == 0)
|
|
319 {
|
|
320 result = 0;
|
|
321 goto end;
|
|
322 }
|
|
323 #ifdef UNMAPPED_FREE
|
|
324 /* Round up to an even number of pages. */
|
|
325 rounded_up_size = ROUND_UP_TO_PAGE (size);
|
|
326 #else
|
|
327 rounded_up_size = size;
|
|
328 #endif
|
|
329 result = malloc (rounded_up_size);
|
|
330 if (!pointer_table)
|
|
331 pointer_table = make_hashtable (FREE_QUEUE_LIMIT * 2);
|
|
332 puthash (result, (void *)size, pointer_table);
|
|
333 __free_hook = check_free;
|
|
334 __malloc_hook = check_malloc;
|
|
335 end:
|
|
336 return result;
|
|
337 }
|
|
338
|
|
339 extern void *(*__realloc_hook) (void *, unsigned long);
|
|
340
|
|
341 #ifdef MIN
|
|
342 #undef MIN
|
|
343 #endif
|
|
344 #define MIN(A, B) ((A) < (B) ? (A) : (B))
|
|
345
|
|
346 /* Don't optimize realloc */
|
|
347
|
|
348 static void *
|
|
349 check_realloc (void * ptr, unsigned long size)
|
|
350 {
|
|
351 EMACS_INT present;
|
|
352 unsigned long old_size;
|
|
353 void *result = malloc (size);
|
185
|
354
|
|
355 present = (EMACS_INT) gethash (ptr, pointer_table, (void **) &old_size);
|
0
|
356 if (!present)
|
267
|
357 {
|
0
|
358 /* This can only happen by reallocing a pointer that didn't
|
|
359 come from malloc. */
|
267
|
360 #if 1
|
|
361 /* see comment in check_free(). */
|
|
362 abort ();
|
|
363 #endif
|
|
364 printf("Realloc'ing unmalloc'ed pointer at %p\n", ptr);
|
|
365 }
|
|
366
|
0
|
367 if (result == 0)
|
|
368 goto end;
|
|
369 memcpy (result, ptr, MIN (size, old_size));
|
|
370 free (ptr);
|
|
371 end:
|
|
372 return result;
|
|
373 }
|
|
374
|
185
|
375 void enable_strict_free_check (void);
|
0
|
376 void
|
|
377 enable_strict_free_check (void)
|
|
378 {
|
|
379 strict_free_check = 1;
|
|
380 }
|
|
381
|
185
|
382 void disable_strict_free_check (void);
|
0
|
383 void
|
|
384 disable_strict_free_check (void)
|
|
385 {
|
|
386 strict_free_check = 0;
|
|
387 }
|
|
388
|
|
389 /* Note: All BLOCK_INPUT stuff removed from this file because it's
|
|
390 completely gone in XEmacs */
|
|
391
|
|
392 static void *
|
|
393 block_input_malloc (unsigned long size);
|
|
394
|
|
395 static void
|
|
396 block_input_free (void* ptr)
|
|
397 {
|
|
398 __free_hook = 0;
|
|
399 __malloc_hook = 0;
|
|
400 free (ptr);
|
|
401 __free_hook = block_input_free;
|
|
402 __malloc_hook = block_input_malloc;
|
|
403 }
|
|
404
|
|
405 static void *
|
|
406 block_input_malloc (unsigned long size)
|
|
407 {
|
|
408 void* result;
|
|
409 __free_hook = 0;
|
|
410 __malloc_hook = 0;
|
|
411 result = malloc (size);
|
|
412 __free_hook = block_input_free;
|
|
413 __malloc_hook = block_input_malloc;
|
|
414 return result;
|
|
415 }
|
|
416
|
|
417
|
|
418 static void *
|
|
419 block_input_realloc (void* ptr, unsigned long size)
|
|
420 {
|
|
421 void* result;
|
|
422 __free_hook = 0;
|
|
423 __malloc_hook = 0;
|
|
424 __realloc_hook = 0;
|
|
425 result = realloc (ptr, size);
|
|
426 __free_hook = block_input_free;
|
|
427 __malloc_hook = block_input_malloc;
|
|
428 __realloc_hook = block_input_realloc;
|
|
429 return result;
|
|
430 }
|
|
431
|
|
432 #ifdef emacs
|
|
433
|
|
434 void disable_free_hook (void);
|
|
435 void
|
|
436 disable_free_hook (void)
|
|
437 {
|
|
438 __free_hook = block_input_free;
|
|
439 __malloc_hook = block_input_malloc;
|
|
440 __realloc_hook = block_input_realloc;
|
|
441 }
|
|
442
|
|
443 void
|
|
444 init_free_hook (void)
|
|
445 {
|
|
446 __free_hook = check_free;
|
|
447 __malloc_hook = check_malloc;
|
|
448 __realloc_hook = check_realloc;
|
|
449 current_free = 0;
|
|
450 strict_free_check = 1;
|
|
451 }
|
|
452
|
|
453 void really_free_one_entry (void *, int, int *);
|
|
454
|
20
|
455 DEFUN ("really-free", Freally_free, 0, 1, "P", /*
|
0
|
456 Actually free the storage held by the free() debug hook.
|
|
457 A no-op if the free hook is disabled.
|
20
|
458 */
|
|
459 (arg))
|
0
|
460 {
|
|
461 int count[2];
|
|
462 Lisp_Object lisp_count[2];
|
|
463
|
|
464 if ((__free_hook != 0) && pointer_table)
|
|
465 {
|
|
466 count[0] = 0;
|
|
467 count[1] = 0;
|
|
468 __free_hook = 0;
|
185
|
469 maphash ((maphash_function)really_free_one_entry,
|
0
|
470 pointer_table, (void *)&count);
|
|
471 memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT);
|
|
472 current_free = 0;
|
|
473 __free_hook = check_free;
|
|
474 XSETINT (lisp_count[0], count[0]);
|
|
475 XSETINT (lisp_count[1], count[1]);
|
|
476 return Fcons (lisp_count[0], lisp_count[1]);
|
|
477 }
|
|
478 else
|
|
479 return Fcons (make_int (0), make_int (0));
|
|
480 }
|
|
481
|
|
482 void
|
|
483 really_free_one_entry (void *key, int contents, int *countp)
|
|
484 {
|
|
485 if (contents < 0)
|
|
486 {
|
|
487 free (key);
|
|
488 #ifdef UNMAPPED_FREE
|
|
489 mprotect (key, -contents, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
490 #endif
|
|
491 remhash (key, pointer_table);
|
|
492 countp[0]++;
|
|
493 countp[1] += -contents;
|
|
494 }
|
|
495 }
|
|
496
|
|
497 void
|
|
498 syms_of_free_hook (void)
|
|
499 {
|
20
|
500 DEFSUBR (Freally_free);
|
0
|
501 }
|
|
502
|
|
503 #else
|
|
504 void (*__free_hook)() = check_free;
|
|
505 void *(*__malloc_hook)() = check_malloc;
|
|
506 void *(*__realloc_hook)() = check_realloc;
|
|
507 #endif
|
|
508
|
267
|
509 #endif /* !defined(HAVE_LIBMCHECK) */
|
0
|
510
|
|
511 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)
|
|
512
|
|
513 /* Note: There is no more input blocking in XEmacs */
|
|
514 typedef enum {
|
|
515 block_type, unblock_type, totally_type,
|
|
516 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, ungcpro_type
|
|
517 } blocktype;
|
|
518
|
185
|
519 struct block_input_history_struct
|
|
520 {
|
0
|
521 char *file;
|
|
522 int line;
|
|
523 blocktype type;
|
|
524 int value;
|
|
525 #ifdef SAVE_STACK
|
|
526 fun_entry backtrace[TRACE_LIMIT];
|
|
527 #endif
|
|
528 };
|
|
529
|
|
530 typedef struct block_input_history_struct block_input_history;
|
|
531
|
|
532 #endif
|
|
533
|
|
534 #ifdef DEBUG_INPUT_BLOCKING
|
|
535
|
|
536 int blhistptr;
|
|
537
|
|
538 #define BLHISTLIMIT 1000
|
|
539
|
|
540 block_input_history blhist[BLHISTLIMIT];
|
|
541
|
|
542 note_block_input (char *file, int line)
|
|
543 {
|
|
544 note_block (file, line, block_type);
|
|
545 if (interrupt_input_blocked > 2) abort();
|
|
546 }
|
|
547
|
|
548 note_unblock_input (char* file, int line)
|
|
549 {
|
|
550 note_block (file, line, unblock_type);
|
|
551 }
|
|
552
|
|
553 note_totally_unblocked (char* file, int line)
|
|
554 {
|
|
555 note_block (file, line, totally_type);
|
|
556 }
|
|
557
|
|
558 note_block (char *file, int line, blocktype type)
|
|
559 {
|
|
560 #ifdef SAVE_STACK
|
|
561 FRAME start_frame;
|
|
562
|
|
563 init_frame (&start_frame);
|
|
564 #endif
|
185
|
565
|
0
|
566 blhist[blhistptr].file = file;
|
|
567 blhist[blhistptr].line = line;
|
|
568 blhist[blhistptr].type = type;
|
|
569 blhist[blhistptr].value = interrupt_input_blocked;
|
|
570
|
|
571 #ifdef SAVE_STACK
|
|
572 save_backtrace (&start_frame,
|
|
573 blhist[blhistptr].backtrace);
|
|
574 #endif
|
|
575
|
|
576 blhistptr++;
|
|
577 if (blhistptr >= BLHISTLIMIT)
|
|
578 blhistptr = 0;
|
|
579 }
|
|
580
|
|
581 #endif
|
|
582
|
|
583
|
|
584 #ifdef DEBUG_GCPRO
|
|
585
|
|
586 int gcprohistptr;
|
|
587 #define GCPROHISTLIMIT 1000
|
|
588 block_input_history gcprohist[GCPROHISTLIMIT];
|
|
589
|
|
590 static void
|
|
591 log_gcpro (char *file, int line, struct gcpro *value, blocktype type)
|
|
592 {
|
|
593 FRAME start_frame;
|
|
594
|
|
595 if (type == ungcpro_type)
|
|
596 {
|
|
597 if (value == gcprolist) goto OK;
|
|
598 if (! gcprolist) abort ();
|
|
599 if (value == gcprolist->next) goto OK;
|
|
600 if (! gcprolist->next) abort ();
|
|
601 if (value == gcprolist->next->next) goto OK;
|
|
602 if (! gcprolist->next->next) abort ();
|
|
603 if (value == gcprolist->next->next->next) goto OK;
|
|
604 abort ();
|
|
605 OK:;
|
|
606 }
|
|
607 #ifdef SAVE_STACK
|
|
608 init_frame (&start_frame);
|
|
609 #endif
|
|
610 gcprohist[gcprohistptr].file = file;
|
|
611 gcprohist[gcprohistptr].line = line;
|
|
612 gcprohist[gcprohistptr].type = type;
|
|
613 gcprohist[gcprohistptr].value = (int) value;
|
|
614 #ifdef SAVE_STACK
|
|
615 save_backtrace (&start_frame, gcprohist[gcprohistptr].backtrace);
|
|
616 #endif
|
|
617 gcprohistptr++;
|
|
618 if (gcprohistptr >= GCPROHISTLIMIT)
|
|
619 gcprohistptr = 0;
|
|
620 }
|
|
621
|
|
622 void
|
|
623 debug_gcpro1 (char *file, int line, struct gcpro *gcpro1, Lisp_Object *var)
|
|
624 {
|
|
625 gcpro1->next = gcprolist; gcpro1->var = var; gcpro1->nvars = 1;
|
|
626 gcprolist = gcpro1;
|
|
627 log_gcpro (file, line, gcpro1, gcpro1_type);
|
|
628 }
|
|
629
|
|
630 void
|
|
631 debug_gcpro2 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
632 Lisp_Object *var1, Lisp_Object *var2)
|
|
633 {
|
|
634 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
635 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
636 gcprolist = gcpro2;
|
|
637 log_gcpro (file, line, gcpro2, gcpro2_type);
|
|
638 }
|
|
639
|
|
640 void
|
|
641 debug_gcpro3 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
642 struct gcpro *gcpro3, Lisp_Object *var1, Lisp_Object *var2,
|
|
643 Lisp_Object *var3)
|
|
644 {
|
|
645 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
646 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
647 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
648 gcprolist = gcpro3;
|
|
649 log_gcpro (file, line, gcpro3, gcpro3_type);
|
|
650 }
|
|
651
|
|
652 void
|
|
653 debug_gcpro4 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
654 struct gcpro *gcpro3, struct gcpro *gcpro4, Lisp_Object *var1,
|
|
655 Lisp_Object *var2, Lisp_Object *var3, Lisp_Object *var4)
|
|
656 {
|
|
657 log_gcpro (file, line, gcpro4, gcpro4_type);
|
|
658 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
659 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
660 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
661 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
|
|
662 gcprolist = gcpro4;
|
|
663 }
|
|
664
|
|
665 void
|
|
666 debug_gcpro5 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
667 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
|
|
668 Lisp_Object *var1, Lisp_Object *var2, Lisp_Object *var3,
|
|
669 Lisp_Object *var4, Lisp_Object *var5)
|
|
670 {
|
|
671 log_gcpro (file, line, gcpro5, gcpro5_type);
|
|
672 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
673 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
674 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
675 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
|
|
676 gcpro5->next = gcpro4; gcpro5->var = var5; gcpro5->nvars = 1;
|
|
677 gcprolist = gcpro5;
|
|
678 }
|
|
679
|
|
680 void
|
|
681 debug_ungcpro (char *file, int line, struct gcpro *gcpro1)
|
|
682 {
|
|
683 log_gcpro (file, line, gcpro1, ungcpro_type);
|
|
684 gcprolist = gcpro1->next;
|
|
685 }
|
|
686
|
|
687 void
|
|
688 show_gcprohist (void)
|
|
689 {
|
|
690 int i, j;
|
|
691 for (i = 0, j = gcprohistptr;
|
|
692 i < GCPROHISTLIMIT;
|
|
693 i++, j++)
|
|
694 {
|
|
695 if (j >= GCPROHISTLIMIT)
|
|
696 j = 0;
|
|
697 printf ("%3d %s %d %s 0x%x\n",
|
|
698 j, gcprohist[j].file, gcprohist[j].line,
|
|
699 (gcprohist[j].type == gcpro1_type ? "GCPRO1" :
|
|
700 gcprohist[j].type == gcpro2_type ? "GCPRO2" :
|
|
701 gcprohist[j].type == gcpro3_type ? "GCPRO3" :
|
|
702 gcprohist[j].type == gcpro4_type ? "GCPRO4" :
|
|
703 gcprohist[j].type == ungcpro_type ? "UNGCPRO" : "???"),
|
|
704 gcprohist[j].value);
|
|
705 }
|
|
706 fflush (stdout);
|
|
707 }
|
|
708
|
|
709 #endif
|