Annotation of OpenXM_contrib2/asir2000/parse/debug.c, Revision 1.23
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.23 ! fujimoto 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/debug.c,v 1.22 2015/08/06 10:01:53 fujimoto 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 {
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;
1.11 noro 78: extern JMP_BUF debug_env;
1.1 noro 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: }
1.9 noro 149: #if 0
1.22 fujimoto 150: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 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: {
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:
1.10 noro 172: void show_alias(char *alias)
1.1 noro 173: {
174: int i;
175: NODE tn;
176:
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.23 ! fujimoto 195: #if defined(__MINGW32__) || defined(__MINGW64__)
! 196: fflush(stderr);
! 197: #endif
1.1 noro 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;
1.22 fujimoto 212: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.10 noro 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.22 fujimoto 219: #if !defined(MPI) && !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
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.22 fujimoto 226: #if defined(VISUAL) || defined(__MINGW32__) || defined(__MINGW64__)
1.1 noro 227: suspend_timer();
228: #endif
229: pvss = PVSS; debug_mode = 1;
1.22 fujimoto 230: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 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:
1.22 fujimoto 253: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 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.22 fujimoto 346: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
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: }
1.20 noro 446: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,NULLP);
1.1 noro 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: }
1.23 ! fujimoto 460: #if defined(__MINGW32__) || defined(__MINGW64__)
! 461: fflush(stderr);
! 462: #endif
1.1 noro 463: }
464:
1.10 noro 465: void settp(char *p)
1.1 noro 466: {
467: int ac;
468: char *_av[BUFSIZ];
469: char **av;
470: char *buf,*savp;
471: char *fname;
472: char *texprname;
473: FUNC r;
474: USRF t;
475: SNODE *snp = 0;
476: FNODE cond,texpr;
477: NODE tn;
478: int n,at,ln,bpi;
479:
480: av = _av;
481: buf = (char *)ALLOCA(strlen(p)+1); strcpy(buf,p); stoarg(buf,&ac,av);
482: if ( ac < 3 )
483: return;
484: texprname = av[0]; ac--; av++;
485: if ( !strcmp(av[0],"at") ) {
486: if ( !targetf )
487: return;
488: n = atoi(av[1]); fname = targetf->f.usrf->fname;
489: for ( tn = usrf; tn; tn = NEXT(tn) ) {
490: r = (FUNC)BDY(tn); t = r->f.usrf;
491: if ( t && t->fname && !strcmp(t->fname,fname)
492: && ( t->startl <= n ) && ( n <= t->endl ) )
493: break;
494: }
495: if ( !r ) {
496: fprintf(stderr,"no such line in %s\n",fname);
497: return;
498: } else {
499: targetf = r; curline = n;
500: }
501: at = 1; searchsn(&BDY(t),n,&snp);
502: } else if ( !strcmp(av[0],"in") ) {
1.15 noro 503: searchuf(av[1],&r);
1.1 noro 504: if ( !r ) {
505: fprintf(stderr,"%s() : no such function\n",av[1]);
506: return;
507: }
508: for ( tn = (NODE)FA0(BDY(r->f.usrf)); tn && !BDY(tn); tn = NEXT(tn) );
509: if ( tn ) {
510: snp = (SNODE *)&(BDY(tn)); at = 0; targetf = r; curline = (*snp)->ln;
511: }
512: } else
513: return;
514: if ( snp ) {
515: cond = 0;
516: exprparse(targetf,texprname,&texpr);
517: if ( ac >= 3 && !strncmp(av[2],"if",2) ) {
518: savp = p+(av[2]-buf)+2;
519: exprparse(targetf,savp,&cond);
520: }
521: bpi = searchbp();
522: if ( bpi < 0 )
523: fprintf(stderr,"too many breakpoints\n");
524: else if ( ID(*snp) == S_BP )
525: return;
526: else {
527: switch ( ID(*snp) ) {
528: case S_IFELSE: case S_FOR: case S_DO:
529: ln = (int)FA0(*snp); break;
530: default:
531: ln = (*snp)->ln; break;
532: }
533: *snp = (SNODE)mksnode(3,S_BP,*snp,cond,texpr);
534: (*snp)->ln = ln;
535: if ( cond ) {
536: bpt[bpi].cond = (char *)MALLOC(strlen(savp)+1);
537: strcpy(bpt[bpi].cond,savp);
538: } else
539: bpt[bpi].cond = 0;
540: bpt[bpi].at = at;
541: bpt[bpi].f = targetf;
542: bpt[bpi].snp = snp;
543: bpt[bpi].texpr = (char *)MALLOC(strlen(texprname)+1);
544: strcpy(bpt[bpi].texpr,texprname);
545: showbp(bpi);
546: }
547: }
1.23 ! fujimoto 548: #if defined(__MINGW32__) || defined(__MINGW64__)
! 549: fflush(stderr);
! 550: #endif
1.1 noro 551: }
552:
1.10 noro 553: void clearbp(FUNC f)
1.1 noro 554: {
555: int i;
556:
557: if ( !f )
558: return;
559: for ( i = 0; i < bpindex; i++ )
560: if ( bpt[i].snp && !strcmp(f->name,bpt[i].f->name) ) {
561: bpt[i].at = 0; bpt[i].f = 0; bpt[i].snp = 0;
562: }
563: }
564:
565: int searchbp()
566: {
567: int i;
568:
569: for ( i = 0; i < bpindex; i++ )
570: if ( !bpt[i].snp )
571: return i;
572: if ( bpindex == MAXBP )
573: return -1;
574: else
575: return bpindex++;
576: }
577:
1.10 noro 578: void delbp(int ac,char **av)
1.1 noro 579: {
580: int n;
581:
582: if ( !ac )
583: return;
584: if ( (n = atoi(av[0])) >= bpindex )
585: return;
586: if ( bpt[n].snp ) {
587: *bpt[n].snp = (SNODE)FA0(*bpt[n].snp);
588: bpt[n].snp = 0;
589: }
590: }
591:
592: void showbps() {
593: int i;
594:
595: for ( i = 0; i < bpindex; i++ )
596: showbp(i);
597: }
598:
1.10 noro 599: void showbp(int n)
1.1 noro 600: {
601: if ( bpt[n].snp )
602: if ( bpt[n].texpr )
603: if ( bpt[n].at ) {
604: if ( bpt[n].cond )
605: fprintf(stderr,"(%d) trace %s at \"%s\":%d if %s\n",
606: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
607: else
608: fprintf(stderr,"(%d) trace %s at \"%s\":%d\n",
609: n,bpt[n].texpr,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
610: } else {
611: if ( bpt[n].cond )
612: fprintf(stderr,"(%d) trace %s in %s if %s\n",
613: n,bpt[n].texpr,bpt[n].f->name,bpt[n].cond);
614: else
615: fprintf(stderr,"(%d) trace %s in %s\n",n,bpt[n].texpr,bpt[n].f->name);
616: }
617: else
618: if ( bpt[n].at ) {
619: if ( bpt[n].cond )
620: fprintf(stderr,"(%d) stop at \"%s\":%d if %s\n",
621: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln,bpt[n].cond);
622: else
623: fprintf(stderr,"(%d) stop at \"%s\":%d\n",
624: n,bpt[n].f->f.usrf->fname,(*bpt[n].snp)->ln);
625: } else {
626: if ( bpt[n].cond )
627: fprintf(stderr,"(%d) stop in %s if %s\n",
628: n,bpt[n].f->name,bpt[n].cond);
629: else
630: fprintf(stderr,"(%d) stop in %s\n",n,bpt[n].f->name);
631: }
1.23 ! fujimoto 632: #if defined(__MINGW32__) || defined(__MINGW64__)
! 633: fflush(stderr);
! 634: #endif
1.1 noro 635: }
636:
1.10 noro 637: void searchsn(SNODE *fp,int n,SNODE **fpp)
1.1 noro 638: {
639: NODE tn;
640: SNODE sn;
641: SNODE *snp;
642:
643: *fpp = 0;
644: switch (ID(*fp)) {
645: case S_CPLX:
646: for ( tn = (NODE)FA0(*fp); tn; tn = NEXT(tn) )
647: if ( sn = (SNODE)BDY(tn) ) {
648: snp = (SNODE *)(ID(sn) == S_BP ? &FA0(sn) : &BDY(tn));
649: if ( (*snp)->ln >= n ) {
650: searchsn(snp,n,fpp); break;
651: }
652: }
653: break;
654: case S_IFELSE:
655: if ( n <= (int)FA0(*fp) )
656: *fpp = fp;
657: else if ( n <= ((SNODE)FA2(*fp))->ln )
658: searchsn((SNODE *)&FA2(*fp),n,fpp);
659: else if ( FA3(*fp) )
660: searchsn((SNODE *)&FA3(*fp),n,fpp);
661: if ( !(*fpp) )
662: *fpp = fp;
663: break;
664: case S_FOR:
665: if ( n <= (int)FA0(*fp) )
666: *fpp = fp;
667: else
668: searchsn((SNODE *)&FA4(*fp),n,fpp);
669: if ( !(*fpp) )
670: *fpp = fp;
671: break;
672: case S_DO:
673: if ( n <= (int)FA0(*fp) )
674: *fpp = fp;
675: else
676: searchsn((SNODE *)&FA1(*fp),n,fpp);
677: if ( !(*fpp) )
678: *fpp = fp;
679: break;
680: case S_BP:
681: switch ( ID((SNODE)FA0(*fp)) ) {
682: case S_SINGLE:
683: *fpp = fp; break;
684: default:
685: searchsn((SNODE *)&FA0(*fp),n,fpp); break;
686: }
687: break;
688: case S_SINGLE: default:
689: *fpp = fp;
690: break;
691: }
692: }
693:
1.10 noro 694: void bp(SNODE f)
1.1 noro 695: {
696: int ln;
697:
698: if ( !f || (CPVS == GPVS) )
699: return;
700:
701: switch ( ID(f) ) {
702: case S_IFELSE: case S_FOR:
703: ln = (int)FA0(f); break;
704: default:
705: ln = f->ln; break;
706: }
1.22 fujimoto 707: #if !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 708: if ( do_server_in_X11 )
709: #endif
710: show_debug_window(1);
711: fprintf(stderr,"stopped in %s at line %d in file \"%s\"\n",
712: CPVS->usrf->name,ln,CPVS->usrf->f.usrf->fname);
1.23 ! fujimoto 713: #if defined(__MINGW32__) || defined(__MINGW64__)
! 714: fflush(stderr);
! 715: #endif
1.1 noro 716: targetf = CPVS->usrf; curline = ln;
717: println(0,0,1);
1.22 fujimoto 718: #if !defined(MPI) && !defined(VISUAL) && !defined(__MINGW32__) && !defined(__MINGW64__)
1.1 noro 719: if ( do_server_in_X11 || isatty(0) )
720: #endif
721: debug(f);
722: }
723:
1.10 noro 724: void println(int ac,char **av,int l)
1.1 noro 725: {
726: FILE *fp;
727: char buf[BUFSIZ+1];
728: int i;
729: int ln;
730: FUNC r;
731:
732: if ( !ac )
733: ln = curline;
734: else if ( isdigit(av[0][0]) )
735: ln = atoi(av[0]);
736: else {
1.15 noro 737: searchuf(av[0],&r);
1.1 noro 738: if ( r && r->id != A_UNDEF ) {
739: targetf = r;
740: ln = r->f.usrf->startl;
741: } else {
742: fprintf(stderr,"%s undefined\n",av[0]);
743: ln = curline;
744: }
745: }
746: if ( !targetf )
747: return;
748: fp = fopen(targetf->f.usrf->fname,"r");
749: if ( !fp ) {
750: fprintf(stderr,"\"%s\" not found\n",targetf->name);
751: return;
752: }
753: for ( i = 1; i < ln; i++ )
754: if ( !fgets(buf,BUFSIZ,fp) )
755: return;
756: for ( i = 0; i < l; i++ ) {
757: if ( !fgets(buf,BUFSIZ,fp) )
758: break;
759: fprintf(stderr,"%d %s",ln+i,buf);
760: }
761: curline = ln + i;
762: fclose(fp);
1.23 ! fujimoto 763: #if defined(__MINGW32__) || defined(__MINGW64__)
! 764: fflush(stderr);
! 765: #endif
1.1 noro 766: }
767:
1.10 noro 768: void printvars(char *s,VS vs)
1.1 noro 769: {
770: FNODE expr;
771: char *p;
772: pointer val = 0;
773: int err;
774: VS cpvs;
775:
776: for ( p = s; *p; p++ )
777: if ( *p == '\n' ) {
778: *p = 0; break;
779: }
780: if ( exprparse(vs==GPVS?0:vs->usrf,s,&expr) ) {
781: cpvs = CPVS; CPVS = vs;
1.11 noro 782: if ( !(err = SETJMP(debug_env)) )
1.1 noro 783: val = eval(expr);
784: CPVS = cpvs;
785: if ( !err ) {
786: asir_out = stderr;
787: for ( p = s; isspace(*p); p++ );
788: fprintf(asir_out,"%s = ",p);
789: if ( val && ID((R)val) == O_MAT )
790: putc('\n',asir_out);
791: #if defined(VISUAL_LIB)
792: w_noflush_stderr(1);
793: #endif
794: printexpr(CO,val); putc('\n',asir_out); fflush(asir_out);
795: #if defined(VISUAL_LIB)
796: w_noflush_stderr(0);
797: #endif
798: asir_out = stdout;
799: }
800: }
801: }
802:
803: void showpos()
804: {
805: NODE n;
806: VS vs;
807: int level;
808:
809: if ( PVSS ) {
810: if ( cur_binf )
811: fprintf(stderr,"%s() (builtin)\n",cur_binf->name);
812: ((VS)BDY(PVSS))->at = evalstatline;
813: level = ((VS)BDY(PVSS))->level;
814: for ( n = PVSS; n; n = NEXT(n) ) {
815: vs = (VS)BDY(n);
816: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
817: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
818: }
1.23 ! fujimoto 819: #if defined(__MINGW32__) || defined(__MINGW64__)
! 820: fflush(stderr);
! 821: #endif
1.1 noro 822: }
823: }
824:
1.10 noro 825: void showpos_to_string(char *buf)
1.1 noro 826: {
827: NODE n;
828: VS vs;
829: int level;
830:
831: buf[0] = 0;
832: if ( PVSS ) {
833: if ( cur_binf )
834: sprintf(buf,"%s() (builtin)\n",cur_binf->name);
835: buf += strlen(buf);
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: sprintf(buf,"#%d %s(), line %d in \"%s\"\n",
841: level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
842: buf += strlen(buf);
843: }
844: }
1.16 noro 845: }
846:
847: /* [[file,line,name],...] */
848:
1.17 noro 849: extern int at_root;
850:
1.16 noro 851: void showpos_to_list(LIST *r)
852: {
853: NODE n,u,u1,t;
854: VS vs;
1.18 noro 855: STRING null,name,fname,kwd;
856: LIST l,b;
1.19 noro 857: USINT us;
1.16 noro 858:
859: u = 0;
860: if ( PVSS ) {
861: if ( cur_binf ) {
862: /* builtin : [0,0,name] */
863: MKSTR(null,"");
864: MKSTR(name,cur_binf->name);
1.20 noro 865: t = mknode(3,null,name,NULLP);
1.16 noro 866: MKLIST(l,t);
867: MKNODE(u1,l,0); u = u1;
868: }
869: ((VS)BDY(PVSS))->at = evalstatline;
870: for ( n = PVSS; n; n = NEXT(n) ) {
871: vs = (VS)BDY(n);
872: MKSTR(fname,vs->usrf->f.usrf->fname);
1.19 noro 873: MKUSINT(us,vs->at);
1.16 noro 874: MKSTR(name,vs->usrf->name);
1.19 noro 875: t = mknode(3,fname,name,us);
1.16 noro 876: MKLIST(l,t);
877: MKNODE(u1,l,u); u = u1;
878: }
879: }
1.17 noro 880: /* line number at the toplevel */
1.19 noro 881: MKSTR(fname,"toplevel"); MKUSINT(us,at_root);
882: t = mknode(2,fname,us); MKLIST(l,t); MKNODE(u1,l,u); u = u1;
1.18 noro 883: MKLIST(b,u);
1.17 noro 884:
1.18 noro 885: MKSTR(kwd,"asir_where");
886: t = mknode(2,kwd,b);
887: MKLIST(*r,t);
1.1 noro 888: }
889:
1.10 noro 890: void change_stack(int level,NODE *pvss)
1.1 noro 891: {
892: extern NODE PVSS;
893: NODE n;
894: int i;
895: VS vs;
896:
897: if ( !level || !PVSS )
898: return;
899: if ( level < 0 ) {
900: for ( n = PVSS, i = 0; n && n != *pvss; n = NEXT(n), i++ );
901: for ( n = PVSS, i = MAX(i+level,0); n && i; n = NEXT(n), i-- );
902: } else
903: for ( n = *pvss, i = level; NEXT(n) && i; n = NEXT(n), i-- );
904: *pvss = n; vs = (VS)BDY(n);
905: ((VS)BDY(PVSS))->at = evalstatline;
906: show_stack(vs);
907: targetf = vs->usrf; curline = vs->at;
908: }
909:
1.10 noro 910: void show_stack(VS vs)
1.1 noro 911: {
912: fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
913: ((VS)BDY(PVSS))->level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
1.23 ! fujimoto 914: #if defined(__MINGW32__) || defined(__MINGW64__)
! 915: fflush(stderr);
! 916: #endif
1.1 noro 917: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>