00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 inline static char *code_to_string(byte *pc)
00028 {
00029 return((char *)(inst_table[*pc][0])) ;
00030 }
00031
00032 static void print_cell(FILE *where, CPtr cell_ptr, int fromwhere)
00033 {
00034 Integer index = 0 ;
00035 Cell cell_val ;
00036 CPtr p ;
00037 int whereto, tag ;
00038 char *s = 0 ;
00039
00040 cell_val = cell(cell_ptr);
00041
00042 if (cell_val == 0) { fprintf(where,"null,0).\n") ; return; }
00043
00044 if (fromwhere == FROM_CP) heap_top++ ;
00045
00046
00047
00048 p = pointer_from_cell(cell_val,&tag,&whereto) ;
00049 if (fromwhere == FROM_CP) heap_top-- ;
00050 switch (whereto)
00051 { case TO_HEAP : index = p - heap_bot ; s = "ref_heap" ; break ;
00052 case TO_NOWHERE : index = (Integer)p ; s = "ref_nowhere" ; break ;
00053 case TO_LS : index = ls_bot - p ; s = "ref_ls" ; break ;
00054 case TO_CP : index = cp_bot - p ; s = "ref_cp" ; break ;
00055 case TO_TR : index = p - tr_bot ; s = "ref_tr" ; break ;
00056 case TO_COMPL : index = p - compl_bot ; s = "ref_compl" ; break ;
00057
00058 }
00059 switch (tag)
00060 {
00061 case XSB_REF:
00062 case XSB_REF1:
00063 if (p == NULL) fprintf(where,"null,0).\n") ;
00064 else
00065 if (p == cell_ptr) fprintf(where,"undef,_).\n") ;
00066 else
00067 { switch (whereto)
00068 {
00069 case TO_HEAP :
00070 case TO_LS :
00071 case TO_TR :
00072 case TO_CP :
00073 fprintf(where,"%s,%ld).\n",s,(long)index) ;
00074 break ;
00075 case TO_COMPL :
00076 fprintf(where,"%s,%ld).\n",s,(long)index) ;
00077 break ;
00078 case TO_NOWHERE:
00079 if (points_into_heap(p))
00080 {
00081 index = (p-heap_bot) ;
00082 fprintf(where,"between_h_ls,'/'(%ld,%p),_) .\n",(long)index,p) ;
00083 }
00084 else
00085 if ((Integer)cell_val < 10000)
00086 fprintf(where,"strange,%ld).\n",(long)cell_val) ;
00087 else
00088 if (fromwhere == FROM_HEAP)
00089 fprintf(where,"funct,'/'('%s',%d)).\n",
00090 get_name((Psc)(cell_val)),
00091 get_arity((Psc)(cell_val))) ;
00092 else
00093 if ((fromwhere == FROM_LS) || (fromwhere == FROM_CP))
00094 {
00095 char *s ;
00096 if ((tr_bot < (CPtr)cell_val) &&
00097 ((CPtr)cell_val < cp_bot))
00098 fprintf(where,"between_trail_cp,%ld).\n",
00099 (long)cell_val) ;
00100 else
00101 {
00102 s = code_to_string((byte *)cell_val) ;
00103 if (s == NULL)
00104 fprintf(where,"dont_know,%ld).\n",cell_val) ;
00105 else fprintf(where,"code,'-'(%ld,%s)).\n",cell_val,s) ;
00106 }
00107 }
00108 else fprintf(where,"strange_ref,%ld).\n",cell_val) ;
00109 break ;
00110 }
00111 }
00112 break ;
00113
00114 case XSB_STRUCT :
00115 if (whereto == TO_NOWHERE)
00116 fprintf(where,"'-'(cs,%s),%lx).\n",s,(long)index) ;
00117 else
00118 fprintf(where,"'-'(cs,%s),%ld).\n",s,(long)index) ;
00119 break ;
00120
00121 case XSB_LIST :
00122 fprintf(where,"'-'(list,%s),%ld).\n",s,(long)index) ;
00123 break ;
00124
00125 case XSB_INT :
00126 fprintf(where,"int ,%ld).\n",(long)int_val(cell_val)) ;
00127 break ;
00128
00129 case XSB_FLOAT :
00130 fprintf(where,"float,%.5g).\n",float_val((Integer)cell_val)) ;
00131 break ;
00132
00133 case XSB_STRING :
00134 fprintf(where,"atom ,'%s').\n",string_val(cell_val)) ;
00135 break ;
00136
00137 case XSB_ATTV :
00138 fprintf(where,"attrv_%s,%ld).\n",s,(long)index) ;
00139 break ;
00140
00141 default :
00142 fprintf(where,"strange,%ld).\n",cell_val) ;
00143 break ;
00144 }
00145 }
00146
00147 void print_heap(CTXTdeclc int start, int end, int add)
00148 {
00149 CPtr startp, endp ;
00150 char buf[100] ;
00151 FILE *where ;
00152
00153 sprintf(buf,"HEAP%d",printnum) ;
00154 printnum += add ;
00155 where = fopen(buf,"w") ;
00156 if (! where)
00157 { xsb_dbgmsg((LOG_GC,"could not open HEAP%d",printnum));
00158 return;
00159 }
00160 stack_boundaries ;
00161
00162 if (start < 0) start = 0 ;
00163 startp = heap_bot + start ;
00164 endp = heap_bot + end ;
00165 if (endp > heap_top) endp = heap_top ;
00166
00167 while ( startp < endp )
00168 { fprintf(where,"heap('%p',%6d,%s,",startp,start,pr_h_marked(startp)) ;
00169 print_cell(where,startp,FROM_HEAP) ;
00170 startp++ ; start++ ;
00171 }
00172
00173 fclose(where) ;
00174 }
00175
00176 void print_ls(CTXTdeclc int add)
00177 {
00178 CPtr startp, endp ;
00179 char buf[100] ;
00180 int start ;
00181 FILE *where ;
00182
00183 sprintf(buf,"LS%d",printnum) ;
00184 printnum += add ;
00185 where = fopen(buf,"w") ;
00186 if (! where)
00187 { xsb_dbgmsg((LOG_GC,"could not open LS%d", printnum));
00188 return;
00189 }
00190 stack_boundaries ;
00191
00192 start = 1 ;
00193 startp = ls_bot - 1 ;
00194 endp = ls_top ;
00195
00196 while ( startp >= endp )
00197 { fprintf(where,"ls(%6d,%s,",start,pr_ls_marked(startp)) ;
00198 print_cell(where,startp,FROM_LS) ;
00199 startp-- ; start++ ;
00200 }
00201
00202 fclose(where) ;
00203 }
00204
00205 void print_cp(CTXTdeclc int add)
00206 {
00207 CPtr startp, endp ;
00208 char buf[100] ;
00209 int start ;
00210 FILE *where ;
00211
00212 sprintf(buf,"CP%d",printnum) ;
00213 printnum += add ;
00214 where = fopen(buf,"w") ;
00215 if (! where)
00216 { xsb_dbgmsg((LOG_GC, "could not open CP%d", printnum));
00217 return;
00218 }
00219 stack_boundaries ;
00220
00221 start = 0 ;
00222 startp = cp_bot ;
00223 endp = cp_top ;
00224
00225 while ( startp >= endp )
00226 { fprintf(where,"cp('%p',%6d,%s,",startp,start,pr_cp_marked(startp)) ;
00227 print_cell(where,startp,FROM_CP) ;
00228 fflush(where);
00229 startp-- ; start++ ;
00230 }
00231
00232 fclose(where) ;
00233 }
00234
00235 void print_tr(CTXTdeclc int add)
00236 {
00237 CPtr startp, endp ;
00238 int start ;
00239 FILE *where ;
00240 char buf[100] ;
00241
00242 sprintf(buf,"TRAIL%d",printnum) ;
00243 printnum += add ;
00244 where = fopen(buf,"w") ;
00245 if (! where)
00246 { xsb_dbgmsg((LOG_GC, "could not open TRAIL%d",printnum));
00247 return;
00248 }
00249 stack_boundaries ;
00250
00251 startp = tr_bot ;
00252 endp = tr_top ;
00253 #ifdef PRE_IMAGE_TRAIL
00254 start = tr_top - tr_bot ;
00255 #else
00256 start = 0 ;
00257 #endif
00258
00259 while ( startp <= endp )
00260 {
00261 #ifdef PRE_IMAGE_TRAIL
00262 if ((*endp) & PRE_IMAGE_MARK) {
00263 Cell tagged_tr_cell = *endp ;
00264 cell(endp) = tagged_tr_cell - PRE_IMAGE_MARK ;
00265 fprintf(where,"trail(%6d,%s, tagged,",start,pr_tr_marked(endp)) ;
00266 print_cell(where,endp,FROM_TR) ;
00267 cell(endp) = tagged_tr_cell ;
00268 endp-- ; start-- ;
00269 fprintf(where,"trail(%6d,%s,pre_imag,",start,pr_tr_marked(endp)) ;
00270 print_cell(where,endp,FROM_TR) ;
00271 endp-- ; start-- ;
00272 } else {
00273 fprintf(where,"trail(%6d,%s,untagged,",start,pr_tr_marked(endp)) ;
00274 print_cell(where,endp,FROM_TR) ;
00275 endp-- ; start-- ;
00276 }
00277 #else
00278 fprintf(where,"trail(%6d,%s,",start,pr_tr_marked(startp)) ;
00279 print_cell(where,startp,FROM_TR) ;
00280 startp++ ; start++ ;
00281 #endif
00282 }
00283
00284 fclose(where) ;
00285 }
00286
00287 void print_regs(CTXTdeclc int a, int add)
00288 {
00289 CPtr startp, endp ;
00290 int start ;
00291 FILE *where ;
00292 char buf[100] ;
00293
00294 sprintf(buf,"REGS%d",printnum) ;
00295 printnum += add ;
00296 where = fopen(buf,"w") ;
00297 if (! where)
00298 { xsb_dbgmsg((LOG_GC, "could not open REGS%d",printnum));
00299 return;
00300 }
00301 stack_boundaries ;
00302
00303 startp = reg+1 ;
00304 endp = reg+a ;
00305 start = 1 ;
00306
00307 while (startp <= endp)
00308 {
00309 fprintf(where,"areg(%6d,",start) ;
00310 print_cell(where,startp,FROM_AREG) ;
00311 startp++ ; start++ ;
00312 }
00313
00314 fprintf(where,"wam_reg(trreg,%ld).\n",(long)((CPtr)trreg-tr_bot)) ;
00315 fprintf(where,"wam_reg(breg,%ld).\n",(long)(cp_bot-breg)) ;
00316 fprintf(where,"wam_reg(hreg,%ld).\n",(long)(hreg-heap_bot)) ;
00317 fprintf(where,"wam_reg(ereg,%ld).\n",(long)(ls_bot-ereg)) ;
00318
00319 fprintf(where,"wam_reg(trfreg,%ld).\n",(long)((CPtr)trfreg-tr_bot)) ;
00320 fprintf(where,"wam_reg(bfreg,%ld).\n",(long)(cp_bot-bfreg)) ;
00321 fprintf(where,"wam_reg(hfreg,%ld).\n",(long)(hfreg-heap_bot)) ;
00322 fprintf(where,"wam_reg(efreg,%ld).\n",(long)(ls_bot-efreg)) ;
00323
00324 fprintf(where,"wam_reg(ptcpreg,%ld).\n",(Cell)ptcpreg) ;
00325
00326 fprintf(where,"wam_reg(ebreg,%ld).\n",(long)(ls_bot-ebreg)) ;
00327 fprintf(where,"wam_reg(hbreg,%ld).\n",(long)(hbreg-heap_bot)) ;
00328
00329 fprintf(where,"wam_reg(cpreg,%ld).\n",(Cell)cpreg) ;
00330 fprintf(where,"wam_reg(pcreg,%ld).\n",(Cell)pcreg) ;
00331
00332 if (delayreg)
00333 {
00334 fprintf(where,"delayreg(");
00335 print_cell(where,(CPtr)(&delayreg),FROM_AREG);
00336 }
00337 else fprintf(where,"wam_reg(delayreg,%ld).\n",(Cell)delayreg);
00338
00339 fclose(where) ;
00340 }
00341
00342
00343 void print_all_stacks(CTXTdeclc int arity)
00344 {
00345 printnum++ ;
00346 print_regs(CTXTc arity,0) ;
00347 print_heap(CTXTc 0,200000,0) ;
00348 print_ls(CTXTc 0) ;
00349 print_tr(CTXTc 0) ;
00350 print_cp(CTXTc 0) ;
00351 }
00352