1 /* $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/print.c,v 1.30 2010/10/22 04:07:33 rtoy Exp $ */
13 static int max_lines = 20, cur_lines = 0;
14 static int max_depth = 5, brief_depth = 2, cur_depth = 0;
15 static int max_length = 5;
16 static boolean dont_decend = FALSE, skip_newline = FALSE;
17 static int cur_clock = 0;
19 static void print_obj(char *prefix, lispobj obj);
21 #define NEWLINE if (continue_p(TRUE)) newline(NULL); else return;
23 char *lowtag_Names[] = {
26 "other immediate [0]",
30 "other immediate [1]",
34 char *subtype_Names[] = {
44 #ifdef type_DoubleDoubleFloat
45 "double-double float",
48 #ifdef type_ComplexSingleFloat
49 "complex single float",
51 #ifdef type_ComplexDoubleFloat
52 "complex double float",
54 #ifdef type_ComplexLongFloat
57 #ifdef type_ComplexDoubleDoubleFloat
58 "complex double-double float",
64 "(simple-array (unsigned-byte 2) (*))",
65 "(simple-array (unsigned-byte 4) (*))",
66 "(simple-array (unsigned-byte 8) (*))",
67 "(simple-array (unsigned-byte 16) (*))",
68 "(simple-array (unsigned-byte 32) (*))",
69 #ifdef type_SimpleArraySignedByte8
70 "(simple-array (signed-byte 8) (*))",
72 #ifdef type_SimpleArraySignedByte16
73 "(simple-array (signed-byte 16) (*))",
75 #ifdef type_SimpleArraySignedByte30
76 "(simple-array fixnum (*))",
78 #ifdef type_SimpleArraySignedByte32
79 "(simple-array (signed-byte 32) (*))",
81 "(simple-array single-float (*))",
82 "(simple-array double-float (*))",
83 #ifdef type_SimpleArrayLongFloat
84 "(simple-array long-float (*))",
86 #ifdef type_SimpleArrayDoubleDoubleFloat
87 "(simple-array double-double-float (*))",
89 #ifdef type_SimpleArrayComplexSingleFloat
90 "(simple-array (complex single-float) (*))",
92 #ifdef type_SimpleArrayComplexDoubleFloat
93 "(simple-array (complex double-float) (*))",
95 #ifdef type_SimpleArrayComplexLongFloat
96 "(simple-array (complex long-float) (*))",
98 #ifdef type_SimpleArrayComplexDoubleDoubleFloat
99 "(simple-array (complex double-double-float) (*))",
102 "complex-bit-vector",
108 "funcallable-instance header",
109 "byte code function",
111 /* "unused function header 3",*/
112 "closure function header",
122 #ifdef type_ScavengerHook
130 static char *spaces =
135 fputs(spaces, stdout);
139 fputs(spaces + 64 - in, stdout);
143 continue_p(boolean newline)
147 if (cur_depth >= max_depth || dont_decend)
152 skip_newline = FALSE;
156 if (cur_lines >= max_lines) {
158 printf("More? [y] ");
161 result = fgets(buffer, sizeof(buffer), stdin);
163 if (result == NULL || buffer[0] == 'n' || buffer[0] == 'N')
178 fputs(label, stdout);
180 indent(cur_depth * 2);
185 brief_fixnum(lispobj obj)
188 printf("%ld", ((long) obj) >> 2);
190 printf("%d", ((s32) obj) >> 2);
195 print_fixnum(lispobj obj)
198 printf(": %ld", ((long) obj) >> 2);
200 printf(": %d", ((s32) obj) >> 2);
205 brief_otherimm(lispobj obj)
213 c = (obj >> 8) & 0xff;
219 printf("#\\Newline");
222 printf("#\\Backspace");
228 strcpy(buffer, "#\\");
230 strcat(buffer, "m-");
234 strcat(buffer, "c-");
237 printf("%s%c", buffer, c);
242 case type_UnboundMarker:
243 printf("<unbound marker>");
248 if (idx < (sizeof(subtype_Names) / sizeof(char *)))
249 printf("%s", subtype_Names[idx]);
252 printf("unknown type (0x%0x)", type);
258 print_otherimm(lispobj obj)
265 if (idx < (sizeof(subtype_Names) / sizeof(char *)))
266 printf(", %s", subtype_Names[idx]);
269 printf(", unknown type (0x%0x)", type);
271 switch (TypeOf(obj)) {
278 case type_UnboundMarker:
282 printf(": data=%ld", (obj >> 8) & 0xffffff);
288 brief_list(lispobj obj)
293 if (!valid_addr((os_vm_address_t) obj))
294 printf("(invalid address)");
299 while (LowtagOf(obj) == type_ListPointer) {
300 struct cons *cons = (struct cons *) PTR(obj);
304 if (++length >= max_length) {
309 print_obj(NULL, cons->car);
317 print_obj(NULL, obj);
324 print_list(lispobj obj)
326 if (!valid_addr((os_vm_address_t) obj))
327 printf("(invalid address)");
331 struct cons *cons = (struct cons *) PTR(obj);
333 print_obj("car: ", cons->car);
334 print_obj("cdr: ", cons->cdr);
339 brief_struct(lispobj obj)
341 printf("#<ptr to 0x%08lx instance>",
342 ((struct instance *) PTR(obj))->slots[0]);
346 print_struct(lispobj obj)
348 struct instance *instance = (struct instance *) PTR(obj);
352 print_obj("type: ", ((struct instance *) PTR(obj))->slots[0]);
353 for (i = 1; i < HeaderValue(instance->header); i++) {
354 sprintf(buffer, "slot %d: ", i);
355 print_obj(buffer, instance->slots[i]);
360 print_string(struct vector* vector)
365 for (charptr = (char *) vector->data; *charptr != '\0'; charptr++) {
371 uint16_t *charptr = (uint16_t *) vector->data;
372 int len = fixnum_value(vector->length);
375 if (*charptr == '"') {
378 /* Just dump out the UTF-16 data */
379 fwrite(charptr, sizeof(*charptr), 1, stdout);
386 brief_otherptr(lispobj obj)
388 lispobj *ptr, header;
390 struct symbol *symbol;
391 struct vector *vector;
393 ptr = (lispobj *) PTR(obj);
395 if (!valid_addr((os_vm_address_t) obj)) {
396 printf("(invalid address)");
401 type = TypeOf(header);
403 case type_SymbolHeader:
404 symbol = (struct symbol *) ptr;
405 vector = (struct vector *) PTR(symbol->name);
406 print_string(vector);
409 case type_SimpleString:
410 vector = (struct vector *) ptr;
412 print_string(vector);
418 brief_otherimm(header);
424 print_slots(char **slots, int count, lispobj * ptr)
428 print_obj(*slots++, *ptr++);
430 print_obj("???: ", *ptr++);
433 static char *symbol_slots[] = { "value: ", "hash: ",
434 "plist: ", "name: ", "package: ", NULL
436 static char *ratio_slots[] = { "numer: ", "denom: ", NULL };
437 static char *complex_slots[] = { "real: ", "imag: ", NULL };
438 static char *code_slots[] = { "words: ", "entry: ", "debug: ", NULL };
439 static char *array_slots[] = { "fill-pointer: ",
445 /* Some reasonable number of dimensions */
456 static char *simple_array_slots[] = { "length: ",
460 #if (defined(i386) || defined(__x86_64))
461 static char *fn_slots[] =
462 { "inst start: ", "next: ", "name: ", "arglist: ", "type: ", NULL };
464 static char *fn_slots[] =
465 { "self: ", "next: ", "name: ", "arglist: ", "type: ", NULL };
468 static char *closure_slots[] = { "fn: ", NULL };
469 static char *funcallable_instance_slots[] =
470 { "fn: ", "lexenv: ", "layout: ", NULL };
471 static char *weak_pointer_slots[] = { "value: ", "broken: ",
477 static char *fdefn_slots[] = { "name: ", "function: ", "raw_addr: ", NULL };
478 static char *value_cell_slots[] = { "value: ", NULL };
480 #ifdef type_ScavengerHook
481 static char *scavenger_hook_slots[] =
483 { "value: ", "function: ", "next: ", NULL };
487 print_otherptr(lispobj obj)
489 if (!valid_addr((os_vm_address_t) obj))
490 printf("(invalid address)");
494 unsigned long header;
495 unsigned long length;
501 int count, type, index;
505 ptr = (unsigned long *) PTR(obj);
506 if (ptr == (unsigned long *) NULL) {
508 ptr = (u32 *) PTR(obj);
509 if (ptr == (u32 *) NULL) {
511 printf(" (NULL Pointer)");
516 length = fixnum_value(*ptr);
518 type = TypeOf(header);
520 print_obj("header: ", header);
521 if (LowtagOf(header) != type_OtherImmediate0
522 && LowtagOf(header) != type_OtherImmediate1) {
524 printf("(invalid header object)");
534 printf("%08lx", *--ptr);
538 print_slots(ratio_slots, count, ptr);
542 print_slots(complex_slots, count, ptr);
545 case type_SymbolHeader:
546 print_slots(symbol_slots, count, ptr);
549 case type_SingleFloat:
551 printf("%g", ((struct single_float *) PTR(obj))->value);
554 case type_DoubleFloat:
556 printf("%.15lg", ((struct double_float *) PTR(obj))->value);
559 #ifdef type_LongFloat
562 printf("%Lg", ((struct long_float *) PTR(obj))->value);
566 #ifdef type_DoubleDoubleFloat
567 case type_DoubleDoubleFloat:
569 printf("%.15lg %.15lg", ((struct double_double_float *) PTR(obj))->hi,
570 ((struct double_double_float *) PTR(obj))->lo);
574 #ifdef type_ComplexSingleFloat
575 case type_ComplexSingleFloat:
577 printf("%g", ((struct complex_single_float *) PTR(obj))->real);
579 printf("%g", ((struct complex_single_float *) PTR(obj))->imag);
583 #ifdef type_ComplexDoubleFloat
584 case type_ComplexDoubleFloat:
586 printf("%.15lg", ((struct complex_double_float *) PTR(obj))->real);
588 printf("%.15lg", ((struct complex_double_float *) PTR(obj))->imag);
592 #ifdef type_ComplexLongFloat
593 case type_ComplexLongFloat:
595 printf("%Lg", ((struct complex_long_float *) PTR(obj))->real);
597 printf("%Lg", ((struct complex_long_float *) PTR(obj))->imag);
601 #ifdef type_ComplexDoubleDoubleFloat
602 case type_ComplexDoubleDoubleFloat:
604 printf("%.15lg %.15lg", ((struct complex_double_double_float *) PTR(obj))->real_hi,
605 ((struct complex_double_double_float *) PTR(obj))->real_lo);
607 printf("%.15lg %.15lg", ((struct complex_double_double_float *) PTR(obj))->imag_hi,
608 ((struct complex_double_double_float *) PTR(obj))->imag_lo);
613 case type_SimpleString:
616 /* Need to back up one to get the start of the vector */
617 print_string((struct vector*) (ptr - 1));
621 case type_SimpleVector:
623 printf("length = %ld", length);
626 while (length-- > 0) {
627 sprintf(buffer, "%d: ", index++);
628 print_obj(buffer, *ptr++);
632 case type_InstanceHeader:
634 printf("length = %d", count);
636 while (count-- > 0) {
637 sprintf(buffer, "%d: ", index++);
638 print_obj(buffer, *ptr++);
642 case type_SimpleArray:
643 case type_SimpleBitVector:
644 case type_SimpleArrayUnsignedByte2:
645 case type_SimpleArrayUnsignedByte4:
646 case type_SimpleArrayUnsignedByte8:
647 case type_SimpleArrayUnsignedByte16:
648 case type_SimpleArrayUnsignedByte32:
649 #ifdef type_SimpleArraySignedByte8
650 case type_SimpleArraySignedByte8:
652 #ifdef type_SimpleArraySignedByte16
653 case type_SimpleArraySignedByte16:
655 #ifdef type_SimpleArraySignedByte30
656 case type_SimpleArraySignedByte30:
658 #ifdef type_SimpleArraySignedByte32
659 case type_SimpleArraySignedByte32:
661 case type_SimpleArraySingleFloat:
662 case type_SimpleArrayDoubleFloat:
663 #ifdef type_SimpleArrayLongFloat
664 case type_SimpleArrayLongFloat:
666 #ifdef type_SimpleArrayDoubleDoubleFloat
667 case type_SimpleArrayDoubleDoubleFloat:
669 #ifdef type_SimpleArrayComplexSingleFloat
670 case type_SimpleArrayComplexSingleFloat:
672 #ifdef type_SimpleArrayComplexDoubleFloat
673 case type_SimpleArrayComplexDoubleFloat:
675 #ifdef type_SimpleArrayComplexLongFloat
676 case type_SimpleArrayComplexLongFloat:
678 #ifdef type_SimpleArrayComplexDoubleDoubleFloat
679 case type_SimpleArrayComplexDoubleDoubleFloat:
681 print_slots(simple_array_slots, 1, ptr);
683 case type_ComplexString:
684 case type_ComplexBitVector:
685 case type_ComplexVector:
686 case type_ComplexArray:
687 print_slots(array_slots, count, ptr);
690 case type_CodeHeader:
691 print_slots(code_slots, count - 1, ptr);
694 case type_FunctionHeader:
695 case type_ClosureFunctionHeader:
696 print_slots(fn_slots, 5, ptr);
699 case type_ReturnPcHeader:
700 print_obj("code: ", obj - (count * 4));
703 case type_ClosureHeader:
704 print_slots(closure_slots, count, ptr);
707 case type_FuncallableInstanceHeader:
708 print_slots(funcallable_instance_slots, count, ptr);
711 case type_ValueCellHeader:
712 print_slots(value_cell_slots, 1, ptr);
718 printf("0x%08lx", *ptr);
720 printf("0x%016lx", *(long *) (ptr + 1));
724 case type_WeakPointer:
725 print_slots(weak_pointer_slots, 3, ptr);
729 case type_UnboundMarker:
731 printf("pointer to an immediate?");
735 print_slots(fdefn_slots, count, ptr);
738 #ifdef type_ScavengerHook
739 case type_ScavengerHook:
740 print_slots(scavenger_hook_slots, count, ptr);
746 printf("Unknown header object?");
753 print_obj(char *prefix, lispobj obj)
755 static void (*verbose_fns[]) (lispobj obj)
756 = { print_fixnum, print_otherptr, print_otherimm, print_list,
757 print_fixnum, print_struct, print_otherimm, print_otherptr
759 static void (*brief_fns[]) (lispobj obj)
760 = { brief_fixnum, brief_otherptr, brief_otherimm, brief_list,
761 brief_fixnum, brief_struct, brief_otherimm, brief_otherptr
763 int type = LowtagOf(obj);
764 struct var *var = lookup_by_obj(obj);
766 boolean verbose = cur_depth < brief_depth;
769 if (!continue_p(verbose))
772 if (var != NULL && var_clock(var) == cur_clock)
776 && (obj & type_FunctionPointer & type_ListPointer & type_InstancePointer
777 & type_OtherPointer) != 0)
778 var = define_var(NULL, obj, FALSE);
781 var_setclock(var, cur_clock);
786 sprintf(buffer, "$%s=", var_name(var));
790 printf("%s0x%08lx: ", prefix, obj);
791 if (cur_depth < brief_depth) {
792 fputs(lowtag_Names[type], stdout);
793 (*verbose_fns[type]) (obj);
795 (*brief_fns[type]) (obj);
798 printf("$%s", var_name(var));
801 printf("$%s=", var_name(var));
802 (*brief_fns[type]) (obj);
831 brief_print(lispobj obj)