s37dbsym.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 691 行 · 第 1/2 页

C
691
字号
        new->base = hwop.sx.b;
    }else{
        new->acc = LACC_REG;
        new->base = hwop.r;
    }
    return( var->n.class == N_TEMP && var->t.temp_flags & STACK_PARM );
}

static void AddSym( cdebug_sym_any *new ) {
/** Add sym to sym list and bump sym index */
    new->common.next = *YSymNext;
    *YSymNext = new;
    ++YTagCount;
    YSymNext = &new->common.next;
}


extern  void    FiniDbgInfo() {
/**********************************************/

}

extern  void    InitDbgInfo() {
/*****************************/
    SrcLine = 1;
    DBTypInit();
    YTagCount = 0;  /* sym count       */
    STagCount = 0;  /* source cue      */
    YSymHead  = NULL;
    YSymNext  = &YSymHead;
    DefSegment( DBG_SEG,  GLOBAL | INIT | ROM,  "_DBG", 4 );
}

extern  void    DbgIO( txtseg_rec *rec ) {
/*** Write out dbg file*****************/

    handle        dbgfile;

    dbgfile = OpenDbg( FEAuxInfo( NULL, DBG_NAME ) );
    DTags( dbgfile, rec->csect );
    LTags( dbgfile, rec->location );
    DbgTypeTags( dbgfile );
    YTags( dbgfile, YSymHead, YTagCount );
    STags( dbgfile, rec->first );
    CloseStream( dbgfile );
}

static uint MkExtName( char *to, const char *from ) {
/*swiped from s37io********************************/
    char *curr;

    curr = to;
    while( *from != '\0' ) {
        *curr = *from == '_' ? '$' :  toupper( *from );
        from++;
        curr++;
   }
   *curr = '\0';
   return( curr-to );
}

static void DTags( handle dbgfile, bead_xsym *bead ) {
/**** Put out csect tags*******/
    hw_sym        *csect;
    id_len        idlen;
    char          name[8+1];
    char          *tag, tagbuff[5+5+4+8];

    csect = ((bead_xsym *)bead)->sym;
    tag = tagbuff;
    *tag++ = 'd';
    tag = DbgFmtInt( tag, 1 );
    *tag++ = 'D';
    tag = DbgFmtInt( tag, 0 );
    idlen = MkExtName( name, csect->name );
    tag = DbgFmtStr( tag, name, idlen );
    PutStream( dbgfile, tagbuff, tag-tagbuff );
}

static void LTags( handle dbgfile, offset size ) {
/**** Put out code length tag********************/
    char     tagbuff[5];

    tagbuff[0] = 'L';
    DbgFmtInt( &tagbuff[1], size );
    PutStream( dbgfile, tagbuff, 5 );
}

static void YTags( handle dbgfile, cdebug_sym_any *list, int index ) {
/*** Put out symbol info*********************************************/
    char             *tag, tagbuff[1+4+4+4+256];
    cdebug_sym_any   *old;
    cdebug_y_class    class;
    id_entry         *id;
    fe_attr           attr;
    int               refno;

    tagbuff[0] = 'y';
    DbgFmtInt( &tagbuff[1], index );
    PutStream( dbgfile, tagbuff, 5 );
    tagbuff[0] = 'Y';
    refno = 0;
    while( list != NULL ) {
        attr = list->common.attr;
        if (attr & FE_IMPORT) {
            if( attr & FE_PROC ){
                class = CDEBUG_Y_EXTPROC;
            }else{
                class = CDEBUG_Y_EXTVAR;
            }
            id = &list->obj.id;
        }else{
            if( attr & FE_PROC ) {
                class = CDEBUG_Y_PROC;
                id = &list->procdef.id;
            }else{
                class = CDEBUG_Y_VAR;
                id = &list->obj.id;
            }
        }
        tag = DbgFmtInt( &tagbuff[1], refno );
        tag = DbgFmtInt( tag, list->common.tref );
        tag = DbgFmtInt( tag, class );
        tag = DbgFmtStr( tag, id->name, id->len );
        PutStream( dbgfile, tagbuff, tag-tagbuff );
        switch( class ) {
        case CDEBUG_Y_PROC:
            DbgProcDef( dbgfile, list );
            break;
        case CDEBUG_Y_VAR:
            DbgVar( dbgfile, list );
            break;
        case CDEBUG_Y_EXTVAR:
            DbgExtVar( dbgfile, list );
            break;
        case CDEBUG_Y_EXTPROC:
            DbgExtProc( dbgfile, list );
            break;
        }
        old  = list;
        list = list->common.next;
        if( attr & FE_IMPORT == 0 && attr & FE_PROC ){
            _Free( old, sizeof( list->procdef )-1+id->len );
        }else{
            _Free( old, sizeof( list->obj )-1+id->len );
        }
        refno++;
    }
}

static void DbgProcDef( handle dbgfile, cdebug_sym_procdef *proc ){
/**** Put out proc defn & local defns*****************************/
    char             *tag, tagbuff[4*7];
    bead_def         *bead;
    hw_sym           *sym;
    dbg_sc            sc;

    tag = DbgFmtInt( &tagbuff[0], 0 ); /* linkage  */
    sc = ( proc->common.attr & FE_STATIC ) ? SC_STATIC : SC_EXPORT;
    tag = DbgFmtInt( tag, sc );
    tag = DbgFmtInt( tag, proc->pindex ); /* pindex  */
    tag = DbgFmtInt( tag, proc->lindex ); /* lindex  */
    sym = AskForHWLabel( proc->common.label );
    bead = sym->def;
    tag = DbgFmtInt( tag, bead->address ); /* start */
    bead = FindBead( bead, BEAD_EPILOGUE );
    tag = DbgFmtInt( tag, bead->address ); /* epilogue */
    bead = FindBead( bead, BEAD_ENDPROC );
    tag = DbgFmtInt( tag, bead->address ); /* end */
    PutStream( dbgfile, tagbuff, tag-tagbuff );
    LocalYTags( dbgfile, proc->list, proc->pindex+proc->lindex );
}

static void LocalYTags( handle dbgfile, cdebug_local *list, int index ) {
/******** Put out local sym tags*************************************/
    char             *tag, tagbuff[1+4+4+4+256];
    cdebug_local     *old;
    int              refno;

    tagbuff[0] = 'y';
    DbgFmtInt( &tagbuff[1], index );
    PutStream( dbgfile, tagbuff, 5 );
    tagbuff[0] = 'Y';
    refno = 0;
    while( list != NULL ){
        tag = DbgFmtInt( &tagbuff[1], refno );
        tag = DbgFmtInt( tag, list->tref );
        tag = DbgFmtInt( tag, CDEBUG_Y_LOCAL );
        tag = DbgFmtStr( tag, list->id.name, list->id.len );
        tag = DbgFmtInt( tag, list->acc );
        if( list->acc == LACC_REG ){
            tag = DbgFmtInt( tag, list->base );
        }else{
            tag = DbgFmtInt( tag, list->disp );
        }
        PutStream( dbgfile, tagbuff, tag-tagbuff );
        old = list;
        list = list->next;
        _Free( old, sizeof( *old )-1 +old->id.len );
        refno++;
    }
}

static void DbgVar( handle dbgfile, cdebug_sym_obj *var ){
/**** Put out file scope var defns*****************************/
    char             *tag, tagbuff[4*4];
    hw_sym           *sym;
    dbg_sc            sc;

    sc = ( var->common.attr & FE_STATIC ) ? SC_STATIC : SC_EXPORT;
    tag = DbgFmtInt( &tagbuff[0], sc );
    tag = DbgFmtInt( tag, 0 ); /* access  */
    tag = DbgFmtInt( tag, 0 ); /* csect   */

    sym = AskForHWLabel( var->common.label );
    tag = DbgFmtInt( tag, sym->def->address ); /* address */
    PutStream( dbgfile, tagbuff, tag-tagbuff );
}

static void DbgExtVar( handle dbgfile, cdebug_sym_obj *var ){
/**** Put out extern variable s*****************************/
    char             *tag, tagbuff[4*3];
    hw_sym           *sym;

    tag = DbgFmtInt( &tagbuff[0], 0 ); /* access  */
    tag = DbgFmtInt( tag, 0 ); /* csect   */
    sym = AskForHWLabel( var->common.label );
    tag = DbgFmtInt( tag, var->def->address  ); /* address */
    PutStream( dbgfile, tagbuff, tag-tagbuff );
}

static void DbgExtProc( handle dbgfile, cdebug_sym_obj *var ){
/**** Put out extern function  ******************************/
    char             *tag, tagbuff[4*4];
    hw_sym           *sym;

    tag = DbgFmtInt( &tagbuff[0], 0 ); /* linkage */
    tag = DbgFmtInt( tag, 0 ); /* access  */
    tag = DbgFmtInt( tag, 0 ); /* csect   */
    sym = AskForHWLabel( var->common.label );
    tag = DbgFmtInt( tag, -1   ); /* address */
    PutStream( dbgfile, tagbuff, tag-tagbuff );
}

static void STags( handle dbgfile, bead_def *start ) {
/**** Put out souce cue tags*******/
//  Currently cdebug has problems with cues
//  if the linenums are the same keep the first
//  if the addresses are the same keep the last

    bead_def      *bead;
    bead_queue    *last;
    int           index;
    char          tagbuff[1+4+4];

    index = 0;
    while( start != NULL ) { /* find first cue */
        if( start->class == BEAD_QUEUE ) {
            index = 1;
            break;
        }
        start = start->next;
    }
    last = (bead_queue *)start;
    bead = start;
    while( bead != NULL ) { /* count ones wanted */
        if( bead->class == BEAD_QUEUE ) {
            if( ((bead_queue *)bead)->num == last->num ){
                /* keep first if nums same */
            }else if( bead->address == last->common.address ){
                /* keep last if addr same */
                last = (bead_queue*)bead;
            }else{
                last = (bead_queue*)bead;
                index++;
            }
        }
        bead = bead->next;
    }
    tagbuff[0] = 's';
    DbgFmtInt( &tagbuff[1], index );
    PutStream( dbgfile, tagbuff, 5 );
    if( index == 0 ){
        return;
    }

    tagbuff[0] = 'S';
    last = (bead_queue *)start;
    bead = start;
    while( index > 1 ) {
        if( bead->class == BEAD_QUEUE ) {
            if( ((bead_queue *)bead)->num == last->num ){
                /* keep first if nums same */
            }else if( bead->address == last->common.address ){
                /* keep last if addr same */
                last = (bead_queue*)bead;
            }else{
                DbgFmtInt( &tagbuff[1], last->num );
                DbgFmtInt( &tagbuff[5], last->common.address );
                PutStream( dbgfile, tagbuff, 9 );
                last = (bead_queue*)bead;
                index--;
            }
        }
        bead = bead->next;
    }
    DbgFmtInt( &tagbuff[1], last->num );
    DbgFmtInt( &tagbuff[5], last->common.address );
    PutStream( dbgfile, tagbuff, 9 );
}

extern char *DbgFmtInt( char *buff, offset num ) {
/** format 32 bit into 4byte dbg number ********/
    buff[0] = num>>24 & 0xff;
    buff[1] = num>>16 & 0xff;
    buff[2] = num>>8  & 0xff;
    buff[3] = num     & 0xff;
    return( &buff[4] );
}

extern char *DbgFmtStr( char *buff, char *str, id_len num ) {
/** format a str into int followed by chars**/
    char   *curr;

    buff[0] = num>>24 & 0xff;
    buff[1] = num>>16 & 0xff;
    buff[2] = num>>8  & 0xff;
    buff[3] = num     & 0xff;
    curr   = &buff[4]; /* skip length */
    while( num != 0 ) {
        *curr++ = *str++;
        --num;
    }
    return( curr );
}

static bead_def *FindBead( bead_def *bead, bead_class class ){
/**********find a bead***************************************/
    while( bead->class != class ) {
        bead = bead->next;
    }
    return( bead );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?