3 This code was written as part of the CMU Common Lisp project at
4 Carnegie Mellon University, and has been placed in the public domain.
13 #include "internals.h"
18 static int max_lines = 20, cur_lines = 0;
19 static int max_depth = 5, brief_depth = 2, cur_depth = 0;
20 static int max_length = 5;
21 static boolean dont_decend = FALSE, skip_newline = FALSE;
22 static int cur_clock = 0;
24 static void print_obj(char *prefix, lispobj obj);
26 #define NEWLINE if (continue_p(TRUE)) newline(NULL); else return;
28 char *lowtag_Names[] = {
31 "other immediate [0]",
35 "other immediate [1]",
39 char *subtype_Names[] = {
49 #ifdef type_DoubleDoubleFloat
50 "double-double float",
53 #ifdef type_ComplexSingleFloat
54 "complex single float",
56 #ifdef type_ComplexDoubleFloat
57 "complex double float",
59 #ifdef type_ComplexLongFloat
62 #ifdef type_ComplexDoubleDoubleFloat
63 "complex double-double float",
69 "(simple-array (unsigned-byte 2) (*))",
70 "(simple-array (unsigned-byte 4) (*))",
71 "(simple-array (unsigned-byte 8) (*))",
72 "(simple-array (unsigned-byte 16) (*))",
73 "(simple-array (unsigned-byte 32) (*))",
74 #ifdef type_SimpleArraySignedByte8
75 "(simple-array (signed-byte 8) (*))",
77 #ifdef type_SimpleArraySignedByte16
78 "(simple-array (signed-byte 16) (*))",
80 #ifdef type_SimpleArraySignedByte30
81 "(simple-array fixnum (*))",
83 #ifdef type_SimpleArraySignedByte32
84 "(simple-array (signed-byte 32) (*))",
86 "(simple-array single-float (*))",
87 "(simple-array double-float (*))",
88 #ifdef type_SimpleArrayLongFloat
89 "(simple-array long-float (*))",
91 #ifdef type_SimpleArrayDoubleDoubleFloat
92 "(simple-array double-double-float (*))",
94 #ifdef type_SimpleArrayComplexSingleFloat
95 "(simple-array (complex single-float) (*))",
97 #ifdef type_SimpleArrayComplexDoubleFloat
98 "(simple-array (complex double-float) (*))",
100 #ifdef type_SimpleArrayComplexLongFloat
101 "(simple-array (complex long-float) (*))",
103 #ifdef type_SimpleArrayComplexDoubleDoubleFloat
104 "(simple-array (complex double-double-float) (*))",
107 "complex-bit-vector",
113 "funcallable-instance header",
114 "byte code function",
116 /* "unused function header 3",*/
117 "closure function header",
127 #ifdef type_ScavengerHook
135 static char *spaces =
140 fputs(spaces, stdout);
144 fputs(spaces + 64 - in, stdout);
148 continue_p(boolean newline)
152 if (cur_depth >= max_depth || dont_decend)
157 skip_newline = FALSE;
161 if (cur_lines >= max_lines) {
163 printf("More? [y] ");
166 result = fgets(buffer, sizeof(buffer), stdin);
168 if (result == NULL || buffer[0] == 'n' || buffer[0] == 'N')
183 fputs(label, stdout);
185 indent(cur_depth * 2);
190 brief_fixnum(lispobj obj)
193 printf("%ld", ((long) obj) >> 2);
195 printf("%d", ((s32) obj) >> 2);
200 print_fixnum(lispobj obj)
203 printf(": %ld", ((long) obj) >> 2);
205 printf(": %d", ((s32) obj) >> 2);
210 brief_otherimm(lispobj obj)
218 c = (obj >> 8) & 0xff;
224 printf("#\\Newline");
227 printf("#\\Backspace");
233 strcpy(buffer, "#\\");
235 strcat(buffer, "m-");
239 strcat(buffer, "c-");
242 printf("%s%c", buffer, c);
247 case type_UnboundMarker:
248 printf("<unbound marker>");
253 if (idx < (sizeof(subtype_Names) / sizeof(char *)))
254 printf("%s", subtype_Names[idx]);
257 printf("unknown type (0x%0x)", type);
263 print_otherimm(lispobj obj)
270 if (idx < (sizeof(subtype_Names) / sizeof(char *)))
271 printf(", %s", subtype_Names[idx]);
274 printf(", unknown type (0x%0x)", type);
276 switch (TypeOf(obj)) {
283 case type_UnboundMarker:
287 printf(": data=%ld", (obj >> 8) & 0xffffff);
293 brief_list(lispobj obj)
298 if (!valid_addr((os_vm_address_t) obj))
299 printf("(invalid address)");
304 while (LowtagOf(obj) == type_ListPointer) {
305 struct cons *cons = (struct cons *) PTR(obj);
309 if (++length >= max_length) {
314 print_obj(NULL, cons->car);
322 print_obj(NULL, obj);
329 print_list(lispobj obj)
331 if (!valid_addr((os_vm_address_t) obj))
332 printf("(invalid address)");
336 struct cons *cons = (struct cons *) PTR(obj);
338 print_obj("car: ", cons->car);
339 print_obj("cdr: ", cons->cdr);
344 brief_struct(lispobj obj)
346 printf("#<ptr to 0x%08lx instance>",
347 ((struct instance *) PTR(obj))->slots[0]);
351 print_struct(lispobj obj)
353 struct instance *instance = (struct instance *) PTR(obj);
357 print_obj("type: ", ((struct instance *) PTR(obj))->slots[0]);
358 for (i = 1; i < HeaderValue(instance->header); i++) {
359 sprintf(buffer, "slot %d: ", i);
360 print_obj(buffer, instance->slots[i]);
365 print_string(struct vector* vector)
370 for (charptr = (char *) vector->data; *charptr != '\0'; charptr++) {
376 uint16_t *charptr = (uint16_t *) vector->data;
377 int len = fixnum_value(vector->length);
380 if (*charptr == '"') {
383 /* Just dump out the UTF-16 data */
384 fwrite(charptr, sizeof(*charptr), 1, stdout);
391 brief_otherptr(lispobj obj)
393 lispobj *ptr, header;
395 struct symbol *symbol;
396 struct vector *vector;
398 ptr = (lispobj *) PTR(obj);
400 if (!valid_addr((os_vm_address_t) obj)) {
401 printf("(invalid address)");
406 type = TypeOf(header);
408 case type_SymbolHeader:
409 symbol = (struct symbol *) ptr;
410 vector = (struct vector *) PTR(symbol->name);
411 print_string(vector);
414 case type_SimpleString:
415 vector = (struct vector *) ptr;
417 print_string(vector);
423 brief_otherimm(header);
429 print_slots(char **slots, int count, lispobj * ptr)
433 print_obj(*slots++, *ptr++);
435 print_obj("???: ", *ptr++);
438 static char *symbol_slots[] = { "value: ", "hash: ",
439 "plist: ", "name: ", "package: ", NULL
441 static char *ratio_slots[] = { "numer: ", "denom: ", NULL };
442 static char *complex_slots[] = { "real: ", "imag: ", NULL };
443 static char *code_slots[] = { "words: ", "entry: ", "debug: ", NULL };
444 static char *array_slots[] = { "fill-pointer: ",
450 /* Some reasonable number of dimensions */
461 static char *simple_array_slots[] = { "length: ",
465 #if (defined(i386) || defined(__x86_64))
466 static char *fn_slots[] =
467 { "inst start: ", "next: ", "name: ", "arglist: ", "type: ", NULL };
469 static char *fn_slots[] =
470 { "self: ", "next: ", "name: ", "arglist: ", "type: ", NULL };
473 static char *closure_slots[] = { "fn: ", NULL };
474 static char *funcallable_instance_slots[] =
475 { "fn: ", "lexenv: ", "layout: ", NULL };
476 static char *weak_pointer_slots[] = { "value: ", "broken: ",
482 static char *fdefn_slots[] = { "name: ", "function: ", "raw_addr: ", NULL };
483 static char *value_cell_slots[] = { "value: ", NULL };
485 #ifdef type_ScavengerHook
486 static char *scavenger_hook_slots[] =
488 { "value: ", "function: ", "next: ", NULL };
492 print_otherptr(lispobj obj)
494 if (!valid_addr((os_vm_address_t) obj))
495 printf("(invalid address)");
499 unsigned long header;
500 unsigned long length;
506 int count, type, index;
510 ptr = (unsigned long *) PTR(obj);
511 if (ptr == (unsigned long *) NULL) {
513 ptr = (u32 *) PTR(obj);
514 if (ptr == (u32 *) NULL) {
516 printf(" (NULL Pointer)");
521 length = fixnum_value(*ptr);
523 type = TypeOf(header);
525 print_obj("header: ", header);
526 if (LowtagOf(header) != type_OtherImmediate0
527 && LowtagOf(header) != type_OtherImmediate1) {
529 printf("(invalid header object)");
539 printf("%08lx", *--ptr);
543 print_slots(ratio_slots, count, ptr);
547 print_slots(complex_slots, count, ptr);
550 case type_SymbolHeader:
551 print_slots(symbol_slots, count, ptr);
554 case type_SingleFloat:
556 printf("%g", ((struct single_float *) PTR(obj))->value);
559 case type_DoubleFloat:
561 printf("%.15lg", ((struct double_float *) PTR(obj))->value);
564 #ifdef type_LongFloat
567 printf("%Lg", ((struct long_float *) PTR(obj))->value);
571 #ifdef type_DoubleDoubleFloat
572 case type_DoubleDoubleFloat:
574 printf("%.15lg %.15lg", ((struct double_double_float *) PTR(obj))->hi,
575 ((struct double_double_float *) PTR(obj))->lo);
579 #ifdef type_ComplexSingleFloat
580 case type_ComplexSingleFloat:
582 printf("%g", ((struct complex_single_float *) PTR(obj))->real);
584 printf("%g", ((struct complex_single_float *) PTR(obj))->imag);
588 #ifdef type_ComplexDoubleFloat
589 case type_ComplexDoubleFloat:
591 printf("%.15lg", ((struct complex_double_float *) PTR(obj))->real);
593 printf("%.15lg", ((struct complex_double_float *) PTR(obj))->imag);
597 #ifdef type_ComplexLongFloat
598 case type_ComplexLongFloat:
600 printf("%Lg", ((struct complex_long_float *) PTR(obj))->real);
602 printf("%Lg", ((struct complex_long_float *) PTR(obj))->imag);
606 #ifdef type_ComplexDoubleDoubleFloat
607 case type_ComplexDoubleDoubleFloat:
609 printf("%.15lg %.15lg", ((struct complex_double_double_float *) PTR(obj))->real_hi,
610 ((struct complex_double_double_float *) PTR(obj))->real_lo);
612 printf("%.15lg %.15lg", ((struct complex_double_double_float *) PTR(obj))->imag_hi,
613 ((struct complex_double_double_float *) PTR(obj))->imag_lo);
618 case type_SimpleString:
621 /* Need to back up one to get the start of the vector */
622 print_string((struct vector*) (ptr - 1));
626 case type_SimpleVector:
628 printf("length = %ld", length);
631 while (length-- > 0) {
632 sprintf(buffer, "%d: ", index++);
633 print_obj(buffer, *ptr++);
637 case type_InstanceHeader:
639 printf("length = %d", count);
641 while (count-- > 0) {
642 sprintf(buffer, "%d: ", index++);
643 print_obj(buffer, *ptr++);
647 case type_SimpleArray:
648 case type_SimpleBitVector:
649 case type_SimpleArrayUnsignedByte2:
650 case type_SimpleArrayUnsignedByte4:
651 case type_SimpleArrayUnsignedByte8:
652 case type_SimpleArrayUnsignedByte16:
653 case type_SimpleArrayUnsignedByte32:
654 #ifdef type_SimpleArraySignedByte8
655 case type_SimpleArraySignedByte8:
657 #ifdef type_SimpleArraySignedByte16
658 case type_SimpleArraySignedByte16:
660 #ifdef type_SimpleArraySignedByte30
661 case type_SimpleArraySignedByte30:
663 #ifdef type_SimpleArraySignedByte32
664 case type_SimpleArraySignedByte32:
666 case type_SimpleArraySingleFloat:
667 case type_SimpleArrayDoubleFloat:
668 #ifdef type_SimpleArrayLongFloat
669 case type_SimpleArrayLongFloat:
671 #ifdef type_SimpleArrayDoubleDoubleFloat
672 case type_SimpleArrayDoubleDoubleFloat:
674 #ifdef type_SimpleArrayComplexSingleFloat
675 case type_SimpleArrayComplexSingleFloat:
677 #ifdef type_SimpleArrayComplexDoubleFloat
678 case type_SimpleArrayComplexDoubleFloat:
680 #ifdef type_SimpleArrayComplexLongFloat
681 case type_SimpleArrayComplexLongFloat:
683 #ifdef type_SimpleArrayComplexDoubleDoubleFloat
684 case type_SimpleArrayComplexDoubleDoubleFloat:
686 print_slots(simple_array_slots, 1, ptr);
688 case type_ComplexString:
689 case type_ComplexBitVector:
690 case type_ComplexVector:
691 case type_ComplexArray:
692 print_slots(array_slots, count, ptr);
695 case type_CodeHeader:
696 print_slots(code_slots, count - 1, ptr);
699 case type_FunctionHeader:
700 case type_ClosureFunctionHeader:
701 print_slots(fn_slots, 5, ptr);
704 case type_ReturnPcHeader:
705 print_obj("code: ", obj - (count * 4));
708 case type_ClosureHeader:
709 print_slots(closure_slots, count, ptr);
712 case type_FuncallableInstanceHeader:
713 print_slots(funcallable_instance_slots, count, ptr);
716 case type_ValueCellHeader:
717 print_slots(value_cell_slots, 1, ptr);
723 printf("0x%08lx", *ptr);
725 printf("0x%016lx", *(long *) (ptr + 1));
729 case type_WeakPointer:
730 print_slots(weak_pointer_slots, 3, ptr);
734 case type_UnboundMarker:
736 printf("pointer to an immediate?");
740 print_slots(fdefn_slots, count, ptr);
743 #ifdef type_ScavengerHook
744 case type_ScavengerHook:
745 print_slots(scavenger_hook_slots, count, ptr);
751 printf("Unknown header object?");
758 print_obj(char *prefix, lispobj obj)
760 static void (*verbose_fns[]) (lispobj obj)
761 = { print_fixnum, print_otherptr, print_otherimm, print_list,
762 print_fixnum, print_struct, print_otherimm, print_otherptr
764 static void (*brief_fns[]) (lispobj obj)
765 = { brief_fixnum, brief_otherptr, brief_otherimm, brief_list,
766 brief_fixnum, brief_struct, brief_otherimm, brief_otherptr
768 int type = LowtagOf(obj);
769 struct var *var = lookup_by_obj(obj);
771 boolean verbose = cur_depth < brief_depth;
774 if (!continue_p(verbose))
777 if (var != NULL && var_clock(var) == cur_clock)
781 && (obj & type_FunctionPointer & type_ListPointer & type_InstancePointer
782 & type_OtherPointer) != 0)
783 var = define_var(NULL, obj, FALSE);
786 var_setclock(var, cur_clock);
791 sprintf(buffer, "$%s=", var_name(var));
795 printf("%s0x%08lx: ", prefix, obj);
796 if (cur_depth < brief_depth) {
797 fputs(lowtag_Names[type], stdout);
798 (*verbose_fns[type]) (obj);
800 (*brief_fns[type]) (obj);
803 printf("$%s", var_name(var));
806 printf("$%s=", var_name(var));
807 (*brief_fns[type]) (obj);
836 brief_print(lispobj obj)