[BACK]Return to debug.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/debug.c, Revision 1.7

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>