[project @ 1999-10-08 14:16:15 by simonmar]
[ghc-hetmet.git] / ghc / rts / Printer.c
index 7d2fe71..8be29aa 100644 (file)
@@ -1,14 +1,15 @@
-/* -*- mode: hugs-c; -*- */
+
 /* -----------------------------------------------------------------------------
- * $Id: Printer.c,v 1.5 1999/02/05 14:44:43 simonm Exp $
+ * $Id: Printer.c,v 1.15 1999/07/14 13:44:19 simonmar Exp $
  *
- * Copyright (c) 1994-1998.
+ * Copyright (c) 1994-1999.
  *
  * Heap printer
  * 
  * ---------------------------------------------------------------------------*/
 
 #include "Rts.h"
+#include "Printer.h"
 
 #ifdef DEBUG
 
@@ -17,8 +18,6 @@
 #include "Bytecodes.h"  /* for InstrPtr */
 #include "Disassembler.h"
 
-#include "Printer.h"
-
 /* --------------------------------------------------------------------------
  * local function decls
  * ------------------------------------------------------------------------*/
@@ -39,14 +38,32 @@ static void    printZcoded   ( const char *raw );
  * Printer
  * ------------------------------------------------------------------------*/
 
-extern void printPtr( StgPtr p )
+
+#ifdef INTERPRETER
+extern void* itblNames[];
+extern int   nItblNames;
+char* lookupHugsItblName ( void* v )
 {
+   int i;
+   for (i = 0; i < nItblNames; i += 2)
+      if (itblNames[i] == v) return itblNames[i+1];
+   return NULL;
+}
+#endif
+
+void printPtr( StgPtr p )
+{
+#ifdef INTERPRETER
+    char* str;
+#endif
     const char *raw;
     if (lookupGHCName( p, &raw )) {
         printZcoded(raw);
 #ifdef INTERPRETER
     } else if ((raw = lookupHugsName(p)) != 0) {
         fprintf(stderr, "%s", raw);
+    } else if ((str = lookupHugsItblName(p)) != 0) {
+        fprintf(stderr, "%p=%s", p, str);
 #endif
     } else {
         fprintf(stderr, "%p", p);
@@ -163,6 +180,14 @@ void printClosure( StgClosure *obj )
             fprintf(stderr,")\n"); 
             break;
 
+    case SE_BLACKHOLE:
+            fprintf(stderr,"SE_BH\n"); 
+            break;
+
+    case SE_CAF_BLACKHOLE:
+            fprintf(stderr,"SE_CAF_BH\n"); 
+            break;
+
     case BLACKHOLE:
             fprintf(stderr,"BH\n"); 
             break;
@@ -273,7 +298,8 @@ void printClosure( StgClosure *obj )
             break;
         }
     default:
-            barf("printClosure %d",get_itbl(obj)->type);
+            //barf("printClosure %d",get_itbl(obj)->type);
+            fprintf(stderr, "*** printClosure: unknown type %d ****\n",get_itbl(obj)->type );
             return;
     }
 }
@@ -331,8 +357,26 @@ StgPtr printStackObj( StgPtr sp )
 #endif
 
     } else {
+        StgClosure* c = (StgClosure*)(*sp);
         printPtr((StgPtr)*sp);
-        fprintf(stderr,"\n");
+#ifdef INTERPRETER
+        if (c == &ret_bco_info) {
+           fprintf(stderr, "\t\t");
+           fprintf(stderr, "ret_bco_info\n" );
+       } else
+        if (IS_HUGS_CONSTR_INFO(GET_INFO(c))) {
+           fprintf(stderr, "\t\t\t");
+           fprintf(stderr, "ConstrInfoTable\n" );
+        } else
+#endif
+        if (get_itbl(c)->type == BCO) {
+           fprintf(stderr, "\t\t\t");
+           fprintf(stderr, "BCO(...)\n"); 
+        }
+        else {
+           fprintf(stderr, "\t\t\t");
+           printClosure ( (StgClosure*)(*sp));
+        }
         sp += 1;
     }
     return sp;
@@ -341,7 +385,7 @@ StgPtr printStackObj( StgPtr sp )
 
 void printStackChunk( StgPtr sp, StgPtr spBottom )
 {
-    StgNat32 bitmap;
+    StgWord32 bitmap;
     const StgInfoTable *info;
 
     ASSERT(sp <= spBottom);
@@ -669,7 +713,10 @@ static void printZcoded( const char *raw )
  * Symbol table loading
  * ------------------------------------------------------------------------*/
 
-#ifdef HAVE_BFD_H
+/* Causing linking trouble on Win32 plats, so I'm
+   disabling this for now. 
+*/
+#if defined(HAVE_BFD_H) && !defined(_WIN32)
 
 #include <bfd.h>
 
@@ -688,6 +735,7 @@ static rtsBool isReal( flagword flags, const char *name )
         return rtsFalse;
     }
 #else
+    (void)flags;   /* keep gcc -Wall happy */
     if (*name == '\0'  || 
        (name[0] == 'g' && name[1] == 'c' && name[2] == 'c') ||
        (name[0] == 'c' && name[1] == 'c' && name[2] == '.')) {
@@ -774,4 +822,36 @@ extern void DEBUG_LoadSymbols( char *name )
 
 #endif /* HAVE_BFD_H */
 
+#include "StoragePriv.h"
+
+void
+findPtr(P_ p)
+{
+  nat s, g;
+  P_ q;
+  bdescr *bd;
+
+  for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
+    for (s = 0; s < generations[g].n_steps; s++) {
+      for (bd = generations[g].steps[s].blocks; bd; bd = bd->link) {
+       for (q = bd->start; q < bd->free; q++) {
+         if (*q == (W_)p) {
+           printf("%p\n", q);
+         }
+       }
+      }
+    }
+  }
+}
+
+#else /* DEBUG */
+void printPtr( StgPtr p )
+{
+    fprintf(stderr, "ptr 0x%p (enable -DDEBUG for more info) " , p );
+}
+  
+void printObj( StgClosure *obj )
+{
+    fprintf(stderr, "obj 0x%p (enable -DDEBUG for more info) " , obj );
+}
 #endif /* DEBUG */