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)
|
|
225 /* This can only happen if you try to free something that didn't
|
|
226 come from malloc */
|
|
227 if (strict_free_check)
|
|
228 abort ();
|
|
229 else
|
|
230 {
|
|
231 __free_hook = check_free;
|
|
232 __malloc_hook = check_malloc;
|
|
233 goto end;
|
|
234 }
|
|
235
|
|
236 if (size < 0)
|
|
237 /* This happens when you free twice */
|
|
238 if (strict_free_check)
|
|
239 abort ();
|
|
240 else
|
|
241 {
|
|
242 __free_hook = check_free;
|
|
243 __malloc_hook = check_malloc;
|
|
244 goto end;
|
|
245 }
|
|
246 puthash (ptr, (void *)-size, pointer_table);
|
|
247 #ifdef UNMAPPED_FREE
|
|
248 /* Round up size to an even number of pages. */
|
|
249 rounded_up_size = ROUND_UP_TO_PAGE (size);
|
|
250 /* Protect the pages freed from all access */
|
|
251 if (strict_free_check)
|
|
252 mprotect (ptr, rounded_up_size, PROT_NONE);
|
|
253 #else
|
|
254 /* Set every word in the block to 0xdeadbeef */
|
|
255 if (strict_free_check)
|
|
256 {
|
|
257 unsigned long long_length = (size + (sizeof (long) - 1))
|
|
258 / sizeof (long);
|
|
259 unsigned long i;
|
|
260
|
|
261 for (i = 0; i < long_length; i++)
|
|
262 ((unsigned long *) ptr)[i] = 0xdeadbeef;
|
|
263 }
|
|
264 #endif
|
|
265 free_queue[current_free].address = ptr;
|
|
266 free_queue[current_free].length = size;
|
|
267 #ifdef SAVE_STACK
|
|
268 save_backtrace (&start_frame,
|
|
269 free_queue[current_free].backtrace);
|
|
270 #endif
|
|
271 current_free++;
|
|
272 if (current_free >= FREE_QUEUE_LIMIT)
|
|
273 current_free = 0;
|
|
274 /* Really free this if there's something there */
|
|
275 {
|
|
276 void *old = free_queue[current_free].address;
|
|
277
|
|
278 if (old)
|
|
279 {
|
|
280 #ifdef UNMAPPED_FREE
|
|
281 unsigned long old_len = free_queue[current_free].length;
|
|
282
|
|
283 mprotect (old, old_len, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
284 #endif
|
|
285 free (old);
|
|
286 remhash (old, pointer_table);
|
|
287 }
|
|
288 }
|
|
289 }
|
|
290 __free_hook = check_free;
|
|
291 __malloc_hook = check_malloc;
|
|
292
|
|
293 end:
|
|
294 return;
|
185
|
295 }
|
0
|
296
|
|
297 static void *
|
|
298 check_malloc (unsigned long size)
|
|
299 {
|
|
300 unsigned long rounded_up_size;
|
|
301 void *result;
|
|
302
|
|
303 __free_hook = 0;
|
|
304 __malloc_hook = 0;
|
|
305 if (size == 0)
|
|
306 {
|
|
307 result = 0;
|
|
308 goto end;
|
|
309 }
|
|
310 #ifdef UNMAPPED_FREE
|
|
311 /* Round up to an even number of pages. */
|
|
312 rounded_up_size = ROUND_UP_TO_PAGE (size);
|
|
313 #else
|
|
314 rounded_up_size = size;
|
|
315 #endif
|
|
316 result = malloc (rounded_up_size);
|
|
317 if (!pointer_table)
|
|
318 pointer_table = make_hashtable (FREE_QUEUE_LIMIT * 2);
|
|
319 puthash (result, (void *)size, pointer_table);
|
|
320 __free_hook = check_free;
|
|
321 __malloc_hook = check_malloc;
|
|
322 end:
|
|
323 return result;
|
|
324 }
|
|
325
|
|
326 extern void *(*__realloc_hook) (void *, unsigned long);
|
|
327
|
|
328 #ifdef MIN
|
|
329 #undef MIN
|
|
330 #endif
|
|
331 #define MIN(A, B) ((A) < (B) ? (A) : (B))
|
|
332
|
|
333 /* Don't optimize realloc */
|
|
334
|
|
335 static void *
|
|
336 check_realloc (void * ptr, unsigned long size)
|
|
337 {
|
|
338 EMACS_INT present;
|
|
339 unsigned long old_size;
|
|
340 void *result = malloc (size);
|
185
|
341
|
|
342 present = (EMACS_INT) gethash (ptr, pointer_table, (void **) &old_size);
|
0
|
343 if (!present)
|
|
344 /* This can only happen by reallocing a pointer that didn't
|
|
345 come from malloc. */
|
|
346 abort ();
|
|
347 if (result == 0)
|
|
348 goto end;
|
|
349 memcpy (result, ptr, MIN (size, old_size));
|
|
350 free (ptr);
|
|
351 end:
|
|
352 return result;
|
|
353 }
|
|
354
|
185
|
355 void enable_strict_free_check (void);
|
0
|
356 void
|
|
357 enable_strict_free_check (void)
|
|
358 {
|
|
359 strict_free_check = 1;
|
|
360 }
|
|
361
|
185
|
362 void disable_strict_free_check (void);
|
0
|
363 void
|
|
364 disable_strict_free_check (void)
|
|
365 {
|
|
366 strict_free_check = 0;
|
|
367 }
|
|
368
|
|
369 /* Note: All BLOCK_INPUT stuff removed from this file because it's
|
|
370 completely gone in XEmacs */
|
|
371
|
|
372 static void *
|
|
373 block_input_malloc (unsigned long size);
|
|
374
|
|
375 static void
|
|
376 block_input_free (void* ptr)
|
|
377 {
|
|
378 __free_hook = 0;
|
|
379 __malloc_hook = 0;
|
|
380 free (ptr);
|
|
381 __free_hook = block_input_free;
|
|
382 __malloc_hook = block_input_malloc;
|
|
383 }
|
|
384
|
|
385 static void *
|
|
386 block_input_malloc (unsigned long size)
|
|
387 {
|
|
388 void* result;
|
|
389 __free_hook = 0;
|
|
390 __malloc_hook = 0;
|
|
391 result = malloc (size);
|
|
392 __free_hook = block_input_free;
|
|
393 __malloc_hook = block_input_malloc;
|
|
394 return result;
|
|
395 }
|
|
396
|
|
397
|
|
398 static void *
|
|
399 block_input_realloc (void* ptr, unsigned long size)
|
|
400 {
|
|
401 void* result;
|
|
402 __free_hook = 0;
|
|
403 __malloc_hook = 0;
|
|
404 __realloc_hook = 0;
|
|
405 result = realloc (ptr, size);
|
|
406 __free_hook = block_input_free;
|
|
407 __malloc_hook = block_input_malloc;
|
|
408 __realloc_hook = block_input_realloc;
|
|
409 return result;
|
|
410 }
|
|
411
|
|
412 #ifdef emacs
|
|
413
|
|
414 void disable_free_hook (void);
|
|
415 void
|
|
416 disable_free_hook (void)
|
|
417 {
|
|
418 __free_hook = block_input_free;
|
|
419 __malloc_hook = block_input_malloc;
|
|
420 __realloc_hook = block_input_realloc;
|
|
421 }
|
|
422
|
|
423 void
|
|
424 init_free_hook (void)
|
|
425 {
|
|
426 __free_hook = check_free;
|
|
427 __malloc_hook = check_malloc;
|
|
428 __realloc_hook = check_realloc;
|
|
429 current_free = 0;
|
|
430 strict_free_check = 1;
|
|
431 }
|
|
432
|
|
433 void really_free_one_entry (void *, int, int *);
|
|
434
|
20
|
435 DEFUN ("really-free", Freally_free, 0, 1, "P", /*
|
0
|
436 Actually free the storage held by the free() debug hook.
|
|
437 A no-op if the free hook is disabled.
|
20
|
438 */
|
|
439 (arg))
|
0
|
440 {
|
|
441 int count[2];
|
|
442 Lisp_Object lisp_count[2];
|
|
443
|
|
444 if ((__free_hook != 0) && pointer_table)
|
|
445 {
|
|
446 count[0] = 0;
|
|
447 count[1] = 0;
|
|
448 __free_hook = 0;
|
185
|
449 maphash ((maphash_function)really_free_one_entry,
|
0
|
450 pointer_table, (void *)&count);
|
|
451 memset (free_queue, 0, sizeof (free_queue_entry) * FREE_QUEUE_LIMIT);
|
|
452 current_free = 0;
|
|
453 __free_hook = check_free;
|
|
454 XSETINT (lisp_count[0], count[0]);
|
|
455 XSETINT (lisp_count[1], count[1]);
|
|
456 return Fcons (lisp_count[0], lisp_count[1]);
|
|
457 }
|
|
458 else
|
|
459 return Fcons (make_int (0), make_int (0));
|
|
460 }
|
|
461
|
|
462 void
|
|
463 really_free_one_entry (void *key, int contents, int *countp)
|
|
464 {
|
|
465 if (contents < 0)
|
|
466 {
|
|
467 free (key);
|
|
468 #ifdef UNMAPPED_FREE
|
|
469 mprotect (key, -contents, PROT_READ | PROT_WRITE | PROT_EXEC);
|
|
470 #endif
|
|
471 remhash (key, pointer_table);
|
|
472 countp[0]++;
|
|
473 countp[1] += -contents;
|
|
474 }
|
|
475 }
|
|
476
|
|
477 void
|
|
478 syms_of_free_hook (void)
|
|
479 {
|
20
|
480 DEFSUBR (Freally_free);
|
0
|
481 }
|
|
482
|
|
483 #else
|
|
484 void (*__free_hook)() = check_free;
|
|
485 void *(*__malloc_hook)() = check_malloc;
|
|
486 void *(*__realloc_hook)() = check_realloc;
|
|
487 #endif
|
|
488
|
|
489
|
|
490 #if defined(DEBUG_INPUT_BLOCKING) || defined (DEBUG_GCPRO)
|
|
491
|
|
492 /* Note: There is no more input blocking in XEmacs */
|
|
493 typedef enum {
|
|
494 block_type, unblock_type, totally_type,
|
|
495 gcpro1_type, gcpro2_type, gcpro3_type, gcpro4_type, ungcpro_type
|
|
496 } blocktype;
|
|
497
|
185
|
498 struct block_input_history_struct
|
|
499 {
|
0
|
500 char *file;
|
|
501 int line;
|
|
502 blocktype type;
|
|
503 int value;
|
|
504 #ifdef SAVE_STACK
|
|
505 fun_entry backtrace[TRACE_LIMIT];
|
|
506 #endif
|
|
507 };
|
|
508
|
|
509 typedef struct block_input_history_struct block_input_history;
|
|
510
|
|
511 #endif
|
|
512
|
|
513 #ifdef DEBUG_INPUT_BLOCKING
|
|
514
|
|
515 int blhistptr;
|
|
516
|
|
517 #define BLHISTLIMIT 1000
|
|
518
|
|
519 block_input_history blhist[BLHISTLIMIT];
|
|
520
|
|
521 note_block_input (char *file, int line)
|
|
522 {
|
|
523 note_block (file, line, block_type);
|
|
524 if (interrupt_input_blocked > 2) abort();
|
|
525 }
|
|
526
|
|
527 note_unblock_input (char* file, int line)
|
|
528 {
|
|
529 note_block (file, line, unblock_type);
|
|
530 }
|
|
531
|
|
532 note_totally_unblocked (char* file, int line)
|
|
533 {
|
|
534 note_block (file, line, totally_type);
|
|
535 }
|
|
536
|
|
537 note_block (char *file, int line, blocktype type)
|
|
538 {
|
|
539 #ifdef SAVE_STACK
|
|
540 FRAME start_frame;
|
|
541
|
|
542 init_frame (&start_frame);
|
|
543 #endif
|
185
|
544
|
0
|
545 blhist[blhistptr].file = file;
|
|
546 blhist[blhistptr].line = line;
|
|
547 blhist[blhistptr].type = type;
|
|
548 blhist[blhistptr].value = interrupt_input_blocked;
|
|
549
|
|
550 #ifdef SAVE_STACK
|
|
551 save_backtrace (&start_frame,
|
|
552 blhist[blhistptr].backtrace);
|
|
553 #endif
|
|
554
|
|
555 blhistptr++;
|
|
556 if (blhistptr >= BLHISTLIMIT)
|
|
557 blhistptr = 0;
|
|
558 }
|
|
559
|
|
560 #endif
|
|
561
|
|
562
|
|
563 #ifdef DEBUG_GCPRO
|
|
564
|
|
565 int gcprohistptr;
|
|
566 #define GCPROHISTLIMIT 1000
|
|
567 block_input_history gcprohist[GCPROHISTLIMIT];
|
|
568
|
|
569 static void
|
|
570 log_gcpro (char *file, int line, struct gcpro *value, blocktype type)
|
|
571 {
|
|
572 FRAME start_frame;
|
|
573
|
|
574 if (type == ungcpro_type)
|
|
575 {
|
|
576 if (value == gcprolist) goto OK;
|
|
577 if (! gcprolist) abort ();
|
|
578 if (value == gcprolist->next) goto OK;
|
|
579 if (! gcprolist->next) abort ();
|
|
580 if (value == gcprolist->next->next) goto OK;
|
|
581 if (! gcprolist->next->next) abort ();
|
|
582 if (value == gcprolist->next->next->next) goto OK;
|
|
583 abort ();
|
|
584 OK:;
|
|
585 }
|
|
586 #ifdef SAVE_STACK
|
|
587 init_frame (&start_frame);
|
|
588 #endif
|
|
589 gcprohist[gcprohistptr].file = file;
|
|
590 gcprohist[gcprohistptr].line = line;
|
|
591 gcprohist[gcprohistptr].type = type;
|
|
592 gcprohist[gcprohistptr].value = (int) value;
|
|
593 #ifdef SAVE_STACK
|
|
594 save_backtrace (&start_frame, gcprohist[gcprohistptr].backtrace);
|
|
595 #endif
|
|
596 gcprohistptr++;
|
|
597 if (gcprohistptr >= GCPROHISTLIMIT)
|
|
598 gcprohistptr = 0;
|
|
599 }
|
|
600
|
|
601 void
|
|
602 debug_gcpro1 (char *file, int line, struct gcpro *gcpro1, Lisp_Object *var)
|
|
603 {
|
|
604 gcpro1->next = gcprolist; gcpro1->var = var; gcpro1->nvars = 1;
|
|
605 gcprolist = gcpro1;
|
|
606 log_gcpro (file, line, gcpro1, gcpro1_type);
|
|
607 }
|
|
608
|
|
609 void
|
|
610 debug_gcpro2 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
611 Lisp_Object *var1, Lisp_Object *var2)
|
|
612 {
|
|
613 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
614 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
615 gcprolist = gcpro2;
|
|
616 log_gcpro (file, line, gcpro2, gcpro2_type);
|
|
617 }
|
|
618
|
|
619 void
|
|
620 debug_gcpro3 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
621 struct gcpro *gcpro3, Lisp_Object *var1, Lisp_Object *var2,
|
|
622 Lisp_Object *var3)
|
|
623 {
|
|
624 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
625 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
626 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
627 gcprolist = gcpro3;
|
|
628 log_gcpro (file, line, gcpro3, gcpro3_type);
|
|
629 }
|
|
630
|
|
631 void
|
|
632 debug_gcpro4 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
633 struct gcpro *gcpro3, struct gcpro *gcpro4, Lisp_Object *var1,
|
|
634 Lisp_Object *var2, Lisp_Object *var3, Lisp_Object *var4)
|
|
635 {
|
|
636 log_gcpro (file, line, gcpro4, gcpro4_type);
|
|
637 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
638 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
639 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
640 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
|
|
641 gcprolist = gcpro4;
|
|
642 }
|
|
643
|
|
644 void
|
|
645 debug_gcpro5 (char *file, int line, struct gcpro *gcpro1, struct gcpro *gcpro2,
|
|
646 struct gcpro *gcpro3, struct gcpro *gcpro4, struct gcpro *gcpro5,
|
|
647 Lisp_Object *var1, Lisp_Object *var2, Lisp_Object *var3,
|
|
648 Lisp_Object *var4, Lisp_Object *var5)
|
|
649 {
|
|
650 log_gcpro (file, line, gcpro5, gcpro5_type);
|
|
651 gcpro1->next = gcprolist; gcpro1->var = var1; gcpro1->nvars = 1;
|
|
652 gcpro2->next = gcpro1; gcpro2->var = var2; gcpro2->nvars = 1;
|
|
653 gcpro3->next = gcpro2; gcpro3->var = var3; gcpro3->nvars = 1;
|
|
654 gcpro4->next = gcpro3; gcpro4->var = var4; gcpro4->nvars = 1;
|
|
655 gcpro5->next = gcpro4; gcpro5->var = var5; gcpro5->nvars = 1;
|
|
656 gcprolist = gcpro5;
|
|
657 }
|
|
658
|
|
659 void
|
|
660 debug_ungcpro (char *file, int line, struct gcpro *gcpro1)
|
|
661 {
|
|
662 log_gcpro (file, line, gcpro1, ungcpro_type);
|
|
663 gcprolist = gcpro1->next;
|
|
664 }
|
|
665
|
|
666 void
|
|
667 show_gcprohist (void)
|
|
668 {
|
|
669 int i, j;
|
|
670 for (i = 0, j = gcprohistptr;
|
|
671 i < GCPROHISTLIMIT;
|
|
672 i++, j++)
|
|
673 {
|
|
674 if (j >= GCPROHISTLIMIT)
|
|
675 j = 0;
|
|
676 printf ("%3d %s %d %s 0x%x\n",
|
|
677 j, gcprohist[j].file, gcprohist[j].line,
|
|
678 (gcprohist[j].type == gcpro1_type ? "GCPRO1" :
|
|
679 gcprohist[j].type == gcpro2_type ? "GCPRO2" :
|
|
680 gcprohist[j].type == gcpro3_type ? "GCPRO3" :
|
|
681 gcprohist[j].type == gcpro4_type ? "GCPRO4" :
|
|
682 gcprohist[j].type == ungcpro_type ? "UNGCPRO" : "???"),
|
|
683 gcprohist[j].value);
|
|
684 }
|
|
685 fflush (stdout);
|
|
686 }
|
|
687
|
|
688 #endif
|