1 /***** spin: guided.c *****/
3 /* Copyright (c) 1989-2003 by Lucent Technologies, Bell Laboratories. */
4 /* All Rights Reserved. This software is for educational purposes only. */
5 /* No guarantee whatsoever is expressed or implied by the distribution of */
6 /* this code. Permission is given to distribute this code provided that */
7 /* this introductory message is not removed and no monies are exchanged. */
8 /* Software written by Gerard J. Holzmann. For tool documentation see: */
9 /* http://spinroot.com/ */
10 /* Send all bug-reports and/or questions to: bugs@spinroot.com */
13 #include <sys/types.h>
17 extern RunList *run, *X;
18 extern Element *Al_El;
19 extern Symbol *Fname, *oFname;
20 extern int verbose, lineno, xspin, jumpsteps, depth, merger, cutoff;
21 extern int nproc, nstop, Tval, ntrail, columns;
22 extern short Have_claim, Skip_claim;
23 extern void ana_src(int, int);
27 static int lastclaim = -1;
29 static void lost_trail(void);
35 for (oX = run; oX; oX = oX->nxt)
37 { printf("(%s) ", oX->n->name);
43 newer(char *f1, char *f2)
45 #if defined(WIN32) || defined(WIN64)
51 if (stat(f1, (struct stat *)&x) < 0) return 0;
52 if (stat(f2, (struct stat *)&y) < 0) return 1;
53 if (x.st_mtime < y.st_mtime) return 0;
62 for (e = Al_El; e; e = e->Nxt)
64 && (e->n->ntyp == ATOMIC
65 || e->n->ntyp == NON_ATOMIC
66 || e->n->ntyp == D_STEP))
73 return (!Have_claim || !X || X->pid != 0);
83 * if source model name is leader.pml
84 * look for the trail file under these names:
92 sprintf(snap, "%s%d.trail", oFname->name, ntrail);
94 sprintf(snap, "%s.trail", oFname->name);
96 if ((fd = fopen(snap, "r")) == NULL)
97 { snap[strlen(snap)-2] = '\0'; /* .tra */
98 if ((fd = fopen(snap, "r")) == NULL)
99 { if ((q = strchr(oFname->name, '.')) != NULL)
102 sprintf(snap, "%s%d.trail",
103 oFname->name, ntrail);
105 sprintf(snap, "%s.trail",
109 if ((fd = fopen(snap, "r")) != NULL)
112 snap[strlen(snap)-2] = '\0'; /* last try */
113 if ((fd = fopen(snap, "r")) != NULL)
116 printf("spin: cannot find trail file\n");
120 if (xspin == 0 && newer(oFname->name, snap))
121 printf("spin: warning, \"%s\" is newer than %s\n",
127 * sets Tval because timeouts may be part of trail
128 * this used to also set m_loss to 1, but that is
129 * better handled with the runtime -m flag
134 while (fscanf(fd, "%d:%d:%d\n", &depth, &pno, &nst) == 3)
135 { if (depth == -2) { start_claim(pno); continue; }
136 if (depth == -4) { merger = 1; ana_src(0, 1); continue; }
140 dotag(stdout, " CYCLE>\n");
142 dotag(stdout, "<<<<<START OF CYCLE>>>>>\n");
147 if (cutoff > 0 && depth >= cutoff)
148 { printf("-------------\n");
149 printf("depth-limit (-u%d steps) reached\n", cutoff);
153 if (Skip_claim && pno == 0) continue;
155 for (dothis = Al_El; dothis; dothis = dothis->Nxt)
156 { if (dothis->Seqno == nst)
160 { printf("%3d: proc %d, no matching stmnt %d\n",
161 depth, pno - Have_claim, nst);
165 i = nproc - nstop + Skip_claim;
167 if (dothis->n->ntyp == '@')
173 { dotag(stdout, "<end>\n");
176 if (Have_claim && pno == 0)
177 printf("%3d: claim terminates\n",
180 printf("%3d: proc %d terminates\n",
181 depth, pno - Have_claim);
185 if (pno <= 1) continue; /* init dies before never */
186 printf("%3d: stop error, ", depth);
187 printf("proc %d (i=%d) trans %d, %c\n",
188 pno - Have_claim, i, nst, dothis->n->ntyp);
191 for (X = run; X; X = X->nxt)
196 { printf("%3d: no process %d ", depth, pno - Have_claim);
197 printf("(state %d)\n", nst);
201 lineno = dothis->n->ln;
202 Fname = dothis->n->fn;
204 if (dothis->n->ntyp == D_STEP)
205 { Element *g, *og = dothis;
208 if (g && depth >= jumpsteps
209 && ((verbose&32) || ((verbose&4) && not_claim())))
213 if (og->n->ntyp == D_STEP)
214 og = og->n->sl->this->frst;
217 comment(stdout, og->n, 0);
220 if (verbose&1) dumpglobals();
221 if (verbose&2) dumplocal(X);
222 if (xspin) printf("\n");
225 } while (g && g != dothis->nxt);
227 { X->pc = g?huntele(g, 0, -1):g;
231 keepgoing: if (dothis->merge_start)
232 a = dothis->merge_start;
237 { X->pc = eval_sub(dothis);
238 if (X->pc) X->pc = huntele(X->pc, 0, a);
241 if (depth >= jumpsteps
242 && ((verbose&32) || ((verbose&4) && not_claim()))) /* -v or -p */
246 if (dothis->n->ntyp == D_STEP)
247 dothis = dothis->n->sl->this->frst;
250 comment(stdout, dothis->n, 0);
252 if (a && (verbose&32))
253 printf("\t<merge %d now @%d>",
255 (X && X->pc)?X->pc->seqno:-1);
258 if (verbose&1) dumpglobals();
259 if (verbose&2) dumplocal(X);
260 if (xspin) printf("\n");
264 printf("\ttransition failed\n");
265 a = 0; /* avoid inf loop */
268 if (a && X && X->pc && X->pc->seqno != a)
273 if (Have_claim && X && X->pid == 0
274 && dothis && dothis->n
275 && lastclaim != dothis->n->ln)
276 { lastclaim = dothis->n->ln;
279 sprintf(t, "#%d", lastclaim);
283 printf("Never claim moves to line %d\t[", lastclaim);
284 comment(stdout, dothis->n, 0);
287 printf("spin: trail ends after %d steps\n", depth);
295 while (fscanf(fd, "%d:%d:%d:%d\n", &d, &p, &n, &l) == 4)
296 { printf("step %d: proc %d ", d, p); whichproc(p);
297 printf("(state %d) - d %d\n", n, l);
299 wrapup(1); /* no return */
304 { int i = nproc - nstop;
308 for (Y = run; Y; Y = Y->nxt)