dfcue.c

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

C
671
字号
    if( stmts == NULL ) {
        DCStatus( DS_FAIL );
        return( WR_CONTINUE );
    }
    wlk.stmts = stmts;
    wlk.ii = ii;
    wlk.imx = imx;
    wlk.wk = wk;
    wlk.ic = ic;
    wlk.d  = d;
    wlk.wr =  WR_CONTINUE;
    DRWalkLFiles( stmts, ACueFileNum, &wlk, ACueDir, NULL );
    return( wlk.wr );
}


cue_file_id     DIPENTRY DIPImpCueFileId( imp_image_handle *ii,
                        imp_cue_handle *ic )
/*************************************************************/
{
    ii = ii;
    return( ic->fno );
}

/*******************************/
/*** Load Cue map find cues  ***/
/*******************************/

typedef struct {
    address         ret;
    cue_list        *list;
    seg_cue         *curr_seg;
} la_walk_info;

static int ACueAddr( void *_info, dr_line_data *curr )
/****************************************************/
{
    la_walk_info    *info = _info;

    if( curr->addr_set ) {  /* a set address */
        info->curr_seg = InitSegCue( info->list, curr->seg, curr->offset );
    }
    AddCue( info->curr_seg, curr );
    return( TRUE );
}


static void LoadCueMap( dr_handle stmts, address *addr, cue_list *list )
/**********************************************************************/
{
    la_walk_info    wlk;

    wlk.ret = *addr;
    wlk.list = list;
    wlk.curr_seg = NULL;
    DRWalkLines( stmts, SEG_CODE, ACueAddr, &wlk );
}


/*
    Adjust the 'src' cue by 'adj' amount and return the result in 'dst'.
    That is, If you get called with "DIPImpCueAdjust( ii, src, 1, dst )",
    the 'dst' handle should be filled in with implementation cue handle
    representing the source cue immediately following the 'src' cue.
    Passing in an 'adj' of -1 will get the immediately preceeding source
    cue. The list of source cues for each file are considered a ring,
    so if 'src' is the first cue in a file, an 'adj' of -1 will return
    the last source cue FOR THAT FILE. The cue adjust never crosses a
    file boundry. Also, if 'src' is the last cue in a file, and 'adj' of
    1 will get the first source cue FOR THAT FILE. If an adjustment
    causes a wrap from begining to end or vice versa, you should return
    DS_WRAPPED status (NOTE: DS_ERR should *not* be or'd in, nor should
    DCStatus be called in this case). Otherwise DS_OK should be returned
    unless an error occurred.
*/
dip_status      DIPENTRY DIPImpCueAdjust( imp_image_handle *ii,
                imp_cue_handle *src, int adj, imp_cue_handle *dst )
/*****************************************************************/
{
    dr_handle       stmts;
    dfline_search   start_state;
    dfline_find     find;
    dip_status      ret;
    imp_mod_handle  imx;
    cue_item        cue;
    cue_list        *cue_map;
    address         map_addr;

    imx = src->imx;
    DRSetDebug( ii->dwarf->handle );    /* must do at each call into DWARF */
    stmts  =  ii->mod_map[imx].stmts;
    if( stmts == NULL ) {
        DCStatus( DS_FAIL );
        return( DS_ERR|DS_FAIL  );
    }
    cue_map= ii->cue_map;
    if( cue_map->imx != imx ) {
        ResetCueInfo( cue_map );
        cue_map->imx = imx;
        map_addr = NilAddr;
        LoadCueMap( stmts, &map_addr, cue_map );
    }
    if( adj < 0 ) {
        start_state = LOOK_LOW;
        adj = -adj;
    } else {
        start_state = LOOK_HIGH;
    }
    cue.fno = src->fno;
    cue.line = src->line;
    cue.col = src->col;
    while( 0 != adj ) {
        find =  FindCue( cue_map, &cue, start_state );
        if( find == LINE_NOT ) break;
        --adj;
    }
    dst->imx = imx;
    dst->fno  =  cue.fno;
    dst->line =  cue.line;
    dst->col  =  cue.col;
    dst->a.mach = cue.mach;
    switch( find ) {
    case LINE_NOT:
        DCStatus( DS_FAIL );
        ret = DS_ERR | DS_FAIL;
        break;
    case LINE_WRAPPED:
        ret = DS_WRAPPED;
        break;
    case LINE_FOUND:
        ret = DS_OK;
        break;
    }
    return( ret );
}


unsigned long   DIPENTRY DIPImpCueLine( imp_image_handle *ii,
                        imp_cue_handle *ic )
/***********************************************************/
{
    ii = ii;
    return( ic->line );
}


unsigned        DIPENTRY DIPImpCueColumn( imp_image_handle *ii, imp_cue_handle *ic )
/**********************************************************************************/
{
    /* Return the column number of source cue. Return zero if there
     * is no column number associated with the cue, or an error occurs in
     * getting the information.
     */
    ii = ii;

    return( ic->col );
}


address         DIPENTRY DIPImpCueAddr( imp_image_handle *ii, imp_cue_handle *ic )
/********************************************************************************/
{
    address     ret;
    /* Return the address of source cue. Return NilAddr if there
     * is no address associated with the cue, or an error occurs in
     * getting the information.
     */
    ret = ic->a;
    DCMapAddr( &ret.mach, ii->dcmap );
    return( ret );
}


search_result   DIPENTRY DIPImpAddrCue( imp_image_handle *ii,
                imp_mod_handle im, address addr, imp_cue_handle *ic )
/*******************************************************************/
{
    /* Search for the closest cue in the given module that has an address
     * less then or equal to the given address. If there is no such cue
     * return SR_NONE. If there is one exactly at the address return
     * SR_EXACT. Otherwise, return SR_CLOSEST.
     */
    address         map_addr;
    search_result   ret;
    im_idx          imx;
    cue_list        *cue_map;
    cue_item        cue;
    dr_handle       stmts;

    if( im == 0 ) {
        DCStatus( DS_FAIL );
        return( SR_NONE );
    }
    DRSetDebug( ii->dwarf->handle ); /* must do at each call into dwarf */
    imx = IM2IMX( im );
    stmts = ii->mod_map[imx].stmts;
    if( stmts == NULL ) {
        return( SR_NONE );
    }
    map_addr = addr;
    cue_map = ii->cue_map;
    Real2Map( ii->addr_map, &map_addr );
    if( cue_map->imx != imx ) {
        ResetCueInfo( cue_map );
        cue_map->imx = imx;
        LoadCueMap( stmts, &map_addr, cue_map );
    }
    ic->imx  = imx;
    ic->fno  = 0;
    ic->line = 0;
    ic->col  = 0;
    ic->a    = NilAddr;
    ret = SR_NONE;
    if( map_addr.mach.segment == cue_map->last.mach.segment
     && map_addr.mach.offset  >= cue_map->last.mach.offset
     && map_addr.mach.offset  <  cue_map->last.next_offset ) {
        ic->fno  = cue_map->last.fno;
        ic->line = cue_map->last.line;
        ic->col  = cue_map->last.col;
        ic->a.mach = cue_map->last.mach;
        if( cue_map->last.mach.offset == map_addr.mach.offset ) {
            ret = SR_EXACT;
        } else {
            ret = SR_CLOSEST;
        }
        return( ret );
     }
    if( FindCueOffset( cue_map, &map_addr.mach, &cue ) ) {
        ic->fno  = cue.fno;
        ic->line = cue.line;
        ic->col  = cue.col;
        ic->a.mach = cue.mach;
        if( cue.mach.offset == map_addr.mach.offset ) {
            ret = SR_EXACT;
        } else {
            ret = SR_CLOSEST;
        }
        cue_map->last = cue;
    }
    return( ret );
}


search_result   DIPENTRY DIPImpLineCue( imp_image_handle *ii,
                imp_mod_handle im, cue_file_id file, unsigned long line,
                unsigned column, imp_cue_handle *ic )
/**********************************************************************/
{
    search_result   ret;
    dfline_find     find;
    dfline_search   what;
    dr_handle       stmts;
    im_idx          imx;
    cue_list        *cue_map;
    address         map_addr;
    cue_item        cue;

    if( im == 0 ) {
        DCStatus( DS_FAIL );
        return( SR_NONE );
    }
    DRSetDebug( ii->dwarf->handle );    /* must do at each call into DWARF */
    imx = IM2IMX( im );
    stmts  = ii->mod_map[imx].stmts;
    if( stmts == NULL ) {
        return( SR_NONE );
    }
    cue_map= ii->cue_map;
    if( cue_map->imx != imx ) {
        ResetCueInfo( cue_map );
        cue_map->imx = imx;
        map_addr = NilAddr;
        LoadCueMap( stmts, &map_addr, cue_map );
    }
    if( file == 0 ) {   // primary file
        cue.fno = 1;
    } else {
        cue.fno = file;
    }
    cue.line = line;
    cue.col = column;
    ic->a = NilAddr;
    if( line == 0 ) {
        what = LOOK_FILE;
    } else {
        what =  LOOK_CLOSEST;
    }
    find = FindCue( cue_map, &cue, what );
    ic->imx  = imx;
    ic->fno  = cue.fno;
    ic->line = cue.line;
    ic->col  = cue.col;
    ic->a.mach = cue.mach;
    switch( find ) {
    case LINE_CLOSEST:
        ret = SR_CLOSEST;
        break;
    case LINE_FOUND:
        ret = SR_EXACT;
        break;
    case LINE_NOT:
        ret = SR_NONE;
        break;
    }
    return( ret );
}


int DIPENTRY DIPImpCueCmp( imp_image_handle *ii, imp_cue_handle *ic1,
                                imp_cue_handle *ic2 )
/*******************************************************************/
{
    /* Compare two cue handles and return 0 if they refer to the same
     * information. If they refer to differnt things return either a
     * positive or negative value to impose an 'order' on the information.
     * The value should obey the following constraints.
     * Given three handles H1, H2, H3:
     *         - if H1 < H2 then H1 is always < H2
     *         - if H1 < H2 and H2 < H3 then H1 is < H3
     * The reason for the constraints is so that a client can sort a
     * list of handles and binary search them.
     */
    long    ret;

    ii = ii;
    ret = ic1->imx - ic2->imx;
    if( ret != 0 ) return( ret );
    ret = ic1->fno - ic2->fno;
    if( ret != 0 ) return( ret );
    ret = ic1->line - ic2->line;
    if( ret != 0 ) return( ret );
    ret = ic1->col - ic2->col;
    return( ret );
}

⌨️ 快捷键说明

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