Add :IMMOBILE-CODE feature.
[sbcl.git] / src / runtime / print.c
bloba936c35e4db8b677953dfcce6fcda899b2a5529b
1 /* code for low-level debugging/diagnostic output */
3 /*
4 * This software is part of the SBCL system. See the README file for
5 * more information.
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.
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.
21 #include <stdio.h>
22 #include <string.h>
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>
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.
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".
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.
44 struct dyndebug_config dyndebug_config = {
45 QSHOW == 2, QSHOW_SIGNALS == 2
48 void
49 dyndebug_init()
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];
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 dyndebug_init1(io, "IO");
73 dyndebug_init1(runtime_link, "RUNTIME_LINK");
75 int n_output_flags = n;
76 dyndebug_init1(backtrace_when_lost, "BACKTRACE_WHEN_LOST");
77 dyndebug_init1(sleep_when_lost, "SLEEP_WHEN_LOST");
79 if (n != DYNDEBUG_NFLAGS)
80 fprintf(stderr, "Bug in dyndebug_init\n");
82 #if defined(LISP_FEATURE_GENCGC)
83 gencgc_verbose = dyndebug_config.dyndebug_gencgc_verbose;
84 #endif
86 char *featurelist = getenv("SBCL_DYNDEBUG");
87 if (featurelist) {
88 int err = 0;
89 featurelist = strdup(featurelist);
90 char *ptr = featurelist;
91 for (;;) {
92 char *token = strtok(ptr, " ");
93 if (!token) break;
94 int i;
95 if (!strcmp(token, "all"))
96 for (i = 0; i < n_output_flags; i++)
97 *ptrs[i] = 1;
98 else {
99 for (i = 0; i < (int)DYNDEBUG_NFLAGS; i++)
100 if (!strcmp(token, names[i])) {
101 *ptrs[i] = 1;
102 break;
104 if (i == DYNDEBUG_NFLAGS) {
105 fprintf(stderr, "No such dyndebug flag: `%s'\n", token);
106 err = 1;
109 ptr = 0;
111 free(featurelist);
112 if (err) {
113 fprintf(stderr, "Valid flags are:\n");
114 fprintf(stderr, " all ;enables all of the following:\n");
115 int i;
116 for (i = 0; i < (int)DYNDEBUG_NFLAGS; i++) {
117 if (i == n_output_flags)
118 fprintf(stderr, "Additional options:\n");
119 fprintf(stderr, " %s\n", names[i]);
124 #undef dyndebug_init1
125 #undef DYNDEBUG_NFLAGS
128 /* Temporarily, odxprint merely performs the equivalent of a traditional
129 * FSHOW call, i.e. it merely formats to stderr. Ultimately, it should
130 * be restored to its full win32 branch functionality, where output to a
131 * file or to the debugger can be selected at runtime. */
133 void vodxprint_fun(const char *, va_list);
135 void
136 odxprint_fun(const char *fmt, ...)
138 va_list args;
139 va_start(args, fmt);
140 vodxprint_fun(fmt, args);
141 va_end(args);
144 void
145 vodxprint_fun(const char *fmt, va_list args)
147 #ifdef LISP_FEATURE_WIN32
148 DWORD lastError = GetLastError();
149 #endif
150 int original_errno = errno;
152 QSHOW_BLOCK;
154 char buf[1024];
155 int n = 0;
157 #ifdef LISP_FEATURE_SB_THREAD
158 struct thread *arch_os_get_current_thread(void);
159 struct thread *self = arch_os_get_current_thread();
160 void *pth = self ? (void *) self->os_thread : 0;
161 snprintf(buf, sizeof(buf), "[%p/%p] ", self, pth);
162 n = strlen(buf);
163 #endif
165 vsnprintf(buf + n, sizeof(buf) - n - 1, fmt, args);
166 /* buf is now zero-terminated (even in case of overflow).
167 * Our caller took care of the newline (if any) through `fmt'. */
169 /* A sufficiently POSIXy implementation of stdio will provide
170 * per-FILE locking, as defined in the spec for flockfile. At least
171 * glibc complies with this. Hence we do not need to perform
172 * locking ourselves here. (Should it turn out, of course, that
173 * other libraries opt for speed rather than safety, we need to
174 * revisit this decision.) */
175 fputs(buf, stderr);
177 #ifdef LISP_FEATURE_WIN32
178 /* stdio's stderr is line-bufferred, i.e. \n ought to flush it.
179 * Unfortunately, MinGW does not behave the way I would expect it
180 * to. Let's be safe: */
181 fflush(stderr);
182 #endif
184 QSHOW_UNBLOCK;
186 #ifdef LISP_FEATURE_WIN32
187 SetLastError(lastError);
188 #endif
189 errno = original_errno;
192 /* Translate the rather awkward syntax
193 * FSHOW((stderr, "xyz"))
194 * into the new and cleaner
195 * odxprint("xyz").
196 * If we were willing to clean up all existing call sites, we could remove
197 * this wrapper function. (This is a function, because I don't know how to
198 * strip the extra parens in a macro.) */
199 void
200 fshow_fun(void __attribute__((__unused__)) *ignored,
201 const char *fmt,
202 ...)
204 va_list args;
205 va_start(args, fmt);
206 vodxprint_fun(fmt, args);
207 va_end(args);
210 /* This file can be skipped if we're not supporting LDB. */
211 #if defined(LISP_FEATURE_SB_LDB)
213 #include "monitor.h"
214 #include "vars.h"
215 #include "os.h"
216 #ifdef LISP_FEATURE_GENCGC
217 #include "gencgc-alloc-region.h" /* genesis/thread.h needs this */
218 #endif
219 #if defined(LISP_FEATURE_WIN32)
220 # include "win32-thread-private-events.h" /* genesis/thread.h needs this */
221 #endif
222 #include "genesis/static-symbols.h"
223 #include "genesis/primitive-objects.h"
224 #include "genesis/static-symbols.h"
225 #include "genesis/tagnames.h"
227 static int max_lines = 20, cur_lines = 0;
228 static int max_depth = 5, brief_depth = 2, cur_depth = 0;
229 static int max_length = 5;
230 static boolean dont_descend = 0, skip_newline = 0;
231 static int cur_clock = 0;
233 static void print_obj(char *prefix, lispobj obj);
235 #define NEWLINE_OR_RETURN if (continue_p(1)) newline(NULL); else return;
237 static void indent(int in)
239 static char *spaces = " ";
241 while (in > 64) {
242 fputs(spaces, stdout);
243 in -= 64;
245 if (in != 0)
246 fputs(spaces + 64 - in, stdout);
249 static boolean continue_p(boolean newline)
251 char buffer[256];
253 if (cur_depth >= max_depth || dont_descend)
254 return 0;
256 if (newline) {
257 if (skip_newline)
258 skip_newline = 0;
259 else
260 putchar('\n');
262 if (cur_lines >= max_lines) {
263 printf("More? [y] ");
264 fflush(stdout);
266 if (fgets(buffer, sizeof(buffer), stdin)) {
267 if (buffer[0] == 'n' || buffer[0] == 'N')
268 throw_to_monitor();
269 else
270 cur_lines = 0;
271 } else {
272 printf("\nUnable to read response, assuming y.\n");
273 cur_lines = 0;
278 return 1;
281 static void newline(char *label)
283 cur_lines++;
284 if (label != NULL)
285 fputs(label, stdout);
286 putchar('\t');
287 indent(cur_depth * 2);
291 static void print_unknown(lispobj obj)
293 printf("unknown object: %p", (void *)obj);
296 static void brief_fixnum(lispobj obj)
298 /* KLUDGE: Rather than update the tables in print_obj(), we
299 declare all fixnum-or-unknown tags to be fixnums and sort it
300 out here with a guard clause. */
301 if (!fixnump(obj)) return print_unknown(obj);
303 #ifndef LISP_FEATURE_ALPHA
304 printf("%ld", ((long)obj)>>N_FIXNUM_TAG_BITS);
305 #else
306 printf("%d", ((s32)obj)>>N_FIXNUM_TAG_BITS);
307 #endif
310 static void print_fixnum(lispobj obj)
312 /* KLUDGE: Rather than update the tables in print_obj(), we
313 declare all fixnum-or-unknown tags to be fixnums and sort it
314 out here with a guard clause. */
315 if (!fixnump(obj)) return print_unknown(obj);
317 #ifndef LISP_FEATURE_ALPHA
318 printf(": %ld", ((long)obj)>>N_FIXNUM_TAG_BITS);
319 #else
320 printf(": %d", ((s32)obj)>>N_FIXNUM_TAG_BITS);
321 #endif
324 static void brief_otherimm(lispobj obj)
326 int type, c;
327 char * charname = 0;
329 type = widetag_of(obj);
330 switch (type) {
331 case CHARACTER_WIDETAG:
332 c = obj>>8; // no mask. show whatever's there
333 printf("#\\");
334 switch (c) {
335 case '\0': charname = "Nul"; break;
336 case '\n': charname = "Newline"; break;
337 case '\b': charname = "Backspace"; break;
338 case '\177': charname = "Delete"; break;
339 default:
340 if (c < 32) printf("^%c", c+64);
341 else printf(c < 128 ? "%c" : "U+%X", c);
343 if (charname)
344 fputs(charname, stdout);
345 break;
347 case UNBOUND_MARKER_WIDETAG:
348 printf("<unbound marker>");
349 break;
351 default:
352 printf("%s", widetag_names[type >> 2]);
353 break;
357 static void print_otherimm(lispobj obj)
359 printf(", %s", widetag_names[widetag_of(obj) >> 2]);
361 switch (widetag_of(obj)) {
362 case CHARACTER_WIDETAG:
363 printf(": ");
364 brief_otherimm(obj);
365 break;
367 case SAP_WIDETAG:
368 case UNBOUND_MARKER_WIDETAG:
369 break;
371 default:
372 printf(": data=%"OBJ_FMTX, (obj>>8));
373 break;
377 static void brief_list(lispobj obj)
379 int space = 0;
380 int length = 0;
382 if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj)))
383 printf("(invalid Lisp-level address)");
384 else if (obj == NIL)
385 printf("NIL");
386 else {
387 putchar('(');
388 while (lowtag_of(obj) == LIST_POINTER_LOWTAG) {
389 struct cons *cons = (struct cons *)native_pointer(obj);
391 if (space)
392 putchar(' ');
393 if (++length >= max_length) {
394 printf("...");
395 obj = NIL;
396 break;
398 print_obj("", cons->car);
399 obj = cons->cdr;
400 space = 1;
401 if (obj == NIL)
402 break;
404 if (obj != NIL) {
405 printf(" . ");
406 print_obj("", obj);
408 putchar(')');
412 static void print_list(lispobj obj)
414 if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj))) {
415 printf("(invalid address)");
416 } else if (obj == NIL) {
417 printf(" (NIL)");
418 } else {
419 struct cons *cons = (struct cons *)native_pointer(obj);
421 print_obj("car: ", cons->car);
422 print_obj("cdr: ", cons->cdr);
426 // takes native pointer as input
427 char * simple_base_stringize(struct vector * string)
429 if (widetag_of(string->header) == SIMPLE_BASE_STRING_WIDETAG)
430 return (char*)string->data;
431 int length = string->length;
432 char * newstring = malloc(length+1);
433 uint32_t * data = (uint32_t*)string->data;
434 int i;
435 for(i=0;i<length;++i)
436 newstring[i] = data[i] < 128 ? data[i] : '?';
437 newstring[length] = 0;
438 return newstring;
441 static void brief_struct(lispobj obj)
443 struct instance *instance = (struct instance *)native_pointer(obj);
444 if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
445 printf("(invalid address)");
446 } else {
447 extern struct vector * instance_classoid_name(lispobj*);
448 struct vector * classoid_name;
449 classoid_name = instance_classoid_name((lispobj*)instance);
450 if ( classoid_name ) {
451 char * namestring = simple_base_stringize(classoid_name);
452 printf("#<ptr to %p %s instance>",
453 (void*)instance_layout((lispobj*)instance), namestring);
454 if ( namestring != (char*)classoid_name->data )
455 free(namestring);
456 } else {
457 printf("#<ptr to %p instance>",
458 (void*)instance_layout((lispobj*)instance));
463 #include "genesis/layout.h"
464 static boolean tagged_slot_p(struct layout * layout,
465 int slot_index)
467 extern boolean positive_bignum_logbitp(int,struct bignum*);
468 lispobj bitmap = layout->bitmap;
469 sword_t fixnum = (sword_t)bitmap >> N_FIXNUM_TAG_BITS; // optimistically
470 return fixnump(bitmap)
471 ? bitmap == make_fixnum(-1) ||
472 (slot_index < N_WORD_BITS && ((fixnum >> slot_index) & 1) != 0)
473 : positive_bignum_logbitp(slot_index,
474 (struct bignum*)native_pointer(bitmap));
477 static void print_struct(lispobj obj)
479 struct instance *instance = (struct instance *)native_pointer(obj);
480 unsigned int i;
481 char buffer[16];
482 if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
483 printf("(invalid address)");
484 } else {
485 lispobj layout_obj = instance_layout(native_pointer(obj));
486 print_obj("type: ", layout_obj);
487 struct layout * layout = (struct layout*)native_pointer(layout_obj);
488 for (i=INSTANCE_DATA_START; i<instance_length(instance->header); i++) {
489 sprintf(buffer, "slot %d: ", i);
490 if (layout != NULL && tagged_slot_p(layout, i)) {
491 print_obj(buffer, instance->slots[i]);
492 } else {
493 newline(NULL);
494 printf("\n\t %s0x%"OBJ_FMTX" [raw]", buffer, instance->slots[i]);
500 void show_lstring(struct vector * string, int quotes, FILE *s)
502 int ucs4_p = 0;
503 int i, len = fixnum_value(string->length);
505 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
506 if (widetag_of(string->header) == SIMPLE_CHARACTER_STRING_WIDETAG) {
507 ucs4_p = 1;
508 if (quotes)
509 putc('u', s); /* an arbitrary notational convention */
511 #endif
512 if (quotes) putc('"', s);
513 for (i=0 ; i<len ; i++) {
514 // hopefully the compiler will optimize out the ucs4_p test
515 // when the runtime is built without Unicode support
516 int ch;
517 if (ucs4_p)
518 ch = i[(uint32_t*)string->data];
519 else
520 ch = i[(char*)string->data];
521 if (ch >= 32 && ch < 127) {
522 if (quotes && (ch == '"' || ch == '\\'))
523 putc('\\', s);
524 putc(ch, s);
525 } else {
526 fprintf(s, ch > 0xffff ? "\\U%08X" :
527 ch > 0xff ? "\\u%04X" : "\\x%02X", ch);
530 if (quotes) putc('"', s);
533 static void brief_otherptr(lispobj obj)
535 lispobj *ptr, header;
536 int type;
537 struct symbol *symbol;
539 ptr = (lispobj *) native_pointer(obj);
541 if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
542 printf("(invalid address)");
543 return;
546 header = *ptr;
547 type = widetag_of(header);
548 switch (type) {
549 case SYMBOL_HEADER_WIDETAG:
550 symbol = (struct symbol *)ptr;
551 if (symbol->package == NIL)
552 printf("#:");
553 show_lstring((struct vector *)native_pointer(symbol->name),
554 0, stdout);
555 break;
557 case SIMPLE_BASE_STRING_WIDETAG:
558 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
559 case SIMPLE_CHARACTER_STRING_WIDETAG:
560 #endif
561 show_lstring((struct vector*)ptr, 1, stdout);
562 break;
564 default:
565 printf("#<ptr to ");
566 brief_otherimm(header);
567 putchar('>');
571 static void print_slots(char **slots, int count, lispobj *ptr)
573 while (count-- > 0) {
574 if (*slots) {
575 print_obj(*slots++, *ptr++);
576 } else {
577 print_obj("???: ", *ptr++);
582 /* FIXME: Yikes! This needs to depend on the values in sbcl.h (or
583 * perhaps be generated automatically by GENESIS as part of
584 * sbcl.h). */
585 static char *symbol_slots[] = {"value: ", "hash: ",
586 "info: ", "name: ", "package: ",
587 #if defined (LISP_FEATURE_SB_THREAD) && !defined(LISP_FEATURE_X86_64)
588 "tls-index: " ,
589 #endif
590 NULL};
591 static char *ratio_slots[] = {"numer: ", "denom: ", NULL};
592 static char *complex_slots[] = {"real: ", "imag: ", NULL};
593 static char *code_slots[] = {"bytes: ", "entry: ", "debug: ", NULL};
594 static char *fn_slots[] = {
595 "self: ", "next: ", "name: ", "arglist: ", "type: ", "info: ", NULL};
596 static char *closure_slots[] = {"fn: ", NULL};
597 static char *funcallable_instance_slots[] = {"raw_fn: ", "fn: ", "layout: ", NULL};
598 static char *weak_pointer_slots[] = {"value: ", NULL};
599 static char *fdefn_slots[] = {"name: ", "function: ", "raw_addr: ", NULL};
600 static char *value_cell_slots[] = {"value: ", NULL};
602 static void print_otherptr(lispobj obj)
604 if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
605 printf("(invalid address)");
606 } else {
607 #ifndef LISP_FEATURE_ALPHA
608 lispobj *ptr;
609 unsigned long header;
610 unsigned long length;
611 #else
612 u32 *ptr;
613 u32 header;
614 u32 length;
615 #endif
616 int count, type, index;
617 char buffer[16];
619 ptr = (lispobj*) native_pointer(obj);
620 if (ptr == NULL) {
621 printf(" (NULL Pointer)");
622 return;
625 header = *ptr++;
626 length = fixnum_value(*ptr);
627 count = HeaderValue(header);
628 type = widetag_of(header);
630 print_obj("header: ", header);
631 if (!other_immediate_lowtag_p(header)) {
632 NEWLINE_OR_RETURN;
633 printf("(invalid header object)");
634 return;
637 if (unprintable_array_types[type/8] & (1<<(type % 8)))
638 return;
639 switch (type) {
640 case BIGNUM_WIDETAG:
641 ptr += count;
642 NEWLINE_OR_RETURN;
643 printf("0x");
644 while (count-- > 0)
645 printf(
646 #if N_WORD_BITS == 32
647 "%08lx%s",
648 #else
649 "%016lx%s",
650 #endif
651 (unsigned long) *--ptr, (count?"_":""));
652 break;
654 case RATIO_WIDETAG:
655 print_slots(ratio_slots, count, ptr);
656 break;
658 case COMPLEX_WIDETAG:
659 print_slots(complex_slots, count, ptr);
660 break;
662 case SYMBOL_HEADER_WIDETAG:
663 // Only 1 byte of a symbol header conveys its size.
664 // The other bytes may be freely used by the backend.
665 print_slots(symbol_slots, count & 0xFF, ptr);
666 break;
668 #if N_WORD_BITS == 32
669 case SINGLE_FLOAT_WIDETAG:
670 NEWLINE_OR_RETURN;
671 printf("%g", ((struct single_float *)native_pointer(obj))->value);
672 break;
673 #endif
674 case DOUBLE_FLOAT_WIDETAG:
675 NEWLINE_OR_RETURN;
676 printf("%g", ((struct double_float *)native_pointer(obj))->value);
677 break;
679 #ifdef LONG_FLOAT_WIDETAG
680 case LONG_FLOAT_WIDETAG:
681 NEWLINE_OR_RETURN;
682 printf("%Lg", ((struct long_float *)native_pointer(obj))->value);
683 break;
684 #endif
686 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
687 case COMPLEX_SINGLE_FLOAT_WIDETAG:
688 NEWLINE_OR_RETURN;
689 #ifdef LISP_FEATURE_64_BIT
690 printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[0]);
691 #else
692 printf("%g", ((struct complex_single_float *)native_pointer(obj))->real);
693 #endif
694 NEWLINE_OR_RETURN;
695 #ifdef LISP_FEATURE_64_BIT
696 printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[1]);
697 #else
698 printf("%g", ((struct complex_single_float *)native_pointer(obj))->imag);
699 #endif
700 break;
701 #endif
703 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
704 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
705 NEWLINE_OR_RETURN;
706 printf("%g", ((struct complex_double_float *)native_pointer(obj))->real);
707 NEWLINE_OR_RETURN;
708 printf("%g", ((struct complex_double_float *)native_pointer(obj))->imag);
709 break;
710 #endif
712 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
713 case COMPLEX_LONG_FLOAT_WIDETAG:
714 NEWLINE_OR_RETURN;
715 printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->real);
716 NEWLINE_OR_RETURN;
717 printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->imag);
718 break;
719 #endif
721 case SIMPLE_BASE_STRING_WIDETAG:
722 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
723 case SIMPLE_CHARACTER_STRING_WIDETAG:
724 #endif
725 NEWLINE_OR_RETURN;
726 show_lstring((struct vector*)native_pointer(obj), 1, stdout);
727 break;
729 case SIMPLE_VECTOR_WIDETAG:
730 NEWLINE_OR_RETURN;
731 printf("length = %ld", length);
732 ptr++;
733 index = 0;
734 while (length-- > 0) {
735 sprintf(buffer, "%d: ", index++);
736 print_obj(buffer, *ptr++);
738 break;
740 // FIXME: This case looks unreachable. print_struct() does it
741 case INSTANCE_HEADER_WIDETAG:
742 NEWLINE_OR_RETURN;
743 count &= SHORT_HEADER_MAX_WORDS;
744 printf("length = %ld", (long) count);
745 index = 0;
746 while (count-- > 0) {
747 sprintf(buffer, "%d: ", index++);
748 print_obj(buffer, *ptr++);
750 break;
752 case CODE_HEADER_WIDETAG:
753 count &= SHORT_HEADER_MAX_WORDS;
754 print_slots(code_slots, count-1, ptr);
755 break;
757 case SIMPLE_FUN_HEADER_WIDETAG:
758 print_slots(fn_slots, 6, ptr);
759 break;
761 #if !defined(LISP_FEATURE_X86) && !defined(LISP_FEATURE_X86_64)
762 case RETURN_PC_HEADER_WIDETAG:
763 print_obj("code: ", obj - (count * 4));
764 break;
765 #endif
767 case CLOSURE_HEADER_WIDETAG:
768 print_slots(closure_slots, count, ptr);
769 break;
771 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
772 print_slots(funcallable_instance_slots, count, ptr);
773 break;
775 case VALUE_CELL_HEADER_WIDETAG:
776 print_slots(value_cell_slots, 1, ptr);
777 break;
779 case SAP_WIDETAG:
780 NEWLINE_OR_RETURN;
781 #ifndef LISP_FEATURE_ALPHA
782 printf("0x%08lx", (unsigned long) *ptr);
783 #else
784 printf("0x%016lx", *(lispobj*)(ptr+1));
785 #endif
786 break;
788 case WEAK_POINTER_WIDETAG:
789 print_slots(weak_pointer_slots, 1, ptr);
790 break;
792 case CHARACTER_WIDETAG:
793 case UNBOUND_MARKER_WIDETAG:
794 NEWLINE_OR_RETURN;
795 printf("pointer to an immediate?");
796 break;
798 case FDEFN_WIDETAG:
799 print_slots(fdefn_slots, count & SHORT_HEADER_MAX_WORDS, ptr);
800 break;
802 default:
803 NEWLINE_OR_RETURN;
804 printf("Unknown header object?");
805 break;
810 static void print_obj(char *prefix, lispobj obj)
812 #ifdef LISP_FEATURE_64_BIT
813 static void (*verbose_fns[])(lispobj obj)
814 = {print_fixnum, print_otherimm, print_fixnum, print_struct,
815 print_fixnum, print_otherimm, print_fixnum, print_list,
816 print_fixnum, print_otherimm, print_fixnum, print_otherptr,
817 print_fixnum, print_otherimm, print_fixnum, print_otherptr};
818 static void (*brief_fns[])(lispobj obj)
819 = {brief_fixnum, brief_otherimm, brief_fixnum, brief_struct,
820 brief_fixnum, brief_otherimm, brief_fixnum, brief_list,
821 brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr,
822 brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr};
823 #else
824 static void (*verbose_fns[])(lispobj obj)
825 = {print_fixnum, print_struct, print_otherimm, print_list,
826 print_fixnum, print_otherptr, print_otherimm, print_otherptr};
827 static void (*brief_fns[])(lispobj obj)
828 = {brief_fixnum, brief_struct, brief_otherimm, brief_list,
829 brief_fixnum, brief_otherptr, brief_otherimm, brief_otherptr};
830 #endif
831 int type = lowtag_of(obj);
832 struct var *var = lookup_by_obj(obj);
833 char buffer[256];
834 boolean verbose = cur_depth < brief_depth;
836 if (!continue_p(verbose))
837 return;
839 if (var != NULL && var_clock(var) == cur_clock)
840 dont_descend = 1;
842 if (var == NULL && is_lisp_pointer(obj))
843 var = define_var(NULL, obj, 0);
845 if (var != NULL)
846 var_setclock(var, cur_clock);
848 cur_depth++;
849 if (verbose) {
850 if (var != NULL) {
851 sprintf(buffer, "$%s=", var_name(var));
852 newline(buffer);
854 else
855 newline(NULL);
856 printf("%s0x%08lx: ", prefix, (unsigned long) obj);
857 if (cur_depth < brief_depth) {
858 fputs(lowtag_names[type], stdout);
859 (*verbose_fns[type])(obj);
861 else
862 (*brief_fns[type])(obj);
864 else {
865 if (dont_descend)
866 printf("$%s", var_name(var));
867 else {
868 if (var != NULL)
869 printf("$%s=", var_name(var));
870 (*brief_fns[type])(obj);
873 cur_depth--;
874 dont_descend = 0;
877 void reset_printer()
879 cur_clock++;
880 cur_lines = 0;
881 dont_descend = 0;
884 void print(lispobj obj)
886 skip_newline = 1;
887 cur_depth = 0;
888 max_depth = 5;
889 max_lines = 20;
891 print_obj("", obj);
893 putchar('\n');
896 void brief_print(lispobj obj)
898 skip_newline = 1;
899 cur_depth = 0;
900 max_depth = 1;
901 max_lines = 5000;
902 cur_lines = 0;
904 print_obj("", obj);
905 putchar('\n');
908 #else
910 void
911 brief_print(lispobj obj)
913 printf("lispobj 0x%lx\n", (unsigned long)obj);
916 #endif /* defined(LISP_FEATURE_SB_LDB) */