/* -----------------------------------------------------------------------------
- * $Id: Printer.c,v 1.48 2001/11/20 16:17:23 simonmar Exp $
+ * $Id: Printer.c,v 1.52 2002/07/17 09:21:50 simonmar Exp $
*
* (c) The GHC Team, 1994-2000.
*
#include "Rts.h"
#include "Printer.h"
+#include <stdio.h>
+
#ifdef DEBUG
#include "RtsUtils.h"
#include "Bytecodes.h" /* for InstrPtr */
#include "Disassembler.h"
-#include "Printer.h"
+#include <stdlib.h>
+#include <string.h>
#if defined(GRAN) || defined(PAR)
// HWL: explicit fixed header size to make debugging easier
static void enZcode ( char *in, char *out );
#endif
static char unZcode ( char ch );
-rtsBool lookupGHCName ( StgPtr addr, const char **result );
+const char * lookupGHCName ( void *addr );
static void printZcoded ( const char *raw );
/* --------------------------------------------------------------------------
void printPtr( StgPtr p )
{
const char *raw;
- if (lookupGHCName( p, &raw )) {
+ raw = lookupGHCName(p);
+ if (raw != NULL) {
printZcoded(raw);
} else {
fprintf(stdout, "%p", p);
printClosure(obj);
}
-static void printStdObject( StgClosure *obj, char* tag )
+static inline void
+printStdObjHdr( StgClosure *obj, char* tag )
{
- StgWord i, j;
- const StgInfoTable* info = get_itbl(obj);
fprintf(stdout,"%s(",tag);
printPtr((StgPtr)obj->header.info);
#ifdef PROFILING
fprintf(stdout,", %s", obj->header.prof.ccs->cc->label);
#endif
+}
+
+static void
+printStdObject( StgClosure *obj, char* tag )
+{
+ StgWord i, j;
+ const StgInfoTable* info;
+
+ printStdObjHdr( obj, tag );
+
+ info = get_itbl(obj);
for (i = 0; i < info->layout.payload.ptrs; ++i) {
fprintf(stdout,", ");
printPtr((StgPtr)obj->payload[i]);
fprintf(stdout,")\n");
}
-void printClosure( StgClosure *obj )
+void
+printClosure( StgClosure *obj )
{
StgInfoTable *info;
case MUT_VAR:
{
StgMutVar* mv = (StgMutVar*)obj;
- fprintf(stderr,"MUT_VAR(var=%p, link=%p)\n", mv->var, mv->mut_link);
+ fprintf(stdout,"MUT_VAR(var=%p, link=%p)\n", mv->var, mv->mut_link);
break;
}
}
case FOREIGN:
- fprintf(stderr,"FOREIGN(");
+ fprintf(stdout,"FOREIGN(");
printPtr((StgPtr)( ((StgForeignObj*)obj)->data ));
- fprintf(stderr,")\n");
+ fprintf(stdout,")\n");
break;
case IND:
break;
case THUNK_SELECTOR:
- printStdObject(obj,"THUNK_SELECTOR");
- break;
+ printStdObjHdr(obj, "THUNK_SELECTOR");
+ fprintf(stdout, ", %p)\n", ((StgSelector *)obj)->selectee);
+ break;
case ARR_WORDS:
{
putchar(arrWordsGetChar(obj,i));
} */
for (i=0; i<((StgArrWords *)obj)->words; i++)
- fprintf(stderr, "%ld", ((StgArrWords *)obj)->payload[i]);
- fprintf(stderr,"\")\n");
+ fprintf(stdout, "%u", ((StgArrWords *)obj)->payload[i]);
+ fprintf(stdout,"\")\n");
break;
}
sp++;
small_bitmap:
while (bitmap != 0) {
- fprintf(stderr," stk[%ld] (%p) = ", spBottom-sp, sp);
+ fprintf(stdout," stk[%ld] (%p) = ", spBottom-sp, sp);
if ((bitmap & 1) == 0) {
printPtr((P_)*sp);
fprintf(stdout,"\n");
} else {
- fprintf(stderr,"Word# %ld\n", *sp);
+ fprintf(stdout,"Word# %ld\n", *sp);
}
sp++;
bitmap = bitmap >> 1;
break;
}
}
- fprintf(stderr,"Stack[%ld] (%p) = ", spBottom-sp, sp);
+ fprintf(stdout,"Stack[%ld] (%p) = ", spBottom-sp, sp);
sp = printStackObj(sp);
}
}
}
#endif
-rtsBool lookupGHCName( StgPtr addr, const char **result )
+const char *lookupGHCName( void *addr )
{
nat i;
for( i = 0; i < table_size && table[i].value != (unsigned) addr; ++i ) {
}
if (i < table_size) {
- *result = table[i].name;
- return rtsTrue;
+ return table[i].name;
} else {
- return rtsFalse;
+ return NULL;
}
}
if (*q == (W_)p) {
if (i < arr_size) {
r = q;
- while (!LOOKS_LIKE_GHC_INFO(*r)) { r--; };
+ while (!LOOKS_LIKE_GHC_INFO(*r) || *r == NULL) {
+ r--;
+ }
fprintf(stdout, "%p = ", r);
printClosure((StgClosure *)r);
arr[i++] = r;