0.pre7.56:
[sbcl.git] / src / runtime / print.c
index 3eb97e1..1097d71 100644 (file)
@@ -1,4 +1,4 @@
-/* code for low-level debugging output */
+/* code for low-level debugging/diagnostic output */
 
 /*
  * This software is part of the SBCL system. See the README file for
  */
 
 /*
- * $Header$
- */
-
-/*
  * FIXME:
- *   1. Ordinary users won't get much out of this code, so it shouldn't
- *      be compiled into the ordinary build of the system. Probably it
- *      should be made conditional on the SB-SHOW target feature.
- *   2. Some of the code in here (subtype_Names[] and the various
- *      foo_slots[], at least) is deeply broken, depending on fixed
- *      (and already out-of-date) values in sbcl.h.
+ *   Some of the code in here (subtype_Names[] and the various
+ *   foo_slots[], at least) is deeply broken, depending on fixed
+ *   (and already out-of-date) values in sbcl.h.
  */
 
 #include <stdio.h>
 
 #include "print.h"
 #include "runtime.h"
+
+/* This file can be skipped if we're not supporting LDB. */
+#if defined(LISP_FEATURE_SB_LDB)
+
 #include "sbcl.h"
 #include "monitor.h"
 #include "vars.h"
@@ -38,11 +35,11 @@ static int max_lines = 20, cur_lines = 0;
 static int max_depth = 5, brief_depth = 2, cur_depth = 0;
 static int max_length = 5;
 static boolean dont_descend = 0, skip_newline = 0;
-static cur_clock = 0;
+static int cur_clock = 0;
 
 static void print_obj(char *prefix, lispobj obj);
 
-#define NEWLINE if (continue_p(1)) newline(NULL); else return;
+#define NEWLINE_OR_RETURN if (continue_p(1)) newline(NULL); else return;
 
 char *lowtag_Names[] = {
     "even fixnum",
@@ -281,7 +278,7 @@ static void print_otherimm(lispobj obj)
             break;
 
         default:
-            printf(": data=%ld", (obj>>8)&0xffffff);
+            printf(": data=%ld", (long) (obj>>8)&0xffffff);
             break;
     }
 }
@@ -297,8 +294,8 @@ static void brief_list(lispobj obj)
         printf("NIL");
     else {
         putchar('(');
-        while (LowtagOf(obj) == type_ListPointer) {
-            struct cons *cons = (struct cons *)PTR(obj);
+        while (lowtagof(obj) == LIST_POINTER_LOWTAG) {
+            struct cons *cons = (struct cons *)native_pointer(obj);
 
             if (space)
                 putchar(' ');
@@ -328,7 +325,7 @@ static void print_list(lispobj obj)
     } else if (obj == NIL) {
         printf(" (NIL)");
     } else {
-        struct cons *cons = (struct cons *)PTR(obj);
+        struct cons *cons = (struct cons *)native_pointer(obj);
 
         print_obj("car: ", cons->car);
         print_obj("cdr: ", cons->cdr);
@@ -338,15 +335,15 @@ static void print_list(lispobj obj)
 static void brief_struct(lispobj obj)
 {
     printf("#<ptr to 0x%08lx instance>",
-           ((struct instance *)PTR(obj))->slots[0]);
+           (unsigned long) ((struct instance *)native_pointer(obj))->slots[0]);
 }
 
 static void print_struct(lispobj obj)
 {
-    struct instance *instance = (struct instance *)PTR(obj);
+    struct instance *instance = (struct instance *)native_pointer(obj);
     int i;
     char buffer[16];
-    print_obj("type: ", ((struct instance *)PTR(obj))->slots[0]);
+    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]);
@@ -361,7 +358,7 @@ static void brief_otherptr(lispobj obj)
     struct vector *vector;
     char *charptr;
 
-    ptr = (lispobj *) PTR(obj);
+    ptr = (lispobj *) native_pointer(obj);
 
     if (!is_valid_lisp_addr((os_vm_address_t)obj)) {
            printf("(invalid address)");
@@ -373,7 +370,7 @@ static void brief_otherptr(lispobj obj)
     switch (type) {
         case type_SymbolHeader:
             symbol = (struct symbol *)ptr;
-            vector = (struct vector *)PTR(symbol->name);
+            vector = (struct vector *)native_pointer(symbol->name);
             for (charptr = (char *)vector->data; *charptr != '\0'; charptr++) {
                 if (*charptr == '"')
                     putchar('\\');
@@ -441,7 +438,7 @@ static void print_otherptr(lispobj obj)
         int count, type, index;
         char *cptr, buffer[16];
 
-       ptr = (lispobj*) PTR(obj);
+       ptr = (lispobj*) native_pointer(obj);
        if (ptr == NULL) {
                printf(" (NULL Pointer)");
                return;
@@ -453,8 +450,9 @@ static void print_otherptr(lispobj obj)
        type = TypeOf(header);
 
         print_obj("header: ", header);
-        if (LowtagOf(header) != type_OtherImmediate0 && LowtagOf(header) != type_OtherImmediate1) {
-            NEWLINE;
+        if (lowtagof(header) != OTHER_IMMEDIATE_0_LOWTAG &&
+           lowtagof(header) != OTHER_IMMEDIATE_1_LOWTAG) {
+            NEWLINE_OR_RETURN;
             printf("(invalid header object)");
             return;
         }
@@ -462,10 +460,10 @@ static void print_otherptr(lispobj obj)
         switch (type) {
             case type_Bignum:
                 ptr += count;
-                NEWLINE;
+                NEWLINE_OR_RETURN;
                 printf("0x");
                 while (count-- > 0)
-                    printf("%08lx", *--ptr);
+                    printf("%08lx", (unsigned long) *--ptr);
                 break;
 
             case type_Ratio:
@@ -481,51 +479,51 @@ static void print_otherptr(lispobj obj)
                 break;
 
             case type_SingleFloat:
-                NEWLINE;
-                printf("%g", ((struct single_float *)PTR(obj))->value);
+                NEWLINE_OR_RETURN;
+                printf("%g", ((struct single_float *)native_pointer(obj))->value);
                 break;
 
             case type_DoubleFloat:
-                NEWLINE;
-                printf("%g", ((struct double_float *)PTR(obj))->value);
+                NEWLINE_OR_RETURN;
+                printf("%g", ((struct double_float *)native_pointer(obj))->value);
                 break;
 
 #ifdef type_LongFloat
             case type_LongFloat:
-                NEWLINE;
-                printf("%Lg", ((struct long_float *)PTR(obj))->value);
+                NEWLINE_OR_RETURN;
+                printf("%Lg", ((struct long_float *)native_pointer(obj))->value);
                 break;
 #endif
 
 #ifdef type_ComplexSingleFloat
             case type_ComplexSingleFloat:
-                NEWLINE;
-                printf("%g", ((struct complex_single_float *)PTR(obj))->real);
-                NEWLINE;
-                printf("%g", ((struct complex_single_float *)PTR(obj))->imag);
+                NEWLINE_OR_RETURN;
+                printf("%g", ((struct complex_single_float *)native_pointer(obj))->real);
+                NEWLINE_OR_RETURN;
+                printf("%g", ((struct complex_single_float *)native_pointer(obj))->imag);
                 break;
 #endif
 
 #ifdef type_ComplexDoubleFloat
             case type_ComplexDoubleFloat:
-                NEWLINE;
-                printf("%g", ((struct complex_double_float *)PTR(obj))->real);
-                NEWLINE;
-                printf("%g", ((struct complex_double_float *)PTR(obj))->imag);
+                NEWLINE_OR_RETURN;
+                printf("%g", ((struct complex_double_float *)native_pointer(obj))->real);
+                NEWLINE_OR_RETURN;
+                printf("%g", ((struct complex_double_float *)native_pointer(obj))->imag);
                 break;
 #endif
 
 #ifdef type_ComplexLongFloat
             case type_ComplexLongFloat:
-                NEWLINE;
-                printf("%Lg", ((struct complex_long_float *)PTR(obj))->real);
-                NEWLINE;
-                printf("%Lg", ((struct complex_long_float *)PTR(obj))->imag);
+                NEWLINE_OR_RETURN;
+                printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->real);
+                NEWLINE_OR_RETURN;
+                printf("%Lg", ((struct complex_long_float *)native_pointer(obj))->imag);
                 break;
 #endif
 
             case type_SimpleString:
-                NEWLINE;
+                NEWLINE_OR_RETURN;
                 cptr = (char *)(ptr+1);
                 putchar('"');
                 while (length-- > 0)
@@ -534,8 +532,7 @@ static void print_otherptr(lispobj obj)
                 break;
 
             case type_SimpleVector:
-            case type_InstanceHeader:
-                NEWLINE;
+                NEWLINE_OR_RETURN;
                 printf("length = %ld", length);
                 ptr++;
                 index = 0;
@@ -545,6 +542,16 @@ static void print_otherptr(lispobj obj)
                 }
                 break;
 
+            case type_InstanceHeader:
+                NEWLINE_OR_RETURN;
+                printf("length = %ld", (long) count);
+                index = 0;
+                while (count-- > 0) {
+                    sprintf(buffer, "%d: ", index++);
+                    print_obj(buffer, *ptr++);
+                }
+                break;
+
             case type_SimpleArray:
             case type_SimpleBitVector:
             case type_SimpleArrayUnsignedByte2:
@@ -588,8 +595,8 @@ static void print_otherptr(lispobj obj)
                 print_slots(code_slots, count-1, ptr);
                 break;
 
-            case type_FunctionHeader:
-            case type_ClosureFunctionHeader:
+            case type_SimpleFunHeader:
+            case type_ClosureFunHeader:
                 print_slots(fn_slots, 5, ptr);
                 break;
 
@@ -610,11 +617,11 @@ static void print_otherptr(lispobj obj)
                 break;
 
             case type_Sap:
-                NEWLINE;
+                NEWLINE_OR_RETURN;
 #ifndef alpha
-                printf("0x%08lx", *ptr);
+                printf("0x%08lx", (unsigned long) *ptr);
 #else
-                printf("0x%016lx", *(long*)(ptr+1));
+                printf("0x%016lx", *(lispobj*)(ptr+1));
 #endif
                 break;
 
@@ -624,7 +631,7 @@ static void print_otherptr(lispobj obj)
 
             case type_BaseChar:
             case type_UnboundMarker:
-                NEWLINE;
+                NEWLINE_OR_RETURN;
                 printf("pointer to an immediate?");
                 break;
 
@@ -633,7 +640,7 @@ static void print_otherptr(lispobj obj)
                break;
                
             default:
-                NEWLINE;
+                NEWLINE_OR_RETURN;
                 printf("Unknown header object?");
                 break;
         }
@@ -648,19 +655,20 @@ static void print_obj(char *prefix, lispobj obj)
     static void (*brief_fns[])(lispobj obj)
        = {brief_fixnum, brief_otherptr, brief_otherimm, brief_list,
           brief_fixnum, brief_struct, brief_otherimm, brief_otherptr};
-    int type = LowtagOf(obj);
+    int type = lowtagof(obj);
     struct var *var = lookup_by_obj(obj);
     char buffer[256];
     boolean verbose = cur_depth < brief_depth;
 
-
     if (!continue_p(verbose))
         return;
 
     if (var != NULL && var_clock(var) == cur_clock)
         dont_descend = 1;
 
-    if (var == NULL && (obj & type_FunctionPointer & type_ListPointer & type_InstancePointer & type_OtherPointer) != 0)
+    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)
         var = define_var(NULL, obj, 0);
 
     if (var != NULL)
@@ -674,7 +682,7 @@ static void print_obj(char *prefix, lispobj obj)
         }
         else
             newline(NULL);
-        printf("%s0x%08lx: ", prefix, obj);
+        printf("%s0x%08lx: ", prefix, (unsigned long) obj);
         if (cur_depth < brief_depth) {
             fputs(lowtag_Names[type], stdout);
             (*verbose_fns[type])(obj);
@@ -724,3 +732,13 @@ void brief_print(lispobj obj)
     print_obj("", obj);
     putchar('\n');
 }
+
+#else
+
+void
+brief_print(lispobj obj)
+{
+    printf("lispobj 0x%lx\n", (unsigned long)obj);
+}
+     
+#endif /* defined(LISP_FEATURE_SB_LDB) */