debug_xsb.c

00001 /* File:      debug_xsb.c
00002 ** Author(s): Xu, Swift, Sagonas, Johnson, Freire
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: debug_xsb.c,v 1.32 2006/07/14 16:49:36 tswift Exp $
00023 ** 
00024 */
00025 
00026 
00027 #include "xsb_config.h"
00028 #include "xsb_debug.h"
00029 
00030 #include <stdio.h>
00031 #include <string.h>
00032 
00033 #include "auxlry.h"
00034 #include "cell_xsb.h"
00035 #include "error_xsb.h"
00036 #include "binding.h"
00037 #include "psc_xsb.h"
00038 #include "memory_xsb.h"
00039 #include "flags_xsb.h"
00040 #include "context.h"
00041 #include "register.h"
00042 #include "deref.h"
00043 #include "trie_internals.h"
00044 #include "choice.h"
00045 #include "macro_xsb.h"
00046 #include "inst_xsb.h"
00047 #include "debug_xsb.h"
00048 #include "varstring_xsb.h"
00049 #include "cinterf.h"
00050 #include "io_defs_xsb.h"
00051 #include "io_builtins_xsb.h"
00052 #include "thread_defs_xsb.h"
00053 #include "thread_xsb.h"
00054 
00055 #if (defined(DEBUG_VERBOSE) || defined(DEBUG_VM))
00056 #include "subp.h"
00057 #endif
00058 
00059 /*=============================================================================*/
00060 /*  The first section of predicates are used for tracing as well as by XSB     */
00061 /*  developers during debugging.  They should always be defined                */
00062 /*=============================================================================*/
00063 
00064 #define CAR             1
00065 #define CDR             0
00066 
00067 static void print_term(FILE *fp, Cell term, byte car, int level)
00068 {
00069   unsigned short i, arity;
00070   Psc psc;
00071   CPtr cptr;
00072 
00073   level--;
00074   if (level < 0) {
00075     fprintf(fp, "...");
00076     return;
00077   }
00078   printderef(term);
00079   switch (cell_tag(term)) {
00080   case XSB_FREE:
00081   case XSB_REF1:
00082     fprintf(fp, "_%p", vptr(term));
00083     return;
00084   case XSB_ATTV:
00085     fprintf(fp, "_%p", (CPtr)dec_addr(term));
00086     return;
00087   case XSB_STRUCT:
00088       //NOTE: Below is a check for boxed numbers. If such is the case, then
00089       //  the behavior is the same as XSB_INT or XSB_FLOAT, but with boxed[X]_val macro
00090       //  instead of [X]_val macro
00091     if (isboxedfloat(term)) {
00092         fprintf(fp, "%f", boxedfloat_val(term));
00093         return;   
00094     }
00095     else if (isboxedinteger(term)) {
00096         fprintf(fp, "%ld", (long)boxedint_val(term));
00097         return;
00098     }
00099     psc = get_str_psc(term);
00100     fprintf(fp, "%s", get_name(psc));
00101     arity = get_arity(psc);
00102     if ( arity == 0 )   /* constant */
00103       return;
00104     /* structure */
00105     fprintf(fp, "(");
00106     cptr = clref_val(term);
00107     for ( i = 1; i <= arity; i++ ) {
00108       print_term(fp, cell(cptr+i), CAR, level);
00109       if ( i < arity )
00110         fprintf(fp, ",");
00111     }
00112     fprintf(fp, ")");
00113     return;
00114   case XSB_STRING:
00115     fprintf(fp, "\"%s\"", string_val(term));
00116     break;
00117   case XSB_INT:
00118     fprintf(fp, "%ld", (long)int_val(term));
00119     return;
00120   case XSB_FLOAT:
00121     fprintf(fp, "%f", float_val(term));
00122     fprintf(fp, "%f", ofloat_val(term));
00123     return;
00124   case XSB_LIST:
00125     cptr = clref_val(term);
00126     if ( car )
00127       fprintf(fp, "[");
00128     print_term(fp, cell(cptr), CAR, level);
00129     term = cell(cptr+1);
00130     XSB_Deref(term);
00131     switch (cell_tag(term)) {
00132     case XSB_FREE:
00133     case XSB_REF1: 
00134     case XSB_ATTV:
00135       goto vertbar;
00136     case XSB_LIST:
00137       fprintf(fp, ",");
00138       print_term(fp, term, CDR, level);
00139       return;
00140     case XSB_STRING:
00141       if (string_val(term) != nil_string)
00142         goto vertbar;
00143       else {
00144         fprintf(fp, "]");
00145         return;
00146       }
00147     case XSB_STRUCT:
00148     case XSB_INT:
00149     case XSB_FLOAT:
00150     vertbar:
00151     fprintf(fp, "|");
00152     print_term(fp, term, CAR, level);
00153     fprintf(fp, "]");
00154     return;
00155     }
00156   }
00157 }
00158 
00159 void printterm(FILE *fp, Cell term, int depth) {
00160 
00161   print_term(fp, term, CAR, depth);
00162   fflush(fp); 
00163 }
00164 
00165 /*------------------------------------------------------------------*/
00166 /* Used to print out call using WAM registers */
00167 
00168 static void print_call(CTXTdeclc Psc psc)
00169 {
00170   int i, arity;
00171 
00172   arity = (int)get_arity(psc);
00173   fprintf(stddbg, "(w1) call: %s", get_name(psc));
00174   if (arity != 0) fprintf(stddbg, "(");
00175   for (i=1; i <= arity; i++) {
00176     printterm(stddbg, cell(reg+i), 3);
00177     fflush(stddbg);
00178     if (i < arity) fprintf(stddbg, ",");
00179   }
00180   if (arity != 0) fprintf(stddbg, ")\n"); else fprintf(stddbg, "\n");
00181   fflush(stddbg);
00182 }
00183 
00184 /*------------------------------------------------------------------*/
00185 /* These variables are global, so in principle, you could run the
00186    instruction debugger with multiple active threads.  It hasn't been
00187    tested out, however. */
00188 
00189 int call_step_gl = 0;
00190 int hitrace_suspend_gl = 0;
00191 
00192 void debug_call(CTXTdeclc Psc psc)
00193 {
00194   if (call_step_gl || get_spy(psc)) {
00195     print_call(CTXTc psc);
00196 #ifdef DEBUG_VM
00197     debug_interact(CTXT);
00198 #endif
00199   } else if (!hitrace_suspend_gl) print_call(CTXTc psc);
00200 }
00201 
00202 /*=============================================================================*/
00203 /*  The second section of predicates I (TLS) use when debugging with gdb.      */
00204 /*  Please ensure they stay defined whenever we compile with -dbg option.      */
00205 /*=============================================================================*/
00206 
00207 /*----------------------------------------------------------------------*/ 
00208 /* This set of routines prints out the CP stack with stuff I happen to
00209    want.  It has different information than print_cp() in gc_print.h, so
00210    please keep it around. */
00211 
00212 #ifdef CP_DEBUG
00213 void print_cpf_pred(CPtr cpf)
00214 {
00215   Psc psc;
00216   
00217   psc = cp_psc(cpf);
00218   if (psc) {
00219     switch(get_type(psc)) {
00220     case T_PRED:
00221       fprintf(stddbg,"choicepoint(address(%p),pred(%s/%d)).\n",
00222               cpf, get_name(psc), get_arity(psc));
00223       break;
00224     case T_DYNA:
00225       fprintf(stddbg,"choicepoint(address(%p),dyna_pred(%s/%d)).\n",
00226               cpf, get_name(psc), get_arity(psc));
00227       break;
00228     case T_ORDI:
00229       fprintf(stddbg,"choicepoint(address(%p),t_ordi).\n",
00230               cpf);
00231       break;
00232     case T_UDEF:
00233       fprintf(stddbg,"choicepoint(address(%p),unloaded(%s/%d)).\n",
00234               cpf, get_name(psc), get_arity(psc));
00235       break;
00236     default:
00237       fprintf(stddbg,"choicepoint(address(%p),unknown_pred).\n", cpf);
00238       break;
00239     }
00240   } else
00241     fprintf(stddbg,"choicepoint(address(%p),unknown_psc).\n", cpf);
00242 
00243 }
00244 
00245 void print_cp_backtrace()
00246 {
00247   CPtr mycp;
00248   mycp = (CPtr) breg;
00249   while (mycp <= tcpstack.high - CP_SIZE -1 && mycp != (CPtr) cp_prevbreg(mycp)) {
00250     print_cpf_pred(mycp);
00251     mycp = cp_prevbreg(mycp);
00252   }
00253 }
00254 
00255 void alt_print_cpf_pred(CPtr cpf,FILE* where)
00256 {
00257   Psc psc;
00258   
00259   psc = * (Psc *)cpf;
00260   if (psc) {
00261     switch(get_type(psc)) {
00262     case T_PRED:
00263       fprintf(where,"   CP stack %p\t Static Predicate: \t%s/%d\n",
00264               cpf, get_name(psc), get_arity(psc));
00265       break;
00266     case T_DYNA:
00267       fprintf(where,"   CP stack %p\t Dyna Predicate: \t%s/%d\n",
00268               cpf, get_name(psc), get_arity(psc));
00269       break;
00270     case T_ORDI:
00271       fprintf(where,"CP stack %p\t ORDI Predicate: \t\n",
00272               cpf);
00273       break;
00274     case T_UDEF:
00275       fprintf(where,"CP stack %p\t UNDEF Predicate: \t\n",
00276               cpf);
00277       break;
00278     default:
00279       fprintf(where,"choicepoint(address(%p),unknown_pred).\n", cpf);
00280       break;
00281     }
00282   } else
00283     fprintf(where,"choicepoint(address(%p),unknown_psc).\n", cpf);
00284 }
00285 
00286 #endif CP_DEBUG
00287 
00288 /*-------------------------------------------*/ 
00289 
00290 static void print_common_cpf_part(CPtr cpf_addr, FILE* where) {
00291 
00292   fprintf(where,"   CP stack %p:\tptr to next clause:\t%p\n",
00293              &(cp_pcreg(cpf_addr)), cp_pcreg(cpf_addr));
00294   fprintf(where,"   CP stack %p:\tprev top:\t%p\n", 
00295              &(cp_prevtop(cpf_addr)), cp_prevtop(cpf_addr));
00296 #ifdef CP_DEBUG
00297   if ( (int) cp_psc(cpf_addr) != 0) 
00298     alt_print_cpf_pred((CPtr) &(cp_psc(cpf_addr)),where);
00299 #endif
00300   fprintf(where,"   CP stack %p:\tprev env cap (ebreg):\t%p\n",
00301              &(cp_ebreg(cpf_addr)), cp_ebreg(cpf_addr));
00302   fprintf(where,"   CP stack %p:\ttop of heap:\t\t%p\n", 
00303              &(cp_hreg(cpf_addr)), cp_hreg(cpf_addr));
00304   fprintf(where,"   CP stack %p:\ttop of trail:\t\t%p\n",
00305              &(cp_trreg(cpf_addr)), cp_trreg(cpf_addr));
00306   fprintf(where,"   CP stack %p:\tcontinuation pointer:\t%p\n", 
00307              &(cp_cpreg(cpf_addr)), cp_cpreg(cpf_addr));
00308   fprintf(where,"   CP stack %p:\ttop of local stack:\t%p\n", 
00309              &(cp_ereg(cpf_addr)), cp_ereg(cpf_addr));
00310   fprintf(where,"   CP stack %p:\tparent subgoal dreg:\t%p\n", 
00311              &(cp_pdreg(cpf_addr)), cp_pdreg(cpf_addr));
00312   fprintf(where,"   CP stack %p:\troot subgoal:\t%p\n", 
00313              &(cp_ptcp(cpf_addr)), cp_ptcp(cpf_addr));
00314   fprintf(where,"   CP stack %p:\tdynamic link:\t\t%p\n", 
00315              &(cp_prevbreg(cpf_addr)), cp_prevbreg(cpf_addr));
00316  }
00317 
00318 static void print_cpf(CPtr cpf_addr, FILE* where) {
00319 
00320   CPtr arg;
00321   int i, num_of_args, cp_type = 0;
00322   byte inst;
00323 
00324   inst = * (byte *) * cpf_addr;
00325 
00326   /* tableretry, tabletrust, check_complete */
00327   if (inst == 0xc3 || inst == 0xc4 || inst == 0xc4) 
00328     cp_type = GENERATOR_CP_FRAME;
00329   /* retryme, trustme, retry, trust, dynretry, dyntrust, retrymeor, trustmeor */
00330   else if (inst == 0xa1 || inst == 0xa2 || inst == 0xa4 
00331            || inst == 0xa5 || inst == 0xba || inst == 0xbb || inst == 0xb8 || inst == 0xb9)
00332     cp_type = STANDARD_CP_FRAME;
00333   else if (inst >= 0x5c && inst <= 0x77)  // tries
00334     cp_type = STANDARD_CP_FRAME;
00335   else if (inst == 0xc5) 
00336     cp_type = CONSUMER_CP_FRAME;
00337   else if (inst == 0xc6) 
00338     cp_type = COMPL_SUSP_CP_FRAME;
00339 
00340   switch (cp_type) {
00341   case STANDARD_CP_FRAME:
00342     fprintf(where,"Standard Choice Point Frame: (%s)\n",(char *)inst_table[inst][0]);
00343 
00344     print_common_cpf_part(cpf_addr,where);
00345 
00346     num_of_args = (cp_prevtop(cpf_addr) - cpf_addr) - CP_SIZE;
00347     for (i = 1, arg = cpf_addr + CP_SIZE; i <= num_of_args; i++, arg++)
00348       fprintf(where,"   CP stack %p:\tpredicate arg #%d:\t0x%p\n",
00349                  arg, i, ref_val(*arg));
00350     break;
00351   case GENERATOR_CP_FRAME:
00352     fprintf(where,"Generator Choice Point Frame:\n");
00353     print_common_cpf_part(cpf_addr,where);
00354     fprintf(where,"   CP stack %p:\ttemplate:\t0x%p", 
00355                &(tcp_template(cpf_addr)), tcp_template(cpf_addr));
00356     fprintf(where,"   CP stack %p:\tsubgoal frame ptr:\t0x%p\n", 
00357                &(tcp_subgoal_ptr(cpf_addr)), tcp_subgoal_ptr(cpf_addr));
00358     fprintf(where,"   CP stack %p:\tCh P  freeze register:\t0x%p\n", 
00359                &(tcp_bfreg(cpf_addr)), tcp_bfreg(cpf_addr));
00360     fprintf(where,"   CP stack %p:\tHeap  freeze register:\t0x%p\n", 
00361                &(tcp_hfreg(cpf_addr)), tcp_hfreg(cpf_addr));
00362     fprintf(where,"   CP stack %p:\tTrail freeze register:\t0x%p\n", 
00363                &(tcp_trfreg(cpf_addr)), tcp_trfreg(cpf_addr));
00364     fprintf(where,"   CP stack %p:\tLo St freeze register:\t0x%p\n", 
00365                &(tcp_efreg(cpf_addr)), tcp_efreg(cpf_addr));
00366 #ifdef LOCAL_EVAL
00367     fprintf(where,"   CP stack %p:\tlocal eval trie_return:\t0x%p\n",
00368                &(tcp_trie_return(cpf_addr)), tcp_trie_return(cpf_addr));
00369 #endif
00370     num_of_args = (cp_prevtop(cpf_addr) - cpf_addr) - TCP_SIZE;
00371     for (i = 1, arg = cpf_addr + TCP_SIZE; i <= num_of_args; i++, arg++)
00372       fprintf(where,"   CP stack %p:\tpredicate arg #%d:\t0x%p\n",
00373               arg, i, ref_val(*arg));
00374     break;
00375   case CONSUMER_CP_FRAME:
00376     fprintf(where,"Consumer Choice Point Frame:\n");
00377     print_common_cpf_part(cpf_addr,where);
00378     fprintf(where,"   CP stack %p:\ttemplate:\t0x%p", 
00379                &(nlcp_template(cpf_addr)), nlcp_template(cpf_addr));
00380     fprintf(where,"   CP stack %p:\tsubgoal frame ptr:\t0x%p\n", 
00381                &(nlcp_subgoal_ptr(cpf_addr)), nlcp_subgoal_ptr(cpf_addr));
00382     fprintf(where,"   CP stack %p:\tPrevlookup:\t0x%p\n", 
00383                &(nlcp_prevlookup(cpf_addr)), nlcp_prevlookup(cpf_addr));
00384 #ifdef LOCAL_EVAL
00385     fprintf(where,"   CP stack %p:\tlocal eval trie_return:\t0x%p\n",
00386                &(nlcp_trie_return(cpf_addr)), nlcp_trie_return(cpf_addr));
00387 #endif
00388     num_of_args = (cp_prevtop(cpf_addr) - cpf_addr) - NLCP_SIZE;
00389     for (i = 1, arg = cpf_addr + NLCP_SIZE; i <= num_of_args; i++, arg++)
00390       fprintf(where,"   CP stack %p:\tpredicate arg #%d:\t0x%p\n",
00391                 arg, i, ref_val(*arg));
00392     break;
00393     case COMPL_SUSP_CP_FRAME:
00394     fprintf(where,"Completion Choice Point Frame:\n");
00395     print_common_cpf_part(cpf_addr,where);
00396     fprintf(where,"   CP stack %p:\tsubgoal frame ptr:\t0x%p\n", 
00397                &(csf_subgoal_ptr(cpf_addr)), csf_subgoal_ptr(cpf_addr));
00398     fprintf(where,"   CP stack %p:\tPrevCSF:\t0x%p\n", 
00399                &(csf_prevcsf(cpf_addr)), csf_prevcsf(cpf_addr));
00400     fprintf(where,"   CP stack %p:\tNeg Loop:\t%d\n",
00401             &(csf_neg_loop(cpf_addr)), (int) csf_neg_loop(cpf_addr));
00402     num_of_args = (cp_prevtop(cpf_addr) - cpf_addr) - CSF_SIZE;
00403     for (i = 1, arg = cpf_addr + CSF_SIZE; i <= num_of_args; i++, arg++)
00404       fprintf(where,"   CP stack %p:\tpredicate arg #%d:\t0x%p\n",
00405                 arg, i, ref_val(*arg));
00406     break;
00407   default:
00408     xsb_error("CP Type %d not handled yet...", cp_type);
00409     break;
00410   }
00411 }
00412 
00413 static int alt_printnum = 0 ;
00414 
00415 void alt_print_cp(CTXTdecl)
00416 {
00417   CPtr startp, endp ;
00418   char buf[100] ;
00419   int  start ;
00420   FILE *where ;
00421 
00422   sprintf(buf,"ACP%d",alt_printnum) ;
00423   alt_printnum++ ;
00424   where = fopen(buf,"w") ;
00425   if (! where)
00426     { xsb_dbgmsg((LOG_GC, "could not open CP%d", printnum));
00427       return;
00428     }
00429 
00430   start = 0 ;
00431   startp = (CPtr)tcpstack.high - 1 ; 
00432   endp = top_of_cpstack ; 
00433 
00434   while ( startp > endp )
00435   { fflush(where);
00436     start++ ;
00437     print_cpf(endp, where );
00438 
00439     endp = cp_prevtop(endp);
00440   }
00441 
00442   fclose(where) ;
00443 } /* print_cp */
00444 
00445 extern void dis_data(FILE *);
00446 extern void dis_text(FILE *);
00447 
00448 void alt_dis(CTXTdecl)
00449 {
00450   FILE *where ;
00451 
00452   alt_printnum++ ;
00453   where = fopen("ALTDIS","w") ;
00454   if (! where)
00455     { xsb_dbgmsg((LOG_GC, "could not open ALTDIS"));
00456       return;
00457     }
00458 
00459   dis_data(where);
00460   dis_text(where);
00461 
00462   fclose(where) ;
00463 } /* print_cp */
00464 
00465 /*======================================================================*/
00466 /*  The third set of routines should be useful with gdb.  They need to  */
00467 /*  be revised to get rid of the xsb_dbg stuff, and so that they're     */
00468 /*  defined whenever we configure with -dbg                             */
00469 /*======================================================================*/
00470 
00471 #if (defined(DEBUG_VERBOSE) || defined(DEBUG_VM))
00472 
00473 static int count_producer_subgoals(void)
00474 {
00475   int i;
00476   TIFptr tif;
00477   VariantSF temp_ptr;
00478 
00479   i = 0;
00480 
00481   SYS_MUTEX_LOCK( MUTEX_TABLE );
00482   for ( tif = tif_list.first;  IsNonNULL(tif);  tif = TIF_NextTIF(tif) )
00483     for ( temp_ptr = TIF_Subgoals(tif);  IsNonNULL(temp_ptr);
00484           temp_ptr = (VariantSF)subg_next_subgoal(temp_ptr) )
00485       i ++;
00486   SYS_MUTEX_UNLOCK( MUTEX_TABLE );
00487   return(i);
00488 }
00489 
00490 /*----- For table debugging --------------------------------------------*/ 
00491 
00492 static Cell cell_array[500];
00493 
00494 static void print_term_of_subgoal(FILE *fp, int *i)
00495 {
00496   Cell term;
00497   int  j, args;
00498 
00499   term = cell_array[*i];
00500   switch (cell_tag(term)) {
00501   case XSB_TrieVar:
00502     fprintf(fp, "_v%d", (int_val(term) & 0xffff));
00503     break;
00504   case XSB_STRUCT:
00505     args = get_arity((Psc)cs_val(term));
00506     write_quotedname(fp,     get_name((Psc)cs_val(term)));
00507     /*    fprintf(fp, "%s", get_name((Psc)cs_val(term))); */
00508     if (args > 0) fprintf(fp, "(");
00509     for (j = args; j > 0; j--) {
00510       (*i)--;
00511       print_term_of_subgoal(fp, i);
00512       if (j > 1) fprintf(fp, ",");
00513     }
00514     if (args > 0) fprintf(fp, ")");
00515     break;
00516   case XSB_LIST:        /* the list [a,b(1),c] is stored as . . . [] c b 1 a */
00517     /*
00518      * This is the old version, which does not work anymore.
00519      *
00520      * if (isnil(cell_array[(*i)-1])) {
00521      *   (*i) -= 2;
00522      *   print_term_of_subgoal(fp, i);
00523      *   fprintf(fp, "]");
00524      * } else xsb_error("Non-single element list in print_subgoal()");
00525      */
00526     fprintf(fp, "[");
00527     (*i)--;
00528     print_term_of_subgoal(fp, i);
00529     (*i)--;
00530     print_term_of_subgoal(fp, i);
00531     fprintf(fp, "]");
00532     break;
00533   case XSB_STRING:
00534     write_quotedname(fp,string_val(term));
00535   /*    fprintf(fp, "%s", string_val(term));*/
00536     break;
00537   case XSB_INT:
00538     fprintf(fp, "%d", int_val(term));
00539     break;
00540   case XSB_FLOAT:
00541     fprintf(fp, "%.5g", float_val(term));
00542     break;
00543   default:
00544     xsb_error("Term with unknown tag (%d) in print_subgoal()",
00545               (int)cell_tag(term));
00546     break;
00547   }
00548 }
00549 
00550 /*----------------------------------------------------------------------*/
00551 
00552 void print_subgoal(FILE *fp, VariantSF subg)
00553 {
00554   BTNptr leaf;
00555   int  i = 0;
00556   Psc  psc = TIF_PSC(subg_tif_ptr(subg));
00557 
00558   for (leaf = subg_leaf_ptr(subg); leaf != NULL; leaf = Parent(leaf)) {
00559     cell_array[i++] = BTN_Symbol(leaf);
00560   }
00561   write_quotedname(fp,     get_name(psc));
00562   /*  fprintf(fp, "%s", get_name(psc)); */
00563   if (get_arity(psc) > 0) {
00564     fprintf(fp, "(");
00565     for (i = i-2; i >= 0 ; i--) {
00566       print_term_of_subgoal(fp, &i);
00567       if (i > 0) fprintf(fp, ", ");
00568     }
00569     fprintf(fp, ")");
00570   }
00571 }
00572 
00573 /*----------------------------------------------------------------------*/
00574 
00575 static void print_delay_element(FILE *fp, Cell del_elem)
00576 {
00577   Psc  psc = 0;
00578   CPtr cptr;
00579   int arity, i;
00580   Cell tmp_cell;
00581   char *name;
00582 
00583   if ((psc = get_str_psc(del_elem)) == delay_psc) {
00584     fprintf(fp, "%s(", get_name(psc));
00585     cptr = (CPtr)cs_val(del_elem);
00586     tmp_cell = cell(cptr + 1);
00587     print_subgoal(fp, (VariantSF) addr_val(tmp_cell)); fprintf(fp, ",");
00588     tmp_cell = cell(cptr + 2);
00589     fprintf(fp, "%p", (BTNptr) addr_val(tmp_cell)); fprintf(fp, ",");
00590     tmp_cell = cell(cptr + 3);
00591     if (isinteger(tmp_cell)) {
00592       fprintf(fp, "NEG");
00593     }
00594     else {
00595       if (isstring(tmp_cell)) {
00596         arity = 0;
00597         name = string_val(tmp_cell);
00598       }
00599       else {
00600         psc = get_str_psc(cell(cptr + 3));
00601         arity = get_arity(psc);
00602         name = get_name(psc);
00603       }
00604       fprintf(fp, "%s/%d(", name, arity);
00605       if (arity > 0) {
00606         cptr = (CPtr) cs_val(cell(cptr + 3));
00607         for (i = 0; i < arity; i++)
00608           printterm(fp, cell(cptr + 1 + i), 25);
00609       }
00610     }
00611     fprintf(fp, ")");
00612   }
00613   else {
00614     xsb_abort("Unknown delay list element in print_delay_element()");
00615   }
00616 }
00617 
00618 /*----------------------------------------------------------------------*/
00619 
00620 void print_delay_list(FILE *fp, CPtr dlist)
00621 {
00622   CPtr cptr;
00623   
00624   if (dlist == NULL) {
00625     fprintf(fp, "[]"); fflush(fp);
00626   } else {
00627     if (islist(dlist) || isnil(dlist)) {
00628       fprintf(fp, "["); cptr = dlist;
00629       while (islist(cptr)) {
00630         cptr = clref_val(cptr);
00631         print_delay_element(fp, cell(cptr));
00632         cptr = (CPtr)cell(cptr+1);
00633         if (islist(cptr)) fprintf(fp, ", ");
00634       }
00635       if (isnil(cptr)) {
00636         fprintf(fp, "]"); fflush(fp);
00637       } else {
00638         xsb_abort("Delay list with unknown tail type in print_delay_list()");
00639       }
00640     } else {
00641       xsb_abort("Delay list with unknown type in print_delay_list()");
00642     }
00643   }
00644 }
00645 
00646 /*-------------------------------------------------------------------------*/
00647 
00648 /*
00649  *                      TableInfoFrame Printing
00650  *                      -----------------------
00651  */
00652 
00653 char *stringTabledEvalMethod(TabledEvalMethod method) {
00654 
00655   switch(method) {
00656     // to be fixed when have time..... dsw
00657     //  case VARIANT_TEM:
00658     //    return ("variant");
00659     //    break;
00660     //  case SUBSUMPTIVE_TEM:
00661     //    return ("subsumption");
00662     //    break;
00663   default:
00664     return ("unknown");
00665     break;
00666   }
00667 }
00668 
00669 /*
00670  * Run the doubly-linked list of Subgoal Frames to the end, then back to
00671  * the beginning -- which may lie beyond `dll' -- counting the number of
00672  * frames encountered in each direction.
00673  */
00674 
00675 void subg_dll_length(VariantSF dll, counter *forward, counter *back) {
00676 
00677   VariantSF cur, prev;
00678   counter f, b;
00679 
00680   /* Count the number of frames on the chain from `dll' forward. */
00681   f = 0;
00682   for ( prev = NULL, cur = dll;
00683         IsNonNULL(cur);
00684         prev = cur, cur = subg_next_subgoal(cur) )
00685     f++;
00686 
00687   /* Count the number of frames on the chain from the end to the beginning */
00688   b = 0;
00689   for ( cur = prev;  IsNonNULL(cur);  cur = subg_prev_subgoal(cur) )
00690     b++;
00691 
00692   *forward = f;
00693   *back = b;
00694 }
00695 
00696 
00697 void printTIF(TIFptr tif) {
00698 
00699   counter forward, back;
00700 
00701   printf("TableInfoFrame  %p\n"
00702          "{ psc_ptr = %p  (%s/%d)\n"
00703          "  method = %s\n"
00704          "  call_trie = %p\n"
00705          "  subgoals = %p  ",
00706          tif,
00707          TIF_PSC(tif), get_name(TIF_PSC(tif)), get_arity(TIF_PSC(tif)),
00708          stringTabledEvalMethod(TIF_EvalMethod(tif)),
00709          TIF_CallTrie(tif),
00710          TIF_Subgoals(tif));
00711   subg_dll_length(TIF_Subgoals(tif),&forward,&back);
00712   if ( forward == back )
00713     printf("(%d total)", forward);
00714   else
00715     printf("(chain length mismatch: %d forward, %d back)", forward, back);
00716   printf("\n  next_tif = %p }\n", TIF_NextTIF(tif));
00717 }
00718 
00719 /*----------------------------------------------------------------------*/ 
00720 
00721 /*
00722  *                      Subgoal Frame Printing
00723  *                      ----------------------
00724  */
00725 
00726 char *stringSubgoalFrameType(byte type) {
00727 
00728   switch(type) {
00729   case VARIANT_PRODUCER_SFT:
00730     return("variant");
00731     break;
00732   case SUBSUMPTIVE_PRODUCER_SFT:
00733     return("subsumptive producer");
00734     break;
00735   case SUBSUMED_CONSUMER_SFT:
00736     return("subsumptive consumer");
00737     break;
00738   default:
00739     return("unknown");
00740     break;
00741   }
00742 }
00743 
00744 void print_tables(void)
00745 {
00746   int i = 0;
00747   char ans = 'y';
00748   TIFptr tif;
00749   VariantSF subg;
00750   SubConsSF cons;
00751 
00752   i = count_producer_subgoals();
00753   xsb_dbgmsg((LOG_DEBUG,"\t There are %d producer subgoal structures...", i));
00754 
00755   i = 0;
00756   SYS_MUTEX_LOCK( MUTEX_TABLE );
00757   for ( tif = tif_list.first;  IsNonNULL(tif) && (ans == 'y');
00758         tif = TIF_NextTIF(tif) ) {
00759     fprintf(stddbg,EOSUBG);
00760     printTIF(tif);
00761     subg = TIF_Subgoals(tif);
00762     while ( IsNonNULL(subg) && (ans == 'y') ) {
00763       i++;
00764       print_subg_header(subg);
00765       fprintf(stddbg, "%p:\n", subg);
00766       xsb_dbgmsg((LOG_DEBUG,"  sf_type = %s,  is_complete = %s,  is_reclaimed = %s,",
00767                  stringSubgoalFrameType(subg_sf_type(subg)),
00768                  (subg_is_complete(subg) ? "YES" : "NO"),
00769                  (subg_is_reclaimed(subg) ? "YES" : "NO")));
00770       xsb_dbgmsg((LOG_DEBUG,"  tif_ptr = %p,  leaf_ptr = %p,  ans_root_ptr = %p,\n"
00771                  "  ans_list_ptr = %p,   ans_list_tail = %p,\n"
00772                  "  next_subgoal = %p,  prev_subgoal = %p,  cp_ptr = %p",
00773                  subg_tif_ptr(subg), subg_leaf_ptr(subg),
00774                  subg_ans_root_ptr(subg),
00775                  subg_ans_list_ptr(subg), subg_ans_list_tail(subg),
00776                  subg_next_subgoal(subg), subg_prev_subgoal(subg), 
00777                  subg_cp_ptr(subg)));
00778       xsb_dbgmsg((LOG_DEBUG,"  asf_list_ptr = %p,", subg_asf_list_ptr(subg)));
00779       xsb_dbgmsg((LOG_DEBUG,"  compl_stk_ptr = %p,  compl_susp_ptr = %p,"
00780                  "  nde_list = %p",
00781                  subg_compl_stack_ptr(subg), subg_compl_susp_ptr(subg),
00782                  subg_nde_list(subg)));
00783       if ( IsSubProdSF(subg) ) {
00784         xsb_dbgmsg((LOG_DEBUG,"  consumers = %p", subg_consumers(subg)));
00785         for ( cons = subg_consumers(subg);  IsNonNULL(cons);
00786               cons = conssf_consumers(cons) )
00787           xsb_dbgmsg((LOG_DEBUG,"Consumer  %p\n"
00788                      "  sf_type = %11s,  tif_ptr = %p,         leaf_ptr = %p\n"
00789                      "  producer = %10p,  ans_list_ptr = %p,"
00790                      "  ans_list_tail = %p\n"
00791                      "  ts = %ul,  consumers = %p",
00792                      cons, subg_sf_type(cons), subg_tif_ptr(cons),
00793                      subg_leaf_ptr(cons), conssf_producer(cons),
00794                      subg_ans_list_ptr(cons), subg_ans_list_tail(cons),
00795                      conssf_timestamp(cons), conssf_consumers(cons)));
00796       }
00797       subg = subg_next_subgoal(subg);
00798       if (subg != NULL)
00799         fprintf(stddbg, EOSUBG);
00800       if (i == 10) {
00801         fprintf(stddbg, "more (y/n)?  ");
00802         scanf("%c", &ans);
00803         skip_to_nl();
00804         i = 0;
00805       }
00806     }
00807   SYS_MUTEX_UNLOCK( MUTEX_TABLE );
00808   }
00809   fprintf(stddbg, EOS);
00810 }
00811 
00812 #endif
00813 
00814 /*======================================================================*/
00815 /*  The final set of routines should be useful with the instruction-    */
00816 /*  level debugger.  This can be useful if you're adding a bunch of new */
00817 /*  instructions, but it hasnt been used for years, so it would need    */
00818 /*  some work to get it back into shape.  These routines should be      */
00819 /*  defined only with DEBUG_VM                                          */
00820 /*======================================================================*/
00821 
00822 #ifdef DEBUG_VM
00823 extern int  xctr;
00824 
00825 int pil_step = 1;
00826 int compl_step = 0;
00827 int debug_ctr = 0;
00828 int print_hide = 0;
00829 int memory_watch_flag = 0;
00830 int register_watch_flag = 0;
00831 #endif
00832 
00833 #ifdef DEBUG_VM
00834 static void debug_interact(CTXTdecl);
00835 
00836 CPtr decode_ptr(Cell cell) {
00837   return ( clref_val(cell) );
00838 }
00839 
00840 int decode_int(Cell cell) {
00841   return ( int_val(cell) );
00842 }
00843 
00844 int decode_tag(Cell cell) {
00845   return ( cell_tag(cell) );
00846 }
00847 
00848 /*----------------------------------------------------------------------*/
00849 
00850 void print_help(void)
00851 {
00852       fprintf(stddbg, "\n      a r/v/d/a <addr>: inspect the content of the address");
00853       fprintf(stddbg, "\n      b <module> <name> <arity>: spy the predicate");
00854       fprintf(stddbg, "\n      B <num>: print detailed Prolog choice points from the top");
00855       fprintf(stddbg, "\n\tof the choice point stack with <num>-Cell overlap");
00856       fprintf(stddbg, "\n      c <num>: print top of choice point stack with <num> overlap");
00857       fprintf(stddbg, "\n      C <num>: print choice point stack (around bfreg) with <num> overlap");
00858       fprintf(stddbg, "\n      d: print disassembled code for module");
00859       fprintf(stddbg, "\n      D: print current value of delay list (pointed by delayreg)");
00860       fprintf(stddbg, "\n      e <size>: expand trail/cp stack to <size> K-byte blocks");
00861       fprintf(stddbg, "\n      E <num>: print top of environment (local) stack with <num> overlap");
00862       fprintf(stddbg, "\n      g: leap to the next check_complete instruction");
00863       fprintf(stddbg, "\n      G: same as 'g', but does not print intermediate info");
00864       fprintf(stddbg, "\n      h: help");
00865       fprintf(stddbg, "\n      H <num>: print top of heap with <num> overlap");
00866       fprintf(stddbg, "\n      k <int>: print and skip <int> instructions");
00867       fprintf(stddbg, "\n      K <int>: skip <int> instructions");
00868       fprintf(stddbg, "\n      l: leap to the next spy point");
00869       fprintf(stddbg, "\n      L: same as 'l', but does not print intermediate info");
00870       fprintf(stddbg, "\n      M: print statistics");
00871       fprintf(stddbg, "\n      n: leap to the next call");
00872       fprintf(stddbg, "\n      N: nodebugging, continue to the end");
00873       fprintf(stddbg, "\n      o: print completion stack");
00874       fprintf(stddbg, "\n      P: print PDLSTK");
00875       fprintf(stddbg, "\n      q: quit XSB");
00876       fprintf(stddbg, "\n      r <num>: print register <num> as term");
00877       fprintf(stddbg, "\n      R <num>: print register <num> as ptr");
00878       fprintf(stddbg, "\n      S: print status registers");
00879       fprintf(stddbg, "\n      T <num>: print top of trail with <num> overlap");
00880       fprintf(stddbg, "\n      u <name> <arity>: unspy the predicate");
00881       fprintf(stddbg, "\n      w <stack> <val>: watch <stack> register for <val>");
00882       fprintf(stddbg, "\n      W <stack> <val>: watch memory area of <stack> for <val>");
00883       fprintf(stddbg, "\n      1: print top of (persistent) subgoal stack");
00884       fprintf(stddbg, "\n      2 <num>: print val of table pointer");
00885       fprintf(stddbg, "\n      ?: help");
00886       fprintf(stddbg, "\n");
00887 }
00888 
00889 /*--------------------------------------------------------------------------*/
00890 
00891 /*
00892  * Tries to make the interface more robust by cleaning-up any extra user
00893  * input supplied to a prompt.  Place a call to this function after any
00894  * input scan which doesn't take the whole input line (ie. which isn't a
00895  * `scanf("%s", &array);').
00896  */
00897 static void skip_to_nl(void)
00898 {
00899   char c;
00900 
00901   do {
00902     c = getchar();
00903   } while (c != '\n');
00904 }
00905 
00906 /*----- For table debugging --------------------------------------------*/ 
00907 
00908 static char *compl_stk_frame_field[] = {
00909   "subgoal_ptr", "level_num",
00910   "del_ret_list", "visited", 
00911 #ifndef LOCAL_EVAL
00912 "DG_edges", "DGT_edges"
00913 #endif
00914 };
00915 
00916 void print_completion_stack(CTXTdecl)
00917 {
00918   int i = 0;
00919   EPtr eptr;
00920   VariantSF subg;
00921   CPtr temp = openreg;
00922 
00923   fprintf(stddbg,"openreg -> ");
00924   while (temp < COMPLSTACKBOTTOM) {
00925     if ((i % COMPLFRAMESIZE) == 0) {
00926       fprintf(stddbg,EOFR);     /* end of frame */
00927       subg = (VariantSF) *temp;
00928       print_subg_header(subg);
00929     }
00930     fprintf(stddbg,"Completion Stack %p: %lx\t(%s)",
00931             temp, *temp, compl_stk_frame_field[(i % COMPLFRAMESIZE)]);
00932     if ((i % COMPLFRAMESIZE) >= COMPLFRAMESIZE-2) {
00933       for (eptr = (EPtr)*temp; eptr != NULL; eptr = next_edge(eptr)) {
00934         fprintf(stddbg," --> %p", edge_to_node(eptr));
00935       }
00936     }
00937     fprintf(stddbg,"\n");
00938     temp++; i++;
00939   }
00940   fprintf(stddbg, EOS);
00941 }
00942 
00943 /*----------------------------------------------------------------------*/
00944 
00945 static void print_pdlstack(CTXTdecl)
00946 {
00947   CPtr temp = pdlreg;
00948 
00949   while (temp <= (CPtr)(pdl.high) - 1) {
00950     xsb_dbgmsg((LOG_DEBUG,"pdlstk %p: %lx", temp, *temp));
00951     temp++;
00952   }
00953 }
00954 
00955 /*----------------------------------------------------------------------*/ 
00956 /* TLS 10/05: now unused? */
00957 
00958 void pofsprint(CPtr base, int arity)
00959 {     
00960   CPtr arg_ptr = base;
00961 
00962   fprintf(stddbg, "( ");
00963   for (arg_ptr = base - 1; arg_ptr >= base - arity; arg_ptr--) {
00964     printterm(stddbg, (Cell)arg_ptr, 8);
00965     if (arg_ptr != base - arity)
00966       fprintf(stddbg, ",");
00967   }
00968   fprintf(stddbg, ")\n");
00969 }
00970 
00971 /*----------------------------------------------------------------------*/ 
00972 
00973 extern void dis(xsbBool);
00974 extern byte *print_inst(FILE *, byte *);
00975 
00976 struct watch_struct {
00977   Integer  heap_flag;
00978   CPtr heap_val;
00979   Integer  stack_flag;
00980   CPtr stack_val;
00981   Integer  choice_flag;
00982   CPtr choice_val;
00983   Integer  trail_flag;
00984   CPtr trail_val;
00985 } reg_watch, mem_watch;
00986 
00987 /*======================================================================*/
00988 static void set_register_watch(int num1, CPtr num2)
00989 {
00990   register_watch_flag = 1;
00991   switch (num1) {
00992   case 1: 
00993     reg_watch.heap_flag = 1;
00994     reg_watch.heap_val = num2;
00995     break;
00996   case 2: 
00997     reg_watch.stack_flag = 1;
00998     reg_watch.stack_val = num2;
00999     break;
01000   case 3: 
01001     reg_watch.choice_flag = 1;
01002     reg_watch.choice_val = num2;
01003     break;
01004   case 4: 
01005     reg_watch.trail_flag = 1;
01006     reg_watch.trail_val = num2;
01007     break;
01008   }
01009 }
01010 
01011 /*----------------------------------------------------------------------*/ 
01012 
01013 static void set_memory_watch(Integer num1, int num2)
01014 {
01015   memory_watch_flag = 1;
01016   switch (num1) {
01017   case 1: 
01018     mem_watch.heap_flag = num2;
01019     mem_watch.heap_val = *(CPtr *) num2;
01020     break;
01021   case 2: 
01022     mem_watch.stack_flag = num2;
01023     mem_watch.stack_val = *(CPtr *) num2;
01024     break;
01025   case 3: 
01026     mem_watch.choice_flag = num2;
01027     mem_watch.choice_val = *(CPtr *) num2;
01028     break;
01029   case 4: 
01030     mem_watch.trail_flag = num2;
01031     mem_watch.trail_val = *(CPtr *) num2;
01032     break;
01033   }
01034 }
01035 
01036 /*----------------------------------------------------------------------*/
01037 
01038 static void monitor_register_watch(CTXTdecl)
01039 {
01040   if (reg_watch.heap_flag) 
01041     if (reg_watch.heap_val == hreg)
01042       xsb_dbgmsg((LOG_DEBUG,"!!! hreg == %p, %d", hreg, xctr));
01043   if (reg_watch.stack_flag) 
01044     if (reg_watch.stack_val == ereg)
01045       xsb_dbgmsg((LOG_DEBUG,"!!! ereg == %p, %d", ereg, xctr));
01046   if (reg_watch.choice_flag) 
01047     if (reg_watch.choice_val == breg)
01048       xsb_dbgmsg((LOG_DEBUG,"!!! breg == %p, %d", breg, xctr));
01049   if (reg_watch.trail_flag) 
01050     if ((CPtr *) reg_watch.trail_val == trreg)
01051       xsb_dbgmsg((LOG_DEBUG,"!!! trreg == %p, %d", trreg, xctr));
01052 }
01053 
01054 /*----------------------------------------------------------------------*/
01055 
01056 static void monitor_memory_watch(void)
01057 {
01058   if (mem_watch.heap_flag)
01059     if (*(CPtr *) mem_watch.heap_flag != mem_watch.heap_val) {
01060       xsb_dbgmsg((LOG_DEBUG,"Heap watch val %x was %p is now %lx, xctr %d",
01061                  mem_watch.heap_flag, mem_watch.heap_val,
01062                  *(CPtr) mem_watch.heap_flag, xctr));
01063       debug_ctr = 0;
01064       mem_watch.heap_val = *(CPtr *) mem_watch.heap_flag;
01065     }
01066   if (mem_watch.stack_flag)
01067     if (*(CPtr *) mem_watch.stack_flag != mem_watch.stack_val) {
01068       xsb_dbgmsg((LOG_DEBUG,"Stack watch val %x was %p is now %lx, xctr %d",
01069                  mem_watch.stack_flag,mem_watch.stack_val,
01070                  *(CPtr) mem_watch.stack_flag,xctr));
01071       debug_ctr = 0;
01072       mem_watch.stack_val = *(CPtr *) mem_watch.stack_flag;
01073     }
01074   if (mem_watch.choice_flag)
01075     if (*(CPtr *) mem_watch.choice_flag != mem_watch.choice_val) {
01076       xsb_dbgmsg((LOG_DEBUG,"Choice watch val %x was %p is now %lx, xctr %d",
01077                  mem_watch.choice_flag,mem_watch.choice_val,
01078                  *(CPtr) mem_watch.choice_flag,xctr));
01079       debug_ctr = 0;
01080       mem_watch.choice_val = *(CPtr *) mem_watch.choice_flag;
01081     }
01082   if (mem_watch.trail_flag)
01083     if (*(CPtr *) mem_watch.trail_flag != mem_watch.trail_val) {
01084       xsb_dbgmsg((LOG_DEBUG,"Trail watch val %x was %p is now %lx, xctr %d",
01085                  mem_watch.trail_flag,mem_watch.trail_val,
01086                  *(CPtr) mem_watch.trail_flag,xctr));
01087       debug_ctr = 0;
01088       mem_watch.trail_val = *(CPtr *) mem_watch.trail_flag;
01089     }
01090 }
01091 void debug_inst(CTXTdeclc byte *lpcreg, CPtr le_reg)
01092 {
01093   if (!print_hide) {
01094     fprintf(stddbg, "\nxctr %d ",xctr);
01095     printf(" (intFlg:%x)",asynint_val);
01096     print_inst(stddbg, lpcreg);
01097   }
01098   if (register_watch_flag) monitor_register_watch(CTXT);
01099   if (memory_watch_flag) monitor_memory_watch();
01100   if (pil_step && debug_ctr == 0) {
01101     print_hide = 0;
01102     pcreg = lpcreg; ereg = le_reg;
01103     debug_interact(CTXT);
01104   } else { 
01105     if (debug_ctr > 0) debug_ctr--;
01106     else 
01107       if (call_step_gl == 1 && *lpcreg == call) {
01108         pil_step = 1; debug_interact(CTXT);
01109       }
01110     if (compl_step == 1 && *lpcreg == check_complete) {
01111       pil_step = 1; debug_interact(CTXT);
01112     }
01113   }
01114 }
01115 
01116 static void print_cell(char *addrtype, CPtr addr, Cell term, char *more_info)
01117 {
01118   switch (cell_tag(term)) {
01119   case XSB_REF:
01120   case XSB_REF1:
01121     fprintf(stddbg, "%s %p: XSB_REF (tag=%ld), value=0x%p",
01122             addrtype, addr, cell_tag(term), ref_val(term));
01123     break;
01124   case XSB_ATTV:
01125     fprintf(stddbg, "%s %p: XSB_ATTV (tag=%ld), value=0x%p",
01126             addrtype, (CPtr)dec_addr(cell(addr)),
01127             cell_tag(term), ref_val(term));
01128     break;
01129   case XSB_STRUCT: 
01130     if (addr == (CPtr)dec_addr(term) || (CPtr)dec_addr(term) == NULL) {
01131       fprintf(stddbg, "Possible source of core dump\n");
01132       fprintf(stddbg, "%s %p: XSB_STRUCT, value=0x%p, hexval=0x%p", 
01133               addrtype, addr, cs_val(term), ref_val(term));
01134     }   else {
01135       fprintf(stddbg, "%s %p: XSB_STRUCT, value=0x%p, hexval=0x%p (%s/%d)", 
01136               addrtype, addr, cs_val(term), ref_val(term),
01137               get_name((struct psc_rec *) follow(cs_val(term))),
01138               get_arity((struct psc_rec *) follow(cs_val(term))));
01139     }
01140     break;
01141   case XSB_INT:
01142     fprintf(stddbg, "%s %p: XSB_INT, value=%d  hexval=0x%p",
01143             addrtype, addr, int_val(term), ref_val(term));
01144     break;
01145   case XSB_STRING:
01146     if (isnil(term)) 
01147       fprintf(stddbg, "%s %p: XSB_STRING, hexval=0x%p\t ([])", 
01148               addrtype, addr, ref_val(term));
01149     else
01150       fprintf(stddbg, "%s %p: XSB_STRING, hexval=0x%p\t (%s)", 
01151               addrtype, addr, ref_val(term), string_val(term));
01152     break;
01153   case XSB_FLOAT:
01154     fprintf(stddbg, "%s %p: XSB_FLOAT, value=%f, hexval=0x%lx", 
01155             addrtype, addr, float_val(term), dec_addr(term));
01156     break;
01157   case XSB_LIST:
01158     fprintf(stddbg, "%s %p: XSB_LIST, clref=%p, hex=%p",
01159             addrtype, addr, clref_val(term), ref_val(term));
01160     break;
01161   default:
01162     fprintf(stddbg, "%s %p: tag=%ld, hex=0x%p, cval=%d", 
01163             addrtype, addr, cell_tag(term), ref_val(term), int_val(term));
01164     break;
01165   }
01166   
01167   if (more_info != NULL)
01168     fprintf(stddbg, ",\t(%s)\n", more_info);
01169   else fprintf(stddbg, "\n");
01170 }
01171 
01172 /*----------------------------------------------------------------------*/ 
01173 
01174 static void print_cp_cell(char *addrtype, CPtr addr, Cell term)
01175 {
01176   if ((ref_val(term) != NULL) && (cell_tag(term) == term)) {
01177     fprintf(stddbg, "NULL cell in %s %p: tag=%ld, value=0x%p\n",
01178             addrtype, addr, cell_tag(term), ref_val(term));
01179   } else {  
01180     switch (cell_tag(term)) {
01181     case XSB_REF: 
01182     case XSB_REF1:
01183       fprintf(stddbg, "%s %p: XSB_REF (tag=%ld), value=0x%p\n",
01184               addrtype, addr, cell_tag(term), ref_val(term));
01185       break;
01186     case XSB_ATTV:
01187       fprintf(stddbg, "%s %p: XSB_ATTV (tag=%ld), value=0x%p\n",
01188               addrtype, (CPtr)dec_addr(cell(addr)),
01189               cell_tag(term), ref_val(term));
01190       break;
01191     case XSB_STRUCT:
01192       fprintf(stddbg, "%s %p: XSB_STRUCT, value=0x%p, hexval=0x%p (%s/%d)\n", 
01193               addrtype, addr, cs_val(term), ref_val(term),
01194               get_name((struct psc_rec *) follow(cs_val(term))),
01195               get_arity((struct psc_rec *) follow(cs_val(term))));
01196       break;
01197     case XSB_INT:
01198       fprintf(stddbg, "%s %p: XSB_INT, value=%d, hexval=0x%p\n",
01199               addrtype, addr, int_val(term), ref_val(term));
01200       break;
01201     case XSB_STRING:
01202       fprintf(stddbg, "%s %p: XSB_STRING, hexval=0x%p (%s)\n", 
01203               addrtype, addr, ref_val(term), string_val(term));
01204       break;
01205     case XSB_FLOAT:
01206       fprintf(stddbg, "%s %p: XSB_FLOAT, value=%f, hexval=0x%lx\n", 
01207               addrtype, addr, float_val(term), dec_addr(term));
01208       break;
01209     case XSB_LIST:
01210       fprintf(stddbg, "%s %p: XSB_LIST, value=%p\n",
01211               addrtype, addr, ref_val(term));
01212       break;
01213     default:
01214       fprintf(stddbg, "%s %p: tag=%ld, value=0x%p\n", 
01215               addrtype, addr, cell_tag(term), ref_val(term));
01216       break;
01217     }
01218   }
01219 }
01220 
01221 /*
01222  * Local Stack grows from high to low memory.
01223  */
01224 
01225 static void print_local_stack(CTXTdeclc int overlap)
01226 {
01227   int i;
01228   CPtr cell_ptr,
01229     local_stack_bottom = (CPtr) glstack.high;
01230   char ans = 'y';
01231 
01232   if (ereg_on_top(ereg)) {
01233     cell_ptr = ereg;
01234     fprintf(stddbg, "ereg on top\n");
01235   }
01236   else {
01237     cell_ptr = ebreg;
01238     fprintf(stddbg, "ebreg on top\n");
01239   }
01240   for (i = -overlap; i < 0; i++) {
01241     if ( cell_ptr+i == efreg ) fprintf(stddbg, "efreg\n");
01242     print_cp_cell("Local Stack", cell_ptr+i, cell(cell_ptr+i));
01243   }
01244   fprintf(stddbg, "top\n");
01245   do {
01246     for (i=0; (i < STRIDESIZE) && (cell_ptr < local_stack_bottom); i++) {
01247       if (cell_ptr == ebreg)
01248         fprintf(stddbg, "ebreg\n");
01249       if (cell_ptr == ereg)
01250         fprintf(stddbg, "ereg\n");
01251       if (cell_ptr == efreg) fprintf(stddbg, "efreg\n");
01252       print_cp_cell("Local Stack", cell_ptr, cell(cell_ptr));
01253       cell_ptr++;
01254     }
01255     if (cell_ptr < local_stack_bottom) {
01256       fprintf(stddbg, "more (y/n)?  ");
01257       scanf("%c", &ans);
01258       skip_to_nl();
01259     }
01260     else {
01261       fprintf(stddbg, EOS);
01262       ans = 'n';
01263     }
01264   } while (ans == 'y');
01265 }
01266 
01267 /*----------------------------------------------------------------------*/ 
01268 
01269 static void print_trail(CTXTdeclc int overlap)  /* trail grows up */
01270 {
01271   int  i, offset=0;
01272   char ans = 'y';
01273   CPtr *temp;
01274 
01275   if (trfreg > trreg) temp = trfreg;  else temp = trreg;
01276   for (i = overlap; (i > 0); i--)
01277     {
01278       if ( (temp + i) == trreg ) xsb_dbgmsg((LOG_DEBUG,"trreg"));
01279       if ( (temp + i) == trfreg ) xsb_dbgmsg((LOG_DEBUG,"trfreg"));
01280       print_cell("Trail", (CPtr)(temp+i), cell((CPtr)(temp+i)), NULL);
01281     }
01282   while (ans == 'y' && temp-offset >= (CPtr *) tcpstack.low) { 
01283     for (i = 0
01284            ; (i <= STRIDESIZE && temp-(offset+i) >= (CPtr *)tcpstack.low)
01285            ; i++ )      {
01286       if ( (temp - (offset+i)) == trreg ) xsb_dbgmsg((LOG_DEBUG,"trreg"));
01287       if ( (temp - (offset+i)) == trfreg ) xsb_dbgmsg((LOG_DEBUG,"trfreg"));
01288       print_cell("Trail", (CPtr)(temp-(offset+i)),
01289                  cell((CPtr)(temp-(offset+i))), NULL);
01290       if ( (temp-(offset+i)) == (CPtr *) tcpstack.low ) 
01291         xsb_dbgmsg((LOG_DEBUG,"bottom"));
01292     }
01293     offset += STRIDESIZE;
01294     fprintf(stddbg, "more (y/n)?  ");
01295     scanf("%c", &ans);
01296     skip_to_nl();
01297   }
01298 }
01299 
01300 /*----------------------------------------------------------------------*/ 
01301 
01302 /* Needs to change when new xwam stacks are introduced.  */
01303 static void terry_print_heap(CTXTdeclc int overlap)     /* Heap grows up */
01304 {
01305   int i = 0;
01306  
01307   for (i = -overlap; i < 0 ; i++) {
01308     print_cp_cell("CP stack", bfreg+i, cell(bfreg+i));
01309     if ( (bfreg + i) == breg ) xsb_dbgmsg((LOG_DEBUG,"breg"));
01310   }
01311   xsb_dbgmsg((LOG_DEBUG,"bfreg"));
01312   for (i = 0; (i <= STRIDESIZE && bfreg+i<=(CPtr)tcpstack.high); i++){
01313     if ( (bfreg + i) == breg ) xsb_dbgmsg((LOG_DEBUG,"breg"));
01314     print_cp_cell("CP stack", bfreg+i, cell(bfreg+i));
01315     if ( (bfreg + i) == (CPtr) tcpstack.high ) fprintf(stddbg, EOS);
01316   }
01317 }
01318 
01319 /*----------------------------------------------------------------------*/
01320 
01321 static void print_freeze_choice_points(CTXTdeclc int overlap)   /* CPs grow down */
01322 {
01323   int i,last = 0;
01324   char ans = 'y';
01325  
01326   for (i = -overlap; i < 0 ; i++) {
01327     print_cp_cell("CP stack", bfreg+i, cell(bfreg+i));
01328     if ( (bfreg + i) == breg ) xsb_dbgmsg((LOG_DEBUG,"breg"));
01329   }
01330   xsb_dbgmsg((LOG_DEBUG, "bfreg"));
01331   for (i = 0; (i <= STRIDESIZE && bfreg+i<=(CPtr)tcpstack.high); i++){
01332     if ( (bfreg + i) == breg ) xsb_dbgmsg((LOG_DEBUG, "breg"));
01333     print_cp_cell("CP stack", bfreg+i, cell(bfreg+i));
01334     if ( (bfreg + i) == (CPtr) tcpstack.high ) fprintf(stddbg, EOS);
01335   }
01336   fprintf(stddbg, "more (y/n)?  ");
01337   scanf("%c", &ans);
01338   skip_to_nl();
01339   while (ans == 'y' && bfreg+last < (CPtr) tcpstack.high ) { 
01340     last = last+STRIDESIZE;
01341     for ( i = last
01342             ; (i <= last+STRIDESIZE && bfreg+i <= (CPtr) tcpstack.high) 
01343             ; i++ ) {
01344       if ( (bfreg + i) == breg ) xsb_dbgmsg((LOG_DEBUG, "breg"));
01345       print_cp_cell("CP stack", bfreg+i, cell(bfreg+i));
01346       if ( (bfreg + i) == (CPtr) tcpstack.high ) fprintf(stddbg, EOS);
01347     }
01348     fprintf(stddbg, "more (y/n)?  ");
01349     scanf("%c", &ans);
01350     skip_to_nl();
01351   }
01352 }
01353 
01354 /*----------------------------------------------------------------------*/ 
01355 
01356 /*
01357  * Choice point stack grows from high to low memory.
01358  */
01359 
01360 static void print_cpfs(CTXTdeclc int overlap)
01361 {
01362   int i, frames = 2;
01363   char ans = 'y';
01364   CPtr  cpf,            /* ptr to choice point frame */
01365     cp_stack_bottom = (CPtr) tcpstack.high;
01366   int  length,          /* needed to increment the stack pointer, hence
01367                            analyze_cpf must supply it */
01368     type;
01369 
01370   for (i = -overlap ; (i < 0) ; i++) {
01371     if ((breg+i) == bfreg) xsb_dbgmsg((LOG_DEBUG,"bfreg"));
01372     print_cp_cell("   CP stack", breg+i, cell(breg+i));
01373   }
01374   xsb_dbgmsg((LOG_DEBUG,"breg"));
01375   cpf = breg;
01376   do {
01377     for (i = 0; (i < frames) && (cpf < cp_stack_bottom); i++) {
01378       if ( cpf == bfreg )
01379         xsb_dbgmsg((LOG_DEBUG,"bfreg"));
01380       analyze_cpf(cpf, &length, &type);
01381       print_cpf(cpf, length, type);
01382       cpf = cpf + length;
01383     }
01384     if (cpf < cp_stack_bottom) {
01385       fprintf(stddbg, "more (y/n)?  ");
01386       scanf("%c", &ans);
01387       skip_to_nl();
01388     }
01389     else {
01390       fprintf(stddbg, EOS);
01391       ans = 'n';
01392     }
01393   } while (ans == 'y');
01394 }
01395 
01396 /*----------------------------------------------------------------------*/ 
01397 
01398 static void print_choice_points(CTXTdeclc int overlap)
01399 {
01400   int i, last = 0;
01401   char ans = 'y';
01402   CPtr cp_stack_bottom = (CPtr)tcpstack.high;
01403  
01404   for (i = -overlap ; (i < 0) ; i++) {
01405     if ((breg+i) == bfreg) xsb_dbgmsg((LOG_DEBUG,"bfreg"));
01406     print_cp_cell("CP stack", breg+i, cell(breg+i));
01407   }
01408   xsb_dbgmsg((LOG_DEBUG,"breg"));
01409   do {
01410     for (i = last;
01411          (i <= last + STRIDESIZE) && (breg+i <= cp_stack_bottom);
01412          i++) {
01413       if ( (breg + i) == bfreg ) xsb_dbgmsg((LOG_DEBUG,"bfreg"));
01414       print_cp_cell("CP stack", breg+i, cell(breg+i));
01415       if ( (breg + i) == cp_stack_bottom ) fprintf(stddbg, EOS);
01416     }
01417     if (breg+i < cp_stack_bottom) {
01418       last = last + STRIDESIZE;
01419       fprintf(stddbg, "more (y/n)?  ");
01420       scanf("%c", &ans);
01421       skip_to_nl();
01422     }
01423     else
01424       ans = 'n';
01425   } while (ans == 'y');
01426 }
01427 
01428 /*----------------------------------------------------------------------*/ 
01429 
01430 /* Needs to change when new xwam stacks are introduced.  */
01431 static void print_heap(int overlap)     /* Heap grows up */
01432 {
01433   int i, offset = 0;
01434   char ans = 'y';
01435 
01436   for (i = overlap; (i > 0); i--) {
01437     print_cell("Heap", hreg+i, cell(hreg+i), NULL);
01438   }
01439   xsb_dbgmsg((LOG_DEBUG,"hreg"));
01440   while (ans == 'y' && hreg-i > (CPtr) glstack.low) {
01441     for (i = 0
01442            ;(i <= STRIDESIZE && hreg-(offset+i) >= (CPtr) glstack.low) 
01443            ; i++) {
01444       if ( (hreg - (offset+i)) == hfreg ) xsb_dbgmsg((LOG_DEBUG,"hfreg"));
01445       if ( (hreg - (offset+i)) == hbreg ) xsb_dbgmsg((LOG_DEBUG,"hbreg"));
01446       print_cell("Heap", hreg-(offset+i), cell(hreg-(offset+i)), NULL);
01447       if ( (hreg-(offset+i)) == (CPtr) glstack.low ) 
01448         xsb_dbgmsg((LOG_DEBUG,"bottom"));
01449     }
01450     if ( (hreg-(offset+i)) != (CPtr) glstack.low ) {
01451       offset += STRIDESIZE;
01452       fprintf(stddbg, "more (y/n)?  ");
01453       scanf("%c", &ans);
01454       skip_to_nl();
01455     }
01456   }
01457 }
01458 
01459 static void print_status(CTXTdecl)
01460 {
01461   xsb_dbgmsg((LOG_DEBUG,"     ereg: 0x%p", ereg));
01462   xsb_dbgmsg((LOG_DEBUG,"    ebreg: 0x%p", ebreg));
01463   xsb_dbgmsg((LOG_DEBUG,"     breg: 0x%p", breg));
01464   xsb_dbgmsg((LOG_DEBUG,"     hreg: 0x%p", hreg));
01465   xsb_dbgmsg((LOG_DEBUG,"    hbreg: 0x%p", hbreg));
01466   xsb_dbgmsg((LOG_DEBUG,"    trreg: 0x%p", trreg));
01467   xsb_dbgmsg((LOG_DEBUG,"    cpreg: 0x%p", cpreg));
01468   xsb_dbgmsg((LOG_DEBUG,"    pcreg: 0x%p", pcreg));
01469 
01470   xsb_dbgmsg((LOG_DEBUG,"    efreg: 0x%p", efreg));
01471   xsb_dbgmsg((LOG_DEBUG,"    bfreg: 0x%p", bfreg));
01472   xsb_dbgmsg((LOG_DEBUG,"    hfreg: 0x%p", hfreg));
01473   xsb_dbgmsg((LOG_DEBUG,"   trfreg: 0x%p", trfreg));
01474   xsb_dbgmsg((LOG_DEBUG,"   pdlreg: 0x%p", pdlreg));
01475   xsb_dbgmsg((LOG_DEBUG,"  ptcpreg: 0x%p", ptcpreg));
01476   xsb_dbgmsg((LOG_DEBUG," delayreg: 0x%p", delayreg));
01477   xsb_dbgmsg((LOG_DEBUG,"neg_delay: %s", (neg_delay == FALSE) ? "False" : "True"));
01478   xsb_dbgmsg((LOG_DEBUG,"   level#: %d", level_num));
01479 
01480   xsb_dbgmsg((LOG_DEBUG,"\nPDL"));
01481   xsb_dbgmsg((LOG_DEBUG,"\tlow:       %p", pdl.low));
01482   xsb_dbgmsg((LOG_DEBUG,"\thigh:      %p", pdl.high));
01483   xsb_dbgmsg((LOG_DEBUG,"\tsize:      %ld", pdl.size)); /* JF: long */
01484   xsb_dbgmsg((LOG_DEBUG,"\tinit size: %ld", pdl.init_size)); /* JF: long */
01485 
01486   xsb_dbgmsg((LOG_DEBUG,"\nGlobal / Local Stack"));
01487   xsb_dbgmsg((LOG_DEBUG,"\tlow:       %p", glstack.low));
01488   xsb_dbgmsg((LOG_DEBUG,"\thigh:      %p", glstack.high));
01489   xsb_dbgmsg((LOG_DEBUG,"\tsize:      %ld", glstack.size)); /* JF: long */
01490   xsb_dbgmsg((LOG_DEBUG,"\tinit size: %ld", glstack.init_size)); /* JF: long */
01491 
01492   xsb_dbgmsg((LOG_DEBUG,"\nTrail / Choice Point Stack"));
01493   xsb_dbgmsg((LOG_DEBUG,"\tlow:       %p", tcpstack.low));
01494   xsb_dbgmsg((LOG_DEBUG,"\thigh:      %p", tcpstack.high));
01495   xsb_dbgmsg((LOG_DEBUG,"\tsize:      %ld", tcpstack.size)); /* JF: long */
01496   xsb_dbgmsg((LOG_DEBUG,"\tinit size: %ld", tcpstack.init_size)); /* JF: long */
01497 
01498   xsb_dbgmsg((LOG_DEBUG,"\nCompletion Stack"));
01499   xsb_dbgmsg((LOG_DEBUG,"\tlow:       %p", complstack.low));
01500   xsb_dbgmsg((LOG_DEBUG,"\thigh:      %p", complstack.high));
01501   xsb_dbgmsg((LOG_DEBUG,"\tsize:      %ld", complstack.size)); /* JF: long */
01502   xsb_dbgmsg((LOG_DEBUG,"\tinit size: %ld", complstack.init_size)); /* JF: long */
01503 }
01504 
01505 static void debug_interact(CTXTdecl)
01506 {
01507   char command, mod[32], name[32];
01508   Integer num, num1;
01509   Pair sym;
01510 
01511  again:
01512   fprintf(stddbg, "\n > ");  
01513   fflush(stddbg);
01514   scanf("%c", &command);
01515   switch (command) {
01516   case 'a':
01517     scanf("%s %x", name, &num);
01518     skip_to_nl();
01519     switch (name[0]) {
01520     case 'a':
01521       xsb_dbgmsg((LOG_DEBUG,"0x%x: 0x%x", num, *(Integer *)num));
01522       break;
01523     case 'r':
01524       print_cell("Reg", (CPtr)num, cell(reg+num), NULL);
01525       break;
01526     case 'v':
01527       print_cell("Var", (CPtr)num, cell(ereg-num), NULL);
01528       break;
01529     case 'd':
01530       print_cell("Addr", (CPtr)num, cell((CPtr)(num)), NULL);
01531       break;
01532     }
01533     goto again;
01534   case 'b':
01535     scanf("%s %s %d", mod, name, &num);
01536     skip_to_nl();
01537     sym = insert_module(0, mod);
01538     sym = insert(name, num, sym->psc_ptr, &num);
01539     set_spy(sym->psc_ptr, 0x80);
01540     goto again;
01541   case 'B':
01542     scanf("%d", &num);
01543     skip_to_nl();
01544     print_cpfs(CTXTc num);
01545     goto again;
01546   case 'c':
01547     scanf("%d", &num);
01548     skip_to_nl();
01549     print_choice_points(CTXTc num);
01550     goto again;
01551   case 'C':
01552     scanf("%d", &num);
01553     skip_to_nl();
01554     print_freeze_choice_points(CTXTc num);
01555     skip_to_nl();
01556     goto again;
01557   case 'd':
01558     skip_to_nl();
01559     dis(1);
01560     goto again;
01561   case 'D':
01562     skip_to_nl();
01563     fprintf(stddbg, "Delay List = ");
01564     print_delay_list(stddbg, delayreg);
01565     fprintf(stddbg, "\n");
01566     goto again;
01567   case 'e':
01568     scanf("%d", &num);
01569     skip_to_nl();
01570     tcpstack_realloc(CTXTc num);
01571     goto again;
01572   case 'E':
01573     scanf("%d", &num);
01574     skip_to_nl();
01575     print_local_stack(CTXTc num);
01576     goto again;
01577   case 'g':
01578     skip_to_nl();
01579     pil_step = hitrace_suspend_gl = call_step_gl = 0;
01580     compl_step = 1;
01581     break;
01582   case 'G':
01583     skip_to_nl();
01584     print_hide = hitrace_suspend_gl = compl_step = 1;
01585     pil_step = call_step_gl = 0;
01586     break;
01587   case 'h':
01588   case '?':
01589     skip_to_nl();
01590     print_help();
01591     goto again;
01592   case 'H':
01593     scanf("%d", &num);
01594     skip_to_nl();
01595     terry_print_heap(CTXTc num);
01596     goto again;
01597   case 'k':
01598     scanf("%d", &num);
01599     skip_to_nl();
01600     debug_ctr = num;
01601     flags[PIL_TRACE] = 1;
01602     break;
01603   case 'K':
01604     scanf("%d", &num);
01605     skip_to_nl();
01606     debug_ctr = num;
01607     print_hide = flags[PIL_TRACE] = 1;
01608     break;
01609   case 'l':
01610     skip_to_nl();
01611     pil_step = call_step_gl = hitrace_suspend_gl = 0;
01612     break;
01613   case 'L':
01614     skip_to_nl();
01615     pil_step = flags[PIL_TRACE] = call_step_gl = 0; 
01616     print_hide = hitrace_suspend_gl = 1;
01617     break;
01618   case 'M':
01619     skip_to_nl();
01620     print_statistics(CTXTc 1);
01621     goto again;
01622   case 'n':
01623     skip_to_nl();
01624     pil_step = hitrace_suspend_gl = 0;
01625     call_step_gl = 1;
01626     break;
01627   case 'N':
01628     skip_to_nl();
01629     pil_step = flags[PIL_TRACE] = flags[HITRACE] = call_step_gl = 0;
01630     print_hide = 1;
01631     break;
01632   case 'o':
01633     skip_to_nl();
01634     print_completion_stack(CTXT);
01635     goto again;
01636   case 'P':
01637     skip_to_nl();
01638     print_pdlstack(CTXT);
01639     goto again;
01640   case 'q':
01641   case 'x':
01642     xsb_exit("Debugging aborted by the user");
01643     break;
01644   case 'r':
01645     scanf("%d", &num);
01646     skip_to_nl();
01647     fprintf(stddbg, "Reg[%d] = ", num);
01648     printterm(stddbg, cell(reg+num), 8);
01649     fprintf(stddbg, "\n"); 
01650     fprintf(stddbg, "%lx\n",*(reg+num));
01651     goto again;
01652   case 'R':
01653     scanf("%d", &num);
01654     skip_to_nl(); 
01655     fprintf(stddbg, "Reg[%d] = %lx\n",num,*(reg+num));
01656     goto again;
01657   case 's':
01658     skip_to_nl();
01659     pil_step = 1;
01660     flags[PIL_TRACE] = 1;
01661     hitrace_suspend_gl = 0;
01662     break;
01663   case 'S':
01664     skip_to_nl(); 
01665     print_status(CTXT);
01666     goto again;
01667   case 'T': 
01668     scanf("%d", &num);
01669     skip_to_nl();
01670     print_trail(CTXTc num);
01671     goto again;
01672   case 'u':
01673     scanf("%s %s %d", mod, name, &num);
01674     skip_to_nl();
01675     sym = insert_module(0, mod);
01676     sym = insert(name, num, sym->psc_ptr, &num);
01677     set_spy(sym->psc_ptr, 0x00);
01678     goto again;
01679   case 'v':
01680     scanf("%d", &num);
01681     skip_to_nl();
01682     fprintf(stddbg, "Var[%d] = ", num);
01683     printterm(stddbg, cell(ereg-num), 8);
01684     fprintf(stddbg, "\n");
01685     goto again;
01686   case 'w':
01687     scanf("%d %x", &num1, &num);
01688     skip_to_nl();
01689     set_register_watch(num1, (CPtr)num);
01690     goto again;      
01691   case 'W':
01692     scanf("%x %x", &num1, &num);
01693     skip_to_nl();
01694     set_memory_watch(num1, num);
01695     goto again;      
01696   case '1':
01697     skip_to_nl();
01698     print_tables();
01699     goto again;
01700   case '2':
01701     scanf("%d",&num);
01702     skip_to_nl();
01703     fprintf(stddbg, "tabptr: 0x%p tabptrval: 0x%lx\n",
01704             ((CPtr) (pdl.low)) + num,
01705             *(((CPtr) (pdl.low)) + num));
01706     goto again;
01707   case '\n':
01708     break;
01709   default:
01710     skip_to_nl();
01711     fprintf(stddbg, "Unknown command\n");
01712     goto again;
01713   }
01714   return;
01715 }
01716 
01717 #endif /* DEBUG_VM */

Generated on Wed Jul 26 13:30:40 2006 for XSB by  doxygen 1.4.5