Parse raw slot data when printing structures in LDB
[sbcl.git] / src / runtime / print.c
blob1c25420a2c4a249c396b362bbc44020b2b727f74
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 if (c < 128) printf("%c", c);
342 else printf("U+%X", c);
344 if (charname)
345 fputs(charname, stdout);
346 break;
348 case UNBOUND_MARKER_WIDETAG:
349 printf("<unbound marker>");
350 break;
352 default:
353 printf("%s", widetag_names[type >> 2]);
354 break;
358 static void print_otherimm(lispobj obj)
360 printf(", %s", widetag_names[widetag_of(obj) >> 2]);
362 switch (widetag_of(obj)) {
363 case CHARACTER_WIDETAG:
364 printf(": ");
365 brief_otherimm(obj);
366 break;
368 case SAP_WIDETAG:
369 case UNBOUND_MARKER_WIDETAG:
370 break;
372 default:
373 printf(": data=%ld", (long) (obj>>8)&0xffffff);
374 break;
378 static void brief_list(lispobj obj)
380 int space = 0;
381 int length = 0;
383 if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj)))
384 printf("(invalid Lisp-level address)");
385 else if (obj == NIL)
386 printf("NIL");
387 else {
388 putchar('(');
389 while (lowtag_of(obj) == LIST_POINTER_LOWTAG) {
390 struct cons *cons = (struct cons *)native_pointer(obj);
392 if (space)
393 putchar(' ');
394 if (++length >= max_length) {
395 printf("...");
396 obj = NIL;
397 break;
399 print_obj("", cons->car);
400 obj = cons->cdr;
401 space = 1;
402 if (obj == NIL)
403 break;
405 if (obj != NIL) {
406 printf(" . ");
407 print_obj("", obj);
409 putchar(')');
413 static void print_list(lispobj obj)
415 if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj))) {
416 printf("(invalid address)");
417 } else if (obj == NIL) {
418 printf(" (NIL)");
419 } else {
420 struct cons *cons = (struct cons *)native_pointer(obj);
422 print_obj("car: ", cons->car);
423 print_obj("cdr: ", cons->cdr);
427 // takes native pointer as input
428 char * simple_base_stringize(struct vector * string)
430 if (widetag_of(string->header) == SIMPLE_BASE_STRING_WIDETAG)
431 return (char*)string->data;
432 int length = string->length;
433 char * newstring = malloc(length+1);
434 uint32_t * data = (uint32_t*)string->data;
435 int i;
436 for(i=0;i<length;++i)
437 newstring[i] = data[i] < 128 ? data[i] : '?';
438 newstring[length] = 0;
439 return newstring;
442 static void brief_struct(lispobj obj)
444 struct instance *instance = (struct instance *)native_pointer(obj);
445 if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
446 printf("(invalid address)");
447 } else {
448 extern struct vector * instance_classoid_name(lispobj*);
449 struct vector * classoid_name;
450 classoid_name = instance_classoid_name((lispobj*)instance);
451 if ( classoid_name ) {
452 char * namestring = simple_base_stringize(classoid_name);
453 printf("#<ptr to 0x%08lx %s instance>",
454 (unsigned long) instance->slots[0], namestring);
455 if ( namestring != (char*)classoid_name->data )
456 free(namestring);
457 } else {
458 printf("#<ptr to 0x%08lx instance>",
459 (unsigned long) instance->slots[0]);
464 #include "genesis/layout.h"
465 static boolean untagged_slot_p(struct layout * layout,
466 int slot_index)
468 #ifdef LISP_FEATURE_INTERLEAVED_RAW_SLOTS
469 extern boolean positive_bignum_logbitp(int,struct bignum*);
470 lispobj bitmap = layout->untagged_bitmap;
471 return fixnump(bitmap)
472 ? (fixnum_value(bitmap) >> slot_index) & 1
473 : positive_bignum_logbitp(slot_index,
474 (struct bignum*)native_pointer(bitmap));
475 #else
476 return slot_index >= (fixnum_value(layout->length)|1)
477 - fixnum_value(layout->n_untagged_slots);
478 #endif
481 static void print_struct(lispobj obj)
483 struct instance *instance = (struct instance *)native_pointer(obj);
484 unsigned int i;
485 char buffer[16];
486 if (!is_valid_lisp_addr((os_vm_address_t)instance)) {
487 printf("(invalid address)");
488 } else {
489 lispobj layout_obj = ((struct instance *)native_pointer(obj))->slots[0];
490 print_obj("type: ", layout_obj);
491 struct layout * layout = (struct layout*)native_pointer(layout_obj);
492 for (i = 1; i < HeaderValue(instance->header); i++) {
493 sprintf(buffer, "slot %d: ", i);
494 if (layout==NULL || untagged_slot_p(layout, i)) {
495 newline(NULL);
496 printf("\n\t %s0x%"OBJ_FMTX" [raw]", buffer, instance->slots[i]);
497 } else
498 print_obj(buffer, instance->slots[i]);
503 void show_lstring(struct vector * string, int quotes, FILE *s)
505 int ucs4_p = 0;
506 int i, len = fixnum_value(string->length);
508 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
509 if (widetag_of(string->header) == SIMPLE_CHARACTER_STRING_WIDETAG) {
510 ucs4_p = 1;
511 if (quotes)
512 putc('u', s); /* an arbitrary notational convention */
514 #endif
515 if (quotes) putc('"', s);
516 for (i=0 ; i<len ; i++) {
517 // hopefully the compiler will optimize out the ucs4_p test
518 // when the runtime is built without Unicode support
519 int ch;
520 if (ucs4_p)
521 ch = i[(uint32_t*)string->data];
522 else
523 ch = i[(char*)string->data];
524 if (ch >= 32 && ch < 127) {
525 if (quotes && (ch == '"' || ch == '\\'))
526 putc('\\', s);
527 putc(ch, s);
528 } else {
529 fprintf(s, ch > 0xffff ? "\\U%08X" :
530 ch > 0xff ? "\\u%04X" : "\\x%02X", ch);
533 if (quotes) putc('"', s);
536 static void brief_otherptr(lispobj obj)
538 lispobj *ptr, header;
539 int type;
540 struct symbol *symbol;
542 ptr = (lispobj *) native_pointer(obj);
544 if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
545 printf("(invalid address)");
546 return;
549 header = *ptr;
550 type = widetag_of(header);
551 switch (type) {
552 case SYMBOL_HEADER_WIDETAG:
553 symbol = (struct symbol *)ptr;
554 if (symbol->package == NIL)
555 printf("#:");
556 show_lstring((struct vector *)native_pointer(symbol->name),
557 0, stdout);
558 break;
560 case SIMPLE_BASE_STRING_WIDETAG:
561 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
562 case SIMPLE_CHARACTER_STRING_WIDETAG:
563 #endif
564 show_lstring((struct vector*)ptr, 1, stdout);
565 break;
567 default:
568 printf("#<ptr to ");
569 brief_otherimm(header);
570 putchar('>');
574 static void print_slots(char **slots, int count, lispobj *ptr)
576 while (count-- > 0) {
577 if (*slots) {
578 print_obj(*slots++, *ptr++);
579 } else {
580 print_obj("???: ", *ptr++);
585 /* FIXME: Yikes! This needs to depend on the values in sbcl.h (or
586 * perhaps be generated automatically by GENESIS as part of
587 * sbcl.h). */
588 static char *symbol_slots[] = {"value: ", "hash: ",
589 "info: ", "name: ", "package: ",
590 #if defined (LISP_FEATURE_SB_THREAD) && !defined(LISP_FEATURE_X86_64)
591 "tls-index: " ,
592 #endif
593 NULL};
594 static char *ratio_slots[] = {"numer: ", "denom: ", NULL};
595 static char *complex_slots[] = {"real: ", "imag: ", NULL};
596 static char *code_slots[] = {"words: ", "entry: ", "debug: ", NULL};
597 static char *fn_slots[] = {
598 "self: ", "next: ", "name: ", "arglist: ", "type: ", NULL};
599 static char *closure_slots[] = {"fn: ", NULL};
600 static char *funcallable_instance_slots[] = {"fn: ", "lexenv: ", "layout: ", NULL};
601 static char *weak_pointer_slots[] = {"value: ", NULL};
602 static char *fdefn_slots[] = {"name: ", "function: ", "raw_addr: ", NULL};
603 static char *value_cell_slots[] = {"value: ", NULL};
605 static void print_otherptr(lispobj obj)
607 if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
608 printf("(invalid address)");
609 } else {
610 #ifndef LISP_FEATURE_ALPHA
611 lispobj *ptr;
612 unsigned long header;
613 unsigned long length;
614 #else
615 u32 *ptr;
616 u32 header;
617 u32 length;
618 #endif
619 int count, type, index;
620 char buffer[16];
622 ptr = (lispobj*) native_pointer(obj);
623 if (ptr == NULL) {
624 printf(" (NULL Pointer)");
625 return;
628 header = *ptr++;
629 length = fixnum_value(*ptr);
630 count = HeaderValue(header);
631 type = widetag_of(header);
633 print_obj("header: ", header);
634 if (!other_immediate_lowtag_p(header)) {
635 NEWLINE_OR_RETURN;
636 printf("(invalid header object)");
637 return;
640 if (unprintable_array_types[type/8] & (1<<(type % 8)))
641 return;
642 switch (type) {
643 case BIGNUM_WIDETAG:
644 ptr += count;
645 NEWLINE_OR_RETURN;
646 printf("0x");
647 while (count-- > 0)
648 printf(
649 #if N_WORD_BITS == 32
650 "%08lx%s",
651 #else
652 "%016lx%s",
653 #endif
654 (unsigned long) *--ptr, (count?"_":""));
655 break;
657 case RATIO_WIDETAG:
658 print_slots(ratio_slots, count, ptr);
659 break;
661 case COMPLEX_WIDETAG:
662 print_slots(complex_slots, count, ptr);
663 break;
665 case SYMBOL_HEADER_WIDETAG:
666 // Only 1 byte of a symbol header conveys its size.
667 // The other bytes may be freely used by the backend.
668 print_slots(symbol_slots, count & 0xFF, ptr);
669 break;
671 #if N_WORD_BITS == 32
672 case SINGLE_FLOAT_WIDETAG:
673 NEWLINE_OR_RETURN;
674 printf("%g", ((struct single_float *)native_pointer(obj))->value);
675 break;
676 #endif
677 case DOUBLE_FLOAT_WIDETAG:
678 NEWLINE_OR_RETURN;
679 printf("%g", ((struct double_float *)native_pointer(obj))->value);
680 break;
682 #ifdef LONG_FLOAT_WIDETAG
683 case LONG_FLOAT_WIDETAG:
684 NEWLINE_OR_RETURN;
685 printf("%Lg", ((struct long_float *)native_pointer(obj))->value);
686 break;
687 #endif
689 #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG
690 case COMPLEX_SINGLE_FLOAT_WIDETAG:
691 NEWLINE_OR_RETURN;
692 #ifdef LISP_FEATURE_X86_64
693 printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[0]);
694 #else
695 printf("%g", ((struct complex_single_float *)native_pointer(obj))->real);
696 #endif
697 NEWLINE_OR_RETURN;
698 #ifdef LISP_FEATURE_X86_64
699 printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[1]);
700 #else
701 printf("%g", ((struct complex_single_float *)native_pointer(obj))->imag);
702 #endif
703 break;
704 #endif
706 #ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG
707 case COMPLEX_DOUBLE_FLOAT_WIDETAG:
708 NEWLINE_OR_RETURN;
709 printf("%g", ((struct complex_double_float *)native_pointer(obj))->real);
710 NEWLINE_OR_RETURN;
711 printf("%g", ((struct complex_double_float *)native_pointer(obj))->imag);
712 break;
713 #endif
715 #ifdef COMPLEX_LONG_FLOAT_WIDETAG
716 case COMPLEX_LONG_FLOAT_WIDETAG:
717 NEWLINE_OR_RETURN;
718 printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->real);
719 NEWLINE_OR_RETURN;
720 printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->imag);
721 break;
722 #endif
724 case SIMPLE_BASE_STRING_WIDETAG:
725 #ifdef SIMPLE_CHARACTER_STRING_WIDETAG
726 case SIMPLE_CHARACTER_STRING_WIDETAG:
727 #endif
728 NEWLINE_OR_RETURN;
729 show_lstring((struct vector*)native_pointer(obj), 1, stdout);
730 break;
732 case SIMPLE_VECTOR_WIDETAG:
733 NEWLINE_OR_RETURN;
734 printf("length = %ld", length);
735 ptr++;
736 index = 0;
737 while (length-- > 0) {
738 sprintf(buffer, "%d: ", index++);
739 print_obj(buffer, *ptr++);
741 break;
743 // FIXME: This case looks unreachable. print_struct() does it
744 case INSTANCE_HEADER_WIDETAG:
745 NEWLINE_OR_RETURN;
746 printf("length = %ld", (long) count);
747 index = 0;
748 while (count-- > 0) {
749 sprintf(buffer, "%d: ", index++);
750 print_obj(buffer, *ptr++);
752 break;
754 case CODE_HEADER_WIDETAG:
755 print_slots(code_slots, count-1, ptr);
756 break;
758 case SIMPLE_FUN_HEADER_WIDETAG:
759 print_slots(fn_slots, 5, ptr);
760 break;
762 case RETURN_PC_HEADER_WIDETAG:
763 print_obj("code: ", obj - (count * 4));
764 break;
766 case CLOSURE_HEADER_WIDETAG:
767 print_slots(closure_slots, count, ptr);
768 break;
770 case FUNCALLABLE_INSTANCE_HEADER_WIDETAG:
771 print_slots(funcallable_instance_slots, count, ptr);
772 break;
774 case VALUE_CELL_HEADER_WIDETAG:
775 print_slots(value_cell_slots, 1, ptr);
776 break;
778 case SAP_WIDETAG:
779 NEWLINE_OR_RETURN;
780 #ifndef LISP_FEATURE_ALPHA
781 printf("0x%08lx", (unsigned long) *ptr);
782 #else
783 printf("0x%016lx", *(lispobj*)(ptr+1));
784 #endif
785 break;
787 case WEAK_POINTER_WIDETAG:
788 print_slots(weak_pointer_slots, 1, ptr);
789 break;
791 case CHARACTER_WIDETAG:
792 case UNBOUND_MARKER_WIDETAG:
793 NEWLINE_OR_RETURN;
794 printf("pointer to an immediate?");
795 break;
797 case FDEFN_WIDETAG:
798 print_slots(fdefn_slots, count, ptr);
799 break;
801 default:
802 NEWLINE_OR_RETURN;
803 printf("Unknown header object?");
804 break;
809 static void print_obj(char *prefix, lispobj obj)
811 #ifdef LISP_FEATURE_X86_64
812 static void (*verbose_fns[])(lispobj obj)
813 = {print_fixnum, print_otherimm, print_fixnum, print_struct,
814 print_fixnum, print_otherimm, print_fixnum, print_list,
815 print_fixnum, print_otherimm, print_fixnum, print_otherptr,
816 print_fixnum, print_otherimm, print_fixnum, print_otherptr};
817 static void (*brief_fns[])(lispobj obj)
818 = {brief_fixnum, brief_otherimm, brief_fixnum, brief_struct,
819 brief_fixnum, brief_otherimm, brief_fixnum, brief_list,
820 brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr,
821 brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr};
822 #else
823 static void (*verbose_fns[])(lispobj obj)
824 = {print_fixnum, print_struct, print_otherimm, print_list,
825 print_fixnum, print_otherptr, print_otherimm, print_otherptr};
826 static void (*brief_fns[])(lispobj obj)
827 = {brief_fixnum, brief_struct, brief_otherimm, brief_list,
828 brief_fixnum, brief_otherptr, brief_otherimm, brief_otherptr};
829 #endif
830 int type = lowtag_of(obj);
831 struct var *var = lookup_by_obj(obj);
832 char buffer[256];
833 boolean verbose = cur_depth < brief_depth;
835 if (!continue_p(verbose))
836 return;
838 if (var != NULL && var_clock(var) == cur_clock)
839 dont_descend = 1;
841 if (var == NULL && is_lisp_pointer(obj))
842 var = define_var(NULL, obj, 0);
844 if (var != NULL)
845 var_setclock(var, cur_clock);
847 cur_depth++;
848 if (verbose) {
849 if (var != NULL) {
850 sprintf(buffer, "$%s=", var_name(var));
851 newline(buffer);
853 else
854 newline(NULL);
855 printf("%s0x%08lx: ", prefix, (unsigned long) obj);
856 if (cur_depth < brief_depth) {
857 fputs(lowtag_names[type], stdout);
858 (*verbose_fns[type])(obj);
860 else
861 (*brief_fns[type])(obj);
863 else {
864 if (dont_descend)
865 printf("$%s", var_name(var));
866 else {
867 if (var != NULL)
868 printf("$%s=", var_name(var));
869 (*brief_fns[type])(obj);
872 cur_depth--;
873 dont_descend = 0;
876 void reset_printer()
878 cur_clock++;
879 cur_lines = 0;
880 dont_descend = 0;
883 void print(lispobj obj)
885 skip_newline = 1;
886 cur_depth = 0;
887 max_depth = 5;
888 max_lines = 20;
890 print_obj("", obj);
892 putchar('\n');
895 void brief_print(lispobj obj)
897 skip_newline = 1;
898 cur_depth = 0;
899 max_depth = 1;
900 max_lines = 5000;
901 cur_lines = 0;
903 print_obj("", obj);
904 putchar('\n');
907 #else
909 void
910 brief_print(lispobj obj)
912 printf("lispobj 0x%lx\n", (unsigned long)obj);
915 #endif /* defined(LISP_FEATURE_SB_LDB) */