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