Annotation of OpenXM_contrib2/asir2000/parse/debug.c, Revision 1.8
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.8 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/debug.c,v 1.7 2000/12/22 10:03:31 saito 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];
1.7 saito 230: char *p,*pe,*line;
1.1 noro 231: NODE tn;
1.8 ! noro 232: extern int do_fep;
1.1 noro 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);
1.8 ! noro 250: sprintf(prompt,"(debug) ");
1.1 noro 251: setjmp(debug_env);
252: while ( 1 ) {
1.7 saito 253: #if FEP
254: if ( !do_fep )
255: #endif
256: if ( !do_server_in_X11 )
257: fputs(prompt,stderr);
1.1 noro 258: bzero(buf,BUFSIZ);
259: while ( 1 ) {
1.7 saito 260: #if FEP
261: if ( do_fep ) {
262: line = (char *)readline_console(prompt);
263: strcpy(buf,line); free(line);
264: } else
265: #endif
1.1 noro 266: {
267: int len;
268:
269: #if !defined(VISUAL)
270: if ( do_server_in_X11 )
271: get_line(buf);
272: else
273: #endif
274: if ( !fgets(buf,BUFSIZ,stdin) )
275: goto LAST;
276: len = strlen(buf);
277: if ( buf[len-1] == '\n' )
278: buf[len-1] = 0;
279: }
280: for ( p = buf; *p && isspace(*p); p++ );
281: if ( *p )
282: break;
283: }
284: for ( pe = p; *pe && !isspace(*pe); pe++ );
285: *pe = 0;
286: for ( i = 0; dckwd[i].names; i++ ) {
287: for ( tn = dckwd[i].names; tn; tn = NEXT(tn) )
288: if ( !strcmp(BDY(tn),p) )
289: break;
290: if ( tn )
291: break;
292: }
293: id = dckwd[i].id; p = pe+1;
294: switch ( id ) {
295: case D_NEXT:
296: if ( f ) { nextbp = 1; nextbplevel = 0; }
297: goto LAST; break;
298: case D_STEP:
299: if ( f ) { nextbp = 1; nextbplevel = -1; }
300: goto LAST; break;
301: case D_FINISH:
302: if ( f ) { nextbp = 1; nextbplevel = 1; }
303: goto LAST; break;
304: case D_CONT: case D_QUIT:
305: goto LAST; break;
306: case D_UP:
307: if ( f ) {
308: stoarg(p,&ac,av); n = ac ? atoi(av[0]) : 1;
309: change_stack(n,&pvss);
310: }
311: break;
312: case D_DOWN:
313: if ( f ) {
314: stoarg(p,&ac,av); n = ac ? atoi(av[0]) : 1;
315: change_stack(-n,&pvss);
316: }
317: break;
318: case D_FRAME:
319: if ( f ) {
320: stoarg(p,&ac,av);
321: if ( !ac )
322: show_stack((VS)BDY(pvss));
323: else {
324: n = atoi(av[0]);
325: change_stack(((VS)BDY(pvss))->level-((VS)BDY(PVSS))->level+n,&pvss);
326: }
327: }
328: break;
329: case D_PRINT:
330: printvars(p,pvss?(VS)BDY(pvss):GPVS); break;
331: case D_LIST:
332: stoarg(p,&ac,av); println(ac,av,10); break;
333: case D_SETF:
334: stoarg(p,&ac,av); setf(ac,av); break;
335: case D_SETBP:
336: setbp(p); break;
337: case D_SETTP:
338: settp(p); break;
339: case D_DELBP:
340: stoarg(p,&ac,av); delbp(ac,av); break;
341: case D_SHOWBP:
342: showbps(); break;
343: case D_WHERE:
344: showpos(); break;
345: case D_ALIAS:
346: stoarg(p,&ac,av);
347: switch ( ac ) {
348: case 0:
349: show_alias(0); break;
350: case 1:
351: show_alias(av[0]); break;
352: case 2: default:
353: add_alias(av[1],av[0]); break;
354: }
355: break;
356: default:
357: break;
358: }
359: }
360: LAST:
361: debug_mode = 0;
1.6 noro 362: #if !defined(VISUAL)
1.1 noro 363: if ( do_server_in_X11 )
364: #endif
365: show_debug_window(0);
366: }
367:
368: void setf(ac,av)
369: int ac;
370: char **av;
371: {
372: FUNC r;
373:
374: if ( !ac )
375: return;
376: searchf(usrf,av[0],&r);
377: if ( r ) {
378: targetf = r;
379: curline = targetf->f.usrf->startl;
380: }
381: }
382:
383: #define MAXBP 64
384:
385: static struct {
386: int at;
387: FUNC f;
388: SNODE *snp;
389: char *texpr;
390: char *cond;
391: } bpt[MAXBP];
392:
393: static int bpindex = 0;
394:
395: void setbp(p)
396: char *p;
397: {
398: int ac;
399: char *av[BUFSIZ];
400: char *buf,*savp;
401: char *fname;
402: FUNC r;
403: USRF t;
404: SNODE *snp = 0;
405: FNODE cond;
406: NODE tn;
407: int n,at,ln,bpi;
408:
409: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
410: if ( ac < 2 )
411: return;
412: if ( !strcmp(av[0],"at") ) {
413: if ( !targetf )
414: return;
415: n = atoi(av[1]); fname = targetf->f.usrf->fname;
416: for ( tn = usrf; tn; tn = NEXT(tn) ) {
417: r = (FUNC)BDY(tn); t = r->f.usrf;
418: if ( t && t->fname && !strcmp(t->fname,fname)
419: && ( t->startl <= n ) && ( n <= t->endl ) )
420: break;
421: }
422: if ( !r ) {
423: fprintf(stderr,"no such line in %s\n",fname);
424: return;
425: } else {
426: targetf = r; curline = n;
427: }
428: at = 1; searchsn(&BDY(t),n,&snp);
429: } else if ( !strcmp(av[0],"in") ) {
430: searchf(usrf,av[1],&r);
431: if ( !r ) {
432: fprintf(stderr,"%s() : no such function\n",av[1]);
433: return;
434: } else if ( r->id == A_UNDEF ) {
435: fprintf(stderr,"%s : undefined\n",av[1]);
436: return;
437: }
438: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
439: if ( tn ) {
440: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
441: }
442: } else
443: return;
444: if ( snp ) {
445: cond = 0;
446: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
447: savp = p+(av[2]-buf)+2;
448: exprparse(targetf,savp,&cond);
449: }
450: bpi = searchbp();
451: if ( bpi < 0 )
452: fprintf(stderr,"too many breakpoints\n");
453: else if ( ID(*snp) == S_BP )
454: return;
455: else {
456: switch ( ID(*snp) ) {
457: case S_IFELSE: case S_FOR: case S_DO:
458: ln = (int)FA0(*snp); break;
459: default:
460: ln = (*snp)->ln; break;
461: }
462: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,0);
463: (*snp)->ln = ln;
464: if ( cond ) {
465: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
466: strcpy(bpt[bpi].cond,savp);
467: } else
468: bpt[bpi].cond = 0;
469: bpt[bpi].at = at;
470: bpt[bpi].f = targetf;
471: bpt[bpi].snp = snp;
472: bpt[bpi].texpr = 0;
473: showbp(bpi);
474: }
475: }
476: }
477:
478: void settp(p)
479: char *p;
480: {
481: int ac;
482: char *_av[BUFSIZ];
483: char **av;
484: char *buf,*savp;
485: char *fname;
486: char *texprname;
487: FUNC r;
488: USRF t;
489: SNODE *snp = 0;
490: FNODE cond,texpr;
491: NODE tn;
492: int n,at,ln,bpi;
493:
494: av = _av;
495: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
496: if ( ac < 3 )
497: return;
498: texprname = av[0]; ac--; av++;
499: if ( !strcmp(av[0],"at") ) {
500: if ( !targetf )
501: return;
502: n = atoi(av[1]); fname = targetf->f.usrf->fname;
503: for ( tn = usrf; tn; tn = NEXT(tn) ) {
504: r = (FUNC)BDY(tn); t = r->f.usrf;
505: if ( t && t->fname && !strcmp(t->fname,fname)
506: && ( t->startl <= n ) && ( n <= t->endl ) )
507: break;
508: }
509: if ( !r ) {
510: fprintf(stderr,"no such line in %s\n",fname);
511: return;
512: } else {
513: targetf = r; curline = n;
514: }
515: at = 1; searchsn(&BDY(t),n,&snp);
516: } else if ( !strcmp(av[0],"in") ) {
517: searchf(usrf,av[1],&r);
518: if ( !r ) {
519: fprintf(stderr,"%s() : no such function\n",av[1]);
520: return;
521: }
522: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
523: if ( tn ) {
524: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
525: }
526: } else
527: return;
528: if ( snp ) {
529: cond = 0;
530: exprparse(targetf,texprname,&texpr);
531: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
532: savp = p+(av[2]-buf)+2;
533: exprparse(targetf,savp,&cond);
534: }
535: bpi = searchbp();
536: if ( bpi < 0 )
537: fprintf(stderr,"too many breakpoints\n");
538: else if ( ID(*snp) == S_BP )
539: return;
540: else {
541: switch ( ID(*snp) ) {
542: case S_IFELSE: case S_FOR: case S_DO:
543: ln = (int)FA0(*snp); break;
544: default:
545: ln = (*snp)->ln; break;
546: }
547: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,texpr);
548: (*snp)->ln = ln;
549: if ( cond ) {
550: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
551: strcpy(bpt[bpi].cond,savp);
552: } else
553: bpt[bpi].cond = 0;
554: bpt[bpi].at = at;
555: bpt[bpi].f = targetf;
556: bpt[bpi].snp = snp;
557: bpt[bpi].texpr = (char *)MALLOC(strlen(texprname)+1);
558: strcpy(bpt[bpi].texpr,texprname);
559: showbp(bpi);
560: }
561: }
562: }
563:
564: void clearbp(f)
565: FUNC f;
566: {
567: int i;
568:
569: if ( !f )
570: return;
571: for ( i = 0; i < bpindex; i++ )
572: if ( bpt[i].snp && !strcmp(f->name,bpt[i].f->name) ) {
573: bpt[i].at = 0; bpt[i].f = 0; bpt[i].snp = 0;
574: }
575: }
576:
577: int searchbp()
578: {
579: int i;
580:
581: for ( i = 0; i < bpindex; i++ )
582: if ( !bpt[i].snp )
583: return i;
584: if ( bpindex == MAXBP )
585: return -1;
586: else
587: return bpindex++;
588: }
589:
590: void delbp(ac,av)
591: int ac;
592: char **av;
593: {
594: int n;
595:
596: if ( !ac )
597: return;
598: if ( (n = atoi(av[0])) >= bpindex )
599: return;
600: if ( bpt[n].snp ) {
601: *bpt[n].snp = (SNODE)FA0(*bpt[n].snp);
602: bpt[n].snp = 0;
603: }
604: }
605:
606: void showbps() {
607: int i;
608:
609: for ( i = 0; i < bpindex; i++ )
610: showbp(i);
611: }
612:
613: void showbp(n)
614: int n;
615: {
616: if ( bpt[n].snp )
617: if ( bpt[n].texpr )
618: if ( bpt[n].at ) {
619: if ( bpt[n].cond )
620: fprintf(stderr,"(%d) trace %s at \"%s\":%d if %s\n",
621: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
622: else
623: fprintf(stderr,"(%d) trace %s at \"%s\":%d\n",
624: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
625: } else {
626: if ( bpt[n].cond )
627: fprintf(stderr,"(%d) trace %s in %s if %s\n",
628: n,bpt[n].texpr,bpt[n].f->name,bpt[n].cond);
629: else
630: fprintf(stderr,"(%d) trace %s in %s\n",n,bpt[n].texpr,bpt[n].f->name);
631: }
632: else
633: if ( bpt[n].at ) {
634: if ( bpt[n].cond )
635: fprintf(stderr,"(%d) stop at \"%s\":%d if %s\n",
636: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
637: else
638: fprintf(stderr,"(%d) stop at \"%s\":%d\n",
639: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
640: } else {
641: if ( bpt[n].cond )
642: fprintf(stderr,"(%d) stop in %s if %s\n",
643: n,bpt[n].f->name,bpt[n].cond);
644: else
645: fprintf(stderr,"(%d) stop in %s\n",n,bpt[n].f->name);
646: }
647: }
648:
649: void searchsn(fp,n,fpp)
650: SNODE *fp;
651: int n;
652: SNODE **fpp;
653: {
654: NODE tn;
655: SNODE sn;
656: SNODE *snp;
657:
658: *fpp = 0;
659: switch (ID(*fp)) {
660: case S_CPLX:
661: for ( tn = (NODE)FA0(*fp); tn; tn = NEXT(tn) )
662: if ( sn = (SNODE)BDY(tn) ) {
663: snp = (SNODE *)(ID(sn) == S_BP ? &FA0(sn) : &BDY(tn));
664: if ( (*snp)->ln >= n ) {
665: searchsn(snp,n,fpp); break;
666: }
667: }
668: break;
669: case S_IFELSE:
670: if ( n <= (int)FA0(*fp) )
671: *fpp = fp;
672: else if ( n <= ((SNODE)FA2(*fp))->ln )
673: searchsn((SNODE *)&FA2(*fp),n,fpp);
674: else if ( FA3(*fp) )
675: searchsn((SNODE *)&FA3(*fp),n,fpp);
676: if ( !(*fpp) )
677: *fpp = fp;
678: break;
679: case S_FOR:
680: if ( n <= (int)FA0(*fp) )
681: *fpp = fp;
682: else
683: searchsn((SNODE *)&FA4(*fp),n,fpp);
684: if ( !(*fpp) )
685: *fpp = fp;
686: break;
687: case S_DO:
688: if ( n <= (int)FA0(*fp) )
689: *fpp = fp;
690: else
691: searchsn((SNODE *)&FA1(*fp),n,fpp);
692: if ( !(*fpp) )
693: *fpp = fp;
694: break;
695: case S_BP:
696: switch ( ID((SNODE)FA0(*fp)) ) {
697: case S_SINGLE:
698: *fpp = fp; break;
699: default:
700: searchsn((SNODE *)&FA0(*fp),n,fpp); break;
701: }
702: break;
703: case S_SINGLE: default:
704: *fpp = fp;
705: break;
706: }
707: }
708:
709: void bp(f)
710: SNODE f;
711: {
712: int ln;
713:
714: if ( !f || (CPVS == GPVS) )
715: return;
716:
717: switch ( ID(f) ) {
718: case S_IFELSE: case S_FOR:
719: ln = (int)FA0(f); break;
720: default:
721: ln = f->ln; break;
722: }
723: #if !defined(VISUAL)
724: if ( do_server_in_X11 )
725: #endif
726: show_debug_window(1);
727: fprintf(stderr,"stopped in %s at line %d in file \"%s\"\n",
728: CPVS->usrf->name,ln,CPVS->usrf->f.usrf->fname);
729: targetf = CPVS->usrf; curline = ln;
730: println(0,0,1);
1.3 noro 731: #if !MPI && !defined(VISUAL)
1.1 noro 732: if ( do_server_in_X11 || isatty(0) )
733: #endif
734: debug(f);
735: }
736:
737: void println(ac,av,l)
738: int ac;
739: char **av;
740: int l;
741: {
742: FILE *fp;
743: char buf[BUFSIZ+1];
744: int i;
745: int ln;
746: FUNC r;
747:
748: if ( !ac )
749: ln = curline;
750: else if ( isdigit(av[0][0]) )
751: ln = atoi(av[0]);
752: else {
753: searchf(usrf,av[0],&r);
754: if ( r && r->id != A_UNDEF ) {
755: targetf = r;
756: ln = r->f.usrf->startl;
757: } else {
758: fprintf(stderr,"%s undefined\n",av[0]);
759: ln = curline;
760: }
761: }
762: if ( !targetf )
763: return;
764: fp = fopen(targetf->f.usrf->fname,"r");
765: if ( !fp ) {
766: fprintf(stderr,"\"%s\" not found\n",targetf->name);
767: return;
768: }
769: for ( i = 1; i < ln; i++ )
770: if ( !fgets(buf,BUFSIZ,fp) )
771: return;
772: for ( i = 0; i < l; i++ ) {
773: if ( !fgets(buf,BUFSIZ,fp) )
774: break;
775: fprintf(stderr,"%d %s",ln+i,buf);
776: }
777: curline = ln + i;
778: fclose(fp);
779: }
780:
781: void printvars(s,vs)
782: char *s;
783: VS vs;
784: {
785: FNODE expr;
786: char *p;
787: pointer val = 0;
788: int err;
789: VS cpvs;
790:
791: for ( p = s; *p; p++ )
792: if ( *p == '\n' ) {
793: *p = 0; break;
794: }
795: if ( exprparse(vs==GPVS?0:vs->usrf,s,&expr) ) {
796: cpvs = CPVS; CPVS = vs;
797: if ( !(err = setjmp(debug_env)) )
798: val = eval(expr);
799: CPVS = cpvs;
800: if ( !err ) {
801: #if PARI
802: #if PARI1
803: outfile = stderr;
804: #else
805: pari_outfile = stderr;
806: #endif
807: #endif
808: asir_out = stderr;
809: for ( p = s; isspace(*p); p++ );
810: fprintf(asir_out,"%s = ",p);
811: if ( val && ID((R)val) == O_MAT )
812: putc('\n',asir_out);
813: #if defined(VISUAL_LIB)
814: w_noflush_stderr(1);
815: #endif
816: printexpr(CO,val); putc('\n',asir_out); fflush(asir_out);
817: #if defined(VISUAL_LIB)
818: w_noflush_stderr(0);
819: #endif
820: #if PARI
821: #if PARI1
822: outfile = stdout;
823: #else
824: pari_outfile = stdout;
825: #endif
826: #endif
827: asir_out = stdout;
828: }
829: }
830: }
831:
832: void showpos()
833: {
834: NODE n;
835: VS vs;
836: int level;
837:
838: if ( PVSS ) {
839: if ( cur_binf )
840: fprintf(stderr,"%s() (builtin)\n",cur_binf->name);
841: ((VS)BDY(PVSS))->at = evalstatline;
842: level = ((VS)BDY(PVSS))->level;
843: for ( n = PVSS; n; n = NEXT(n) ) {
844: vs = (VS)BDY(n);
845: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
846: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
847: }
848: }
849: }
850:
851: void showpos_to_string(buf)
852: char *buf;
853: {
854: NODE n;
855: VS vs;
856: int level;
857:
858: buf[0] = 0;
859: if ( PVSS ) {
860: if ( cur_binf )
861: sprintf(buf,"%s() (builtin)\n",cur_binf->name);
862: buf += strlen(buf);
863: ((VS)BDY(PVSS))->at = evalstatline;
864: level = ((VS)BDY(PVSS))->level;
865: for ( n = PVSS; n; n = NEXT(n) ) {
866: vs = (VS)BDY(n);
867: sprintf(buf,"#%d %s(), line %d in \"%s\"\n",
868: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
869: buf += strlen(buf);
870: }
871: }
872: }
873:
874: void change_stack(level,pvss)
875: int level;
876: NODE *pvss;
877: {
878: extern NODE PVSS;
879: NODE n;
880: int i;
881: VS vs;
882:
883: if ( !level || !PVSS )
884: return;
885: if ( level < 0 ) {
886: for ( n = PVSS, i = 0; n && n != *pvss; n = NEXT(n), i++ );
887: for ( n = PVSS, i = MAX(i+level,0); n && i; n = NEXT(n), i-- );
888: } else
889: for ( n = *pvss, i = level; NEXT(n) && i; n = NEXT(n), i-- );
890: *pvss = n; vs = (VS)BDY(n);
891: ((VS)BDY(PVSS))->at = evalstatline;
892: show_stack(vs);
893: targetf = vs->usrf; curline = vs->at;
894: }
895:
896: void show_stack(vs)
897: VS vs;
898: {
899: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
900: ((VS)BDY(PVSS))->level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
901: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>