cvsyms.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 841 行 · 第 1/2 页
C
841 行
cs_gdata *ptr;
sg_index kind;
if( attr & FE_GLOBAL ) {
kind = SG_GDATA;
} else {
kind = SG_LDATA;
}
ptr = StartSym( out, kind );
ptr->offset = 0;
ptr->segment = 0;
ptr->type = tipe;
CVPutStr( out, nm );
EndSym( out );
} else {
FrameVar( out, nm, tipe, 0 );
}
}
extern void CVGenStatic( sym_handle sym, dbg_loc loc, bool mem )
/******************************************************************/
{
dbg_type tipe;
cv_out out[1];
fe_attr attr;
cs_gdata *ptr;
sg_index kind;
char *name;
attr = FEAttr( sym );
tipe = FEDbgType( sym );
NewBuff( out, CVSyms );
attr = FEAttr( sym );
if( attr & FE_GLOBAL ) {
kind = SG_GDATA;
} else {
kind = SG_LDATA;
}
ptr = StartSym( out, kind );
ptr->offset = 0;
ptr->segment = 0;
ptr->type = tipe;
if( mem ){
name = FEAuxInfo( sym, CLASS_APPENDED_NAME );
} else {
name = FEName( sym );
}
CVPutStr( out, name );
EndSym( out );
if( LocSimpStatic( loc ) == sym ) {
BuffWrite( out, &ptr->offset );
SymReloc( CVSyms, sym, 0 );
BuffSkip( out, &ptr->type );
} else {
/*TODO:can't handle locs */
}
BuffEnd( out );
}
extern void CVTypedef( char *nm, dbg_type tipe )
/*** emit UDT**************************************/
{
cv_out out[1];
cs_udt *ptr;
NewBuff( out, CVSyms );
ptr = StartSym( out, SG_UDT );
ptr->type = tipe;
CVPutStr( out, nm );
EndSym( out );
BuffEnd( out );
}
extern void CVOutSymICon( cv_out *out, char *nm, long val, dbg_type tipe )
/*** Put a const sym to out**************************************************/
{
cs_constant *ptr;
void *ptr1;
ptr1 = out->beg;
out->beg = out->ptr;
ptr = StartSym( out, SG_CONSTANT );
ptr->type = tipe;
CVPutINum( out, val );
CVPutStr( out, nm );
EndSym( out );
out->beg = ptr1;
CVEndType( out );
BuffEnd( out );
}
extern void CVSymIConst( char *nm, long val, dbg_type tipe )
/*** emit UDT**************************************************/
{
cv_out out[1];
cs_constant *ptr;
NewBuff( out, CVSyms );
ptr = StartSym( out, SG_CONSTANT );
ptr->type = tipe;
CVPutINum( out, val );
CVPutStr( out, nm );
EndSym( out );
BuffEnd( out );
}
extern void CVSymIConst64( char *nm, signed_64 val, dbg_type tipe )
/*** emit UDT*********************************************************/
{
cv_out out[1];
cs_constant *ptr;
NewBuff( out, CVSyms );
ptr = StartSym( out, SG_CONSTANT );
ptr->type = tipe;
CVPutINum64( out, val );
CVPutStr( out, nm );
EndSym( out );
BuffEnd( out );
}
extern void CVSetBase( void )
/*******************************/
/* don't know about this yet */
{
}
/**/
/* Coming out of optimizer queue*/
/**/
extern void CVRtnBeg( dbg_rtn *rtn, offset lc )
/*************************************************/
{
rtn = rtn;
lc = lc;
}
static dbg_patch_handle RtnPatch[1];
static name *LocSymBP( dbg_loc loc )
/**************************************/
{
if( loc == NULL ) return( NULL );
if( (loc->class & 0xf0) != LOC_BP_OFFSET ){
return( NULL );
}
return( loc->u.be_sym );
}
static dbg_local *UnLinkLoc( dbg_local **owner, sym_handle sym )
/***************************************************************/
// unlink dbg_local with sym from owner
{
dbg_local *curr;
while( (curr = *owner) != NULL ) {
if( curr->sym == sym ){
*owner = curr->link;
break;
}
owner = &(*owner)->link;
}
return( curr );
}
static void DumpParms( dbg_local *parm, dbg_local **locals )
{
dbg_local *alt;
cv_out out[1];
dbg_local *junk;
while( parm != NULL ) { /* find and unlink from locals */
alt = UnLinkLoc( locals, parm->sym );
if( alt != NULL ){
dbg_type tipe;
type_length offset;
name *t;
if( alt->kind == DBG_SYM_VAR ){
tipe = FEDbgType( alt->sym );
t = LocSymBP( alt->loc );
if( t != NULL ){
offset = NewBase( t );
NewBuff( out, CVSyms );
FrameVar( out, FEName( alt->sym ), tipe, offset );
BuffEnd( out );
}else{
CVGenStatic( alt->sym, alt->loc, FALSE );
}
}
DBLocFini( alt->loc );
_Free( alt, sizeof( dbg_local ) );
}
DBLocFini( parm->loc );
junk = parm;
parm = parm->link;
_Free( junk, sizeof( dbg_local ) );
}
//#if _TARGET & _TARG_AXP
#if 0 // seems like it screws CVPACK on intel
NewBuff( out, CVSyms );
StartSym( out, SG_ENDARG );
EndSym( out );
BuffEnd( out );
#endif
}
extern void CVProEnd( dbg_rtn *rtn, offset lc )
/*************************************************/
{
sym_handle sym;
dbg_type tipe;
fe_attr attr;
char *name;
call_class *class_ptr;
cs_gproc *ptr;
sg_index kind;
cv_out out[1];
lc = lc;
sym = AskForLblSym( CurrProc->label );
class_ptr = FEAuxInfo( FEAuxInfo( sym, AUX_LOOKUP ), CALL_CLASS );
attr = FEAttr( sym );
if( attr & FE_GLOBAL ){
kind = SG_GPROC;
}else{
kind = SG_LPROC;
}
NewBuff( out, CVSyms );
ptr = StartSym( out, kind );
ptr->pParent = 0;
ptr->pEnd = 0;
ptr->pNext = 0;
ptr->proc_length = 0;
ptr->debug_start = rtn->pro_size;
ptr->debug_end = 0;
ptr->offset = 0;
ptr->segment = 0;
tipe = FEDbgType( sym );
ptr->proctype = tipe;
ptr->flags.s = 0;
#if _TARGET &( _TARG_IAPX86 | _TARG_80386 )
if( *class_ptr & FAR ) {
ptr->flags.f.far_ret = TRUE;
}
#endif
if( rtn->obj_type != DBG_NIL_TYPE ) {
name = FEAuxInfo( sym, CLASS_APPENDED_NAME );
} else {
name = FEName( sym );
}
CVPutStr( out, name );
EndSym( out );
BuffPatchSet( CVSyms, RtnPatch );
BuffWrite( out, &ptr->offset );
SymReloc( CVSyms, sym, 0 );
BuffSkip( out, &ptr->proctype );
BuffEnd( out );
DBLocFini( rtn->reeturn );
DBLocFini( rtn->obj_loc );
if( rtn->parms != NULL ){
DumpParms( rtn->parms, &rtn->blk->locals );
}
DumpLocals( rtn->blk->locals );
}
extern void CVBlkBeg( dbg_block *blk, offset lc )
/***************************************************/
{
block_patch *patch;
dbg_patch_handle *handle;
cv_out out[1];
offset start;
sym_handle sym;
cs_block *ptr;
char *nm;
_Alloc( patch, sizeof( block_patch ) );
blk->patches = patch;
NewBuff( out, CVSyms );
ptr = StartSym( out, SG_BLOCK );
ptr->pParent = NULL;
ptr->pEnd = NULL;
ptr->length = 0;
ptr->offset = 0;
ptr->segment = 0;
nm = out->ptr; /* mark name */
CVPutNullStr( out );
EndSym( out );
handle = &((block_patch *)(blk->patches))->handle;
BuffPatchSet( CVSyms, handle );
BuffWrite( out, &ptr->offset );
sym = AskForLblSym( CurrProc->label );
start = lc - CurrProc_debug->blk->start;
SymReloc( CVSyms, sym, start );
BuffSkip( out, nm ); /* skip addr */
BuffEnd( out );
DumpLocals( blk->locals );
}
extern void CVBlkEnd( dbg_block *blk, offset lc )
/***************************************************/
{
fsize length;
long_offset here;
seg_id old;
dbg_patch_handle *handle;
cv_out out[1];
handle = &((block_patch *)(blk->patches))->handle;
old = SetOP( handle->segment );
here = AskBigLocation();
SetBigLocation( handle->offset + offsetof( s_block, f.length ) );
length = lc - blk->start;
DataBytes( sizeof( fsize ), (char *)&length );
SetBigLocation( here );
SetOP( old );
NewBuff( out, CVSyms );
StartSym( out, SG_END );
EndSym( out );
BuffEnd( out );
_Free( blk->patches, sizeof( block_patch ) );
}
extern void CVEpiBeg( dbg_rtn *blk, offset lc )
/*************************************************/
{
blk = blk;
lc = lc;
}
extern void CVRtnEnd( dbg_rtn *rtn, offset lc )
/*************************************************/
{
cv_out out[1];
fsize proc_length;
fsize debug_end;
dbg_patch_handle *handle;
long_offset here;
seg_id old;
handle = RtnPatch;
old = SetOP( handle->segment );
here = AskBigLocation();
SetBigLocation( handle->offset + offsetof( s_gproc, f.proc_length ) );
proc_length = lc - rtn->blk->start;
DataBytes( sizeof( fsize ), (char *)&proc_length );
SetBigLocation( handle->offset+ offsetof( s_gproc, f.debug_end ) );
debug_end = rtn->epi_start - rtn->blk->start;
DataBytes( sizeof( fsize ), (char*)&debug_end );
SetBigLocation( here );
SetOP( old );
NewBuff( out, CVSyms );
StartSym( out, SG_END );
EndSym( out );
BuffEnd( out );
}
static void DumpLocals( dbg_local *local )
/********************************************/
{
dbg_local *old;
type_length offset;
cv_out out[1];
dbg_type tipe;
name *t;
while( local != NULL ) {
switch( local->kind ){
case DBG_SYM_VAR:
tipe = FEDbgType( local->sym );
t = LocSymBP( local->loc );
if( t != NULL ){
offset = NewBase( t );
NewBuff( out, CVSyms );
FrameVar( out, FEName( local->sym ), tipe, offset );
BuffEnd( out );
}else{
CVGenStatic( local->sym, local->loc, FALSE );
}
break;
case DBG_SYM_TYPE:
break;
case DBG_SYM_TYPEDEF:
tipe = FEDbgType( local->sym );
CVTypedef( FEName( local->sym ), tipe );
break;
}
DBLocFini( local->loc );
old = local;
local = local->link;
_Free( old, sizeof( dbg_local ) );
}
}
extern void CVOutLocal( cv_out *out, name *t, int disp, dbg_type tipe )
/*** Put a local back sym out**********************************************/
{
type_length offset;
void *ptr1;
offset = NewBase( t );
ptr1 = out->beg;
out->beg = out->ptr;
FrameVar( out, "__bck", tipe, offset+disp );
out->beg = ptr1;
CVEndType( out );
BuffEnd( out );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?