[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.13

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.13    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/debug.c,v 1.12 2003/02/14 22:29:18 ohara Exp $
1.4       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include <ctype.h>
1.12      ohara      53: #if defined(PARI)
1.1       noro       54: #include "genpari.h"
1.2       noro       55: #endif
1.1       noro       56:
                     57: extern do_server_in_X11,do_file;
                     58:
                     59: typedef enum {
                     60:        D_NEXT, D_STEP, D_FINISH, D_CONT, D_QUIT,
                     61:        D_UP, D_DOWN, D_FRAME,
                     62:        D_LIST, D_PRINT,
                     63:        D_SETF, D_SETBP, D_SETTP, D_DELBP,
                     64:        D_SHOWBP, D_WHERE, D_ALIAS, D_UNKNOWN
                     65: } did;
                     66:
                     67: struct oDEBCOM {
                     68:        NODE names;
                     69:        did id;
                     70: };
                     71:
                     72: int nextbp,nextbplevel;
                     73: FUNC cur_binf;
                     74:
                     75: static FUNC targetf;
                     76: static int curline = 1;
                     77:
                     78: extern NODE PVSS;
                     79: extern unsigned int evalstatline;
                     80: extern int debug_mode;
1.11      noro       81: extern JMP_BUF debug_env;
1.1       noro       82:
                     83: char *debcom[] = {
                     84:        "next",
                     85:        "step",
                     86:        "finish",
                     87:        "cont",
                     88:        "quit",
                     89:        "up",
                     90:        "down",
                     91:        "frame",
                     92:        "list",
                     93:        "print",
                     94:        "func",
                     95:        "stop",
                     96:        "trace",
                     97:        "delete",
                     98:        "status",
                     99:        "where",
                    100:        "alias",
                    101: };
                    102:
                    103: struct oDEBCOM dckwd[] = {
                    104:        {0, D_NEXT},
                    105:        {0, D_STEP},
                    106:        {0, D_FINISH},
                    107:        {0, D_CONT},
                    108:        {0, D_QUIT},
                    109:        {0, D_UP},
                    110:        {0, D_DOWN},
                    111:        {0, D_FRAME},
                    112:        {0, D_LIST},
                    113:        {0, D_PRINT},
                    114:        {0, D_SETF},
                    115:        {0, D_SETBP},
                    116:        {0, D_SETTP},
                    117:        {0, D_DELBP},
                    118:        {0, D_SHOWBP},
                    119:        {0, D_WHERE},
                    120:        {0, D_ALIAS},
                    121:        {0, D_UNKNOWN}
                    122: };
                    123:
                    124: void debug_init() {
                    125:        int i,n,ac;
                    126:        char *home;
                    127:        char buf[BUFSIZ+1];
                    128: #if defined(__MWERKS__)
                    129:        char *av[64];
                    130: #else
                    131:        char *av[BUFSIZ];
                    132: #endif
                    133:        FILE *fp;
                    134:
                    135:        for ( n = 0; dckwd[n].id != D_UNKNOWN; n++ );
                    136:        for ( i = 0; i < n; i++ )
                    137:                MKNODE(dckwd[i].names,debcom[i],0);
                    138:        home = (char *)getenv("HOME");
                    139:        if ( home )
                    140:                strcpy(buf,home);
                    141:        else
                    142:                buf[0] = 0;
                    143:        strcat(buf,"/.dbxinit");
                    144:        if ( (fp = fopen(".dbxinit","r")) || (fp = fopen(buf,"r")) ) {
                    145:                while ( fgets(buf,BUFSIZ,fp) ) {
                    146:                        stoarg(buf,&ac,av);
                    147:                        if ((ac == 3) && !strcmp(av[0],"alias"))
                    148:                                add_alias(av[2],av[1]);
                    149:                }
                    150:                fclose(fp);
                    151:        }
1.9       noro      152: #if 0
1.1       noro      153: #if !defined(VISUAL)
                    154:        if ( do_server_in_X11 )
                    155:                init_cmdwin();
1.9       noro      156: #endif
1.1       noro      157: #endif
                    158: }
                    159:
1.10      noro      160: void add_alias(char *com,char *alias)
1.1       noro      161: {
                    162:        int i;
                    163:        NODE tn;
                    164:        char *s;
                    165:
                    166:        for ( i = 0; dckwd[i].names; i++ )
                    167:                if (!strcmp(com,debcom[i])) {
                    168:                        for ( tn = dckwd[i].names; NEXT(tn); tn = NEXT(tn) );
                    169:                        s = (char *)MALLOC(strlen(alias)+1); strcpy(s,alias);
                    170:                        MKNODE(NEXT(tn),s,0);
                    171:                        return;
                    172:                }
                    173: }
                    174:
1.10      noro      175: void show_alias(char *alias)
1.1       noro      176: {
                    177:        int i;
                    178:        NODE tn;
                    179:
                    180:        if ( !alias )
                    181:                for ( i = 0; dckwd[i].names; i++ ) {
                    182:                        if ( tn = NEXT(dckwd[i].names) )
                    183:                                fprintf(stderr,"%s\t",debcom[i]);
                    184:                        for ( ; tn; tn = NEXT(tn) ) {
                    185:                                fputs(BDY(tn),stderr);
                    186:                                if ( NEXT(tn) )
                    187:                                        fputc(' ',stderr);
                    188:                                else
                    189:                                        fputc('\n',stderr);
                    190:                        }
                    191:                }
                    192:        else
                    193:                for ( i = 0; dckwd[i].names; i++ )
                    194:                        for ( tn = dckwd[i].names; tn; tn = NEXT(tn) )
                    195:                                if ( !strcmp(alias,BDY(tn)) ) {
                    196:                                        fprintf(stderr,"%s->%s\n",alias,debcom[i]); return;
                    197:                                }
                    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;
                    212: #if !defined(VISUAL)
                    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.13    ! noro      219: #if !MPI && !defined(VISUAL)
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.6       noro      226: #if defined(VISUAL)
1.1       noro      227:        suspend_timer();
                    228: #endif
                    229:        pvss = PVSS; debug_mode = 1;
                    230: #if !defined(VISUAL)
                    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:
                    253: #if !defined(VISUAL)
                    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.6       noro      346: #if !defined(VISUAL)
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;
                    358:        searchf(usrf,av[0],&r);
                    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;
                    384:        USRF t;
                    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;
                    396:                n = atoi(av[1]); fname = targetf->f.usrf->fname;
                    397:                for ( tn = usrf; 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:                searchf(usrf,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 = (int)FA0(*snp); break;
                    440:                                default:
                    441:                                        ln = (*snp)->ln; break;
                    442:                        }
                    443:                        *snp = (SNODE)mksnode(3,S_BP,*snp,cond,0);
                    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:
1.10      noro      459: void settp(char *p)
1.1       noro      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:                searchf(usrf,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 = (int)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:
1.10      noro      544: void clearbp(FUNC f)
1.1       noro      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:
1.10      noro      569: void delbp(int ac,char **av)
1.1       noro      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:
1.10      noro      590: void showbp(int n)
1.1       noro      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:
1.10      noro      625: void searchsn(SNODE *fp,int n,SNODE **fpp)
1.1       noro      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 <= (int)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 <= (int)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 <= (int)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:
1.10      noro      682: void bp(SNODE f)
1.1       noro      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 = (int)FA0(f); break;
                    692:                default:
                    693:                        ln = f->ln; break;
                    694:        }
                    695: #if !defined(VISUAL)
                    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);
1.13    ! noro      703: #if !MPI && !defined(VISUAL)
1.1       noro      704:        if ( do_server_in_X11 || isatty(0) )
                    705: #endif
                    706:                debug(f);
                    707: }
                    708:
1.10      noro      709: void println(int ac,char **av,int l)
1.1       noro      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:                searchf(usrf,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:
1.10      noro      750: void printvars(char *s,VS vs)
1.1       noro      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;
1.11      noro      764:                if ( !(err = SETJMP(debug_env)) )
1.1       noro      765:                        val = eval(expr);
                    766:                CPVS = cpvs;
                    767:                if ( !err ) {
1.12      ohara     768: #if defined(PARI)
                    769: #if defined(PARI1)
1.1       noro      770:                        outfile = stderr;
                    771: #else
                    772:                        pari_outfile = stderr;
                    773: #endif
                    774: #endif
                    775:                        asir_out = stderr;
                    776:                        for ( p = s; isspace(*p); p++ );
                    777:                        fprintf(asir_out,"%s = ",p);
                    778:                        if ( val && ID((R)val) == O_MAT )
                    779:                                putc('\n',asir_out);
                    780: #if defined(VISUAL_LIB)
                    781:                        w_noflush_stderr(1);
                    782: #endif
                    783:                        printexpr(CO,val); putc('\n',asir_out); fflush(asir_out);
                    784: #if defined(VISUAL_LIB)
                    785:                        w_noflush_stderr(0);
                    786: #endif
1.12      ohara     787: #if defined(PARI)
                    788: #if defined(PARI1)
1.1       noro      789:                        outfile = stdout;
                    790: #else
                    791:                        pari_outfile = stdout;
                    792: #endif
                    793: #endif
                    794:                        asir_out = stdout;
                    795:                }
                    796:        }
                    797: }
                    798:
                    799: void showpos()
                    800: {
                    801:        NODE n;
                    802:        VS vs;
                    803:        int level;
                    804:
                    805:        if ( PVSS ) {
                    806:                if ( cur_binf )
                    807:                        fprintf(stderr,"%s() (builtin)\n",cur_binf->name);
                    808:                ((VS)BDY(PVSS))->at = evalstatline;
                    809:                level = ((VS)BDY(PVSS))->level;
                    810:                for ( n = PVSS; n; n = NEXT(n) ) {
                    811:                        vs = (VS)BDY(n);
                    812:                        fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
                    813:                                level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
                    814:                }
                    815:        }
                    816: }
                    817:
1.10      noro      818: void showpos_to_string(char *buf)
1.1       noro      819: {
                    820:        NODE n;
                    821:        VS vs;
                    822:        int level;
                    823:
                    824:        buf[0] = 0;
                    825:        if ( PVSS ) {
                    826:                if ( cur_binf )
                    827:                        sprintf(buf,"%s() (builtin)\n",cur_binf->name);
                    828:                buf += strlen(buf);
                    829:                ((VS)BDY(PVSS))->at = evalstatline;
                    830:                level = ((VS)BDY(PVSS))->level;
                    831:                for ( n = PVSS; n; n = NEXT(n) ) {
                    832:                        vs = (VS)BDY(n);
                    833:                        sprintf(buf,"#%d %s(), line %d in \"%s\"\n",
                    834:                                level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
                    835:                        buf += strlen(buf);
                    836:                }
                    837:        }
                    838: }
                    839:
1.10      noro      840: void change_stack(int level,NODE *pvss)
1.1       noro      841: {
                    842:        extern NODE PVSS;
                    843:        NODE n;
                    844:        int i;
                    845:        VS vs;
                    846:
                    847:        if ( !level || !PVSS )
                    848:                return;
                    849:        if ( level < 0 ) {
                    850:                for ( n = PVSS, i = 0; n && n != *pvss; n = NEXT(n), i++ );
                    851:                for ( n = PVSS, i = MAX(i+level,0); n && i; n = NEXT(n), i-- );
                    852:        } else
                    853:                for ( n = *pvss, i = level; NEXT(n) && i; n = NEXT(n), i-- );
                    854:        *pvss = n; vs = (VS)BDY(n);
                    855:        ((VS)BDY(PVSS))->at = evalstatline;
                    856:        show_stack(vs);
                    857:        targetf = vs->usrf; curline = vs->at;
                    858: }
                    859:
1.10      noro      860: void show_stack(VS vs)
1.1       noro      861: {
                    862:        fprintf(stderr,"#%d %s(), line %d in \"%s\"\n",
                    863:                ((VS)BDY(PVSS))->level-vs->level,vs->usrf->name,vs->at,vs->usrf->f.usrf->fname);
                    864: }

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