dfsyms.c

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

C
1,126
字号
/****************************************************************************
*
*                            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:  Emit DWARF symbol information.
*
****************************************************************************/


#include "standard.h"
#include "hostsys.h"
#include "coderep.h"
#include "pattern.h"
#include "procdef.h"
#include "cgdefs.h"
#include "sysmacro.h"
#include "symdbg.h"
#include "model.h"
#include "ocentry.h"
//#include "objrep.h"
#include "offset.h"
#include "zoiks.h"
#include "cgaux.h"
#include "typedef.h"
#include "dbgstrct.h"
#include <stdio.h>
#include <stdarg.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include "dw.h"
#include "dwarf.h"
#include "dfdbg.h"
#include "dbcue.h"
#define BY_CG
#include "cgprotos.h"
#include "feprotos.h"

extern  void            FEPtr(sym_handle,type_def *,offset);
extern  void            FEPtrBase(sym_handle);
extern  type_def        *TypeAddress(cg_type);
extern  seg_id          AskOP(void);
extern  void            BackPtr( bck_info*, seg_id, offset, type_def* );
extern  void            BackBigOffset( bck_info *, seg_id, offset );
extern  void            BackPtrBase( bck_info *, seg_id );
extern  void            OutLabel(label_handle);
extern  void            DoBigBckPtr(back_handle,offset);
extern  name            *DeAlias(name*);
extern  seg_id          SetOP(seg_id);
extern  seg_id          AskCodeSeg(void);
extern  segment_id      AskSegID(pointer,cg_class);
extern  sym_handle      AskForLblSym(label_handle);
extern  offset          AskLocation(void);
extern  void            SetLocation(offset);
extern  offset          AskMaxSize(void);
extern  void            SetBigLocation( long_offset loc );
extern  long_offset     AskBigLocation(void);
extern  long_offset     AskBigMaxSize(void);
extern  offset          AskAddress(label_handle);
extern  bool            NeedBaseSet(void);
extern  void            DataInt(short_offset);
extern  void            DataLong( long );
extern  void            DataBytes(unsigned_32,byte*);
extern  void            IterBytes( offset len, byte pat );
extern  void            DataLabel( label_handle );
extern  void            DoBigLblPtr(sym_handle);
extern  void            DoBigBckPtr(back_handle,offset);
extern dw_loc_handle    DBGLoc2DF( dbg_loc loc );
extern dw_loc_id        DBGLoc2DFCont( dbg_loc loc, dw_loc_id df_locid );
extern uint             DFStkReg( void );
extern uint             DFDisplayReg( void );
extern void             DFFEPtrRef( sym_handle sym );
extern char             GetMemModel( void );
extern  name            *DeAlias(name*);
extern  name            *AllocUserTemp(pointer,type_class_def);
extern  type_length     NewBase(name*);

extern    source_line_number    SrcLine;
extern    proc_def              *CurrProc;
extern    struct opcode_entry   DbgInfo[];

extern  void            DFBlkBeg( dbg_block *blk, offset lc );
static  void            DumpLocals( dbg_local *local );

#define CurrProc_debug ((dbg_rtn *)CurrProc->targ.debug)

dw_client                  Client;
static short               CurrFNo;
static bool                CcuDef;


struct sect_info DwarfSegs[ DW_DEBUG_MAX ];

static bck_info  *Pc_High;
static bck_info  *Pc_Low;
static bck_info  *Comp_High;
static bck_info  *ARange;

static void CLIWrite( dw_sectnum sect, const void *block, dw_size_t size ) {
/******************************************************************/
    struct sect_info   *curr;
    seg_id              old;
    long_offset         off;

    curr = &DwarfSegs[sect];
    old = SetOP( curr->seg );
    off = AskBigLocation();
    DataBytes( size, (byte*)block );
    SetOP( old );
}

static long CLITell( dw_sectnum sect ) {
/*********************************/
    struct sect_info   *curr;
    long_offset         off;
    seg_id              old;

   curr = &DwarfSegs[sect];
   old = SetOP( curr->seg );
   off = AskBigLocation();
   SetOP( old );
   return( off );
}

static void CLISeek( dw_sectnum sect, long offs, uint type ) {
/******************************************************/
    struct sect_info   *curr;
    long_offset         from;
    seg_id              old;

    curr = &DwarfSegs[sect];
    old = SetOP( curr->seg );
    switch( type ) {
    case DW_SEEK_CUR:
        from = AskBigLocation();
        break;
    case DW_SEEK_SET:
        from = 0;
        break;
    case DW_SEEK_END:
        from = AskBigMaxSize();
        break;
    }
    offs += from;
    SetBigLocation( offs );
    SetOP( old );
}

static void DoReloc( dw_sym_handle sym, dw_addr_offset disp ){
/**********************************/
    type_def            *ptr_type;

    ptr_type = TypeAddress( T_NEAR_POINTER );
    FEPtr( (sym_handle) sym, ptr_type, disp );
}


static void DoSegReloc( dw_sym_handle sym ){
/*************************************/

    FEPtrBase( (sym_handle) sym );
}

static void DoLblReloc( bck_info *bck, long disp ){
/**********************************/
    type_def            *ptr_type;
    seg_id              id;

    id = AskSegID( bck, CG_BACK );
    ptr_type = TypeAddress( T_NEAR_POINTER );
    BackPtr( bck, id, disp, ptr_type );
}

static void DoSegLblReloc( bck_info *bck ){
/**********************************/
    seg_id              id;

    id = AskSegID( bck, CG_BACK );
    BackPtrBase( bck, id );
}

static void DoSectOffset( dw_sectnum section  ){
/**********************************/
    bck_info    *bck;
    uint_32     pos;
    seg_id      id;

    pos = CLITell( section );
    bck = DwarfSegs[section].bck;
    id = DwarfSegs[section].seg;
    BackBigOffset( bck, id, pos );

}

typedef struct {
    unsigned    segment;
    long_offset offset;
} big_patch_handle;

static big_patch_handle UnitSize[1];

typedef struct {
    bck_info    *bck;
    int_32       disp;
}loc_range;

static void CLIReloc( dw_sectnum sect, dw_relocs reloc_type, ... ){
/******************************************************/
    static uint_32              const zero  = 0;
    struct sect_info           *curr;
    dw_sym_handle               sym;
    dw_sym_handle               bck;
    loc_range                   *low;
    loc_range                   *high;
    dw_sectnum                  section;
    va_list                     args;
    seg_id                      old;
    long_offset                 off;

    va_start( args, reloc_type );
    curr = &DwarfSegs[sect];
    old = SetOP( curr->seg );
    off = AskBigLocation();
    switch( reloc_type ) {
    case DW_W_LOW_PC:
        if( Pc_Low != NULL ){
            DoLblReloc( Pc_Low, 0 );
        }else{
            Zoiks( ZOIKS_107 ); /* No Low PC */
        }
        break;
    case DW_W_HIGH_PC:
        if( Pc_High != NULL ){
            DoLblReloc( Pc_High, 0 );
        }else{
            Zoiks( ZOIKS_107 ); /* No High PC */
        }
        break;
    case DW_W_STATIC:
        sym = va_arg( args, dw_sym_handle );
        DoReloc( sym, 0  );
        break;
    case DW_W_LABEL:
        bck = va_arg( args, dw_sym_handle );
        DoLblReloc( (bck_info *)bck, 0 );
        break;
    case DW_W_SEGMENT:
        sym = va_arg( args, dw_sym_handle );
        DoSegReloc( sym );
        break;
    case DW_W_LABEL_SEG:
        bck = va_arg( args, dw_sym_handle );
        DoSegLblReloc( (bck_info *)bck );
        break;
    case DW_W_LOC_RANGE:
        low =  va_arg( args, loc_range* );
        high = va_arg( args, loc_range* );
        DoLblReloc( low->bck, low->disp );
        DoLblReloc( high->bck, high->disp );
        break;
    case DW_W_DEFAULT_FUNCTION:
        break;
    case DW_W_ARANGE_ADDR:
        DoLblReloc( ARange, 0 );
#if _TARGET &( _TARG_IAPX86 | _TARG_80386 )
        if( _IsntTargetModel( FLAT_MODEL ) ) {
            DoSegLblReloc( ARange );
        }
#endif
        break;
    case DW_W_UNIT_SIZE:
        UnitSize->segment = curr->seg;
        UnitSize->offset =  AskBigLocation();
        DataBytes( sizeof( uint_32 ), (char *)&zero );
        break;
    case DW_W_SECTION_POS:
        section = va_arg( args, uint );
        DoSectOffset( section );
        break;
    case DW_W_EXT_REF:
      {
        long_offset disp;

        sym = va_arg( args, dw_sym_handle );
        disp = va_arg( args, dw_addr_offset );
        DoReloc( sym, disp );
//      DFFEPtrRef( (sym_handle )sym, disp );
        break;
      }
    default:
        abort();
        break;
    }
    SetOP( old );
}


static void *CLIAlloc( size_t size ) {

    void        *p;

    p = CGAlloc( size );
    return( p );
}


static void CLIFree( void *p ) {

    CGFreeSize( p, 0 );
}

static bck_info  *MakeLabel( void ){
    bck_info            *bck;

    bck = BENewBack( NULL );
    bck->seg = AskOP();
    return( bck );
}

extern  void    DFInitDbgInfo(){
/******************************/
/* called after ObjInit */
    CurrFNo = 0;
    CcuDef = FALSE;
    Client = NULL;
}
#define MAX_LANG 4
struct lang_map{
     uint       lang;
     char       name[10];
};

static struct lang_map LangNames[MAX_LANG] = {
    {DWLANG_C,       "C"},
    {DWLANG_CPP,     "CPP"},
    {DWLANG_FORTRAN, "FORTRAN"},
    {DWLANG_FORTRAN, "FORTRAN77"},
};

static int SetLang( void ){
    int     ret;
    char    *name;
    int     index;

    ret = DWLANG_C;
    name =  FEAuxInfo( NULL, SOURCE_LANGUAGE );
    for( index = 0; index < MAX_LANG; ++index ){
        if( strcmp( name, LangNames[index].name ) == 0 ){
            ret = LangNames[index].lang;
            break;
        }
    }
    return( ret );
}

⌨️ 快捷键说明

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