drinfo.c

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

C
741
字号
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_artificial ) != 0 ) {
        return( DWRReadFlag( abbrev, entry ) );
    }
    return( FALSE );
}

extern int DRIsSymDefined( dr_handle entry )
/******************************************/
{
    dr_handle   abbrev;

    abbrev = DWRGetAbbrev( &entry );
    return( DWRScanForAttrib( &abbrev, &entry, DW_AT_declaration ) == 0 );
}

extern int DRIsMemberStatic( dr_handle entry )
/********************************************/
{
    dr_handle   abbrev;
    dw_tagnum   tag;

    abbrev = DWRVMReadULEB128( &entry );
    abbrev = DWRLookupAbbrev( entry, abbrev );
    tag = DWRVMReadULEB128( &abbrev );
    return( tag == DW_TAG_variable );
}

extern int DRIsFunc( dr_handle entry )
/************************************/
{
    dr_handle   abbrev;
    dw_tagnum   tag;

    abbrev = DWRVMReadULEB128( &entry );
    abbrev = DWRLookupAbbrev( entry, abbrev );
    tag = DWRVMReadULEB128( &abbrev );
    return( tag == DW_TAG_subprogram );
}

extern int DRIsParm( dr_handle entry )
/************************************/
{
    dr_handle   abbrev;
    dw_tagnum   tag;

    abbrev = DWRVMReadULEB128( &entry );
    abbrev = DWRLookupAbbrev( entry, abbrev );
    tag = DWRVMReadULEB128( &abbrev );
    return( tag == DW_TAG_formal_parameter );
}

extern dr_virtuality DRGetVirtuality( dr_handle entry )
/*****************************************************/
{
    dr_handle   abbrev;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_virtuality ) != 0 ) {
        return( DWRReadConstant( abbrev, entry ) );
    }
    return( DR_VIRTUALITY_NONE );
}

extern unsigned DRGetByteSize( dr_handle entry )
/**********************************************/
{
    dr_handle   abbrev;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_byte_size ) != 0 ) {
        return( DWRReadConstant( abbrev, entry ) );
    }
    return( 0 );
}

extern int DRGetLowPc( dr_handle entry, uint_32 *num )
/****************************************************/
{
    dr_handle   abbrev;
    uint_32     offset;
    int         ret;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_low_pc ) != 0 ) {
        offset = DWRReadAddr( abbrev, entry );
        *num = offset;
        ret = TRUE;
    } else {
        ret = FALSE;
    }
    return( ret );
}

extern int DRGetHighPc( dr_handle entry, uint_32 *num )
/*****************************************************/
{
    dr_handle   abbrev;
    uint_32     offset;
    int         ret;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_high_pc ) != 0 ) {
        offset = DWRReadAddr( abbrev, entry );
        *num = offset;
        ret = TRUE;
    } else {
        ret = FALSE;
    }
    return( offset );
}

extern dr_handle DRGetContaining( dr_handle entry )
/*************************************************/
{
    dr_handle   abbrev;
    dr_handle   ret;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_containing_type ) != 0 ) {
        ret = DWRReadReference( abbrev, entry );
    } else {
        ret = NULL;
    }
    return( ret );
}

extern dr_handle DRWalkParent( dr_search_context * context )
/**********************************************************/
// get past relative
{
    dr_handle   prev;
    stack_op      op;

    op = DWRContext( &context->stack, 0 );
    switch( op ) {
    case DO_NOTHING:
        prev = DWRContext( &context->stack, 1 );
        break;
    case SET_CLASS:
        prev = context->classhdl;
        break;
    case SET_FUNCTION:
        prev = context->functionhdl;
        break;
    }
    return( prev );
}

struct wlk_wlk {
    DRWLKMODF   wlk;
    void        *d;
};

static bool CheckAFunc( dr_handle abbrev, dr_handle mod, mod_scan_info *x,
                        void *_d )
/************************************************************************/
{
    int                 ret;
    struct  wlk_wlk     *d = _d;

    abbrev = abbrev;

    mod = x->handle;
    ret = d->wlk( mod, d->d, x->context );
    return( ret );
}

static unsigned_16 const BlockTags[] = {
    DW_TAG_subprogram, DW_TAG_lexical_block, 0
};

static unsigned_16 const EntryTags[] = {
    DW_TAG_subprogram, DW_TAG_label, DW_TAG_variable, 0
};

extern int DRWalkModFunc( dr_handle mod, bool blocks, DRWLKMODF wlk, void *d )
/****************************************************************************/
{
    int             ret;
    struct wlk_wlk  dat;

    dat.wlk = wlk;
    dat.d = d;
    if( blocks ) {
        ret = DWRWalkCompileUnit( mod, CheckAFunc, BlockTags, DR_DEPTH_FUNCTIONS, &dat );
    } else {
        ret = DWRWalkCompileUnit( mod, CheckAFunc, EntryTags, 0, &dat );
    }
    return( ret );
}

static unsigned_16 const TypeTags[] = { // any type
    DW_TAG_array_type,
    DW_TAG_enumeration_type,
    DW_TAG_pointer_type,
    DW_TAG_string_type,
    DW_TAG_structure_type,
    DW_TAG_union_type,
    DW_TAG_class_type,
    DW_TAG_subprogram,
    DW_TAG_subroutine_type,
    DW_TAG_reference_type,
    DW_TAG_ptr_to_member_type,
    DW_TAG_set_type,
    DW_TAG_subrange_type,
    DW_TAG_base_type,
    DW_TAG_file_type,
    DW_TAG_thrown_type,
    DW_TAG_const_type,
    DW_TAG_volatile_type,
    DW_TAG_packed_type,
    DW_TAG_typedef,
};

extern int DRWalkModTypes( dr_handle mod, DRWLKMODF wlk, void *d )
/****************************************************************/
{
    int             ret;
    struct wlk_wlk  dat;

    dat.wlk = wlk;
    dat.d = d;
    ret = DWRWalkCompileUnit( mod, CheckAFunc,
        TypeTags, DR_DEPTH_FUNCTIONS | DR_DEPTH_CLASSES, &dat );
    return( ret );
}

extern int DRWalkScope( dr_handle mod, DRWLKBLK wlk, void *d )
/************************************************************/
{
    int ret;

    ret = DWRWalkScope( mod, &BlockTags[1], wlk, d );
    return( ret );
}

static unsigned_16 const CodeDataTags[] = {
    DW_TAG_subprogram, DW_TAG_variable, DW_TAG_label,
    DW_TAG_WATCOM_namespace, DW_TAG_formal_parameter, 0
};

static unsigned_16 const ParmTags[] = {
    DW_TAG_formal_parameter, 0
};

static unsigned_16 const CTypeTags[] = {    // visible c type names
    DW_TAG_typedef, 0
};

static unsigned_16 const CPPTypeTags[] = {  // visible c++ type names
    DW_TAG_base_type, DW_TAG_typedef,
    DW_TAG_enumeration_type, DW_TAG_class_type,
    DW_TAG_union_type, DW_TAG_structure_type, 0
};

static unsigned_16 const * const SrchTags[DR_SRCH_LAST] = {
    CodeDataTags,
    FunctionTags,
    ClassTags,
    EnumTags,
    TypedefTags,
    CTypeTags,
    CPPTypeTags,
    VariableTags,
    ParmTags,
    LabelTags,
};

#define MAX_TAG_WLK   8   //check max size of tag search array
extern int DRWalkBlock( dr_handle mod, dr_srch what,
                        DRWLKBLK  wlk, void    *d )
/**************************************************/
{
    int                 ret;
    unsigned_16 const   *tags;
    DRWLKBLK            wlks[MAX_TAG_WLK];
    int                 index;

    tags = SrchTags[what];
    index = 0;
    while( tags[index] != 0 ) {
            wlks[index] = wlk;
            ++index;
    }
    wlks[index] = NULL;
    ret = DWRWalkChildren( mod, tags, wlks, d );
    return( ret );
}

extern int DRStartScopeAT( dr_handle entry, uint_32 *num )
/********************************************************/
{
    dr_handle   abbrev;
    uint_32     offset;
    int         ret;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_start_scope ) != 0 ) {
        offset =  DWRReadConstant( abbrev, entry );
        *num = offset;
        ret = TRUE;
    } else {
        ret = FALSE;
    }
    return( ret );
}

extern unsigned DRGetAddrSize( dr_handle mod )
/********************************************/
// returns the size of the address for the compile unit
{
    return( DWRVMReadByte( mod + 10 ) );
}

extern dr_handle DRDebugPCHDef( dr_handle entry )
/***********************************************/
{
    dr_handle   abbrev;
    dr_handle   ret;

    abbrev = DWRGetAbbrev( &entry );
    if( DWRScanForAttrib( &abbrev, &entry, DW_AT_base_types ) != 0 ) {
        ret = DWRReadReference( abbrev, entry );
    } else {
        ret = NULL;
    }
    return( ret );
}

extern dr_tag_type DRGetTagType( dr_handle entry )
/************************************************/
{
    dr_tag_type tagtype;
    dw_tagnum   tag;

    tag = GetTag( entry );
    switch( tag ) {
    case DW_TAG_subprogram:
        tagtype =  DR_TAG_FUNCTION;
        break;
    case DW_TAG_class_type:
    case DW_TAG_union_type:
    case DW_TAG_structure_type:
        tagtype =  DR_TAG_CLASS;
        break;
    case DW_TAG_enumeration_type:
        tagtype =  DR_TAG_ENUM;
        break;
    case DW_TAG_typedef:
        tagtype =  DR_TAG_TYPEDEF;
        break;
    case DW_TAG_common_block:
    case DW_TAG_variable:
    case DW_TAG_formal_parameter:
    case DW_TAG_member:
        tagtype =  DR_TAG_VARIABLE;
        break;
    case  DW_TAG_label:
        tagtype =  DR_TAG_LABEL;
        break;
    case  DW_TAG_WATCOM_namespace:
        tagtype =  DR_TAG_NAMESPACE;
        break;
    default:
        tagtype =  DR_TAG_NONE;
        break;
    }
    return( tagtype );
}

⌨️ 快捷键说明

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