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