Annotation of OpenXM_contrib2/asir2000/parse/debug.c, Revision 1.6
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.6 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/debug.c,v 1.5 2000/08/22 05:04:26 noro Exp $
1.4 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52: #include <ctype.h>
1.2 noro 53: #if PARI
1.1 noro 54: #include "genpari.h"
1.2 noro 55: #endif
1.1 noro 56:
57: void show_stack(VS);
58: void change_stack(int,NODE *);
59: void showpos(void);
60: void printvars(char *,VS);
61: void println(int,char **,int);
62: void bp(SNODE);
63: void searchsn(SNODE *,int,SNODE **);
64: void showbp(int);
65: void showbps(void);
66: void delbp(int,char **);
67: int searchbp(void);
68: void clearbp(FUNC);
69: void settp(char *);
70: void setbp(char *);
71: void setf(int,char **);
72: void show_alias(char *);
73: void add_alias(char *,char *);
74:
75: extern do_server_in_X11,do_file;
76:
77: typedef enum {
78: D_NEXT, D_STEP, D_FINISH, D_CONT, D_QUIT,
79: D_UP, D_DOWN, D_FRAME,
80: D_LIST, D_PRINT,
81: D_SETF, D_SETBP, D_SETTP, D_DELBP,
82: D_SHOWBP, D_WHERE, D_ALIAS, D_UNKNOWN
83: } did;
84:
85: struct oDEBCOM {
86: NODE names;
87: did id;
88: };
89:
90: int nextbp,nextbplevel;
91: FUNC cur_binf;
92:
93: static FUNC targetf;
94: static int curline = 1;
95:
96: extern NODE PVSS;
97: extern unsigned int evalstatline;
98: extern int debug_mode;
99: extern jmp_buf debug_env;
100:
101: char *debcom[] = {
102: "next",
103: "step",
104: "finish",
105: "cont",
106: "quit",
107: "up",
108: "down",
109: "frame",
110: "list",
111: "print",
112: "func",
113: "stop",
114: "trace",
115: "delete",
116: "status",
117: "where",
118: "alias",
119: };
120:
121: struct oDEBCOM dckwd[] = {
122: {0, D_NEXT},
123: {0, D_STEP},
124: {0, D_FINISH},
125: {0, D_CONT},
126: {0, D_QUIT},
127: {0, D_UP},
128: {0, D_DOWN},
129: {0, D_FRAME},
130: {0, D_LIST},
131: {0, D_PRINT},
132: {0, D_SETF},
133: {0, D_SETBP},
134: {0, D_SETTP},
135: {0, D_DELBP},
136: {0, D_SHOWBP},
137: {0, D_WHERE},
138: {0, D_ALIAS},
139: {0, D_UNKNOWN}
140: };
141:
142: void debug_init() {
143: int i,n,ac;
144: char *home;
145: char buf[BUFSIZ+1];
146: #if defined(__MWERKS__)
147: char *av[64];
148: #else
149: char *av[BUFSIZ];
150: #endif
151: FILE *fp;
152:
153: for ( n = 0; dckwd[n].id != D_UNKNOWN; n++ );
154: for ( i = 0; i < n; i++ )
155: MKNODE(dckwd[i].names,debcom[i],0);
156: home = (char *)getenv("HOME");
157: if ( home )
158: strcpy(buf,home);
159: else
160: buf[0] = 0;
161: strcat(buf,"/.dbxinit");
162: if ( (fp = fopen(".dbxinit","r")) || (fp = fopen(buf,"r")) ) {
163: while ( fgets(buf,BUFSIZ,fp) ) {
164: stoarg(buf,&ac,av);
165: if ((ac == 3) && !strcmp(av[0],"alias"))
166: add_alias(av[2],av[1]);
167: }
168: fclose(fp);
169: }
170: #if !defined(VISUAL)
171: if ( do_server_in_X11 )
172: init_cmdwin();
173: #endif
174: }
175:
176: void add_alias(com,alias)
177: char *com,*alias;
178: {
179: int i;
180: NODE tn;
181: char *s;
182:
183: for ( i = 0; dckwd[i].names; i++ )
184: if (!strcmp(com,debcom[i])) {
185: for ( tn = dckwd[i].names; NEXT(tn); tn = NEXT(tn) );
186: s = (char *)MALLOC(strlen(alias)+1); strcpy(s,alias);
187: MKNODE(NEXT(tn),s,0);
188: return;
189: }
190: }
191:
192: void show_alias(alias)
193: char *alias;
194: {
195: int i;
196: NODE tn;
197:
198: if ( !alias )
199: for ( i = 0; dckwd[i].names; i++ ) {
200: if ( tn = NEXT(dckwd[i].names) )
201: fprintf(stderr,"%s\t",debcom[i]);
202: for ( ; tn; tn = NEXT(tn) ) {
203: fputs(BDY(tn),stderr);
204: if ( NEXT(tn) )
205: fputc(' ',stderr);
206: else
207: fputc('\n',stderr);
208: }
209: }
210: else
211: for ( i = 0; dckwd[i].names; i++ )
212: for ( tn = dckwd[i].names; tn; tn = NEXT(tn) )
213: if ( !strcmp(alias,BDY(tn)) ) {
214: fprintf(stderr,"%s->%s\n",alias,debcom[i]); return;
215: }
216: }
217:
218: void debug(f)
219: SNODE f;
220: {
221: int ac,i,n;
222: did id;
223: #if defined(__MWERKS__)
224: char *av[64];
225: #else
226: char *av[BUFSIZ];
227: #endif
228: char buf[BUFSIZ];
229: char prompt[BUFSIZ];
230: char *p,*pe;
231: NODE tn;
232: extern int kernelmode,do_fep;
233: NODE pvss;
234:
1.3 noro 235: #if !MPI && !defined(VISUAL)
1.1 noro 236: if ( !isatty(fileno(stdin)) && !do_server_in_X11 )
237: if ( do_file )
238: ExitAsir();
239: else
240: return;
241: #endif
1.6 ! noro 242: #if defined(VISUAL)
1.1 noro 243: suspend_timer();
244: #endif
245: pvss = PVSS; debug_mode = 1;
246: #if !defined(VISUAL)
247: if ( do_server_in_X11 )
248: #endif
249: show_debug_window(1);
250: sprintf(prompt,"(debug)%c",kernelmode?0xfe:' ');
251: if ( kernelmode )
252: fputc('\0',stderr);
253: setjmp(debug_env);
254: while ( 1 ) {
255: if ( !do_server_in_X11 )
256: fputs(prompt,stderr);
257: bzero(buf,BUFSIZ);
258: while ( 1 ) {
259: {
260: int len;
261:
262: #if !defined(VISUAL)
263: if ( do_server_in_X11 )
264: get_line(buf);
265: else
266: #endif
267: if ( !fgets(buf,BUFSIZ,stdin) )
268: goto LAST;
269: len = strlen(buf);
270: if ( buf[len-1] == '\n' )
271: buf[len-1] = 0;
272: }
273: for ( p = buf; *p && isspace(*p); p++ );
274: if ( *p )
275: break;
276: }
277: for ( pe = p; *pe && !isspace(*pe); pe++ );
278: *pe = 0;
279: for ( i = 0; dckwd[i].names; i++ ) {
280: for ( tn = dckwd[i].names; tn; tn = NEXT(tn) )
281: if ( !strcmp(BDY(tn),p) )
282: break;
283: if ( tn )
284: break;
285: }
286: id = dckwd[i].id; p = pe+1;
287: switch ( id ) {
288: case D_NEXT:
289: if ( f ) { nextbp = 1; nextbplevel = 0; }
290: goto LAST; break;
291: case D_STEP:
292: if ( f ) { nextbp = 1; nextbplevel = -1; }
293: goto LAST; break;
294: case D_FINISH:
295: if ( f ) { nextbp = 1; nextbplevel = 1; }
296: goto LAST; break;
297: case D_CONT: case D_QUIT:
298: goto LAST; break;
299: case D_UP:
300: if ( f ) {
301: stoarg(p,&ac,av); n = ac ? atoi(av[0]) : 1;
302: change_stack(n,&pvss);
303: }
304: break;
305: case D_DOWN:
306: if ( f ) {
307: stoarg(p,&ac,av); n = ac ? atoi(av[0]) : 1;
308: change_stack(-n,&pvss);
309: }
310: break;
311: case D_FRAME:
312: if ( f ) {
313: stoarg(p,&ac,av);
314: if ( !ac )
315: show_stack((VS)BDY(pvss));
316: else {
317: n = atoi(av[0]);
318: change_stack(((VS)BDY(pvss))->level-((VS)BDY(PVSS))->level+n,&pvss);
319: }
320: }
321: break;
322: case D_PRINT:
323: printvars(p,pvss?(VS)BDY(pvss):GPVS); break;
324: case D_LIST:
325: stoarg(p,&ac,av); println(ac,av,10); break;
326: case D_SETF:
327: stoarg(p,&ac,av); setf(ac,av); break;
328: case D_SETBP:
329: setbp(p); break;
330: case D_SETTP:
331: settp(p); break;
332: case D_DELBP:
333: stoarg(p,&ac,av); delbp(ac,av); break;
334: case D_SHOWBP:
335: showbps(); break;
336: case D_WHERE:
337: showpos(); break;
338: case D_ALIAS:
339: stoarg(p,&ac,av);
340: switch ( ac ) {
341: case 0:
342: show_alias(0); break;
343: case 1:
344: show_alias(av[0]); break;
345: case 2: default:
346: add_alias(av[1],av[0]); break;
347: }
348: break;
349: default:
350: break;
351: }
352: }
353: LAST:
354: if ( kernelmode )
355: fputc('\0',stderr);
356: debug_mode = 0;
1.6 ! noro 357: #if !defined(VISUAL)
1.1 noro 358: if ( do_server_in_X11 )
359: #endif
360: show_debug_window(0);
361: }
362:
363: void setf(ac,av)
364: int ac;
365: char **av;
366: {
367: FUNC r;
368:
369: if ( !ac )
370: return;
371: searchf(usrf,av[0],&r);
372: if ( r ) {
373: targetf = r;
374: curline = targetf->f.usrf->startl;
375: }
376: }
377:
378: #define MAXBP 64
379:
380: static struct {
381: int at;
382: FUNC f;
383: SNODE *snp;
384: char *texpr;
385: char *cond;
386: } bpt[MAXBP];
387:
388: static int bpindex = 0;
389:
390: void setbp(p)
391: char *p;
392: {
393: int ac;
394: char *av[BUFSIZ];
395: char *buf,*savp;
396: char *fname;
397: FUNC r;
398: USRF t;
399: SNODE *snp = 0;
400: FNODE cond;
401: NODE tn;
402: int n,at,ln,bpi;
403:
404: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
405: if ( ac < 2 )
406: return;
407: if ( !strcmp(av[0],"at") ) {
408: if ( !targetf )
409: return;
410: n = atoi(av[1]); fname = targetf->f.usrf->fname;
411: for ( tn = usrf; tn; tn = NEXT(tn) ) {
412: r = (FUNC)BDY(tn); t = r->f.usrf;
413: if ( t && t->fname && !strcmp(t->fname,fname)
414: && ( t->startl <= n ) && ( n <= t->endl ) )
415: break;
416: }
417: if ( !r ) {
418: fprintf(stderr,"no such line in %s\n",fname);
419: return;
420: } else {
421: targetf = r; curline = n;
422: }
423: at = 1; searchsn(&BDY(t),n,&snp);
424: } else if ( !strcmp(av[0],"in") ) {
425: searchf(usrf,av[1],&r);
426: if ( !r ) {
427: fprintf(stderr,"%s() : no such function\n",av[1]);
428: return;
429: } else if ( r->id == A_UNDEF ) {
430: fprintf(stderr,"%s : undefined\n",av[1]);
431: return;
432: }
433: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
434: if ( tn ) {
435: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
436: }
437: } else
438: return;
439: if ( snp ) {
440: cond = 0;
441: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
442: savp = p+(av[2]-buf)+2;
443: exprparse(targetf,savp,&cond);
444: }
445: bpi = searchbp();
446: if ( bpi < 0 )
447: fprintf(stderr,"too many breakpoints\n");
448: else if ( ID(*snp) == S_BP )
449: return;
450: else {
451: switch ( ID(*snp) ) {
452: case S_IFELSE: case S_FOR: case S_DO:
453: ln = (int)FA0(*snp); break;
454: default:
455: ln = (*snp)->ln; break;
456: }
457: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,0);
458: (*snp)->ln = ln;
459: if ( cond ) {
460: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
461: strcpy(bpt[bpi].cond,savp);
462: } else
463: bpt[bpi].cond = 0;
464: bpt[bpi].at = at;
465: bpt[bpi].f = targetf;
466: bpt[bpi].snp = snp;
467: bpt[bpi].texpr = 0;
468: showbp(bpi);
469: }
470: }
471: }
472:
473: void settp(p)
474: char *p;
475: {
476: int ac;
477: char *_av[BUFSIZ];
478: char **av;
479: char *buf,*savp;
480: char *fname;
481: char *texprname;
482: FUNC r;
483: USRF t;
484: SNODE *snp = 0;
485: FNODE cond,texpr;
486: NODE tn;
487: int n,at,ln,bpi;
488:
489: av = _av;
490: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
491: if ( ac < 3 )
492: return;
493: texprname = av[0]; ac--; av++;
494: if ( !strcmp(av[0],"at") ) {
495: if ( !targetf )
496: return;
497: n = atoi(av[1]); fname = targetf->f.usrf->fname;
498: for ( tn = usrf; tn; tn = NEXT(tn) ) {
499: r = (FUNC)BDY(tn); t = r->f.usrf;
500: if ( t && t->fname && !strcmp(t->fname,fname)
501: && ( t->startl <= n ) && ( n <= t->endl ) )
502: break;
503: }
504: if ( !r ) {
505: fprintf(stderr,"no such line in %s\n",fname);
506: return;
507: } else {
508: targetf = r; curline = n;
509: }
510: at = 1; searchsn(&BDY(t),n,&snp);
511: } else if ( !strcmp(av[0],"in") ) {
512: searchf(usrf,av[1],&r);
513: if ( !r ) {
514: fprintf(stderr,"%s() : no such function\n",av[1]);
515: return;
516: }
517: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
518: if ( tn ) {
519: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
520: }
521: } else
522: return;
523: if ( snp ) {
524: cond = 0;
525: exprparse(targetf,texprname,&texpr);
526: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
527: savp = p+(av[2]-buf)+2;
528: exprparse(targetf,savp,&cond);
529: }
530: bpi = searchbp();
531: if ( bpi < 0 )
532: fprintf(stderr,"too many breakpoints\n");
533: else if ( ID(*snp) == S_BP )
534: return;
535: else {
536: switch ( ID(*snp) ) {
537: case S_IFELSE: case S_FOR: case S_DO:
538: ln = (int)FA0(*snp); break;
539: default:
540: ln = (*snp)->ln; break;
541: }
542: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,texpr);
543: (*snp)->ln = ln;
544: if ( cond ) {
545: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
546: strcpy(bpt[bpi].cond,savp);
547: } else
548: bpt[bpi].cond = 0;
549: bpt[bpi].at = at;
550: bpt[bpi].f = targetf;
551: bpt[bpi].snp = snp;
552: bpt[bpi].texpr = (char *)MALLOC(strlen(texprname)+1);
553: strcpy(bpt[bpi].texpr,texprname);
554: showbp(bpi);
555: }
556: }
557: }
558:
559: void clearbp(f)
560: FUNC f;
561: {
562: int i;
563:
564: if ( !f )
565: return;
566: for ( i = 0; i < bpindex; i++ )
567: if ( bpt[i].snp && !strcmp(f->name,bpt[i].f->name) ) {
568: bpt[i].at = 0; bpt[i].f = 0; bpt[i].snp = 0;
569: }
570: }
571:
572: int searchbp()
573: {
574: int i;
575:
576: for ( i = 0; i < bpindex; i++ )
577: if ( !bpt[i].snp )
578: return i;
579: if ( bpindex == MAXBP )
580: return -1;
581: else
582: return bpindex++;
583: }
584:
585: void delbp(ac,av)
586: int ac;
587: char **av;
588: {
589: int n;
590:
591: if ( !ac )
592: return;
593: if ( (n = atoi(av[0])) >= bpindex )
594: return;
595: if ( bpt[n].snp ) {
596: *bpt[n].snp = (SNODE)FA0(*bpt[n].snp);
597: bpt[n].snp = 0;
598: }
599: }
600:
601: void showbps() {
602: int i;
603:
604: for ( i = 0; i < bpindex; i++ )
605: showbp(i);
606: }
607:
608: void showbp(n)
609: int n;
610: {
611: if ( bpt[n].snp )
612: if ( bpt[n].texpr )
613: if ( bpt[n].at ) {
614: if ( bpt[n].cond )
615: fprintf(stderr,"(%d) trace %s at \"%s\":%d if %s\n",
616: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
617: else
618: fprintf(stderr,"(%d) trace %s at \"%s\":%d\n",
619: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
620: } else {
621: if ( bpt[n].cond )
622: fprintf(stderr,"(%d) trace %s in %s if %s\n",
623: n,bpt[n].texpr,bpt[n].f->name,bpt[n].cond);
624: else
625: fprintf(stderr,"(%d) trace %s in %s\n",n,bpt[n].texpr,bpt[n].f->name);
626: }
627: else
628: if ( bpt[n].at ) {
629: if ( bpt[n].cond )
630: fprintf(stderr,"(%d) stop at \"%s\":%d if %s\n",
631: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
632: else
633: fprintf(stderr,"(%d) stop at \"%s\":%d\n",
634: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
635: } else {
636: if ( bpt[n].cond )
637: fprintf(stderr,"(%d) stop in %s if %s\n",
638: n,bpt[n].f->name,bpt[n].cond);
639: else
640: fprintf(stderr,"(%d) stop in %s\n",n,bpt[n].f->name);
641: }
642: }
643:
644: void searchsn(fp,n,fpp)
645: SNODE *fp;
646: int n;
647: SNODE **fpp;
648: {
649: NODE tn;
650: SNODE sn;
651: SNODE *snp;
652:
653: *fpp = 0;
654: switch (ID(*fp)) {
655: case S_CPLX:
656: for ( tn = (NODE)FA0(*fp); tn; tn = NEXT(tn) )
657: if ( sn = (SNODE)BDY(tn) ) {
658: snp = (SNODE *)(ID(sn) == S_BP ? &FA0(sn) : &BDY(tn));
659: if ( (*snp)->ln >= n ) {
660: searchsn(snp,n,fpp); break;
661: }
662: }
663: break;
664: case S_IFELSE:
665: if ( n <= (int)FA0(*fp) )
666: *fpp = fp;
667: else if ( n <= ((SNODE)FA2(*fp))->ln )
668: searchsn((SNODE *)&FA2(*fp),n,fpp);
669: else if ( FA3(*fp) )
670: searchsn((SNODE *)&FA3(*fp),n,fpp);
671: if ( !(*fpp) )
672: *fpp = fp;
673: break;
674: case S_FOR:
675: if ( n <= (int)FA0(*fp) )
676: *fpp = fp;
677: else
678: searchsn((SNODE *)&FA4(*fp),n,fpp);
679: if ( !(*fpp) )
680: *fpp = fp;
681: break;
682: case S_DO:
683: if ( n <= (int)FA0(*fp) )
684: *fpp = fp;
685: else
686: searchsn((SNODE *)&FA1(*fp),n,fpp);
687: if ( !(*fpp) )
688: *fpp = fp;
689: break;
690: case S_BP:
691: switch ( ID((SNODE)FA0(*fp)) ) {
692: case S_SINGLE:
693: *fpp = fp; break;
694: default:
695: searchsn((SNODE *)&FA0(*fp),n,fpp); break;
696: }
697: break;
698: case S_SINGLE: default:
699: *fpp = fp;
700: break;
701: }
702: }
703:
704: void bp(f)
705: SNODE f;
706: {
707: int ln;
708:
709: if ( !f || (CPVS == GPVS) )
710: return;
711:
712: switch ( ID(f) ) {
713: case S_IFELSE: case S_FOR:
714: ln = (int)FA0(f); break;
715: default:
716: ln = f->ln; break;
717: }
718: #if !defined(VISUAL)
719: if ( do_server_in_X11 )
720: #endif
721: show_debug_window(1);
722: fprintf(stderr,"stopped in %s at line %d in file \"%s\"\n",
723: CPVS->usrf->name,ln,CPVS->usrf->f.usrf->fname);
724: targetf = CPVS->usrf; curline = ln;
725: println(0,0,1);
1.3 noro 726: #if !MPI && !defined(VISUAL)
1.1 noro 727: if ( do_server_in_X11 || isatty(0) )
728: #endif
729: debug(f);
730: }
731:
732: void println(ac,av,l)
733: int ac;
734: char **av;
735: int l;
736: {
737: FILE *fp;
738: char buf[BUFSIZ+1];
739: int i;
740: int ln;
741: FUNC r;
742:
743: if ( !ac )
744: ln = curline;
745: else if ( isdigit(av[0][0]) )
746: ln = atoi(av[0]);
747: else {
748: searchf(usrf,av[0],&r);
749: if ( r && r->id != A_UNDEF ) {
750: targetf = r;
751: ln = r->f.usrf->startl;
752: } else {
753: fprintf(stderr,"%s undefined\n",av[0]);
754: ln = curline;
755: }
756: }
757: if ( !targetf )
758: return;
759: fp = fopen(targetf->f.usrf->fname,"r");
760: if ( !fp ) {
761: fprintf(stderr,"\"%s\" not found\n",targetf->name);
762: return;
763: }
764: for ( i = 1; i < ln; i++ )
765: if ( !fgets(buf,BUFSIZ,fp) )
766: return;
767: for ( i = 0; i < l; i++ ) {
768: if ( !fgets(buf,BUFSIZ,fp) )
769: break;
770: fprintf(stderr,"%d %s",ln+i,buf);
771: }
772: curline = ln + i;
773: fclose(fp);
774: }
775:
776: void printvars(s,vs)
777: char *s;
778: VS vs;
779: {
780: FNODE expr;
781: char *p;
782: pointer val = 0;
783: int err;
784: VS cpvs;
785:
786: for ( p = s; *p; p++ )
787: if ( *p == '\n' ) {
788: *p = 0; break;
789: }
790: if ( exprparse(vs==GPVS?0:vs->usrf,s,&expr) ) {
791: cpvs = CPVS; CPVS = vs;
792: if ( !(err = setjmp(debug_env)) )
793: val = eval(expr);
794: CPVS = cpvs;
795: if ( !err ) {
796: #if PARI
797: #if PARI1
798: outfile = stderr;
799: #else
800: pari_outfile = stderr;
801: #endif
802: #endif
803: asir_out = stderr;
804: for ( p = s; isspace(*p); p++ );
805: fprintf(asir_out,"%s = ",p);
806: if ( val && ID((R)val) == O_MAT )
807: putc('\n',asir_out);
808: #if defined(VISUAL_LIB)
809: w_noflush_stderr(1);
810: #endif
811: printexpr(CO,val); putc('\n',asir_out); fflush(asir_out);
812: #if defined(VISUAL_LIB)
813: w_noflush_stderr(0);
814: #endif
815: #if PARI
816: #if PARI1
817: outfile = stdout;
818: #else
819: pari_outfile = stdout;
820: #endif
821: #endif
822: asir_out = stdout;
823: }
824: }
825: }
826:
827: void showpos()
828: {
829: NODE n;
830: VS vs;
831: int level;
832:
833: if ( PVSS ) {
834: if ( cur_binf )
835: fprintf(stderr,"%s() (builtin)\n",cur_binf->name);
836: ((VS)BDY(PVSS))->at = evalstatline;
837: level = ((VS)BDY(PVSS))->level;
838: for ( n = PVSS; n; n = NEXT(n) ) {
839: vs = (VS)BDY(n);
840: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
841: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
842: }
843: }
844: }
845:
846: void showpos_to_string(buf)
847: char *buf;
848: {
849: NODE n;
850: VS vs;
851: int level;
852:
853: buf[0] = 0;
854: if ( PVSS ) {
855: if ( cur_binf )
856: sprintf(buf,"%s() (builtin)\n",cur_binf->name);
857: buf += strlen(buf);
858: ((VS)BDY(PVSS))->at = evalstatline;
859: level = ((VS)BDY(PVSS))->level;
860: for ( n = PVSS; n; n = NEXT(n) ) {
861: vs = (VS)BDY(n);
862: sprintf(buf,"#%d %s(), line %d in \"%s\"\n",
863: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
864: buf += strlen(buf);
865: }
866: }
867: }
868:
869: void change_stack(level,pvss)
870: int level;
871: NODE *pvss;
872: {
873: extern NODE PVSS;
874: NODE n;
875: int i;
876: VS vs;
877:
878: if ( !level || !PVSS )
879: return;
880: if ( level < 0 ) {
881: for ( n = PVSS, i = 0; n && n != *pvss; n = NEXT(n), i++ );
882: for ( n = PVSS, i = MAX(i+level,0); n && i; n = NEXT(n), i-- );
883: } else
884: for ( n = *pvss, i = level; NEXT(n) && i; n = NEXT(n), i-- );
885: *pvss = n; vs = (VS)BDY(n);
886: ((VS)BDY(PVSS))->at = evalstatline;
887: show_stack(vs);
888: targetf = vs->usrf; curline = vs->at;
889: }
890:
891: void show_stack(vs)
892: VS vs;
893: {
894: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
895: ((VS)BDY(PVSS))->level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
896: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>