Beispiel #1
0
/*
 * ProcImgSymInfo -- initialize symbolic information
 *
 * Note: This function should try to open files locally first, for two
 * reasons:
 * 1) If a local file is open as remote, then local caching may interfere with
 *    file operations (notably seeks with DIO_SEEK_CUR)
 * 2) Remote access goes through extra layer of indirection; this overhead
 *    is completely unnecessary for local debugging.
 */
static bool ProcImgSymInfo( image_entry *image )
{
    file_handle fh;
    unsigned    last;
    char        buff[TXT_LEN];
    char        *symfile_name;
    const char  *nopath;
    size_t      len;

    image->deferred_symbols = false;
    if( _IsOff( SW_LOAD_SYMS ) )
        return( NO_MOD );
    if( image->symfile_name != NULL ) {
        last = DIP_PRIOR_MAX;
        fh = PathOpen( image->symfile_name, strlen( image->symfile_name ), "sym" );
        if( fh == NIL_HANDLE ) {
            nopath = SkipPathInfo( image->symfile_name, OP_REMOTE );
            fh = PathOpen( nopath, strlen( nopath ), "sym" );
            if( fh == NIL_HANDLE ) {
                /* try the sym file without an added extension */
                fh = FileOpen( image->symfile_name, OP_READ );
            }
        }
    } else {
        last = DIP_PRIOR_EXPORTS - 1;
        fh = FileOpen( image->image_name, OP_READ );
        if( fh == NIL_HANDLE ) {
            fh = FileOpen( image->image_name, OP_READ | OP_REMOTE );
        }
    }
    if( fh != NIL_HANDLE ) {
        if( CheckLoadDebugInfo( image, fh, DIP_PRIOR_MIN, last ) ) {
            return( true );
        }
        FileClose( fh );
    }
    if( image->symfile_name != NULL )
        return( false );
    _AllocA( symfile_name, strlen( image->image_name ) + 1 );
    strcpy( symfile_name, image->image_name );
    symfile_name[ExtPointer( symfile_name, OP_REMOTE ) - symfile_name] = NULLCHAR;
    len = MakeFileName( buff, symfile_name, "sym", OP_REMOTE );
    _Alloc( image->symfile_name, len + 1 );
    if( image->symfile_name != NULL ) {
        memcpy( image->symfile_name, buff, len + 1 );
        fh = FileOpen( image->symfile_name, OP_READ );
        if( fh == NIL_HANDLE ) {
            fh = FileOpen( image->symfile_name, OP_READ | OP_REMOTE );
        }
        if( fh == NIL_HANDLE ) {
            fh = PathOpen( image->symfile_name, strlen( image->symfile_name ), "" );
        }
        if( fh != NIL_HANDLE ) {
            if( CheckLoadDebugInfo( image, fh, DIP_PRIOR_MIN, DIP_PRIOR_MAX ) ) {
                return( true );
            }
            FileClose( fh );
        }
        _Free( image->symfile_name );
    }
    image->symfile_name = NULL;
    if( _IsOff( SW_NO_EXPORT_SYMS ) ) {
        if( _IsOn( SW_DEFER_SYM_LOAD ) ) {
            image->deferred_symbols = true;
        } else {
            fh = FileOpen( image->image_name, OP_READ | OP_REMOTE );
            if( fh != NIL_HANDLE ) {
                if( CheckLoadDebugInfo( image, fh, DIP_PRIOR_EXPORTS - 1, DIP_PRIOR_MAX ) ) {
                    return( true );
                }
                FileClose( fh );
            }
        }
    }
    return( false );
}
Beispiel #2
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    char                *err;
    char                *parm;
    char                *end;
    handle              dh;
    trap_file_header    __far *head;
    char                init_error[256];


    if( trapbuff == NULL ) {
        trapbuff = DEFAULT_TRP_NAME;
    }
    end = strchr( trapbuff, PARM_SEPARATOR );
    if( end == NULL ) {
        end = &trapbuff[ strlen( trapbuff ) ];
        parm = end;
    } else {
        parm = end + 1;
    }
    dh = PathOpen( trapbuff, end - trapbuff, DEFAULT_TRP_EXT );
    if( dh == NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    err = ReadInTrap( GetSystemHandle( dh ) );
    FileClose( dh );
    if( err != NULL ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        KillTrap();
        return( buff );
    }
    err = SetTrapHandler();
    if( err != NULL ) {
        KillTrap();
        return( err );
    }
    err = CopyEnv();
    if( err != NULL ) {
        KillTrap();
        return( err );
    }
    head = MK_PM( TrapMem.s.rm, 0 );
    if( head->sig != TRAP_SIGNATURE ) {
        KillTrap();
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        return( buff );
    }
    PMData->initfunc.s.offset = head->init;
    PMData->reqfunc.s.offset  = head->req;
    PMData->finifunc.s.offset = head->fini;
    PMData->initfunc.s.segment = TrapMem.s.rm;
    PMData->reqfunc.s.segment  = TrapMem.s.rm;
    PMData->finifunc.s.segment = TrapMem.s.rm;
    if( !CallTrapInit( parm, init_error, trap_ver ) ) {
        KillTrap();
        strcpy( buff, init_error );
        return( buff );
    }
    if( !TrapVersionOK( *trap_ver ) ) {
        KillTrap();
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        return( buff );
    }
    TrapVer = *trap_ver;
    ReqFunc = DoTrapAccess;
    return( NULL );
}