VIS

src/mc/mcDbg.c

Go to the documentation of this file.
00001 
00032 #include "mcInt.h"
00033 
00034 static char rcsid[] UNUSED = "$Id: mcDbg.c,v 1.43 2005/04/23 04:40:54 fabio Exp $";
00035 
00036 /*---------------------------------------------------------------------------*/
00037 /* Macro declarations                                                        */
00038 /*---------------------------------------------------------------------------*/
00039 
00040 
00043 /*---------------------------------------------------------------------------*/
00044 /* Static function prototypes                                                */
00045 /*---------------------------------------------------------------------------*/
00046 
00047 static void DebugID(McOptions_t *options, Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm);
00048 static void DebugTrueFalse(Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm);
00049 static void DebugBoolean(McOptions_t *options, Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray);
00050 static McPath_t * DebugEX(Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray);
00051 static McPath_t * DebugEU(Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray);
00052 static McPath_t * DebugEG(Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, McOptions_t *options);
00053 static void FsmStateDebugConvertedFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray);
00054 static void FsmPathDebugFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray);
00055 static void FsmPathDebugEXFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray);
00056 static void FsmPathDebugEUFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray);
00057 static void FsmPathDebugEGFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray);
00058 static void FsmPathDebugEFFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray);
00059 static void FsmPathDebugAXFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray);
00060 static void FsmPathDebugAFFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray);
00061 static void FsmPathDebugAGFormula(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray);
00062 static void FsmPathDebugAUFormula(McOptions_t *options, mdd_t *aState, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, array_t *careSetArray);
00063 
00067 /*---------------------------------------------------------------------------*/
00068 /* Definition of exported functions                                          */
00069 /*---------------------------------------------------------------------------*/
00070 
00071 /*---------------------------------------------------------------------------*/
00072 /* Definition of internal functions                                          */
00073 /*---------------------------------------------------------------------------*/
00074 
00098 int
00099 McFsmDebugFormula(
00100   McOptions_t *options,
00101   Ctlp_Formula_t *ctlFormula,
00102   Fsm_Fsm_t *modelFsm,
00103   array_t *careSetArray)
00104 {
00105   mdd_t *modelInitialStates = Fsm_FsmComputeInitialStates(modelFsm);
00106   mdd_t *goodStates = Ctlp_FormulaObtainLatestApprox(ctlFormula);
00107   mdd_t *badStates = mdd_and(modelInitialStates, goodStates, 1, 0);
00108   mdd_t *witnessSuccState;
00109   FILE *debugFile = McOptionsReadDebugFile(options);
00110   FILE *oldStdOut;
00111   FILE *oldStdErr;
00112   extern FILE *vis_stdpipe;
00113   char *nrOfTracesString;
00114   int nrOfTraces;   /* nr of debug traces that we output */
00115   int i;            /* counts debug traces               */
00116 
00117   mdd_free(modelInitialStates);
00118 
00119   oldStdOut = vis_stdout;
00120   oldStdErr = vis_stderr;
00121   
00122   nrOfTracesString = Cmd_FlagReadByName("nr_counterexamples");
00123   if(nrOfTracesString == NIL(char))
00124     nrOfTraces = 1;
00125   else
00126     nrOfTraces = atoi(nrOfTracesString);
00127   
00128   if (debugFile) {
00129     vis_stdpipe = debugFile;
00130     vis_stdout = vis_stdpipe;
00131    (void)fprintf(vis_stdpipe, "# MC: formula failed --- ");
00132     Ctlp_FormulaPrint(vis_stdpipe,Ctlp_FormulaReadOriginalFormula(ctlFormula));
00133     (void)fprintf(vis_stdpipe, "\n");
00134   } else if (McOptionsReadUseMore(options)){
00135     vis_stdpipe = popen("more", "w");
00136     vis_stdout = vis_stdpipe;
00137     vis_stderr = vis_stdpipe;
00138   }
00139   else
00140     vis_stdpipe = vis_stdout;
00141 
00142   for(i = 0; i < nrOfTraces; i++){
00143     (void)fprintf(vis_stdout, "# MC: Calling debugger for trace %d\n",
00144                   i+1);
00145     witnessSuccState = McComputeACloseState(badStates, goodStates, modelFsm);
00146     McFsmStateDebugFormula(options, ctlFormula, witnessSuccState, modelFsm,
00147                            careSetArray);
00148     (void)fprintf(vis_stdout, "\n");
00149 
00150     mdd_free(witnessSuccState);
00151   }
00152   mdd_free(badStates);
00153   mdd_free(goodStates);
00154 
00155   if (vis_stdout != oldStdOut && vis_stdout != debugFile)
00156     (void)pclose(vis_stdpipe);
00157 
00158   vis_stdout = oldStdOut;
00159   vis_stderr = oldStdErr;
00160 
00161   return 1;
00162 }
00163 
00175 void
00176 McFsmStateDebugFormula(
00177   McOptions_t *options,
00178   Ctlp_Formula_t *ctlFormula,
00179   mdd_t *aState,
00180   Fsm_Fsm_t *modelFsm,
00181   array_t *careSetArray)
00182 {
00183   Ctlp_Formula_t *originalFormula;
00184   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
00185 
00186   if ( ctlFormula == NIL(Ctlp_Formula_t) )
00187     return;
00188 
00189   if ( Ctlp_FormulaTestIsConverted( ctlFormula ) ) {
00190     FsmStateDebugConvertedFormula(options, ctlFormula, aState, modelFsm,
00191                                   careSetArray);
00192     return;
00193   }
00194 
00195   originalFormula = Ctlp_FormulaReadOriginalFormula( ctlFormula );
00196 
00197   switch ( Ctlp_FormulaReadType( ctlFormula ) ) {
00198 
00199     case Ctlp_ID_c :
00200       DebugID( options, ctlFormula, aState, modelFsm );
00201       break;
00202 
00203     case Ctlp_TRUE_c:
00204     case Ctlp_FALSE_c:
00205       DebugTrueFalse( ctlFormula, aState, modelFsm );
00206       break;
00207 
00208     case Ctlp_EQ_c:
00209     case Ctlp_XOR_c:
00210     case Ctlp_THEN_c:
00211     case Ctlp_NOT_c:
00212     case Ctlp_AND_c:
00213     case Ctlp_OR_c:
00214       DebugBoolean(options, ctlFormula, aState, modelFsm, careSetArray);
00215       break;
00216 
00217     case Ctlp_EX_c:
00218     case Ctlp_EU_c:
00219     case Ctlp_EG_c:
00220       if ( !McStateSatisfiesFormula( ctlFormula, aState ) ) {
00221         mdd_t *passStates = Ctlp_FormulaObtainLatestApprox(ctlFormula);
00222         mdd_t *closeState;
00223         Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm);
00224         array_t *PSVars = Fsm_FsmReadPresentStateVars(modelFsm);
00225         McStateFailsFormula(aState, originalFormula, debugLevel, modelFsm);
00226         if (mdd_is_tautology(passStates, 0)) {
00227           fprintf(vis_stdout,
00228                   "--No state satisfies the formula\n");
00229           mdd_free(passStates);
00230           break;
00231         }
00232         fprintf(vis_stdout,
00233                 "--A simple counter example does not exist since it\n");
00234         fprintf(vis_stdout,
00235                 "  requires generating all paths from the state\n");
00236         fprintf(vis_stdout,
00237                 "--A state at minimum distance satisfying the formula is\n");
00238         closeState = McComputeACloseState(passStates, aState, modelFsm);
00239         mdd_free(passStates);
00240         Mc_MintermPrint(closeState, PSVars, modelNetwork);
00241         mdd_free(closeState);
00242         break;
00243       }
00244       else {
00245         McPath_t *witnessPath = NIL(McPath_t);
00246         if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EX_c ) {
00247           witnessPath = DebugEX(ctlFormula, aState, modelFsm, careSetArray);
00248         }
00249         else if  ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EU_c ) {
00250           witnessPath = DebugEU(ctlFormula, aState, modelFsm, careSetArray);
00251         }
00252         else {
00253           witnessPath = DebugEG(ctlFormula, aState, modelFsm, careSetArray,
00254                                 options);
00255         }
00256 
00257         FsmPathDebugFormula(options, ctlFormula, modelFsm, witnessPath,
00258                             careSetArray);
00259         McPathFree( witnessPath );
00260       }
00261       break;
00262 
00263     case Ctlp_Cmp_c:
00264     case Ctlp_Init_c:
00265     case Ctlp_FwdU_c:
00266     case Ctlp_FwdG_c:
00267     case Ctlp_EY_c:
00268     case Ctlp_EH_c:
00269       break;
00270 
00271     default: {
00272       fail("Bad switch in debugging normal formula\n");
00273     }
00274   }
00275 }
00276 
00277 
00278 
00279 
00301 McPath_t *
00302 McBuildFairPath(
00303   mdd_t *startState,
00304   mdd_t *invariantStates,
00305   array_t *arrayOfOnionRings,
00306   Fsm_Fsm_t *modelFsm,
00307   array_t *careSetArray,
00308   Mc_VerbosityLevel verbosity,
00309   Mc_DcLevel dcLevel,
00310   Mc_FwdBwdAnalysis fwdBwd )
00311 {
00312   mdd_t *tmpState;
00313   mdd_t *lastState;
00314   mdd_t *rootState = mdd_dup( startState );
00315   mdd_t *currentState = mdd_dup( rootState );
00316   mdd_t *stemState = NIL(mdd_t);
00317 
00318   array_t *tmpStemArray;
00319   array_t *dupArrayOfOnionRings = array_dup( arrayOfOnionRings );
00320   array_t *stemArray = array_alloc(mdd_t *, 0 );
00321   array_t *cycleArray = NIL(array_t);
00322   McPath_t *fairPath;
00323 
00324   array_insert_last( mdd_t *, stemArray, currentState );
00325 
00326   while ( array_n( dupArrayOfOnionRings ) > 0 ) {
00327     int index = McComputeOnionRingsWithClosestCore(currentState,
00328                         dupArrayOfOnionRings, modelFsm);
00329     array_t *onionRingsWithClosestFairness = array_fetch(array_t *,
00330                         dupArrayOfOnionRings, index);
00331     array_t *tmpArray = Mc_BuildPathToCore(currentState,
00332                                 onionRingsWithClosestFairness,
00333                                 modelFsm, McGreaterOrEqualZero_c);
00334 
00335     if ( stemState == NIL(mdd_t) ) {
00336       tmpState = array_fetch_last( mdd_t *, tmpArray );
00337       stemState = mdd_dup( tmpState );
00338     }
00339 
00340     tmpStemArray = McCreateMergedPath( stemArray, tmpArray );
00341     McNormalizeBddPointer(stemArray);
00342     McNormalizeBddPointer(tmpArray);
00343     mdd_array_free( stemArray );
00344     mdd_array_free( tmpArray );
00345     stemArray = tmpStemArray;
00346 
00347     currentState = array_fetch_last( mdd_t *, stemArray );
00348 
00349     tmpArray = McRemoveIndexedOnionRings( index, dupArrayOfOnionRings );
00350     array_free( dupArrayOfOnionRings );
00351     dupArrayOfOnionRings = tmpArray;
00352   } /* while onionrings left */
00353     array_free( dupArrayOfOnionRings );
00354 
00355   tmpState = GET_NORMAL_PT(array_fetch_last( mdd_t *, stemArray ));
00356   lastState = mdd_dup( tmpState );
00357 
00358   cycleArray = Mc_CompletePath(lastState, stemState, invariantStates, modelFsm,
00359                                careSetArray, verbosity, dcLevel, fwdBwd);
00360 
00361   if ( cycleArray != NIL(array_t) ) {
00362     mdd_free( lastState );
00363   }
00364   else {
00365     McPath_t *tmpFairPath;
00366     array_t *tmpStemArray;
00367 
00368     /*
00369      * Get shortest path to lastState
00370      */
00371     McNormalizeBddPointer(stemArray);
00372     mdd_array_free( stemArray );
00373     if ( !mdd_equal( rootState, lastState ) ) {
00374       stemArray = Mc_CompletePath(rootState, lastState, invariantStates,
00375                                   modelFsm, careSetArray, verbosity, dcLevel,
00376                                   fwdBwd);
00377     }
00378     else {
00379       stemArray = array_alloc( mdd_t *, 0 );
00380       tmpState = mdd_dup( rootState );
00381       array_insert_last( mdd_t *, stemArray, tmpState );
00382     }
00383     mdd_free( lastState );
00384 
00385     tmpState = GET_NORMAL_PT(array_fetch_last( mdd_t *, stemArray ));
00386     lastState = mdd_dup( tmpState );
00387 
00388     if ( mdd_equal( lastState, rootState ) ) {
00389       /*
00390        * Force a descent in the SCC DAG
00391       mdd_t *descendantState = McGetSuccessorInTarget(lastState,
00392                                                 invariantStates, modelFsm);
00393        */
00394       mdd_t *descendantState = McGetSuccessorInTargetAmongFairStates(lastState,
00395                                                 invariantStates, arrayOfOnionRings, modelFsm);
00396       tmpFairPath = McBuildFairPath(descendantState, invariantStates,
00397                                     arrayOfOnionRings, modelFsm,
00398                                     careSetArray,
00399                                     verbosity, dcLevel, fwdBwd);
00400       tmpStemArray = McCreateJoinedPath(stemArray,
00401                                         McPathReadStemArray(tmpFairPath));
00402       mdd_free( descendantState );
00403     }
00404     else {
00405       tmpFairPath = McBuildFairPath(lastState, invariantStates,
00406                                     arrayOfOnionRings, modelFsm,
00407                                     careSetArray, 
00408                                     verbosity, dcLevel, fwdBwd);
00409       tmpStemArray = McCreateMergedPath(stemArray,
00410                                         McPathReadStemArray(tmpFairPath));
00411     }
00412     mdd_free( lastState );
00413     McNormalizeBddPointer(stemArray);
00414     mdd_array_free( stemArray );
00415     stemArray = tmpStemArray;
00416 
00417     cycleArray = McMddArrayDuplicateFAFW( McPathReadCycleArray( tmpFairPath ) );
00418 
00419     McPathFree( tmpFairPath );
00420 
00421     if(Fsm_FsmReadUniQuantifyInputCube(modelFsm)) {
00422        mdd_t *S = GET_NORMAL_PT(array_fetch(mdd_t *, stemArray, 0));
00423        mdd_t *T = GET_NORMAL_PT(array_fetch(mdd_t *, stemArray, array_n(stemArray)-1));
00424        array_t *forwardRings = Mc_BuildForwardRingsWithInvariants(
00425                                 S, T, invariantStates, modelFsm);
00426        tmpStemArray = Mc_BuildPathFromCoreFAFW(
00427                                 T, forwardRings, modelFsm, McGreaterOrEqualZero_c);
00428        McNormalizeBddPointer(stemArray);
00429        mdd_array_free(stemArray);
00430        mdd_array_free(forwardRings);
00431        stemArray = tmpStemArray;
00432     }
00433   }
00434 
00435   mdd_free( rootState );
00436   mdd_free( stemState );
00437 
00438   fairPath = McPathAlloc();
00439   McPathSetStemArray( fairPath, stemArray );
00440   McPathSetCycleArray( fairPath, cycleArray );
00441 
00442   return fairPath;
00443 }
00444 
00445 
00446 /*---------------------------------------------------------------------------*/
00447 /* Definition of static functions                                            */
00448 /*---------------------------------------------------------------------------*/
00449 
00450 
00465 static void
00466 DebugID(
00467   McOptions_t *options,
00468   Ctlp_Formula_t *aFormula,
00469   mdd_t *aState,
00470   Fsm_Fsm_t *modelFsm)
00471 {
00472   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(aFormula); 
00473   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
00474 
00475   if ( McStateSatisfiesFormula( aFormula, aState ) ) {
00476     McStatePassesFormula( aState, originalFormula, debugLevel, modelFsm );
00477   }
00478   else {
00479     McStateFailsFormula( aState, originalFormula, debugLevel, modelFsm );
00480   }
00481 }
00482 
00490 static void
00491 DebugTrueFalse(
00492   Ctlp_Formula_t *aFormula,
00493   mdd_t *aState,
00494   Fsm_Fsm_t *modelFsm)
00495 {
00496   fprintf(vis_stdout, "--Nothing to debug for %s\n",
00497     ((Ctlp_FormulaReadType(aFormula) == Ctlp_TRUE_c) ? "TRUE\n" : "FALSE\n"));
00498 }
00499 
00511 static void
00512 DebugBoolean(
00513   McOptions_t *options,
00514   Ctlp_Formula_t *aFormula,
00515   mdd_t *aState,
00516   Fsm_Fsm_t *modelFsm,
00517   array_t *careSetArray)
00518 {
00519   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(aFormula);
00520   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( aFormula );
00521   Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( aFormula );
00522   McDbgLevel debugLevel = McOptionsReadDbgLevel(options);
00523 
00524   if (McStateSatisfiesFormula(aFormula, aState)) {
00525     McStatePassesFormula(aState, originalFormula, debugLevel, modelFsm);
00526   } else {
00527     McStateFailsFormula(aState, originalFormula, debugLevel, modelFsm);
00528   }
00529 
00530   /* We always debug the first (left) child. */
00531   McFsmStateDebugFormula(options, lFormula, aState, modelFsm, careSetArray);
00532 
00533   /* What we do for the second child depends on the type of the formula.
00534    * For Ctlp_AND_c, Ctlp_OR_c, Ctlp_THEN_c the right child may not be
00535    * needed.  With early termination, the right child may not have the
00536    * information required to produce a counterexample;  hence, its debugging
00537    * is not optional.  (We may get incorrect answers.) 
00538    */
00539   if (Ctlp_FormulaReadType(aFormula) == Ctlp_AND_c) {
00540     /* If aFormula fails and aState does not satisfy lFormula
00541      * 1. The information about aState at the right child is not
00542      *    necessarilty correct.  (aState was a don't care state.)
00543      * 2. A counterexample to lFormula is a counterexample to
00544      *    aFormula.
00545      * So, if aFormula fails, we should debug the right child only if
00546      * aState satisfies lFormula.
00547      * If, on the other hand, aFormula passes, then aState must satisfy
00548      * lFormula, and we need to witness both lFormula and rFormula.
00549      */
00550     if (McStateSatisfiesFormula(lFormula, aState)) {
00551       McFsmStateDebugFormula(options, rFormula, aState, modelFsm,
00552                              careSetArray);
00553     }
00554   } else if (Ctlp_FormulaReadType(aFormula) == Ctlp_OR_c) {
00555     /* if aFormula passes, we should debug the right child only if
00556      * aState does not satisfy lFormula.
00557      * If, on the other hand, aFormula fails, then aState may not satisfy
00558      * lFormula, and we need to produce counterexamples for both lFormula
00559      * and rFormula.
00560      */
00561     if (!McStateSatisfiesFormula(lFormula, aState)) {
00562       McFsmStateDebugFormula(options, rFormula, aState, modelFsm,
00563                              careSetArray);
00564     }
00565   } else if (Ctlp_FormulaReadType(aFormula) == Ctlp_THEN_c) {
00566     /* This case is like the OR, with the polarity of the left
00567      * left child reversed.
00568      */
00569     if (McStateSatisfiesFormula(lFormula, aState)) {
00570       McFsmStateDebugFormula(options, rFormula, aState, modelFsm,
00571                              careSetArray);
00572     }
00573   } else if (Ctlp_FormulaReadType(aFormula) != Ctlp_NOT_c) {
00574     /* For Ctlp_EQ_c and Ctlp_XOR_c both children must be debugged. */
00575     McFsmStateDebugFormula(options, rFormula, aState, modelFsm, careSetArray);
00576   }
00577 }
00578 
00589 static McPath_t *
00590 DebugEX(
00591   Ctlp_Formula_t *aFormula,
00592   mdd_t *aState,
00593   Fsm_Fsm_t *modelFsm,
00594   array_t *careSetArray)
00595 {
00596   mdd_t *aDupState = mdd_dup( aState );
00597   mdd_t *aStateSuccs;
00598   mdd_t *statesSatisfyingLeftFormula;
00599   mdd_t *targetStates;
00600   mdd_t *witnessSuccState;
00601   Ctlp_Formula_t *lFormula;
00602   McPath_t *witnessPath = McPathAlloc();
00603   array_t *stemArray = array_alloc( mdd_t *, 0 );
00604   Img_ImageInfo_t * imageInfo = Fsm_FsmReadOrCreateImageInfo(modelFsm, 0, 1);
00605 
00606   /*
00607    * By using careSet here, can end up with unreachable successors
00608    */
00609   aStateSuccs = Img_ImageInfoComputeImageWithDomainVars(imageInfo,
00610                         aState, aState, careSetArray);
00611 
00612   lFormula = Ctlp_FormulaReadLeftChild( aFormula );
00613   statesSatisfyingLeftFormula = Ctlp_FormulaObtainLatestApprox( lFormula );
00614 
00615   targetStates = mdd_and( aStateSuccs, statesSatisfyingLeftFormula, 1, 1 );
00616   mdd_free( aStateSuccs ); mdd_free( statesSatisfyingLeftFormula );
00617 
00618   witnessSuccState = Mc_ComputeACloseState( targetStates, aState, modelFsm );
00619   mdd_free( targetStates );
00620 
00621   array_insert_last( mdd_t *, stemArray, aDupState );
00622   array_insert_last( mdd_t *, stemArray, witnessSuccState );
00623 
00624   McPathSetStemArray( witnessPath, stemArray );
00625 
00626   return witnessPath;
00627 }
00628 
00639 static McPath_t *
00640 DebugEU(
00641   Ctlp_Formula_t *aFormula,
00642   mdd_t *aState,
00643   Fsm_Fsm_t *modelFsm,
00644   array_t *careSetArray)
00645 {
00646   McPath_t *witnessPath = McPathAlloc();
00647   array_t *OnionRings = (array_t *) Ctlp_FormulaReadDebugData( aFormula );
00648   array_t *pathToCore = Mc_BuildPathToCore(aState, OnionRings, 
00649                                            modelFsm,
00650                                            McGreaterOrEqualZero_c );
00651 
00652   McPathSetStemArray( witnessPath, pathToCore );
00653 
00654   return witnessPath;
00655 }
00656 
00668 static McPath_t *
00669 DebugEG(
00670   Ctlp_Formula_t *aFormula,
00671   mdd_t *aState,
00672   Fsm_Fsm_t *modelFsm,
00673   array_t *careSetArray,
00674   McOptions_t *options)
00675 {
00676   array_t *arrayOfOnionRings = (array_t *) Ctlp_FormulaReadDebugData(aFormula);
00677   mdd_t *invariantMdd = Ctlp_FormulaObtainLatestApprox( aFormula );
00678   McPath_t *fairPath = McBuildFairPath(aState, invariantMdd, arrayOfOnionRings,
00679                                         modelFsm, careSetArray,
00680                                         McOptionsReadVerbosityLevel(options),
00681                                         McOptionsReadDcLevel(options),
00682                                         McOptionsReadFwdBwd(options));
00683   mdd_free( invariantMdd );
00684 
00685   return fairPath;
00686 }
00687 
00688 
00703 static void
00704 FsmStateDebugConvertedFormula(
00705   McOptions_t *options,
00706   Ctlp_Formula_t *ctlFormula,
00707   mdd_t *aState,
00708   Fsm_Fsm_t *modelFsm,
00709   array_t *careSetArray)
00710 {
00711   McPath_t *witnessPath;
00712   McPath_t *counterExamplePath;
00713 
00714   Ctlp_Formula_t *originalFormula =Ctlp_FormulaReadOriginalFormula(ctlFormula);
00715   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
00716   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
00717 
00718   if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EU_c ) {
00719     if ( !McStateSatisfiesFormula( ctlFormula, aState ) ) {
00720       mdd_t *passStates = Ctlp_FormulaObtainLatestApprox(ctlFormula);
00721       mdd_t *closeState;
00722       Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm);
00723       array_t *PSVars = Fsm_FsmReadPresentStateVars(modelFsm);
00724       McStateFailsFormula( aState, originalFormula, debugLevel, modelFsm );
00725       if (mdd_is_tautology(passStates, 0)) {
00726           fprintf(vis_stdout,
00727                   "--No state satisfies the formula\n");
00728       } else {
00729         fprintf(vis_stdout,
00730                 "\n--A simple counter example does not exist since it\n");
00731         fprintf(vis_stdout,
00732                 "  requires generating all paths from the state\n");
00733         fprintf(vis_stdout,
00734                 "--A state at minimum distance satisfying the formula is\n");
00735         closeState = McComputeACloseState(passStates, aState, modelFsm);
00736         Mc_MintermPrint(closeState, PSVars, modelNetwork);
00737         mdd_free(closeState);
00738       }
00739       mdd_free(passStates);
00740     }
00741     else {
00742       witnessPath = DebugEU(ctlFormula, aState, modelFsm, careSetArray);
00743       FsmPathDebugEFFormula(options, ctlFormula, modelFsm, witnessPath,
00744                             careSetArray);
00745       McPathFree( witnessPath );
00746     }
00747     return;
00748   }
00749 
00750   /*
00751    * The original formula must be an AX,AF,AG, or AU formula
00752    */
00753   if ( McStateSatisfiesFormula( ctlFormula, aState ) ) {
00754     McStatePassesFormula( aState, originalFormula, debugLevel, modelFsm );
00755     fprintf(vis_stdout,
00756             "--A simple witness does not exist since it requires\n");
00757     fprintf(vis_stdout, "  generating all paths from the state\n");
00758     return;
00759   }
00760 
00761   switch ( Ctlp_FormulaReadType( lFormula ) ) {
00762     case Ctlp_EX_c: {
00763       counterExamplePath = DebugEX(lFormula, aState, modelFsm, careSetArray);
00764       FsmPathDebugAXFormula(options, ctlFormula, modelFsm, counterExamplePath,
00765                             careSetArray);
00766       McPathFree( counterExamplePath );
00767       break;
00768     }
00769 
00770     case Ctlp_EG_c: {
00771       counterExamplePath = DebugEG(lFormula, aState, modelFsm, careSetArray,
00772                                    options);
00773       FsmPathDebugAFFormula(options, ctlFormula, modelFsm, counterExamplePath,
00774                             careSetArray);
00775       McPathFree( counterExamplePath );
00776       break;
00777     }
00778 
00779     case Ctlp_EU_c: {
00780       counterExamplePath = DebugEU(lFormula, aState, modelFsm, careSetArray);
00781       FsmPathDebugAGFormula(options, ctlFormula, modelFsm, counterExamplePath,
00782                             careSetArray);
00783       McPathFree( counterExamplePath );
00784       break;
00785     }
00786 
00787     case Ctlp_OR_c: {
00788       /*
00789        * need special functions bcoz of two possibilities
00790        */
00791       FsmPathDebugAUFormula(options, aState, ctlFormula, modelFsm,
00792                             careSetArray);
00793       break;
00794     }
00795 
00796     default: fail("Bad formula type in handling converted operator\n");
00797   }
00798 }
00799 
00800 
00808 static void
00809 FsmPathDebugFormula(
00810   McOptions_t *options,
00811   Ctlp_Formula_t *ctlFormula,
00812   Fsm_Fsm_t *modelFsm,
00813   McPath_t *witnessPath,
00814   array_t *careSetArray)
00815 {
00816   switch ( Ctlp_FormulaReadType( ctlFormula ) ) {
00817     case Ctlp_EX_c: {
00818       FsmPathDebugEXFormula(options, ctlFormula, modelFsm, witnessPath,
00819                             careSetArray);
00820       break;
00821     }
00822 
00823     case Ctlp_EU_c: {
00824       FsmPathDebugEUFormula(options, ctlFormula, modelFsm, witnessPath,
00825                             careSetArray);
00826       break;
00827     }
00828 
00829     case Ctlp_EG_c: {
00830       FsmPathDebugEGFormula(options, ctlFormula, modelFsm, witnessPath,
00831                             careSetArray);
00832       break;
00833     }
00834     default: {
00835       fail("bad switch in converting converted formula\n");
00836     }
00837   }
00838 }
00839 
00847 static void
00848 FsmPathDebugEXFormula(
00849   McOptions_t *options,
00850   Ctlp_Formula_t *ctlFormula,
00851   Fsm_Fsm_t *modelFsm,
00852   McPath_t *witnessPath,
00853   array_t *careSetArray)
00854 {
00855   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
00856   array_t *witnessArray = McPathReadStemArray( witnessPath );
00857   mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 );
00858   char *firstStateName = Mc_MintermToString(firstState, PSVars,
00859                                 Fsm_FsmReadNetwork(modelFsm));
00860   Ctlp_Formula_t *lChild = Ctlp_FormulaReadLeftChild( ctlFormula );
00861   char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula );
00862   boolean printInputs = McOptionsReadPrintInputs( options );
00863   mdd_t *secondlastState;
00864   if(array_n(witnessArray)<2)
00865     {
00866       fprintf(vis_stdout,"witnessArray has less than two elements, return\n");
00867       return;
00868     }
00869   secondlastState= array_fetch( mdd_t *, witnessArray, (array_n(witnessArray)-1) );
00870 
00871   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
00872     fprintf(vis_stdout, "--State\n%spasses EX formula\n\n",
00873             firstStateName); 
00874   else
00875     fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName,
00876             ctlFormulaText );
00877   
00878   FREE(firstStateName);
00879   FREE(ctlFormulaText);
00880   
00881   
00882   switch ( McOptionsReadDbgLevel( options ) ) {
00883   case McDbgLevelMin_c:
00884   case McDbgLevelMinVerbose_c:
00885   case McDbgLevelMax_c:
00886     fprintf(vis_stdout, " --Counter example begins\n");
00887     Mc_PrintPath( witnessArray, modelFsm, printInputs );
00888     fprintf(vis_stdout, " --Counter example ends\n\n");
00889     McFsmStateDebugFormula(options, lChild, secondlastState, modelFsm,
00890                            careSetArray);
00891     break;
00892   case McDbgLevelInteractive_c:
00893     fprintf(vis_stdout, " --Counter example begins\n");
00894     Mc_PrintPath( witnessArray, modelFsm, printInputs );
00895     fprintf(vis_stdout, " --Counter example ends\n\n");
00896     if (McQueryContinue("Continue debugging EX formula? (1-yes,0-no)\n")) 
00897     McFsmStateDebugFormula(options, lChild, secondlastState, modelFsm,
00898                              careSetArray);
00899     break;
00900   default: 
00901     fail("Reached bad switch in FsmPathDebugEXFormula\n");
00902   }
00903 }
00904 
00912 static void
00913 FsmPathDebugEUFormula(
00914   McOptions_t *options,
00915   Ctlp_Formula_t *ctlFormula,
00916   Fsm_Fsm_t *modelFsm,
00917   McPath_t *witnessPath,
00918   array_t *careSetArray)
00919 {
00920   char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula );
00921   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
00922   Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( ctlFormula );
00923   char *lFormulaText = Ctlp_FormulaConvertToString( lFormula );
00924   char *rFormulaText = Ctlp_FormulaConvertToString( rFormula );
00925   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
00926   array_t *witnessArray = McPathReadStemArray( witnessPath );
00927   mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 );
00928   mdd_t *lastState = GET_NORMAL_PT(array_fetch_last( mdd_t *, witnessArray ));
00929   char *firstStateName = Mc_MintermToString(firstState, PSVars,
00930                                             Fsm_FsmReadNetwork(modelFsm));
00931   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
00932   boolean printInputs = McOptionsReadPrintInputs( options );
00933 
00934  if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
00935    fprintf(vis_stdout, "--State\n%spasses EU formula\n\n",
00936            firstStateName); 
00937  else
00938    fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName,
00939            ctlFormulaText );
00940 
00941  FREE(firstStateName);
00942  FREE(ctlFormulaText);
00943  
00944   switch ( debugLevel ) {
00945   case McDbgLevelMin_c:
00946   case McDbgLevelMinVerbose_c:
00947       if ( array_n(witnessArray ) == 1 ) {
00948         if( debugLevel != McDbgLevelMin_c )
00949           fprintf(vis_stdout, "since %s is true at this state", rFormulaText);
00950         McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
00951                                careSetArray);
00952       }
00953       else {
00954         if( debugLevel != McDbgLevelMin_c )
00955           fprintf(vis_stdout, "--Path on which %s is true till %s is true\n",
00956                   lFormulaText, rFormulaText);
00957         fprintf(vis_stdout, " --Counter example begins\n");
00958         Mc_PrintPath(witnessArray, modelFsm, printInputs);
00959         fprintf(vis_stdout, " --Counter example ends\n\n");
00960         McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
00961                                careSetArray);
00962       }
00963     break;
00964   case McDbgLevelMax_c:
00965   case McDbgLevelInteractive_c: 
00966     if ( array_n(witnessArray ) == 1 ) {
00967       fprintf(vis_stdout, "since %s is true at this state", rFormulaText);
00968       McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
00969                              careSetArray); 
00970     }
00971     else {
00972       int i;
00973       fprintf(vis_stdout, "--Path on which %s is true till %s is true\n",
00974                   lFormulaText, rFormulaText);
00975       fprintf(vis_stdout, " --Counter example begins\n");
00976       Mc_PrintPath(witnessArray,modelFsm,printInputs);
00977       fprintf(vis_stdout, " --Counter example ends\n\n");
00978       for( i=0 ; i < ( array_n( witnessArray ) - 1 ); i++ ) {
00979         mdd_t *aState = array_fetch( mdd_t *, witnessArray, i );
00980       
00981         if (debugLevel == McDbgLevelMax_c ||
00982             (debugLevel == McDbgLevelInteractive_c &&
00983              McQueryContinue(
00984                "Continue debugging EU formula? (1-yes,0-no)\n"))) {
00985           McFsmStateDebugFormula(options, lFormula, aState, modelFsm,
00986                                  careSetArray);
00987         }
00988     }
00989       McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
00990                              careSetArray);
00991     }
00992     break;
00993   default: 
00994     fail("Should not be here - bad switch in debugging EU formula\n");
00995   }
00996   FREE(lFormulaText);
00997   FREE(rFormulaText);
00998 }
01006 static void
01007 FsmPathDebugEGFormula(
01008   McOptions_t *options,
01009   Ctlp_Formula_t *ctlFormula,
01010   Fsm_Fsm_t *modelFsm,
01011   McPath_t *witnessPath,
01012   array_t *careSetArray)
01013 {
01014   mdd_t *firstState;
01015   char *firstStateName;
01016   array_t *witnessArray;
01017   char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula );
01018   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
01019   array_t *stemArray = McPathReadStemArray( witnessPath );
01020   array_t *cycleArray = McPathReadCycleArray( witnessPath );
01021   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
01022   char *lFormulaText = Ctlp_FormulaConvertToString( lFormula );
01023   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
01024   boolean printInputs = McOptionsReadPrintInputs( options );
01025 
01026   witnessArray = McCreateMergedPath( stemArray, cycleArray );
01027   firstState = array_fetch( mdd_t *, witnessArray, 0 );
01028   firstStateName = Mc_MintermToString(firstState, PSVars,Fsm_FsmReadNetwork(modelFsm));
01029   
01030   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
01031     fprintf(vis_stdout, "--State\n%spasses EG formula\n\n",
01032             firstStateName); 
01033   else
01034     fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName,
01035             ctlFormulaText );
01036  
01037   FREE(firstStateName);
01038   FREE(ctlFormulaText);
01039 
01040   switch ( debugLevel ) {
01041   case McDbgLevelMin_c:
01042   case McDbgLevelMinVerbose_c: {
01043     McPath_t *normalPath = McPathNormalize( witnessPath );
01044     array_t *stem = McPathReadStemArray( normalPath );
01045     array_t *cycle = McPathReadCycleArray( normalPath );
01046 
01047     if(debugLevel != McDbgLevelMin_c)
01048       fprintf(vis_stdout, "--Witness is a fair path where %s is always true\n",
01049               lFormulaText);
01050     
01051     FREE( lFormulaText );
01052     fprintf(vis_stdout, " --Counter example begins\n");
01053     (void) fprintf( vis_stdout, "--Fair path stem:\n");
01054     Mc_PrintPath( stem, modelFsm, printInputs );
01055     
01056     (void) fprintf( vis_stdout, "--Fair path cycle:\n");
01057     Mc_PrintPath( cycle, modelFsm, printInputs );
01058     fprintf(vis_stdout, "\n");
01059     fprintf(vis_stdout, " --Counter example ends\n\n");
01060     McPathFree( normalPath );
01061     break;
01062   }
01063   case McDbgLevelMax_c:
01064   case McDbgLevelInteractive_c: {
01065     McPath_t *normalPath = McPathNormalize( witnessPath );
01066     array_t *stem = McPathReadStemArray( normalPath );
01067     array_t *cycle = McPathReadCycleArray( normalPath );
01068     int i;
01069     fprintf(vis_stdout, "--Witness is a fair path where %s is always true\n",
01070               lFormulaText);
01071     fprintf(vis_stdout, " --Counter example begins\n");
01072     (void) fprintf( vis_stdout, "--Fair path stem:\n");
01073     Mc_PrintPath( stem, modelFsm, printInputs );
01074     (void) fprintf( vis_stdout, "--Fair path cycle:\n");
01075     Mc_PrintPath( cycle, modelFsm, printInputs );
01076     fprintf(vis_stdout, " --Counter example ends\n\n");
01077     for( i=0 ; i < ( array_n( witnessArray )-1  ); i++ ) {
01078       mdd_t *aState = array_fetch( mdd_t *, witnessArray, i );
01079    
01080       if (debugLevel == McDbgLevelMax_c ||
01081           (debugLevel == McDbgLevelInteractive_c &&
01082            McQueryContinue(
01083              "--Continue debugging EG formula? (1-yes,0-no)\n"))) {
01084         McFsmStateDebugFormula(options, lFormula, aState, modelFsm,
01085                                careSetArray);
01086       }
01087     }
01088     break;
01089   }
01090   default:
01091     fail("Bad switch in FsmPathDebugEGFormula\n");
01092   }
01093   McNormalizeBddPointer(witnessArray);
01094   mdd_array_free( witnessArray );
01095 }
01096 
01104 static void
01105 FsmPathDebugEFFormula(
01106   McOptions_t *options,
01107   Ctlp_Formula_t *ctlFormula,
01108   Fsm_Fsm_t *modelFsm,
01109   McPath_t *witnessPath,
01110   array_t *careSetArray)
01111 {
01112   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula);
01113   char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula );
01114 
01115   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
01116   array_t *witnessArray = McPathReadStemArray( witnessPath );
01117 
01118   mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 );
01119   mdd_t *lastState = array_fetch_last( mdd_t *, witnessArray );
01120   char *firstStateName = Mc_MintermToString(firstState, PSVars,
01121                                         Fsm_FsmReadNetwork(modelFsm));
01122 
01123   Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( ctlFormula );
01124   Ctlp_Formula_t *rOriginalFormula = Ctlp_FormulaReadOriginalFormula(rFormula);
01125   char *rOriginalFormulaText = Ctlp_FormulaConvertToString( rOriginalFormula );
01126   char *rFormulaText = Ctlp_FormulaConvertToString( rFormula );
01127   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
01128   boolean printInputs = McOptionsReadPrintInputs( options );
01129 
01130   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
01131     fprintf(vis_stdout, "--State\n%spasses EF formula\n\n",
01132             firstStateName); 
01133   else
01134     fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName,
01135           originalFormulaText );
01136   
01137   FREE(firstStateName);
01138   FREE(originalFormulaText);
01139 
01140   switch ( debugLevel ) {
01141   case McDbgLevelMin_c:
01142   case McDbgLevelMinVerbose_c:
01143     if ( array_n(witnessArray ) == 1 ) {
01144       if( debugLevel !=  McDbgLevelMin_c)
01145         fprintf(vis_stdout, "since %s is true at this state\n",
01146                 rOriginalFormulaText);
01147       
01148       FREE( rOriginalFormulaText );
01149       McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
01150                              careSetArray);
01151     }
01152     else {
01153       if( debugLevel !=  McDbgLevelMin_c)
01154         fprintf(vis_stdout,
01155                 "--Witness is a path to a state where %s is finally true\n",
01156                 rOriginalFormulaText);
01157       (void) fprintf( vis_stdout, "\n--Fair path stem:\n");
01158       FREE( rOriginalFormulaText );
01159       fprintf(vis_stdout, " --Counter example begins\n");
01160       Mc_PrintPath( witnessArray, modelFsm, printInputs );
01161       fprintf(vis_stdout, " --Counter example ends\n\n");
01162     }
01163     break;
01164   case McDbgLevelMax_c:
01165   case McDbgLevelInteractive_c:
01166     if ( array_n(witnessArray ) == 1 ) {
01167       McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
01168                              careSetArray);
01169     }
01170     else
01171       {
01172         fprintf(vis_stdout,
01173                 "--Witness is a path to a state where %s is finally true\n",
01174                 rOriginalFormulaText);
01175         fprintf(vis_stdout, " --Counter example begins\n");
01176       Mc_PrintPath( witnessArray, modelFsm, printInputs);
01177       fprintf(vis_stdout, " --Counter example ends\n\n");
01178       if (debugLevel == McDbgLevelMax_c ||
01179           (debugLevel == McDbgLevelInteractive_c &&
01180            McQueryContinue(
01181              "--Continue debugging EF formula? (1-yes,0-no)\n")))
01182         {
01183         McFsmStateDebugFormula(options, rFormula, lastState, modelFsm,
01184                                careSetArray);
01185         }
01186       }
01187     break;
01188   default:
01189     fail("bad switch in debugging EF\n");
01190   }
01191   FREE(rFormulaText);
01192 }
01193 
01201 static void
01202 FsmPathDebugAXFormula(
01203   McOptions_t *options,
01204   Ctlp_Formula_t *ctlFormula,
01205   Fsm_Fsm_t *modelFsm,
01206   McPath_t *counterExamplePath,
01207   array_t *careSetArray)
01208 {
01209   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula);
01210   char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula );
01211   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
01212   Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula );
01213   Ctlp_Formula_t *lllFormula = Ctlp_FormulaReadLeftChild( llFormula );
01214 
01215   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
01216   array_t *witnessArray = McPathReadStemArray( counterExamplePath );
01217   mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 );
01218   mdd_t *lastState = array_fetch( mdd_t *, witnessArray, 1 );
01219   char *firstStateName = Mc_MintermToString(firstState, PSVars,
01220                                             Fsm_FsmReadNetwork(modelFsm));
01221   boolean printInputs = McOptionsReadPrintInputs( options );
01222 
01223   
01224   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
01225     fprintf(vis_stdout, "--State\n%sfails AX formula\n\n",
01226             firstStateName); 
01227   else
01228       fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName,
01229           originalFormulaText );
01230 
01231   FREE(firstStateName);
01232   FREE(originalFormulaText);
01233 
01234   switch ( McOptionsReadDbgLevel( options ) ) {
01235   case McDbgLevelMin_c:
01236   case McDbgLevelMinVerbose_c:
01237   case McDbgLevelMax_c:
01238     fprintf(vis_stdout, " --Counter example begins\n"); 
01239     Mc_PrintPath( witnessArray, modelFsm, printInputs );
01240     fprintf(vis_stdout, " --Counter example ends\n\n");
01241     fprintf(vis_stdout, "\n");
01242     McFsmStateDebugFormula(options, lllFormula, lastState, modelFsm,
01243                            careSetArray);
01244     break;
01245   case McDbgLevelInteractive_c:
01246     fprintf(vis_stdout, " --Counter example begins\n");
01247     Mc_PrintPath( witnessArray, modelFsm, printInputs );
01248     fprintf(vis_stdout, " --Counter example ends\n\n");
01249     if ( McQueryContinue("Continue debugging EX formula? (1-yes,0-no)\n") ) {
01250       McFsmStateDebugFormula(options, lllFormula, lastState, modelFsm,
01251                              careSetArray);
01252     }
01253     break;
01254   default: 
01255     fail("Bad switch in FsmPathDebugAXFormula\n");
01256   }
01257 }
01258 
01266 static void
01267 FsmPathDebugAFFormula(
01268   McOptions_t *options,
01269   Ctlp_Formula_t *ctlFormula,
01270   Fsm_Fsm_t *modelFsm,
01271   McPath_t *counterExamplePath,
01272   array_t *careSetArray)
01273 {
01274   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula);
01275   char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula );
01276   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
01277   Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula );
01278   Ctlp_Formula_t *lllFormula = Ctlp_FormulaReadLeftChild( llFormula );
01279   Ctlp_Formula_t *lllOriginalFormula = Ctlp_FormulaReadOriginalFormula(
01280                                         lllFormula);
01281   char *lllOriginalFormulaText = Ctlp_FormulaConvertToString(
01282                                         lllOriginalFormula);
01283 
01284   mdd_t *firstState;
01285   array_t *witnessArray;
01286   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
01287   array_t *stemArray = McPathReadStemArray( counterExamplePath );
01288   array_t *cycleArray = McPathReadCycleArray( counterExamplePath );
01289   char *firstStateName;
01290   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
01291   boolean printInputs = McOptionsReadPrintInputs( options );
01292 
01293   witnessArray = McCreateMergedPath( stemArray, cycleArray );
01294   firstState = array_fetch( mdd_t *, witnessArray, 0 );
01295   firstStateName = Mc_MintermToString(firstState, PSVars,
01296                                         Fsm_FsmReadNetwork(modelFsm));
01297 
01298   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
01299     fprintf(vis_stdout, "--State\n%sfails AF formula\n\n",
01300             firstStateName); 
01301   else
01302     fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName,
01303             originalFormulaText );
01304   FREE(firstStateName);
01305   FREE(originalFormulaText);
01306 
01307   switch ( debugLevel ) {
01308   case McDbgLevelMin_c:
01309   case McDbgLevelMinVerbose_c: {
01310     McPath_t *normalPath = McPathNormalize( counterExamplePath );
01311     array_t *stem = McPathReadStemArray( normalPath );
01312     array_t *cycle = McPathReadCycleArray( normalPath );
01313     if( debugLevel !=  McDbgLevelMin_c)
01314       fprintf(vis_stdout, "--A fair path on which %s is always false:\n",
01315               lllOriginalFormulaText );
01316     
01317     fprintf(vis_stdout, " --Counter example begins\n");
01318     (void) fprintf( vis_stdout, "--Fair path stem:\n");
01319     Mc_PrintPath( stem, modelFsm, printInputs );
01320     
01321     (void) fprintf( vis_stdout, "--Fair path cycle:\n");
01322     Mc_PrintPath( cycle, modelFsm, printInputs );
01323     fprintf(vis_stdout, "\n");
01324     fprintf(vis_stdout, " --Counter example ends\n\n");
01325     McPathFree( normalPath );
01326     break;
01327   }
01328   case McDbgLevelMax_c:
01329   case McDbgLevelInteractive_c: {
01330     int i;
01331     McPath_t *normalPath = McPathNormalize( counterExamplePath );
01332     array_t *stem = McPathReadStemArray( normalPath );
01333     array_t *cycle = McPathReadCycleArray( normalPath );
01334     fprintf(vis_stdout, "--A fair path on which %s is always false:\n",
01335               lllOriginalFormulaText ); 
01336     fprintf(vis_stdout, " --Counter example begins\n");
01337     (void) fprintf( vis_stdout, "--Fair path stem:\n");
01338     Mc_PrintPath( stem, modelFsm, printInputs );
01339     
01340     (void) fprintf( vis_stdout, "--Fair path cycle:\n");
01341     Mc_PrintPath( cycle, modelFsm, printInputs );
01342     fprintf(vis_stdout, "\n");
01343     fprintf(vis_stdout, " --Counter example ends\n\n");
01344     McPathFree( normalPath );
01345     for( i=0 ; i < ( array_n( witnessArray )-1  ); i++ ) {
01346       mdd_t *aState = array_fetch( mdd_t *, witnessArray, i );
01347    
01348       if (debugLevel == McDbgLevelMax_c ||
01349           (debugLevel == McDbgLevelInteractive_c &&
01350            McQueryContinue(
01351              "--Continue debugging AF formula? (1-yes,0-no)\n"))) {
01352         McFsmStateDebugFormula(options, lllFormula, aState, modelFsm,
01353                                careSetArray);
01354       }
01355     }
01356 
01357     break;
01358   }
01359   default: {
01360     fail("Bad case in switch for debugging AF formula\n");
01361   }
01362   }
01363   McNormalizeBddPointer(witnessArray);
01364   mdd_array_free( witnessArray );
01365   FREE(lllOriginalFormulaText);
01366 }
01367 
01380 static void
01381 FsmPathDebugAGFormula(
01382   McOptions_t *options,
01383   Ctlp_Formula_t *ctlFormula,
01384   Fsm_Fsm_t *modelFsm,
01385   McPath_t *counterExamplePath,
01386   array_t *careSetArray)
01387 {
01388   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula);
01389   char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula );
01390   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
01391   Ctlp_Formula_t *lrFormula = Ctlp_FormulaReadRightChild( lFormula );
01392   Ctlp_Formula_t *lrlFormula = Ctlp_FormulaReadLeftChild( lrFormula );
01393   Ctlp_Formula_t *lrlOriginalFormula = Ctlp_FormulaReadOriginalFormula(
01394                                         lrlFormula);
01395   char *lrlOriginalFormulaText = Ctlp_FormulaConvertToString(
01396                                         lrlOriginalFormula);
01397 
01398   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
01399   array_t *witnessArray = McPathReadStemArray( counterExamplePath );
01400   mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 );
01401   mdd_t *lastState = GET_NORMAL_PT(array_fetch_last( mdd_t *, witnessArray ));
01402   char *firstStateName = Mc_MintermToString(firstState, PSVars,
01403                                             Fsm_FsmReadNetwork(modelFsm));
01404   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
01405   boolean printInputs = McOptionsReadPrintInputs( options );
01406 
01407   assert( Ctlp_FormulaReadType(ctlFormula) == Ctlp_NOT_c );
01408   assert( Ctlp_FormulaTestIsConverted(ctlFormula) );
01409   assert( Ctlp_FormulaReadType(originalFormula) == Ctlp_AG_c );
01410   assert( originalFormulaText != NIL(char) );
01411   assert( Ctlp_FormulaReadType(lFormula) == Ctlp_EU_c );
01412   assert( Ctlp_FormulaReadType(Ctlp_FormulaReadLeftChild(lFormula)) ==
01413           Ctlp_TRUE_c );
01414   assert( Ctlp_FormulaReadType(lrFormula) == Ctlp_NOT_c  );
01415   assert( lrlOriginalFormula != NIL(Ctlp_Formula_t) );
01416   
01417   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
01418     fprintf(vis_stdout, "--State\n%sfails AG formula\n\n",
01419             firstStateName); 
01420   else
01421     fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName,
01422             originalFormulaText );
01423   FREE(firstStateName);
01424   FREE(originalFormulaText);
01425 
01426   switch ( debugLevel ) {
01427   case McDbgLevelMin_c:
01428   case McDbgLevelMinVerbose_c:{
01429     if ( array_n(witnessArray ) == 1 ) {
01430       if( debugLevel !=  McDbgLevelMin_c)
01431         fprintf(vis_stdout, "since %s is false at this state\n",
01432                 lrlOriginalFormulaText );
01433       McFsmStateDebugFormula(options, lrlFormula, lastState, modelFsm,
01434                              careSetArray);
01435     }
01436     else {
01437       if( debugLevel !=  McDbgLevelMin_c)
01438         fprintf(vis_stdout,
01439                 "--Counter example is a path to a state where %s is false\n",
01440                 lrlOriginalFormulaText);
01441       fprintf(vis_stdout, " --Counter example begins\n");
01442       Mc_PrintPath(witnessArray, modelFsm, printInputs);
01443       fprintf(vis_stdout, " --Counter example ends\n\n");
01444       McFsmStateDebugFormula(options, lrlFormula, lastState, modelFsm,
01445                              careSetArray);
01446     }
01447     break;
01448   }
01449   case McDbgLevelMax_c:
01450   case McDbgLevelInteractive_c: {
01451     if ( array_n(witnessArray ) == 1 ) {
01452       if( debugLevel !=  McDbgLevelMin_c)
01453         fprintf(vis_stdout, "since %s is false at this state\n",
01454                 lrlOriginalFormulaText );
01455       McFsmStateDebugFormula(options, lrlFormula, lastState, modelFsm,
01456                              careSetArray);
01457     }
01458     else {
01459       fprintf(vis_stdout,
01460                 "--Counter example is a path to a state where %s is false\n",
01461                 lrlOriginalFormulaText);
01462       fprintf(vis_stdout, " --Counter example begins\n");
01463       Mc_PrintPath( witnessArray, modelFsm, printInputs);
01464       fprintf(vis_stdout, " --Counter example ends\n\n");
01465       if (debugLevel == McDbgLevelMax_c ||
01466           (debugLevel == McDbgLevelInteractive_c &&
01467            McQueryContinue(
01468              "--Continue debugging AG formula? (1-yes,0-no)\n")))
01469         {
01470         McFsmStateDebugFormula(options, lrlFormula, lastState, modelFsm,
01471                                careSetArray);
01472         }
01473       }
01474     break;
01475   }
01476   default: {
01477     fail("bad switch in debugging AG\n");
01478   }
01479   }
01480   FREE(lrlOriginalFormulaText);
01481 }
01482 
01490 static void
01491 FsmPathDebugAUFormula(
01492   McOptions_t *options,
01493   mdd_t *aState,
01494   Ctlp_Formula_t *ctlFormula,
01495   Fsm_Fsm_t *modelFsm,
01496   array_t *careSetArray)
01497 {
01498   Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula);
01499   char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula );
01500   Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula );
01501   Ctlp_Formula_t *lrFormula = Ctlp_FormulaReadRightChild( lFormula );
01502   Ctlp_Formula_t *lrlFormula = Ctlp_FormulaReadLeftChild( lrFormula );
01503   Ctlp_Formula_t *lrllFormula = Ctlp_FormulaReadLeftChild( lrlFormula );
01504   Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula );
01505   Ctlp_Formula_t *llrFormula = Ctlp_FormulaReadRightChild( llFormula );
01506   Ctlp_Formula_t *llrlFormula = Ctlp_FormulaReadLeftChild( llrFormula );
01507   Ctlp_Formula_t *llrllFormula = Ctlp_FormulaReadLeftChild( llrlFormula );
01508   Ctlp_Formula_t *fFormula = llrllFormula;
01509   Ctlp_Formula_t *gFormula = lrllFormula;
01510   Ctlp_Formula_t *fOriginalFormula = Ctlp_FormulaReadOriginalFormula(fFormula);
01511   Ctlp_Formula_t *gOriginalFormula = Ctlp_FormulaReadOriginalFormula(gFormula);
01512   char *fText = Ctlp_FormulaConvertToString( fOriginalFormula );
01513   char *gText = Ctlp_FormulaConvertToString( gOriginalFormula );
01514 
01515   array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm );
01516   char *firstStateName = Mc_MintermToString(aState, PSVars,
01517                                         Fsm_FsmReadNetwork(modelFsm));
01518   McDbgLevel debugLevel = McOptionsReadDbgLevel( options );
01519   boolean printInputs = McOptionsReadPrintInputs( options );
01520 
01521   if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c)
01522     fprintf(vis_stdout, "--State\n%sfails AU formula\n\n",
01523             firstStateName); 
01524   else
01525     fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName,
01526             originalFormulaText );
01527   FREE(firstStateName);
01528   FREE(originalFormulaText);
01529 
01530   /* orginal formula is A(fUg) => converted is !((E[!g U (!f*!g)]) + (EG!g)) */
01531 
01532   if ( McStateSatisfiesFormula( llFormula, aState ) ) {
01533     /*
01534      * the case E[!g U (!f*!g)] is true
01535      */
01536     McPath_t *counterExamplePath = DebugEU(llFormula, aState, modelFsm,
01537                                            careSetArray);
01538     
01539     array_t *stemArray = McPathReadStemArray( counterExamplePath );
01540     array_t *witnessArray = stemArray;
01541     mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 );
01542     mdd_t *lastState = array_fetch_last( mdd_t *, witnessArray );
01543     char *firstStateName = Mc_MintermToString(firstState, PSVars,
01544                                 Fsm_FsmReadNetwork(modelFsm));
01545 
01546     switch ( debugLevel ) {
01547     case McDbgLevelMinVerbose_c: 
01548       fprintf(vis_stdout,
01549               "--Counter example is a fair path where %s is false until %s is also false\n",
01550               gText, fText);
01551     case McDbgLevelMin_c:
01552       fprintf(vis_stdout, " --Counter example begins\n");
01553       Mc_PrintPath(witnessArray, modelFsm, printInputs);
01554       fprintf(vis_stdout, " --Counter example ends\n\n");
01555       McFsmStateDebugFormula(options, llrFormula, lastState, modelFsm,
01556                              careSetArray);
01557       break;
01558         
01559     case McDbgLevelMax_c:
01560     case McDbgLevelInteractive_c: {
01561       if ( array_n(witnessArray ) == 1 ) {
01562         fprintf(vis_stdout,
01563                 "--At state %s\nformula %s is false and\nformula %s is also false\n",
01564                 firstStateName, fText, gText);
01565         if (debugLevel == McDbgLevelMax_c ||
01566             (debugLevel == McDbgLevelInteractive_c &&
01567              McQueryContinue(
01568                "Continue debugging AU formula? (1-yes,0-no)\n"))) {
01569           McFsmStateDebugFormula(options, fFormula, aState, modelFsm,
01570                                  careSetArray);
01571           McFsmStateDebugFormula(options, gFormula, aState, modelFsm,
01572                                  careSetArray);
01573         }
01574       }
01575       else {
01576         int i;
01577         fprintf(vis_stdout, " --Counter example begins\n");
01578         Mc_PrintPath(witnessArray,modelFsm,printInputs);
01579         fprintf(vis_stdout, " --Counter example ends\n\n");
01580         for( i=0 ; i < ( array_n( witnessArray ) - 1 ); i++ ) {
01581           mdd_t *aState = array_fetch( mdd_t *, witnessArray, i );
01582           
01583           if (debugLevel == McDbgLevelMax_c ||
01584               (debugLevel == McDbgLevelInteractive_c &&
01585                McQueryContinue(
01586                  "Continue debugging AU formula? (1-yes,0-no)\n"))) {
01587             McFsmStateDebugFormula(options, gFormula, aState, modelFsm,
01588                                    careSetArray);
01589           }
01590         }
01591         
01592         if (debugLevel == McDbgLevelMax_c ||
01593             (debugLevel == McDbgLevelInteractive_c &&
01594              McQueryContinue(
01595                "Continue debugging AU formula? (1-yes,0-no)\n"))) {
01596           McFsmStateDebugFormula(options, fFormula, lastState, modelFsm,
01597                                  careSetArray);
01598           McFsmStateDebugFormula(options, gFormula, lastState, modelFsm,
01599                                  careSetArray);
01600         }
01601       }
01602       break;
01603     }
01604     
01605     default: {
01606       fail("Unknown case in debugging AU\n");
01607     }
01608     }/* case */
01609     McPathFree( counterExamplePath );
01610   }
01611   else {
01612     /*
01613      * must be the case that EG!g
01614      */
01615     McPath_t *counterExamplePath = DebugEG(lrFormula, aState, modelFsm,
01616                                            careSetArray, 
01617                                            options);
01618 
01619     assert( McStateSatisfiesFormula( lrFormula, aState ) );
01620 
01621     if( debugLevel !=  McDbgLevelMin_c)
01622       fprintf(vis_stdout,
01623               "--Counter example is a fair path where %s is always false\n",
01624               gText);
01625 
01626     switch ( debugLevel ) {
01627     case McDbgLevelMin_c:
01628     case McDbgLevelMinVerbose_c:{
01629       McPath_t *normalPath = McPathNormalize( counterExamplePath );
01630       array_t *stem = McPathReadStemArray( normalPath );
01631       array_t *cycle = McPathReadCycleArray( normalPath );
01632       
01633       fprintf(vis_stdout, " --Counter example begins\n");
01634       (void) fprintf( vis_stdout, "--Fair path stem:\n");
01635       Mc_PrintPath( stem, modelFsm, printInputs );
01636       
01637       (void) fprintf( vis_stdout, "--Fair path cycle:\n");
01638       Mc_PrintPath( cycle, modelFsm, printInputs );
01639       fprintf(vis_stdout, " --Counter example ends\n\n");
01640       McPathFree( normalPath );
01641       break;
01642     }
01643     
01644     case McDbgLevelMax_c:
01645     case McDbgLevelInteractive_c:
01646       {
01647     int i;
01648     array_t *stemArray = McPathReadStemArray( counterExamplePath );
01649     array_t *cycleArray = McPathReadCycleArray( counterExamplePath );
01650     array_t *witnessArray = McCreateMergedPath( stemArray, cycleArray );
01651     McPath_t *normalPath = McPathNormalize( counterExamplePath );
01652     array_t *stem = McPathReadStemArray( normalPath );
01653     array_t *cycle = McPathReadCycleArray( normalPath );
01654     
01655     fprintf(vis_stdout, " --Counter example begins\n");
01656     (void) fprintf( vis_stdout, "--Fair path stem:\n");
01657     Mc_PrintPath( stem, modelFsm, printInputs );
01658     
01659     (void) fprintf( vis_stdout, "--Fair path cycle:\n");
01660     Mc_PrintPath( cycle, modelFsm, printInputs );
01661     fprintf(vis_stdout, " --Counter example ends\n\n");
01662     McPathFree( normalPath );
01663     for( i=0 ; i < ( array_n( witnessArray )-1  ); i++ ) {
01664       mdd_t *aState = array_fetch( mdd_t *, witnessArray, i );
01665    
01666       if (debugLevel == McDbgLevelMax_c ||
01667           (debugLevel == McDbgLevelInteractive_c &&
01668            McQueryContinue(
01669              "--Continue debugging AU formula? (1-yes,0-no)\n"))) {
01670         McFsmStateDebugFormula(options, lrllFormula, aState, modelFsm,
01671                                careSetArray);
01672       }
01673     }
01674     break;
01675   }
01676 
01677     default: {
01678       fail("Bad switch in debugging AU formula\n");
01679     }
01680     }/* case */
01681     McPathFree( counterExamplePath );
01682   }
01683   
01684   FREE( fText );
01685   FREE( gText );
01686 }