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