Fix the cheneygc build
[sbcl.git] / src / runtime / print.c
1 /* code for low-level debugging/diagnostic output */
2
3 /*
4  * This software is part of the SBCL system. See the README file for
5  * more information.
6  *
7  * This software is derived from the CMU CL system, which was
8  * written at Carnegie Mellon University and released into the
9  * public domain. The software is in the public domain and is
10  * provided with absolutely no warranty. See the COPYING and CREDITS
11  * files for more information.
12  */
13
14 /*
15  * FIXME:
16  *   Some of the code in here (the various
17  *   foo_slots[], at least) is deeply broken, depending on guessing
18  *   already out-of-date values instead of getting them from sbcl.h.
19  */
20
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "sbcl.h"
25 #include "print.h"
26 #include "runtime.h"
27 #include <stdarg.h>
28 #include "thread.h"              /* genesis/primitive-objects.h needs this */
29 #include <errno.h>
30 #include <stdlib.h>
31
32 /* FSHOW and odxprint provide debugging output for low-level information
33  * (signal handling, exceptions, safepoints) which is hard to debug by
34  * other means.
35  *
36  * If enabled at all, environment variables control whether calls of the
37  * form odxprint(name, ...) are enabled at run-time, e.g. using
38  * SBCL_DYNDEBUG="fshow fshow_signal safepoints".
39  *
40  * In the case of FSHOW and FSHOW_SIGNAL, old-style code from runtime.h
41  * can also be used to enable or disable these more aggressively.
42  */
43
44 struct dyndebug_config dyndebug_config = {
45     QSHOW == 2, QSHOW_SIGNALS == 2
46 };
47
48 void
49 dyndebug_init()
50 {
51 #define DYNDEBUG_NFLAGS (sizeof(struct dyndebug_config) / sizeof(int))
52 #define dyndebug_init1(lowercase, uppercase)                    \
53     do {                                                        \
54         int *ptr = &dyndebug_config.dyndebug_##lowercase;       \
55         ptrs[n] = ptr;                                          \
56         names[n] = #lowercase;                                  \
57         char *val = getenv("SBCL_DYNDEBUG__" uppercase);        \
58         *ptr = val && strlen(val);                              \
59         n++;                                                    \
60     } while (0)
61     int n = 0;
62     char *names[DYNDEBUG_NFLAGS];
63     int *ptrs[DYNDEBUG_NFLAGS];
64
65     dyndebug_init1(fshow,          "FSHOW");
66     dyndebug_init1(fshow_signal,   "FSHOW_SIGNAL");
67     dyndebug_init1(gencgc_verbose, "GENCGC_VERBOSE");
68     dyndebug_init1(safepoints,     "SAFEPOINTS");
69     dyndebug_init1(seh,            "SEH");
70     dyndebug_init1(misc,           "MISC");
71     dyndebug_init1(pagefaults,     "PAGEFAULTS");
72
73     int n_output_flags = n;
74     dyndebug_init1(backtrace_when_lost, "BACKTRACE_WHEN_LOST");
75     dyndebug_init1(sleep_when_lost,     "SLEEP_WHEN_LOST");
76
77     if (n != DYNDEBUG_NFLAGS)
78         fprintf(stderr, "Bug in dyndebug_init\n");
79
80 #if defined(LISP_FEATURE_GENCGC)
81     gencgc_verbose = dyndebug_config.dyndebug_gencgc_verbose;
82 #endif
83
84     char *featurelist = getenv("SBCL_DYNDEBUG");
85     if (featurelist) {
86         int err = 0;
87         featurelist = strdup(featurelist);
88         char *ptr = featurelist;
89         for (;;) {
90             char *token = strtok(ptr, " ");
91             if (!token) break;
92             unsigned i;
93             if (!strcmp(token, "all"))
94                 for (i = 0; i < n_output_flags; i++)
95                     *ptrs[i] = 1;
96             else {
97                 for (i = 0; i < DYNDEBUG_NFLAGS; i++)
98                     if (!strcmp(token, names[i])) {
99                         *ptrs[i] = 1;
100                         break;
101                     }
102                 if (i == DYNDEBUG_NFLAGS) {
103                     fprintf(stderr, "No such dyndebug flag: `%s'\n", token);
104                     err = 1;
105                 }
106             }
107             ptr = 0;
108         }
109         free(featurelist);
110         if (err) {
111             fprintf(stderr, "Valid flags are:\n");
112             fprintf(stderr, "  all  ;enables all of the following:\n");
113             unsigned i;
114             for (i = 0; i < DYNDEBUG_NFLAGS; i++) {
115                 if (i == n_output_flags)
116                     fprintf(stderr, "Additional options:\n");
117                 fprintf(stderr, "  %s\n", names[i]);
118             }
119         }
120     }
121
122 #undef dyndebug_init1
123 #undef DYNDEBUG_NFLAGS
124 }
125
126 /* Temporarily, odxprint merely performs the equivalent of a traditional
127  * FSHOW call, i.e. it merely formats to stderr.  Ultimately, it should
128  * be restored to its full win32 branch functionality, where output to a
129  * file or to the debugger can be selected at runtime. */
130
131 void vodxprint_fun(const char *, va_list);
132
133 void
134 odxprint_fun(const char *fmt, ...)
135 {
136     va_list args;
137     va_start(args, fmt);
138     vodxprint_fun(fmt, args);
139     va_end(args);
140 }
141
142 void
143 vodxprint_fun(const char *fmt, va_list args)
144 {
145 #ifdef LISP_FEATURE_WIN32
146     DWORD lastError = GetLastError();
147 #else
148     int original_errno = errno;
149 #endif
150
151     QSHOW_BLOCK;
152
153     char buf[1024];
154
155 #ifdef LISP_FEATURE_SB_THREAD
156     struct thread *arch_os_get_current_thread(void);
157     struct thread *self = arch_os_get_current_thread();
158     void *pth = self ? (void *) self->os_thread : 0;
159     snprintf(buf, sizeof(buf), "[%p/%p] ", self, pth);
160 #endif
161
162     int n = strlen(buf);
163     vsnprintf(buf + n, sizeof(buf) - n - 1, fmt, args);
164     /* buf is now zero-terminated (even in case of overflow).
165      * Our caller took care of the newline (if any) through `fmt'. */
166
167     /* A sufficiently POSIXy implementation of stdio will provide
168      * per-FILE locking, as defined in the spec for flockfile.  At least
169      * glibc complies with this.  Hence we do not need to perform
170      * locking ourselves here.  (Should it turn out, of course, that
171      * other libraries opt for speed rather than safety, we need to
172      * revisit this decision.) */
173     fputs(buf, stderr);
174
175 #ifdef LISP_FEATURE_WIN32
176     /* stdio's stderr is line-bufferred, i.e. \n ought to flush it.
177      * Unfortunately, MinGW does not behave the way I would expect it
178      * to.  Let's be safe: */
179     fflush(stderr);
180 #endif
181
182     QSHOW_UNBLOCK;
183
184 #ifdef LISP_FEATURE_WIN32
185     SetLastError(lastError);
186 #else
187     errno = original_errno;
188 #endif
189 }
190
191 /* Translate the rather awkward syntax
192  *   FSHOW((stderr, "xyz"))
193  * into the new and cleaner
194  *   odxprint("xyz").
195  * If we were willing to clean up all existing call sites, we could remove
196  * this wrapper function.  (This is a function, because I don't know how to
197  * strip the extra parens in a macro.) */
198 void
199 fshow_fun(void __attribute__((__unused__)) *ignored,
200           const char *fmt,
201           ...)
202 {
203     va_list args;
204     va_start(args, fmt);
205     vodxprint_fun(fmt, args);
206     va_end(args);
207 }
208
209 /* This file can be skipped if we're not supporting LDB. */
210 #if defined(LISP_FEATURE_SB_LDB)
211
212 #include "monitor.h"
213 #include "vars.h"
214 #include "os.h"
215 #ifdef LISP_FEATURE_GENCGC
216 #include "gencgc-alloc-region.h" /* genesis/thread.h needs this */
217 #endif
218 #include "genesis/static-symbols.h"
219 #include "genesis/primitive-objects.h"
220 #include "genesis/static-symbols.h"
221 #include "genesis/tagnames.h"
222
223 static int max_lines = 20, cur_lines = 0;
224 static int max_depth = 5, brief_depth = 2, cur_depth = 0;
225 static int max_length = 5;
226 static boolean dont_descend = 0, skip_newline = 0;
227 static int cur_clock = 0;
228
229 static void print_obj(char *prefix, lispobj obj);
230
231 #define NEWLINE_OR_RETURN if (continue_p(1)) newline(NULL); else return;
232
233 static void indent(int in)
234 {
235     static char *spaces = "                                                                ";
236
237     while (in > 64) {
238         fputs(spaces, stdout);
239         in -= 64;
240     }
241     if (in != 0)
242         fputs(spaces + 64 - in, stdout);
243 }
244
245 static boolean continue_p(boolean newline)
246 {
247     char buffer[256];
248
249     if (cur_depth >= max_depth || dont_descend)
250         return 0;
251
252     if (newline) {
253         if (skip_newline)
254             skip_newline = 0;
255         else
256             putchar('\n');
257
258         if (cur_lines >= max_lines) {
259             printf("More? [y] ");
260             fflush(stdout);
261
262             if (fgets(buffer, sizeof(buffer), stdin)) {
263                 if (buffer[0] == 'n' || buffer[0] == 'N')
264                     throw_to_monitor();
265                 else
266                     cur_lines = 0;
267             } else {
268                 printf("\nUnable to read response, assuming y.\n");
269                 cur_lines = 0;
270             }
271         }
272     }
273
274     return 1;
275 }
276
277 static void newline(char *label)
278 {
279     cur_lines++;
280     if (label != NULL)
281         fputs(label, stdout);
282     putchar('\t');
283     indent(cur_depth * 2);
284 }
285
286
287 static void print_unknown(lispobj obj)
288 {
289   printf("unknown object: %p", (void *)obj);
290 }
291
292 static void brief_fixnum(lispobj obj)
293 {
294     /* KLUDGE: Rather than update the tables in print_obj(), we
295        declare all fixnum-or-unknown tags to be fixnums and sort it
296        out here with a guard clause. */
297     if (!fixnump(obj)) return print_unknown(obj);
298
299 #ifndef LISP_FEATURE_ALPHA
300     printf("%ld", ((long)obj)>>2);
301 #else
302     printf("%d", ((s32)obj)>>2);
303 #endif
304 }
305
306 static void print_fixnum(lispobj obj)
307 {
308     /* KLUDGE: Rather than update the tables in print_obj(), we
309        declare all fixnum-or-unknown tags to be fixnums and sort it
310        out here with a guard clause. */
311     if (!fixnump(obj)) return print_unknown(obj);
312
313 #ifndef LISP_FEATURE_ALPHA
314     printf(": %ld", ((long)obj)>>2);
315 #else
316     printf(": %d", ((s32)obj)>>2);
317 #endif
318 }
319
320 static void brief_otherimm(lispobj obj)
321 {
322     int type, c;
323     char buffer[10];
324
325     type = widetag_of(obj);
326     switch (type) {
327         case CHARACTER_WIDETAG:
328             c = (obj>>8)&0xff;
329             switch (c) {
330                 case '\0':
331                     printf("#\\Null");
332                     break;
333                 case '\n':
334                     printf("#\\Newline");
335                     break;
336                 case '\b':
337                     printf("#\\Backspace");
338                     break;
339                 case '\177':
340                     printf("#\\Delete");
341                     break;
342                 default:
343                     strcpy(buffer, "#\\");
344                     if (c >= 128) {
345                         strcat(buffer, "m-");
346                         c -= 128;
347                     }
348                     if (c < 32) {
349                         strcat(buffer, "c-");
350                         c += '@';
351                     }
352                     printf("%s%c", buffer, c);
353                     break;
354             }
355             break;
356
357         case UNBOUND_MARKER_WIDETAG:
358             printf("<unbound marker>");
359             break;
360
361         default:
362             printf("%s", widetag_names[type >> 2]);
363             break;
364     }
365 }
366
367 static void print_otherimm(lispobj obj)
368 {
369     printf(", %s", widetag_names[widetag_of(obj) >> 2]);
370
371     switch (widetag_of(obj)) {
372         case CHARACTER_WIDETAG:
373             printf(": ");
374             brief_otherimm(obj);
375             break;
376
377         case SAP_WIDETAG:
378         case UNBOUND_MARKER_WIDETAG:
379             break;
380
381         default:
382             printf(": data=%ld", (long) (obj>>8)&0xffffff);
383             break;
384     }
385 }
386
387 static void brief_list(lispobj obj)
388 {
389     int space = 0;
390     int length = 0;
391
392     if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj)))
393         printf("(invalid Lisp-level address)");
394     else if (obj == NIL)
395         printf("NIL");
396     else {
397         putchar('(');
398         while (lowtag_of(obj) == LIST_POINTER_LOWTAG) {
399             struct cons *cons = (struct cons *)native_pointer(obj);
400
401             if (space)
402                 putchar(' ');
403             if (++length >= max_length) {
404                 printf("...");
405                 obj = NIL;
406                 break;
407             }
408             print_obj("", cons->car);
409             obj = cons->cdr;
410             space = 1;
411             if (obj == NIL)
412                 break;
413         }
414         if (obj != NIL) {
415             printf(" . ");
416             print_obj("", obj);
417         }
418         putchar(')');
419     }
420 }
421
422 static void print_list(lispobj obj)
423 {
424     if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj))) {
425         printf("(invalid address)");
426     } else if (obj == NIL) {
427         printf(" (NIL)");
428     } else {
429         struct cons *cons = (struct cons *)native_pointer(obj);
430
431         print_obj("car: ", cons->car);
432         print_obj("cdr: ", cons->cdr);
433     }
434 }
435
436 static void brief_struct(lispobj obj)
437 {
438     struct instance *instance = (struct instance *)native_pointer(obj);
439     if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
440         printf("(invalid address)");
441     } else {
442         printf("#<ptr to 0x%08lx instance>",
443                (unsigned long) instance->slots[0]);
444     }
445 }
446
447 static void print_struct(lispobj obj)
448 {
449     struct instance *instance = (struct instance *)native_pointer(obj);
450     unsigned int i;
451     char buffer[16];
452     if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
453         printf("(invalid address)");
454     } else {
455         print_obj("type: ", ((struct instance *)native_pointer(obj))->slots[0]);
456         for (i = 1; i < HeaderValue(instance->header); i++) {
457             sprintf(buffer, "slot %d: ", i);
458             print_obj(buffer, instance->slots[i]);
459         }
460     }
461 }
462
463 static void brief_otherptr(lispobj obj)
464 {
465     lispobj *ptr, header;
466     int type;
467     struct symbol *symbol;
468     struct vector *vector;
469     char *charptr;
470
471     ptr = (lispobj *) native_pointer(obj);
472
473     if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
474             printf("(invalid address)");
475             return;
476     }
477
478     header = *ptr;
479     type = widetag_of(header);
480     switch (type) {
481         case SYMBOL_HEADER_WIDETAG:
482             symbol = (struct symbol *)ptr;
483             vector = (struct vector *)native_pointer(symbol->name);
484             for (charptr = (char *)vector->data; *charptr != '\0'; charptr++) {
485                 if (*charptr == '"')
486                     putchar('\\');
487                 putchar(*charptr);
488             }
489             break;
490
491         case SIMPLE_BASE_STRING_WIDETAG:
492             vector = (struct vector *)ptr;
493             putchar('"');
494             for (charptr = (char *)vector->data; *charptr != '\0'; charptr++) {
495                 if (*charptr == '"')
496                     putchar('\\');
497                 putchar(*charptr);
498             }
499             putchar('"');
500             break;
501
502         default:
503             printf("#<ptr to ");
504             brief_otherimm(header);
505             putchar('>');
506     }
507 }
508
509 static void print_slots(char **slots, int count, lispobj *ptr)
510 {
511     while (count-- > 0) {
512         if (*slots) {
513             print_obj(*slots++, *ptr++);
514         } else {
515             print_obj("???: ", *ptr++);
516         }
517     }
518 }
519
520 /* FIXME: Yikes! This needs to depend on the values in sbcl.h (or
521  * perhaps be generated automatically by GENESIS as part of
522  * sbcl.h). */
523 static char *symbol_slots[] = {"value: ", "hash: ",
524     "plist: ", "name: ", "package: ",
525 #ifdef LISP_FEATURE_SB_THREAD
526     "tls-index: " ,
527 #endif
528     NULL};
529 static char *ratio_slots[] = {"numer: ", "denom: ", NULL};
530 static char *complex_slots[] = {"real: ", "imag: ", NULL};
531 static char *code_slots[] = {"words: ", "entry: ", "debug: ", NULL};
532 static char *fn_slots[] = {
533     "self: ", "next: ", "name: ", "arglist: ", "type: ", NULL};
534 static char *closure_slots[] = {"fn: ", NULL};
535 static char *funcallable_instance_slots[] = {"fn: ", "lexenv: ", "layout: ", NULL};
536 static char *weak_pointer_slots[] = {"value: ", NULL};
537 static char *fdefn_slots[] = {"name: ", "function: ", "raw_addr: ", NULL};
538 static char *value_cell_slots[] = {"value: ", NULL};
539
540 static void print_otherptr(lispobj obj)
541 {
542     if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
543         printf("(invalid address)");
544     } else {
545 #ifndef LISP_FEATURE_ALPHA
546         lispobj *ptr;
547         unsigned long header;
548         unsigned long length;
549 #else
550         u32 *ptr;
551         u32 header;
552         u32 length;
553 #endif
554         int count, type, index;
555         char *cptr, buffer[16];
556
557         ptr = (lispobj*) native_pointer(obj);
558         if (ptr == NULL) {
559                 printf(" (NULL Pointer)");
560                 return;
561         }
562
563         header = *ptr++;
564         length = fixnum_value(*ptr);
565         count = HeaderValue(header);
566         type = widetag_of(header);
567
568         print_obj("header: ", header);
569         if (!other_immediate_lowtag_p(header)) {
570             NEWLINE_OR_RETURN;
571             printf("(invalid header object)");
572             return;
573         }
574
575         switch (type) {
576             case BIGNUM_WIDETAG:
577                 ptr += count;
578                 NEWLINE_OR_RETURN;
579                 printf("0x");
580                 while (count-- > 0)
581                     printf("%08lx", (unsigned long) *--ptr);
582                 break;
583
584             case RATIO_WIDETAG:
585                 print_slots(ratio_slots, count, ptr);
586                 break;
587
588             case COMPLEX_WIDETAG:
589                 print_slots(complex_slots, count, ptr);
590                 break;
591
592             case SYMBOL_HEADER_WIDETAG:
593                 print_slots(symbol_slots, count, ptr);
594                 break;
595
596 #if N_WORD_BITS == 32
597             case SINGLE_FLOAT_WIDETAG:
598                 NEWLINE_OR_RETURN;
599                 printf("%g", ((struct single_float *)native_pointer(obj))->value);
600                 break;
601 #endif
602             case DOUBLE_FLOAT_WIDETAG:
603                 NEWLINE_OR_RETURN;
604                 printf("%g", ((struct double_float *)native_pointer(obj))->value);
605                 break;
606
607 #ifdef LONG_FLOAT_WIDETAG
608             case LONG_FLOAT_WIDETAG:
609                 NEWLINE_OR_RETURN;
610                 printf("%Lg", ((struct long_float *)native_pointer(obj))->value);
611                 break;
612 #endif
613
614 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
615             case COMPLEX_SINGLE_FLOAT_WIDETAG:
616                 NEWLINE_OR_RETURN;
617 #ifdef LISP_FEATURE_X86_64
618                 printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[0]);
619 #else
620                 printf("%g", ((struct complex_single_float *)native_pointer(obj))->real);
621 #endif
622                 NEWLINE_OR_RETURN;
623 #ifdef LISP_FEATURE_X86_64
624                 printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[1]);
625 #else
626                 printf("%g", ((struct complex_single_float *)native_pointer(obj))->imag);
627 #endif
628                 break;
629 #endif
630
631 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
632             case COMPLEX_DOUBLE_FLOAT_WIDETAG:
633                 NEWLINE_OR_RETURN;
634                 printf("%g", ((struct complex_double_float *)native_pointer(obj))->real);
635                 NEWLINE_OR_RETURN;
636                 printf("%g", ((struct complex_double_float *)native_pointer(obj))->imag);
637                 break;
638 #endif
639
640 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
641             case COMPLEX_LONG_FLOAT_WIDETAG:
642                 NEWLINE_OR_RETURN;
643                 printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->real);
644                 NEWLINE_OR_RETURN;
645                 printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->imag);
646                 break;
647 #endif
648
649             case SIMPLE_BASE_STRING_WIDETAG:
650 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
651         case SIMPLE_CHARACTER_STRING_WIDETAG: /* FIXME */
652 #endif
653                 NEWLINE_OR_RETURN;
654                 cptr = (char *)(ptr+1);
655                 putchar('"');
656                 while (length-- > 0)
657                     putchar(*cptr++);
658                 putchar('"');
659                 break;
660
661             case SIMPLE_VECTOR_WIDETAG:
662                 NEWLINE_OR_RETURN;
663                 printf("length = %ld", length);
664                 ptr++;
665                 index = 0;
666                 while (length-- > 0) {
667                     sprintf(buffer, "%d: ", index++);
668                     print_obj(buffer, *ptr++);
669                 }
670                 break;
671
672             case INSTANCE_HEADER_WIDETAG:
673                 NEWLINE_OR_RETURN;
674                 printf("length = %ld", (long) count);
675                 index = 0;
676                 while (count-- > 0) {
677                     sprintf(buffer, "%d: ", index++);
678                     print_obj(buffer, *ptr++);
679                 }
680                 break;
681
682             case SIMPLE_ARRAY_WIDETAG:
683             case SIMPLE_BIT_VECTOR_WIDETAG:
684             case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG:
685             case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG:
686             case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG:
687             case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG:
688             case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG:
689             case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG:
690
691             case SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG:
692
693             case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG:
694             case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG:
695 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG
696             case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG:
697 #endif
698 #ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG
699             case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG:
700 #endif
701 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG
702             case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG:
703 #endif
704 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG
705             case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG:
706 #endif
707
708             case SIMPLE_ARRAY_FIXNUM_WIDETAG:
709
710 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG
711             case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG:
712 #endif
713 #ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG
714             case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG:
715 #endif
716             case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG:
717             case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG:
718 #ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG
719             case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG:
720 #endif
721 #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG
722             case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG:
723 #endif
724 #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG
725             case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG:
726 #endif
727 #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG
728             case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG:
729 #endif
730             case COMPLEX_BASE_STRING_WIDETAG:
731 #ifdef COMPLEX_CHARACTER_STRING_WIDETAG
732         case COMPLEX_CHARACTER_STRING_WIDETAG:
733 #endif
734             case COMPLEX_VECTOR_NIL_WIDETAG:
735             case COMPLEX_BIT_VECTOR_WIDETAG:
736             case COMPLEX_VECTOR_WIDETAG:
737             case COMPLEX_ARRAY_WIDETAG:
738                 break;
739
740             case CODE_HEADER_WIDETAG:
741                 print_slots(code_slots, count-1, ptr);
742                 break;
743
744             case SIMPLE_FUN_HEADER_WIDETAG:
745                 print_slots(fn_slots, 5, ptr);
746                 break;
747
748             case RETURN_PC_HEADER_WIDETAG:
749                 print_obj("code: ", obj - (count * 4));
750                 break;
751
752             case CLOSURE_HEADER_WIDETAG:
753                 print_slots(closure_slots, count, ptr);
754                 break;
755
756             case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
757                 print_slots(funcallable_instance_slots, count, ptr);
758                 break;
759
760             case VALUE_CELL_HEADER_WIDETAG:
761                 print_slots(value_cell_slots, 1, ptr);
762                 break;
763
764             case SAP_WIDETAG:
765                 NEWLINE_OR_RETURN;
766 #ifndef LISP_FEATURE_ALPHA
767                 printf("0x%08lx", (unsigned long) *ptr);
768 #else
769                 printf("0x%016lx", *(lispobj*)(ptr+1));
770 #endif
771                 break;
772
773             case WEAK_POINTER_WIDETAG:
774                 print_slots(weak_pointer_slots, 1, ptr);
775                 break;
776
777             case CHARACTER_WIDETAG:
778             case UNBOUND_MARKER_WIDETAG:
779                 NEWLINE_OR_RETURN;
780                 printf("pointer to an immediate?");
781                 break;
782
783             case FDEFN_WIDETAG:
784                 print_slots(fdefn_slots, count, ptr);
785                 break;
786
787             default:
788                 NEWLINE_OR_RETURN;
789                 printf("Unknown header object?");
790                 break;
791         }
792     }
793 }
794
795 static void print_obj(char *prefix, lispobj obj)
796 {
797 #ifdef LISP_FEATURE_X86_64
798     static void (*verbose_fns[])(lispobj obj)
799         = {print_fixnum, print_otherimm, print_fixnum, print_struct,
800            print_fixnum, print_otherimm, print_fixnum, print_list,
801            print_fixnum, print_otherimm, print_fixnum, print_otherptr,
802            print_fixnum, print_otherimm, print_fixnum, print_otherptr};
803     static void (*brief_fns[])(lispobj obj)
804         = {brief_fixnum, brief_otherimm, brief_fixnum, brief_struct,
805            brief_fixnum, brief_otherimm, brief_fixnum, brief_list,
806            brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr,
807            brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr};
808 #else
809     static void (*verbose_fns[])(lispobj obj)
810         = {print_fixnum, print_struct, print_otherimm, print_list,
811            print_fixnum, print_otherptr, print_otherimm, print_otherptr};
812     static void (*brief_fns[])(lispobj obj)
813         = {brief_fixnum, brief_struct, brief_otherimm, brief_list,
814            brief_fixnum, brief_otherptr, brief_otherimm, brief_otherptr};
815 #endif
816     int type = lowtag_of(obj);
817     struct var *var = lookup_by_obj(obj);
818     char buffer[256];
819     boolean verbose = cur_depth < brief_depth;
820
821     if (!continue_p(verbose))
822         return;
823
824     if (var != NULL && var_clock(var) == cur_clock)
825         dont_descend = 1;
826
827     if (var == NULL && is_lisp_pointer(obj))
828         var = define_var(NULL, obj, 0);
829
830     if (var != NULL)
831         var_setclock(var, cur_clock);
832
833     cur_depth++;
834     if (verbose) {
835         if (var != NULL) {
836             sprintf(buffer, "$%s=", var_name(var));
837             newline(buffer);
838         }
839         else
840             newline(NULL);
841         printf("%s0x%08lx: ", prefix, (unsigned long) obj);
842         if (cur_depth < brief_depth) {
843             fputs(lowtag_names[type], stdout);
844             (*verbose_fns[type])(obj);
845         }
846         else
847             (*brief_fns[type])(obj);
848     }
849     else {
850         if (dont_descend)
851             printf("$%s", var_name(var));
852         else {
853             if (var != NULL)
854                 printf("$%s=", var_name(var));
855             (*brief_fns[type])(obj);
856         }
857     }
858     cur_depth--;
859     dont_descend = 0;
860 }
861
862 void reset_printer()
863 {
864     cur_clock++;
865     cur_lines = 0;
866     dont_descend = 0;
867 }
868
869 void print(lispobj obj)
870 {
871     skip_newline = 1;
872     cur_depth = 0;
873     max_depth = 5;
874     max_lines = 20;
875
876     print_obj("", obj);
877
878     putchar('\n');
879 }
880
881 void brief_print(lispobj obj)
882 {
883     skip_newline = 1;
884     cur_depth = 0;
885     max_depth = 1;
886     max_lines = 5000;
887     cur_lines = 0;
888
889     print_obj("", obj);
890     putchar('\n');
891 }
892
893 #else
894
895 void
896 brief_print(lispobj obj)
897 {
898     printf("lispobj 0x%lx\n", (unsigned long)obj);
899 }
900
901 #endif /* defined(LISP_FEATURE_SB_LDB) */