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

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

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