X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fprint.c;h=61d5a73995514b2efd9534130ea888b89445f645;hb=b30f21a9cf8366ec88022e84c698f1d8d45e885e;hp=bdfbfdafc28f9ec606d61c58a7eed18b50d16b76;hpb=902e93736a0888aa6b04dc328b1eb328423bf426;p=sbcl.git diff --git a/src/runtime/print.c b/src/runtime/print.c index bdfbfda..61d5a73 100644 --- a/src/runtime/print.c +++ b/src/runtime/print.c @@ -19,10 +19,11 @@ */ #include +#include +#include "sbcl.h" #include "print.h" #include "runtime.h" -#include "sbcl.h" /* This file can be skipped if we're not supporting LDB. */ #if defined(LISP_FEATURE_SB_LDB) @@ -33,10 +34,8 @@ #include "gencgc-alloc-region.h" /* genesis/thread.h needs this */ #include "genesis/static-symbols.h" #include "genesis/primitive-objects.h" - #include "genesis/static-symbols.h" - - +#include "genesis/tagnames.h" static int max_lines = 20, cur_lines = 0; static int max_depth = 5, brief_depth = 2, cur_depth = 0; @@ -48,100 +47,6 @@ static void print_obj(char *prefix, lispobj obj); #define NEWLINE_OR_RETURN if (continue_p(1)) newline(NULL); else return; -char *lowtag_Names[] = { - "even fixnum", - "instance pointer", - "other immediate [0]", - "list pointer", - "odd fixnum", - "function pointer", - "other immediate [1]", - "other pointer" -}; - -/* FIXME: Yikes! This table implicitly depends on the values in sbcl.h, - * but doesn't actually depend on them, so if they change, it gets - * all broken. We should either get rid of it or - * rewrite the code so that it's cleanly initialized by gc_init_tables[] - * in a way which varies correctly with the values in sbcl.h. */ -char *subtype_Names[] = { - "unused 0", - "unused 1", - "bignum", - "ratio", - "single float", - "double float", -#ifdef LONG_FLOAT_WIDETAG - "long float", -#endif - "complex", -#ifdef COMPLEX_SINGLE_FLOAT_WIDETAG - "complex single float", -#endif -#ifdef COMPLEX_DOUBLE_FLOAT_WIDETAG - "complex double float", -#endif -#ifdef COMPLEX_LONG_FLOAT_WIDETAG - "complex long float", -#endif - "simple-array", - "simple-string", - "simple-bit-vector", - "simple-vector", - "(simple-array (unsigned-byte 2) (*))", - "(simple-array (unsigned-byte 4) (*))", - "(simple-array (unsigned-byte 8) (*))", - "(simple-array (unsigned-byte 16) (*))", - "(simple-array (unsigned-byte 32) (*))", -#ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG - "(simple-array (signed-byte 8) (*))", -#endif -#ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG - "(simple-array (signed-byte 16) (*))", -#endif -#ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG - "(simple-array fixnum (*))", -#endif -#ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG - "(simple-array (signed-byte 32) (*))", -#endif - "(simple-array single-float (*))", - "(simple-array double-float (*))", -#ifdef SIMPLE_ARRAY_LONG_FLOAT_WIDETAG - "(simple-array long-float (*))", -#endif -#ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG - "(simple-array (complex single-float) (*))", -#endif -#ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG - "(simple-array (complex double-float) (*))", -#endif -#ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG - "(simple-array (complex long-float) (*))", -#endif - "complex-string", - "complex-bit-vector", - "(array * (*))", - "array", - "code header", - "function header", - "closure header", - "funcallable-instance header", - "unused function header 1", - "unused function header 2", - "unused function header 3", - "closure function header", - "return PC header", - "value cell header", - "symbol header", - "character", - "SAP", - "unbound marker", - "weak pointer", - "instance header", - "fdefn" -}; - static void indent(int in) { static char *spaces = " "; @@ -171,12 +76,15 @@ static boolean continue_p(boolean newline) printf("More? [y] "); fflush(stdout); - fgets(buffer, sizeof(buffer), stdin); - - if (buffer[0] == 'n' || buffer[0] == 'N') - throw_to_monitor(); - else + if (fgets(buffer, sizeof(buffer), stdin)) { + if (buffer[0] == 'n' || buffer[0] == 'N') + throw_to_monitor(); + else + cur_lines = 0; + } else { + printf("\nUnable to read response, assuming y.\n"); cur_lines = 0; + } } } @@ -193,9 +101,19 @@ static void newline(char *label) } +static void print_unknown(lispobj obj) +{ + printf("unknown object: %p", (void *)obj); +} + static void brief_fixnum(lispobj obj) { -#ifndef alpha + /* KLUDGE: Rather than update the tables in print_obj(), we + declare all fixnum-or-unknown tags to be fixnums and sort it + out here with a guard clause. */ + if (!fixnump(obj)) return print_unknown(obj); + +#ifndef LISP_FEATURE_ALPHA printf("%ld", ((long)obj)>>2); #else printf("%d", ((s32)obj)>>2); @@ -204,7 +122,12 @@ static void brief_fixnum(lispobj obj) static void print_fixnum(lispobj obj) { -#ifndef alpha + /* KLUDGE: Rather than update the tables in print_obj(), we + declare all fixnum-or-unknown tags to be fixnums and sort it + out here with a guard clause. */ + if (!fixnump(obj)) return print_unknown(obj); + +#ifndef LISP_FEATURE_ALPHA printf(": %ld", ((long)obj)>>2); #else printf(": %d", ((s32)obj)>>2); @@ -213,12 +136,12 @@ static void print_fixnum(lispobj obj) static void brief_otherimm(lispobj obj) { - int type, c, idx; + int type, c; char buffer[10]; type = widetag_of(obj); switch (type) { - case BASE_CHAR_WIDETAG: + case CHARACTER_WIDETAG: c = (obj>>8)&0xff; switch (c) { case '\0': @@ -253,29 +176,17 @@ static void brief_otherimm(lispobj obj) break; default: - idx = type >> 2; - if (idx < (sizeof(lowtag_Names) / sizeof(char *))) - printf("%s", lowtag_Names[idx]); - else - printf("unknown type (0x%0x)", type); + printf("%s", widetag_names[type >> 2]); break; } } static void print_otherimm(lispobj obj) { - int type, idx; - - type = widetag_of(obj); - idx = type >> 2; - - if (idx < (sizeof(lowtag_Names) / sizeof(char *))) - printf(", %s", lowtag_Names[idx]); - else - printf(", unknown type (0x%0x)", type); + printf(", %s", widetag_names[widetag_of(obj) >> 2]); switch (widetag_of(obj)) { - case BASE_CHAR_WIDETAG: + case CHARACTER_WIDETAG: printf(": "); brief_otherimm(obj); break; @@ -296,7 +207,7 @@ static void brief_list(lispobj obj) int length = 0; if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj))) - printf("(invalid Lisp-level address)"); + printf("(invalid Lisp-level address)"); else if (obj == NIL) printf("NIL"); else { @@ -311,7 +222,7 @@ static void brief_list(lispobj obj) obj = NIL; break; } - print_obj(NULL, cons->car); + print_obj("", cons->car); obj = cons->cdr; space = 1; if (obj == NIL) @@ -319,7 +230,7 @@ static void brief_list(lispobj obj) } if (obj != NIL) { printf(" . "); - print_obj(NULL, obj); + print_obj("", obj); } putchar(')'); } @@ -328,7 +239,7 @@ static void brief_list(lispobj obj) static void print_list(lispobj obj) { if (!is_valid_lisp_addr((os_vm_address_t)native_pointer(obj))) { - printf("(invalid address)"); + printf("(invalid address)"); } else if (obj == NIL) { printf(" (NIL)"); } else { @@ -341,19 +252,28 @@ static void print_list(lispobj obj) static void brief_struct(lispobj obj) { - printf("#", - (unsigned long) ((struct instance *)native_pointer(obj))->slots[0]); + struct instance *instance = (struct instance *)native_pointer(obj); + if (!is_valid_lisp_addr((os_vm_address_t)instance)) { + printf("(invalid address)"); + } else { + printf("#", + (unsigned long) instance->slots[0]); + } } static void print_struct(lispobj obj) { struct instance *instance = (struct instance *)native_pointer(obj); - int i; + unsigned int i; char buffer[16]; - print_obj("type: ", ((struct instance *)native_pointer(obj))->slots[0]); - for (i = 1; i < HeaderValue(instance->header); i++) { - sprintf(buffer, "slot %d: ", i); - print_obj(buffer, instance->slots[i]); + if (!is_valid_lisp_addr((os_vm_address_t)instance)) { + printf("(invalid address)"); + } else { + print_obj("type: ", ((struct instance *)native_pointer(obj))->slots[0]); + for (i = 1; i < HeaderValue(instance->header); i++) { + sprintf(buffer, "slot %d: ", i); + print_obj(buffer, instance->slots[i]); + } } } @@ -368,8 +288,8 @@ static void brief_otherptr(lispobj obj) ptr = (lispobj *) native_pointer(obj); if (!is_valid_lisp_addr((os_vm_address_t)obj)) { - printf("(invalid address)"); - return; + printf("(invalid address)"); + return; } header = *ptr; @@ -410,18 +330,18 @@ static void print_slots(char **slots, int count, lispobj *ptr) print_obj(*slots++, *ptr++); } else { print_obj("???: ", *ptr++); - } + } } } -/* FIXME: Yikes again! This, like subtype_Names[], needs to depend - * on the values in sbcl.h (or perhaps be generated automatically - * by GENESIS as part of sbcl.h). */ -static char *symbol_slots[] = {"value: ", "unused: ", +/* FIXME: Yikes! This needs to depend on the values in sbcl.h (or + * perhaps be generated automatically by GENESIS as part of + * sbcl.h). */ +static char *symbol_slots[] = {"value: ", "hash: ", "plist: ", "name: ", "package: ", #ifdef LISP_FEATURE_SB_THREAD "tls-index: " , -#endif +#endif NULL}; static char *ratio_slots[] = {"numer: ", "denom: ", NULL}; static char *complex_slots[] = {"real: ", "imag: ", NULL}; @@ -437,9 +357,9 @@ static char *value_cell_slots[] = {"value: ", NULL}; static void print_otherptr(lispobj obj) { if (!is_valid_lisp_addr((os_vm_address_t)obj)) { - printf("(invalid address)"); + printf("(invalid address)"); } else { -#ifndef alpha +#ifndef LISP_FEATURE_ALPHA lispobj *ptr; unsigned long header; unsigned long length; @@ -451,20 +371,19 @@ static void print_otherptr(lispobj obj) int count, type, index; char *cptr, buffer[16]; - ptr = (lispobj*) native_pointer(obj); - if (ptr == NULL) { - printf(" (NULL Pointer)"); - return; - } + ptr = (lispobj*) native_pointer(obj); + if (ptr == NULL) { + printf(" (NULL Pointer)"); + return; + } - header = *ptr++; - length = (*ptr) >> 2; - count = header>>8; - type = widetag_of(header); + header = *ptr++; + length = fixnum_value(*ptr); + count = HeaderValue(header); + type = widetag_of(header); print_obj("header: ", header); - if (lowtag_of(header) != OTHER_IMMEDIATE_0_LOWTAG && - lowtag_of(header) != OTHER_IMMEDIATE_1_LOWTAG) { + if (!other_immediate_lowtag_p(header)) { NEWLINE_OR_RETURN; printf("(invalid header object)"); return; @@ -491,11 +410,12 @@ static void print_otherptr(lispobj obj) print_slots(symbol_slots, count, ptr); break; +#if N_WORD_BITS == 32 case SINGLE_FLOAT_WIDETAG: NEWLINE_OR_RETURN; printf("%g", ((struct single_float *)native_pointer(obj))->value); break; - +#endif case DOUBLE_FLOAT_WIDETAG: NEWLINE_OR_RETURN; printf("%g", ((struct double_float *)native_pointer(obj))->value); @@ -511,9 +431,17 @@ static void print_otherptr(lispobj obj) #ifdef COMPLEX_SINGLE_FLOAT_WIDETAG case COMPLEX_SINGLE_FLOAT_WIDETAG: NEWLINE_OR_RETURN; +#ifdef LISP_FEATURE_X86_64 + printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[0]); +#else printf("%g", ((struct complex_single_float *)native_pointer(obj))->real); +#endif NEWLINE_OR_RETURN; +#ifdef LISP_FEATURE_X86_64 + printf("%g", ((struct complex_single_float *)native_pointer(obj))->data.data[1]); +#else printf("%g", ((struct complex_single_float *)native_pointer(obj))->imag); +#endif break; #endif @@ -536,6 +464,9 @@ static void print_otherptr(lispobj obj) #endif case SIMPLE_BASE_STRING_WIDETAG: +#ifdef SIMPLE_CHARACTER_STRING_WIDETAG + case SIMPLE_CHARACTER_STRING_WIDETAG: /* FIXME */ +#endif NEWLINE_OR_RETURN; cptr = (char *)(ptr+1); putchar('"'); @@ -569,20 +500,35 @@ static void print_otherptr(lispobj obj) case SIMPLE_BIT_VECTOR_WIDETAG: case SIMPLE_ARRAY_UNSIGNED_BYTE_2_WIDETAG: case SIMPLE_ARRAY_UNSIGNED_BYTE_4_WIDETAG: + case SIMPLE_ARRAY_UNSIGNED_BYTE_7_WIDETAG: case SIMPLE_ARRAY_UNSIGNED_BYTE_8_WIDETAG: + case SIMPLE_ARRAY_UNSIGNED_BYTE_15_WIDETAG: case SIMPLE_ARRAY_UNSIGNED_BYTE_16_WIDETAG: + + case SIMPLE_ARRAY_UNSIGNED_FIXNUM_WIDETAG: + + case SIMPLE_ARRAY_UNSIGNED_BYTE_31_WIDETAG: case SIMPLE_ARRAY_UNSIGNED_BYTE_32_WIDETAG: +#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG + case SIMPLE_ARRAY_UNSIGNED_BYTE_63_WIDETAG: +#endif +#ifdef SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG + case SIMPLE_ARRAY_UNSIGNED_BYTE_64_WIDETAG: +#endif #ifdef SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG - case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG: + case SIMPLE_ARRAY_SIGNED_BYTE_8_WIDETAG: #endif #ifdef SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG - case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG: -#endif -#ifdef SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG - case SIMPLE_ARRAY_SIGNED_BYTE_30_WIDETAG: + case SIMPLE_ARRAY_SIGNED_BYTE_16_WIDETAG: #endif + + case SIMPLE_ARRAY_FIXNUM_WIDETAG: + #ifdef SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG - case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG: + case SIMPLE_ARRAY_SIGNED_BYTE_32_WIDETAG: +#endif +#ifdef SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG + case SIMPLE_ARRAY_SIGNED_BYTE_64_WIDETAG: #endif case SIMPLE_ARRAY_SINGLE_FLOAT_WIDETAG: case SIMPLE_ARRAY_DOUBLE_FLOAT_WIDETAG: @@ -590,15 +536,18 @@ static void print_otherptr(lispobj obj) case SIMPLE_ARRAY_LONG_FLOAT_WIDETAG: #endif #ifdef SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG - case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG: + case SIMPLE_ARRAY_COMPLEX_SINGLE_FLOAT_WIDETAG: #endif #ifdef SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG - case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG: + case SIMPLE_ARRAY_COMPLEX_DOUBLE_FLOAT_WIDETAG: #endif #ifdef SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG - case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG: + case SIMPLE_ARRAY_COMPLEX_LONG_FLOAT_WIDETAG: #endif case COMPLEX_BASE_STRING_WIDETAG: +#ifdef COMPLEX_CHARACTER_STRING_WIDETAG + case COMPLEX_CHARACTER_STRING_WIDETAG: +#endif case COMPLEX_VECTOR_NIL_WIDETAG: case COMPLEX_BIT_VECTOR_WIDETAG: case COMPLEX_VECTOR_WIDETAG: @@ -610,7 +559,6 @@ static void print_otherptr(lispobj obj) break; case SIMPLE_FUN_HEADER_WIDETAG: - case CLOSURE_FUN_HEADER_WIDETAG: print_slots(fn_slots, 5, ptr); break; @@ -627,12 +575,12 @@ static void print_otherptr(lispobj obj) break; case VALUE_CELL_HEADER_WIDETAG: - print_slots(value_cell_slots, 1, ptr); + print_slots(value_cell_slots, 1, ptr); break; case SAP_WIDETAG: NEWLINE_OR_RETURN; -#ifndef alpha +#ifndef LISP_FEATURE_ALPHA printf("0x%08lx", (unsigned long) *ptr); #else printf("0x%016lx", *(lispobj*)(ptr+1)); @@ -640,19 +588,19 @@ static void print_otherptr(lispobj obj) break; case WEAK_POINTER_WIDETAG: - print_slots(weak_pointer_slots, 1, ptr); + print_slots(weak_pointer_slots, 1, ptr); break; - case BASE_CHAR_WIDETAG: + case CHARACTER_WIDETAG: case UNBOUND_MARKER_WIDETAG: NEWLINE_OR_RETURN; printf("pointer to an immediate?"); break; - case FDEFN_WIDETAG: - print_slots(fdefn_slots, count, ptr); - break; - + case FDEFN_WIDETAG: + print_slots(fdefn_slots, count, ptr); + break; + default: NEWLINE_OR_RETURN; printf("Unknown header object?"); @@ -663,12 +611,25 @@ static void print_otherptr(lispobj obj) static void print_obj(char *prefix, lispobj obj) { +#ifdef LISP_FEATURE_X86_64 + static void (*verbose_fns[])(lispobj obj) + = {print_fixnum, print_otherimm, print_fixnum, print_struct, + print_fixnum, print_otherimm, print_fixnum, print_list, + print_fixnum, print_otherimm, print_fixnum, print_otherptr, + print_fixnum, print_otherimm, print_fixnum, print_otherptr}; + static void (*brief_fns[])(lispobj obj) + = {brief_fixnum, brief_otherimm, brief_fixnum, brief_struct, + brief_fixnum, brief_otherimm, brief_fixnum, brief_list, + brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr, + brief_fixnum, brief_otherimm, brief_fixnum, brief_otherptr}; +#else static void (*verbose_fns[])(lispobj obj) - = {print_fixnum, print_struct, print_otherimm, print_list, - print_fixnum, print_otherptr, print_otherimm, print_otherptr}; + = {print_fixnum, print_struct, print_otherimm, print_list, + print_fixnum, print_otherptr, print_otherimm, print_otherptr}; static void (*brief_fns[])(lispobj obj) - = {brief_fixnum, brief_struct, brief_otherimm, brief_list, - brief_fixnum, brief_otherptr, brief_otherimm, brief_otherptr}; + = {brief_fixnum, brief_struct, brief_otherimm, brief_list, + brief_fixnum, brief_otherptr, brief_otherimm, brief_otherptr}; +#endif int type = lowtag_of(obj); struct var *var = lookup_by_obj(obj); char buffer[256]; @@ -680,9 +641,7 @@ static void print_obj(char *prefix, lispobj obj) if (var != NULL && var_clock(var) == cur_clock) dont_descend = 1; - if (var == NULL && - /* FIXME: What does this "x & y & z & .." expression mean? */ - (obj & FUN_POINTER_LOWTAG & LIST_POINTER_LOWTAG & INSTANCE_POINTER_LOWTAG & OTHER_POINTER_LOWTAG) != 0) + if (var == NULL && is_lisp_pointer(obj)) var = define_var(NULL, obj, 0); if (var != NULL) @@ -698,7 +657,7 @@ static void print_obj(char *prefix, lispobj obj) newline(NULL); printf("%s0x%08lx: ", prefix, (unsigned long) obj); if (cur_depth < brief_depth) { - fputs(lowtag_Names[type], stdout); + fputs(lowtag_names[type], stdout); (*verbose_fns[type])(obj); } else @@ -754,5 +713,5 @@ brief_print(lispobj obj) { printf("lispobj 0x%lx\n", (unsigned long)obj); } - + #endif /* defined(LISP_FEATURE_SB_LDB) */