s37dbsym.c

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

C
691
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include "standard.h"
#include "coderep.h"
#include "procdef.h"
#include "cgdefs.h"
#include "cg.h"
#include "cgaux.h"
#include "sysmacro.h"
#include "offset.h"
#include "s37bead.h"
#include "model.h"
#include "s37dbg.h"

typedef int handle;
#include "s37dbsym.def"


extern    source_line_number    SrcLine;
extern    unsigned_16           TypeIdx;
extern    proc_def              *CurrProc;

extern  uint            Length(char*);
extern  byte           *Copy(void*,void*,uint);
extern  pointer         FEAuxInfo(pointer,int);
extern  fe_attr         FEAttr(pointer);
extern  dbg_type        FEDbgType(pointer);
extern  char           *FEName(pointer);
extern bool             MemNeedsReloc(pointer ,cg_class );
extern bead_def        *GetanAddr(label_handle ,bool );
extern  name           *DeAlias(name*);
extern  name           *AllocUserTemp(pointer,type_class_def);
extern  label_handle    AskForSymLabel( pointer, cg_class );
extern  sym_handle      AskForLblSym(label_handle);
extern  hw_sym         *AskForHWLabel(label_handle );
extern void             GetOpName(hwins_op_any *,name *);
extern void             HWMKAddrGen(bead_def **,hw_sym *,offset );
extern  void            DefSegment(seg_id,seg_attr,char*,uint);
extern seg_id           SetOP(seg_id );

extern    proc_def              *CurrProc;

static  dbg_rtn  *CurrProc_debug;
static short int YTagCount;
static short int STagCount;

static cdebug_sym_any    *YSymHead;
static cdebug_sym_any   **YSymNext;


extern void DBTypInit(void);
extern void DbgTypeTags(handle );

extern handle   OpenDbg( char *name );
extern void     CloseStream(handle );
extern void     PutStream(handle ,byte *,uint );

#define DBG_SEG 6 /* hardwired till i figure it out */
extern  void    DBLineNum( uint no ) {
/************************************/

    SrcLine = no;
}

extern  void    DBModSym( sym_handle sym, cg_type indirect ) {
/**Add a sym to the dbglist sym******************************/
    fe_attr          attr;

    indirect = indirect;
    attr = FEAttr( sym );
    if( (attr & FE_IMPORT) == 0 && attr & FE_PROC ) {
        BegProcDef();
    }else{
        DBModObj( sym, attr );
    }
}

static  void    BegProcDef() {
/** start procdef in parallel with obj generation**********/

    CurrProc->state.attr |= ROUTINE_WANTS_DEBUGGING;
    _Alloc( CurrProc_debug, sizeof( dbg_rtn ) );
    CurrProc_debug->blk = NULL;
    CurrProc_debug->parms = NULL;
    CurrProc_debug->reeturn.class = 0;
    MkBlock();
}

static  void    DBModObj( sym_handle sym, fe_attr attr ) {
/**Add a non procdefn to dbglist sym ************************/
    char            *name;
    uint             len;
    cdebug_sym_obj  *new;
    label_handle     label;
    seg_id           id;

    name = FEName( sym );
    len = Length( name );
    _Alloc( new, sizeof( *new )-1 +len );
    new->id.len = len;
    Copy( name, new->id.name, len );
    new->common.attr = attr;
    label =  AskForSymLabel( sym, CG_FE );
    new->common.label =  label;
    if (attr & FE_IMPORT) {
        id = SetOP( DBG_SEG ); /* stupid segments */
        new->def = GetanAddr( label, MemNeedsReloc(sym, CG_FE) );
        SetOP( id ); /* stupid segments */
    }
    new->common.tref  =  FEDbgType( sym );
    AddSym( new );
}

extern  void    DBAllocReg( name *reg, name *temp )
/*************************************************/
{
    dbg_block   *blk;
    dbg_local   *loc;

    if( temp->n.class != N_TEMP ) return;
    for( blk = CurrProc_debug->blk; blk != NULL; blk = blk->parent ) {
        for( loc = blk->locals; loc != NULL; loc = loc->link ) {
            if( temp == loc->where.where ) {
                loc->where.class = LOC_REG;
                loc->where.where = reg;
            }
        }
    }
}


extern  void    DBLocalSym( sym_handle sym, cg_type indirect ) {
/***Add a local symbol  ***************************************/
    dbg_block   *blk;
    dbg_local   *new;
    name        *temp;
    fe_attr     attr;

    indirect = indirect;
    if( CurrProc_debug != NULL ) {
        attr = FEAttr( sym );
        if( attr & FE_STATIC ) {
            DBModObj( sym, attr );
        }else if( (attr & FE_IMPORT) == 0 ) {
            blk = CurrProc_debug->blk;
            _Alloc( new, sizeof( dbg_local ) );
            new->link = blk->locals;
            blk->locals = new;
            new->sym = sym;
            new->where.class = LOC_STACK;
            temp = DeAlias( AllocUserTemp( sym, XX ) );
            temp->v.usage |= VAR_VOLATILE+NEEDS_MEMORY+USE_IN_ANOTHER_BLOCK+USE_ADDRESS;
            new->where.where = temp;
        }
    }
}

extern  void    DBBegBlock() {
/****************************/
#if 0 /* block scopes not supported */
    if( CurrProc->targ.debug != NULL ) {  scopes not supported
        MkBlock();
    }
#endif
}

static  void    MkBlock() {
/** make a new scope block**/
    dbg_block   *new;

    _Alloc( new, sizeof( dbg_block ) );
    new->parent = CurrProc_debug->blk;
    CurrProc_debug->blk = new;
    new->locals = NULL;
}

extern  void    DBEndBlock() {
/**end block scope***********/
#if 0 /* block scopes not supported yet */
    dbg_block   *blk;

    if( CurrProc->targ.debug != NULL ) {
        blk = CurrProc_debug->blk;
        CurrProc_debug->blk = blk->parent;
    }
#endif
}

extern  void    DbgParmLoc( name_def *parm ) {
/** fill in parm location********************/
    location_list       *new;
    location_list       **owner;

    owner = &CurrProc_debug->parms;
    while( *owner != NULL ) {
       owner = &(*owner)->link;
    }
    _Alloc( new, sizeof( location_list ) );
    *owner = new;
    new->link = NULL;
    new->data.class = LOC_REG;
    new->data.where = parm;
}


extern  void    DbgRetLoc() {
/**********************************************/

}

/* after object before post optimizer */

extern  void    EmitRtnEnd() {
/****************************/
    DbgRtnEnd( CurrProc_debug );
}


extern  void    DbgBlkEnd( dbg_block *blk, offset lc ) {
/****************************************************/
#if 0
    DumpDbgLocals( blk->locals );
    _Free( blk, sizeof( dbg_block ) );
#else
    blk = 0;
    lc = 0;
#endif
}


static  void    DbgRtnEnd( dbg_rtn *rtn ) {
/** Add a cdebug_sym_procdef***************/
    uint                 len;
    location_list       *parm;
    location_list       *junk;
    sym_handle           sym;
    char                *name;
    cdebug_sym_procdef  *proc;

    sym = AskForLblSym( CurrProc->label );
    name = FEName( sym  );
    len  = Length( name );
    proc = _Alloc( proc, sizeof( *proc )-1 +len );
    proc->id.len = len;
    Copy( name, proc->id.name, len );
    proc->common.label = CurrProc->label;
    proc->common.attr = FEAttr( sym );
    proc->common.tref = FEDbgType( sym );
    len = 0;
    parm = rtn->parms;
    while( parm != NULL ) {
        ++len;
        parm = parm->link;
    }
    proc->pindex = len;
    parm = rtn->parms;
    while( parm != NULL ) {
        junk = parm;
        parm = parm->link;
        _Free( junk, sizeof( location_list ) );
    }
    DumpDbgLocals( rtn->blk->locals, proc );
    _Free( rtn->blk, sizeof( dbg_block ) );
    _Free( rtn, sizeof( dbg_rtn ) );
    AddSym( proc );
}

static  void   DumpDbgLocals( dbg_local *loc, cdebug_sym_procdef *proc ) {
/*************************************************/
    dbg_local   *junk;
    int          lindex,pindex;
    char        *name;
    uint         len;
    cdebug_local *new, **next;

    lindex = 0;
    pindex = 0;
    proc->list = NULL;
    next = &proc->list;
    while( loc != NULL ) {
        name = FEName( loc->sym );
        len = Length( name );
        _Alloc( new, sizeof( *new )-1+len );
        new->id.len = len;
        Copy( name, new->id.name, len );
        new->tref = FEDbgType( loc->sym );
        if( GetLocAddr( new, loc ) ){
            pindex++;
        }else{
            lindex++;
        }
        *next = new;
        next = &new->next;
        *next = NULL;
        junk = loc;
        loc = loc->link;
        _Free( junk, sizeof( dbg_local ) );
    }
    proc->lindex = lindex;
    proc->pindex = pindex;
}

static bool  GetLocAddr( cdebug_local *new, dbg_local *loc ){
/********** Get 370 addr for local***************************/
    hwins_op_any hwop;
    name        *var;

    var = loc->where.where;
    GetOpName( &hwop, var );
    if( loc->where.class == LOC_STACK ){
        new->acc = LACC_STACK;
        new->disp = hwop.sx.disp;

⌨️ 快捷键说明

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