Annotation of OpenXM_contrib2/asir2000/parse/debug.c, Revision 1.15
1.4 noro 1: /*
2: * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
3: * All rights reserved.
4: *
5: * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
6: * non-exclusive and royalty-free license to use, copy, modify and
7: * redistribute, solely for non-commercial and non-profit purposes, the
8: * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
9: * conditions of this Agreement. For the avoidance of doubt, you acquire
10: * only a limited right to use the SOFTWARE hereunder, and FLL or any
11: * third party developer retains all rights, including but not limited to
12: * copyrights, in and to the SOFTWARE.
13: *
14: * (1) FLL does not grant you a license in any way for commercial
15: * purposes. You may use the SOFTWARE only for non-commercial and
16: * non-profit purposes only, such as academic, research and internal
17: * business use.
18: * (2) The SOFTWARE is protected by the Copyright Law of Japan and
19: * international copyright treaties. If you make copies of the SOFTWARE,
20: * with or without modification, as permitted hereunder, you shall affix
21: * to all such copies of the SOFTWARE the above copyright notice.
22: * (3) An explicit reference to this SOFTWARE and its copyright owner
23: * shall be made on your publication or presentation in any form of the
24: * results obtained by use of the SOFTWARE.
25: * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.5 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.4 noro 27: * for such modification or the source code of the modified part of the
28: * SOFTWARE.
29: *
30: * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
31: * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
32: * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
33: * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
34: * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
35: * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
36: * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
37: * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
38: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
39: * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
40: * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
41: * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
42: * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
43: * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
44: * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
45: * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
46: * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
47: *
1.15 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/debug.c,v 1.14 2003/03/07 06:39:59 noro Exp $
1.4 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include <ctype.h>
1.12 ohara 53: #if defined(PARI)
1.1 noro 54: #include "genpari.h"
1.2 noro 55: #endif
1.1 noro 56:
57: extern do_server_in_X11,do_file;
58:
59: typedef enum {
60: D_NEXT, D_STEP, D_FINISH, D_CONT, D_QUIT,
61: D_UP, D_DOWN, D_FRAME,
62: D_LIST, D_PRINT,
63: D_SETF, D_SETBP, D_SETTP, D_DELBP,
64: D_SHOWBP, D_WHERE, D_ALIAS, D_UNKNOWN
65: } did;
66:
67: struct oDEBCOM {
68: NODE names;
69: did id;
70: };
71:
72: int nextbp,nextbplevel;
73: FUNC cur_binf;
74:
75: static FUNC targetf;
76: static int curline = 1;
77:
78: extern NODE PVSS;
79: extern unsigned int evalstatline;
80: extern int debug_mode;
1.11 noro 81: extern JMP_BUF debug_env;
1.1 noro 82:
83: char *debcom[] = {
84: "next",
85: "step",
86: "finish",
87: "cont",
88: "quit",
89: "up",
90: "down",
91: "frame",
92: "list",
93: "print",
94: "func",
95: "stop",
96: "trace",
97: "delete",
98: "status",
99: "where",
100: "alias",
101: };
102:
103: struct oDEBCOM dckwd[] = {
104: {0, D_NEXT},
105: {0, D_STEP},
106: {0, D_FINISH},
107: {0, D_CONT},
108: {0, D_QUIT},
109: {0, D_UP},
110: {0, D_DOWN},
111: {0, D_FRAME},
112: {0, D_LIST},
113: {0, D_PRINT},
114: {0, D_SETF},
115: {0, D_SETBP},
116: {0, D_SETTP},
117: {0, D_DELBP},
118: {0, D_SHOWBP},
119: {0, D_WHERE},
120: {0, D_ALIAS},
121: {0, D_UNKNOWN}
122: };
123:
124: void debug_init() {
125: int i,n,ac;
126: char *home;
127: char buf[BUFSIZ+1];
128: #if defined(__MWERKS__)
129: char *av[64];
130: #else
131: char *av[BUFSIZ];
132: #endif
133: FILE *fp;
134:
135: for ( n = 0; dckwd[n].id != D_UNKNOWN; n++ );
136: for ( i = 0; i < n; i++ )
137: MKNODE(dckwd[i].names,debcom[i],0);
138: home = (char *)getenv("HOME");
139: if ( home )
140: strcpy(buf,home);
141: else
142: buf[0] = 0;
143: strcat(buf,"/.dbxinit");
144: if ( (fp = fopen(".dbxinit","r")) || (fp = fopen(buf,"r")) ) {
145: while ( fgets(buf,BUFSIZ,fp) ) {
146: stoarg(buf,&ac,av);
147: if ((ac == 3) && !strcmp(av[0],"alias"))
148: add_alias(av[2],av[1]);
149: }
150: fclose(fp);
151: }
1.9 noro 152: #if 0
1.1 noro 153: #if !defined(VISUAL)
154: if ( do_server_in_X11 )
155: init_cmdwin();
1.9 noro 156: #endif
1.1 noro 157: #endif
158: }
159:
1.10 noro 160: void add_alias(char *com,char *alias)
1.1 noro 161: {
162: int i;
163: NODE tn;
164: char *s;
165:
166: for ( i = 0; dckwd[i].names; i++ )
167: if (!strcmp(com,debcom[i])) {
168: for ( tn = dckwd[i].names; NEXT(tn); tn = NEXT(tn) );
169: s = (char *)MALLOC(strlen(alias)+1); strcpy(s,alias);
170: MKNODE(NEXT(tn),s,0);
171: return;
172: }
173: }
174:
1.10 noro 175: void show_alias(char *alias)
1.1 noro 176: {
177: int i;
178: NODE tn;
179:
180: if ( !alias )
181: for ( i = 0; dckwd[i].names; i++ ) {
182: if ( tn = NEXT(dckwd[i].names) )
183: fprintf(stderr,"%s\t",debcom[i]);
184: for ( ; tn; tn = NEXT(tn) ) {
185: fputs(BDY(tn),stderr);
186: if ( NEXT(tn) )
187: fputc(' ',stderr);
188: else
189: fputc('\n',stderr);
190: }
191: }
192: else
193: for ( i = 0; dckwd[i].names; i++ )
194: for ( tn = dckwd[i].names; tn; tn = NEXT(tn) )
195: if ( !strcmp(alias,BDY(tn)) ) {
196: fprintf(stderr,"%s->%s\n",alias,debcom[i]); return;
197: }
198: }
199:
1.10 noro 200: void debug(SNODE f)
1.1 noro 201: {
202: int ac,i,n;
203: did id;
204: #if defined(__MWERKS__)
205: char *av[64];
206: #else
207: char *av[BUFSIZ];
208: #endif
209: char buf[BUFSIZ];
210: char prompt[BUFSIZ];
1.10 noro 211: char *p,*pe;
212: #if !defined(VISUAL)
213: char *line;
214: #endif
1.1 noro 215: NODE tn;
1.8 noro 216: extern int do_fep;
1.1 noro 217: NODE pvss;
218:
1.14 noro 219: #if !defined(MPI) && !defined(VISUAL)
1.1 noro 220: if ( !isatty(fileno(stdin)) && !do_server_in_X11 )
221: if ( do_file )
222: ExitAsir();
223: else
224: return;
225: #endif
1.6 noro 226: #if defined(VISUAL)
1.1 noro 227: suspend_timer();
228: #endif
229: pvss = PVSS; debug_mode = 1;
230: #if !defined(VISUAL)
231: if ( do_server_in_X11 )
232: #endif
233: show_debug_window(1);
1.8 noro 234: sprintf(prompt,"(debug) ");
1.11 noro 235: SETJMP(debug_env);
1.1 noro 236: while ( 1 ) {
1.13 noro 237: #if FEP
1.7 saito 238: if ( !do_fep )
239: #endif
240: if ( !do_server_in_X11 )
241: fputs(prompt,stderr);
1.1 noro 242: bzero(buf,BUFSIZ);
243: while ( 1 ) {
1.13 noro 244: #if FEP
1.7 saito 245: if ( do_fep ) {
246: line = (char *)readline_console(prompt);
247: strcpy(buf,line); free(line);
248: } else
249: #endif
1.1 noro 250: {
251: int len;
252:
253: #if !defined(VISUAL)
254: if ( do_server_in_X11 )
255: get_line(buf);
256: else
257: #endif
258: if ( !fgets(buf,BUFSIZ,stdin) )
259: goto LAST;
260: len = strlen(buf);
261: if ( buf[len-1] == '\n' )
262: buf[len-1] = 0;
263: }
264: for ( p = buf; *p && isspace(*p); p++ );
265: if ( *p )
266: break;
267: }
268: for ( pe = p; *pe && !isspace(*pe); pe++ );
269: *pe = 0;
270: for ( i = 0; dckwd[i].names; i++ ) {
271: for ( tn = dckwd[i].names; tn; tn = NEXT(tn) )
272: if ( !strcmp(BDY(tn),p) )
273: break;
274: if ( tn )
275: break;
276: }
277: id = dckwd[i].id; p = pe+1;
278: switch ( id ) {
279: case D_NEXT:
280: if ( f ) { nextbp = 1; nextbplevel = 0; }
281: goto LAST; break;
282: case D_STEP:
283: if ( f ) { nextbp = 1; nextbplevel = -1; }
284: goto LAST; break;
285: case D_FINISH:
286: if ( f ) { nextbp = 1; nextbplevel = 1; }
287: goto LAST; break;
288: case D_CONT: case D_QUIT:
289: goto LAST; break;
290: case D_UP:
291: if ( f ) {
292: stoarg(p,&ac,av); n = ac ? atoi(av[0]) : 1;
293: change_stack(n,&pvss);
294: }
295: break;
296: case D_DOWN:
297: if ( f ) {
298: stoarg(p,&ac,av); n = ac ? atoi(av[0]) : 1;
299: change_stack(-n,&pvss);
300: }
301: break;
302: case D_FRAME:
303: if ( f ) {
304: stoarg(p,&ac,av);
305: if ( !ac )
306: show_stack((VS)BDY(pvss));
307: else {
308: n = atoi(av[0]);
309: change_stack(((VS)BDY(pvss))->level-((VS)BDY(PVSS))->level+n,&pvss);
310: }
311: }
312: break;
313: case D_PRINT:
314: printvars(p,pvss?(VS)BDY(pvss):GPVS); break;
315: case D_LIST:
316: stoarg(p,&ac,av); println(ac,av,10); break;
317: case D_SETF:
318: stoarg(p,&ac,av); setf(ac,av); break;
319: case D_SETBP:
320: setbp(p); break;
321: case D_SETTP:
322: settp(p); break;
323: case D_DELBP:
324: stoarg(p,&ac,av); delbp(ac,av); break;
325: case D_SHOWBP:
326: showbps(); break;
327: case D_WHERE:
328: showpos(); break;
329: case D_ALIAS:
330: stoarg(p,&ac,av);
331: switch ( ac ) {
332: case 0:
333: show_alias(0); break;
334: case 1:
335: show_alias(av[0]); break;
336: case 2: default:
337: add_alias(av[1],av[0]); break;
338: }
339: break;
340: default:
341: break;
342: }
343: }
344: LAST:
345: debug_mode = 0;
1.6 noro 346: #if !defined(VISUAL)
1.1 noro 347: if ( do_server_in_X11 )
348: #endif
349: show_debug_window(0);
350: }
351:
1.10 noro 352: void setf(int ac,char **av)
1.1 noro 353: {
354: FUNC r;
355:
356: if ( !ac )
357: return;
1.15 ! noro 358: searchuf(av[0],&r);
1.1 noro 359: if ( r ) {
360: targetf = r;
361: curline = targetf->f.usrf->startl;
362: }
363: }
364:
365: #define MAXBP 64
366:
367: static struct {
368: int at;
369: FUNC f;
370: SNODE *snp;
371: char *texpr;
372: char *cond;
373: } bpt[MAXBP];
374:
375: static int bpindex = 0;
376:
1.10 noro 377: void setbp(char *p)
1.1 noro 378: {
379: int ac;
380: char *av[BUFSIZ];
381: char *buf,*savp;
382: char *fname;
383: FUNC r;
1.15 ! noro 384: USRF uf,t;
1.1 noro 385: SNODE *snp = 0;
386: FNODE cond;
387: NODE tn;
388: int n,at,ln,bpi;
389:
390: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
391: if ( ac < 2 )
392: return;
393: if ( !strcmp(av[0],"at") ) {
394: if ( !targetf )
395: return;
1.15 ! noro 396: n = atoi(av[1]);
! 397: uf = targetf->f.usrf;
! 398: fname = uf->fname;
! 399: tn = uf->module?uf->module->usrf_list:usrf;
! 400: for ( ; tn; tn = NEXT(tn) ) {
1.1 noro 401: r = (FUNC)BDY(tn); t = r->f.usrf;
402: if ( t && t->fname && !strcmp(t->fname,fname)
403: && ( t->startl <= n ) && ( n <= t->endl ) )
404: break;
405: }
406: if ( !r ) {
407: fprintf(stderr,"no such line in %s\n",fname);
408: return;
409: } else {
410: targetf = r; curline = n;
411: }
412: at = 1; searchsn(&BDY(t),n,&snp);
413: } else if ( !strcmp(av[0],"in") ) {
1.15 ! noro 414: searchuf(av[1],&r);
1.1 noro 415: if ( !r ) {
416: fprintf(stderr,"%s() : no such function\n",av[1]);
417: return;
418: } else if ( r->id == A_UNDEF ) {
419: fprintf(stderr,"%s : undefined\n",av[1]);
420: return;
421: }
422: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
423: if ( tn ) {
424: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
425: }
426: } else
427: return;
428: if ( snp ) {
429: cond = 0;
430: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
431: savp = p+(av[2]-buf)+2;
432: exprparse(targetf,savp,&cond);
433: }
434: bpi = searchbp();
435: if ( bpi < 0 )
436: fprintf(stderr,"too many breakpoints\n");
437: else if ( ID(*snp) == S_BP )
438: return;
439: else {
440: switch ( ID(*snp) ) {
441: case S_IFELSE: case S_FOR: case S_DO:
442: ln = (int)FA0(*snp); break;
443: default:
444: ln = (*snp)->ln; break;
445: }
446: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,0);
447: (*snp)->ln = ln;
448: if ( cond ) {
449: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
450: strcpy(bpt[bpi].cond,savp);
451: } else
452: bpt[bpi].cond = 0;
453: bpt[bpi].at = at;
454: bpt[bpi].f = targetf;
455: bpt[bpi].snp = snp;
456: bpt[bpi].texpr = 0;
457: showbp(bpi);
458: }
459: }
460: }
461:
1.10 noro 462: void settp(char *p)
1.1 noro 463: {
464: int ac;
465: char *_av[BUFSIZ];
466: char **av;
467: char *buf,*savp;
468: char *fname;
469: char *texprname;
470: FUNC r;
471: USRF t;
472: SNODE *snp = 0;
473: FNODE cond,texpr;
474: NODE tn;
475: int n,at,ln,bpi;
476:
477: av = _av;
478: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
479: if ( ac < 3 )
480: return;
481: texprname = av[0]; ac--; av++;
482: if ( !strcmp(av[0],"at") ) {
483: if ( !targetf )
484: return;
485: n = atoi(av[1]); fname = targetf->f.usrf->fname;
486: for ( tn = usrf; tn; tn = NEXT(tn) ) {
487: r = (FUNC)BDY(tn); t = r->f.usrf;
488: if ( t && t->fname && !strcmp(t->fname,fname)
489: && ( t->startl <= n ) && ( n <= t->endl ) )
490: break;
491: }
492: if ( !r ) {
493: fprintf(stderr,"no such line in %s\n",fname);
494: return;
495: } else {
496: targetf = r; curline = n;
497: }
498: at = 1; searchsn(&BDY(t),n,&snp);
499: } else if ( !strcmp(av[0],"in") ) {
1.15 ! noro 500: searchuf(av[1],&r);
1.1 noro 501: if ( !r ) {
502: fprintf(stderr,"%s() : no such function\n",av[1]);
503: return;
504: }
505: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
506: if ( tn ) {
507: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
508: }
509: } else
510: return;
511: if ( snp ) {
512: cond = 0;
513: exprparse(targetf,texprname,&texpr);
514: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
515: savp = p+(av[2]-buf)+2;
516: exprparse(targetf,savp,&cond);
517: }
518: bpi = searchbp();
519: if ( bpi < 0 )
520: fprintf(stderr,"too many breakpoints\n");
521: else if ( ID(*snp) == S_BP )
522: return;
523: else {
524: switch ( ID(*snp) ) {
525: case S_IFELSE: case S_FOR: case S_DO:
526: ln = (int)FA0(*snp); break;
527: default:
528: ln = (*snp)->ln; break;
529: }
530: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,texpr);
531: (*snp)->ln = ln;
532: if ( cond ) {
533: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
534: strcpy(bpt[bpi].cond,savp);
535: } else
536: bpt[bpi].cond = 0;
537: bpt[bpi].at = at;
538: bpt[bpi].f = targetf;
539: bpt[bpi].snp = snp;
540: bpt[bpi].texpr = (char *)MALLOC(strlen(texprname)+1);
541: strcpy(bpt[bpi].texpr,texprname);
542: showbp(bpi);
543: }
544: }
545: }
546:
1.10 noro 547: void clearbp(FUNC f)
1.1 noro 548: {
549: int i;
550:
551: if ( !f )
552: return;
553: for ( i = 0; i < bpindex; i++ )
554: if ( bpt[i].snp && !strcmp(f->name,bpt[i].f->name) ) {
555: bpt[i].at = 0; bpt[i].f = 0; bpt[i].snp = 0;
556: }
557: }
558:
559: int searchbp()
560: {
561: int i;
562:
563: for ( i = 0; i < bpindex; i++ )
564: if ( !bpt[i].snp )
565: return i;
566: if ( bpindex == MAXBP )
567: return -1;
568: else
569: return bpindex++;
570: }
571:
1.10 noro 572: void delbp(int ac,char **av)
1.1 noro 573: {
574: int n;
575:
576: if ( !ac )
577: return;
578: if ( (n = atoi(av[0])) >= bpindex )
579: return;
580: if ( bpt[n].snp ) {
581: *bpt[n].snp = (SNODE)FA0(*bpt[n].snp);
582: bpt[n].snp = 0;
583: }
584: }
585:
586: void showbps() {
587: int i;
588:
589: for ( i = 0; i < bpindex; i++ )
590: showbp(i);
591: }
592:
1.10 noro 593: void showbp(int n)
1.1 noro 594: {
595: if ( bpt[n].snp )
596: if ( bpt[n].texpr )
597: if ( bpt[n].at ) {
598: if ( bpt[n].cond )
599: fprintf(stderr,"(%d) trace %s at \"%s\":%d if %s\n",
600: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
601: else
602: fprintf(stderr,"(%d) trace %s at \"%s\":%d\n",
603: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
604: } else {
605: if ( bpt[n].cond )
606: fprintf(stderr,"(%d) trace %s in %s if %s\n",
607: n,bpt[n].texpr,bpt[n].f->name,bpt[n].cond);
608: else
609: fprintf(stderr,"(%d) trace %s in %s\n",n,bpt[n].texpr,bpt[n].f->name);
610: }
611: else
612: if ( bpt[n].at ) {
613: if ( bpt[n].cond )
614: fprintf(stderr,"(%d) stop at \"%s\":%d if %s\n",
615: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
616: else
617: fprintf(stderr,"(%d) stop at \"%s\":%d\n",
618: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
619: } else {
620: if ( bpt[n].cond )
621: fprintf(stderr,"(%d) stop in %s if %s\n",
622: n,bpt[n].f->name,bpt[n].cond);
623: else
624: fprintf(stderr,"(%d) stop in %s\n",n,bpt[n].f->name);
625: }
626: }
627:
1.10 noro 628: void searchsn(SNODE *fp,int n,SNODE **fpp)
1.1 noro 629: {
630: NODE tn;
631: SNODE sn;
632: SNODE *snp;
633:
634: *fpp = 0;
635: switch (ID(*fp)) {
636: case S_CPLX:
637: for ( tn = (NODE)FA0(*fp); tn; tn = NEXT(tn) )
638: if ( sn = (SNODE)BDY(tn) ) {
639: snp = (SNODE *)(ID(sn) == S_BP ? &FA0(sn) : &BDY(tn));
640: if ( (*snp)->ln >= n ) {
641: searchsn(snp,n,fpp); break;
642: }
643: }
644: break;
645: case S_IFELSE:
646: if ( n <= (int)FA0(*fp) )
647: *fpp = fp;
648: else if ( n <= ((SNODE)FA2(*fp))->ln )
649: searchsn((SNODE *)&FA2(*fp),n,fpp);
650: else if ( FA3(*fp) )
651: searchsn((SNODE *)&FA3(*fp),n,fpp);
652: if ( !(*fpp) )
653: *fpp = fp;
654: break;
655: case S_FOR:
656: if ( n <= (int)FA0(*fp) )
657: *fpp = fp;
658: else
659: searchsn((SNODE *)&FA4(*fp),n,fpp);
660: if ( !(*fpp) )
661: *fpp = fp;
662: break;
663: case S_DO:
664: if ( n <= (int)FA0(*fp) )
665: *fpp = fp;
666: else
667: searchsn((SNODE *)&FA1(*fp),n,fpp);
668: if ( !(*fpp) )
669: *fpp = fp;
670: break;
671: case S_BP:
672: switch ( ID((SNODE)FA0(*fp)) ) {
673: case S_SINGLE:
674: *fpp = fp; break;
675: default:
676: searchsn((SNODE *)&FA0(*fp),n,fpp); break;
677: }
678: break;
679: case S_SINGLE: default:
680: *fpp = fp;
681: break;
682: }
683: }
684:
1.10 noro 685: void bp(SNODE f)
1.1 noro 686: {
687: int ln;
688:
689: if ( !f || (CPVS == GPVS) )
690: return;
691:
692: switch ( ID(f) ) {
693: case S_IFELSE: case S_FOR:
694: ln = (int)FA0(f); break;
695: default:
696: ln = f->ln; break;
697: }
698: #if !defined(VISUAL)
699: if ( do_server_in_X11 )
700: #endif
701: show_debug_window(1);
702: fprintf(stderr,"stopped in %s at line %d in file \"%s\"\n",
703: CPVS->usrf->name,ln,CPVS->usrf->f.usrf->fname);
704: targetf = CPVS->usrf; curline = ln;
705: println(0,0,1);
1.14 noro 706: #if !defined(MPI) && !defined(VISUAL)
1.1 noro 707: if ( do_server_in_X11 || isatty(0) )
708: #endif
709: debug(f);
710: }
711:
1.10 noro 712: void println(int ac,char **av,int l)
1.1 noro 713: {
714: FILE *fp;
715: char buf[BUFSIZ+1];
716: int i;
717: int ln;
718: FUNC r;
719:
720: if ( !ac )
721: ln = curline;
722: else if ( isdigit(av[0][0]) )
723: ln = atoi(av[0]);
724: else {
1.15 ! noro 725: searchuf(av[0],&r);
1.1 noro 726: if ( r && r->id != A_UNDEF ) {
727: targetf = r;
728: ln = r->f.usrf->startl;
729: } else {
730: fprintf(stderr,"%s undefined\n",av[0]);
731: ln = curline;
732: }
733: }
734: if ( !targetf )
735: return;
736: fp = fopen(targetf->f.usrf->fname,"r");
737: if ( !fp ) {
738: fprintf(stderr,"\"%s\" not found\n",targetf->name);
739: return;
740: }
741: for ( i = 1; i < ln; i++ )
742: if ( !fgets(buf,BUFSIZ,fp) )
743: return;
744: for ( i = 0; i < l; i++ ) {
745: if ( !fgets(buf,BUFSIZ,fp) )
746: break;
747: fprintf(stderr,"%d %s",ln+i,buf);
748: }
749: curline = ln + i;
750: fclose(fp);
751: }
752:
1.10 noro 753: void printvars(char *s,VS vs)
1.1 noro 754: {
755: FNODE expr;
756: char *p;
757: pointer val = 0;
758: int err;
759: VS cpvs;
760:
761: for ( p = s; *p; p++ )
762: if ( *p == '\n' ) {
763: *p = 0; break;
764: }
765: if ( exprparse(vs==GPVS?0:vs->usrf,s,&expr) ) {
766: cpvs = CPVS; CPVS = vs;
1.11 noro 767: if ( !(err = SETJMP(debug_env)) )
1.1 noro 768: val = eval(expr);
769: CPVS = cpvs;
770: if ( !err ) {
1.12 ohara 771: #if defined(PARI)
772: #if defined(PARI1)
1.1 noro 773: outfile = stderr;
774: #else
775: pari_outfile = stderr;
776: #endif
777: #endif
778: asir_out = stderr;
779: for ( p = s; isspace(*p); p++ );
780: fprintf(asir_out,"%s = ",p);
781: if ( val && ID((R)val) == O_MAT )
782: putc('\n',asir_out);
783: #if defined(VISUAL_LIB)
784: w_noflush_stderr(1);
785: #endif
786: printexpr(CO,val); putc('\n',asir_out); fflush(asir_out);
787: #if defined(VISUAL_LIB)
788: w_noflush_stderr(0);
789: #endif
1.12 ohara 790: #if defined(PARI)
791: #if defined(PARI1)
1.1 noro 792: outfile = stdout;
793: #else
794: pari_outfile = stdout;
795: #endif
796: #endif
797: asir_out = stdout;
798: }
799: }
800: }
801:
802: void showpos()
803: {
804: NODE n;
805: VS vs;
806: int level;
807:
808: if ( PVSS ) {
809: if ( cur_binf )
810: fprintf(stderr,"%s() (builtin)\n",cur_binf->name);
811: ((VS)BDY(PVSS))->at = evalstatline;
812: level = ((VS)BDY(PVSS))->level;
813: for ( n = PVSS; n; n = NEXT(n) ) {
814: vs = (VS)BDY(n);
815: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
816: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
817: }
818: }
819: }
820:
1.10 noro 821: void showpos_to_string(char *buf)
1.1 noro 822: {
823: NODE n;
824: VS vs;
825: int level;
826:
827: buf[0] = 0;
828: if ( PVSS ) {
829: if ( cur_binf )
830: sprintf(buf,"%s() (builtin)\n",cur_binf->name);
831: buf += strlen(buf);
832: ((VS)BDY(PVSS))->at = evalstatline;
833: level = ((VS)BDY(PVSS))->level;
834: for ( n = PVSS; n; n = NEXT(n) ) {
835: vs = (VS)BDY(n);
836: sprintf(buf,"#%d %s(), line %d in \"%s\"\n",
837: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
838: buf += strlen(buf);
839: }
840: }
841: }
842:
1.10 noro 843: void change_stack(int level,NODE *pvss)
1.1 noro 844: {
845: extern NODE PVSS;
846: NODE n;
847: int i;
848: VS vs;
849:
850: if ( !level || !PVSS )
851: return;
852: if ( level < 0 ) {
853: for ( n = PVSS, i = 0; n && n != *pvss; n = NEXT(n), i++ );
854: for ( n = PVSS, i = MAX(i+level,0); n && i; n = NEXT(n), i-- );
855: } else
856: for ( n = *pvss, i = level; NEXT(n) && i; n = NEXT(n), i-- );
857: *pvss = n; vs = (VS)BDY(n);
858: ((VS)BDY(PVSS))->at = evalstatline;
859: show_stack(vs);
860: targetf = vs->usrf; curline = vs->at;
861: }
862:
1.10 noro 863: void show_stack(VS vs)
1.1 noro 864: {
865: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
866: ((VS)BDY(PVSS))->level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
867: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>