STATIC void findRtnFromRow( sio_data *curr_sio, int row ) /*******************************************************/ { file_info *curr_file; rtn_info *curr_rtn; cue_handle *ch; sym_handle *sh; int index; mod_handle mh; address addr; index = 0; ch = alloca( DIPHandleSize( HK_CUE ) ); curr_file = curr_sio->curr_file; mh = curr_sio->curr_mod->mh; if( LineCue( mh, curr_sio->curr_file->fid, row, 0, ch ) == SR_NONE ) { if( LineCue( mh, curr_sio->curr_file->fid, 0, 0, ch ) == SR_NONE ) return; } sh = alloca( DIPHandleSize( HK_SYM ) ); addr = CueAddr( ch ); if( AddrSym( mh, addr, sh ) == SR_NONE ) return; while( index < curr_file->rtn_count ) { curr_rtn = curr_file->routine[index]; if( curr_rtn->sh != NULL && SymCmp( curr_rtn->sh, sh ) == 0 ) { curr_sio->curr_rtn = curr_rtn; break; } index++; } }
static walk_result FindModCue( mod_handle mod, void *d ) { DIPHDL( cue, ch ); cue_find *fd = d; unsigned long curr_line; fd->id = 0; fd->ambig = FALSE; fd->match = CMP_NONE; if( mod != NO_MOD && fd->len != 0 ) { WalkFileList( mod, FindCue, fd ); if( fd->id == 0 ) return( WR_CONTINUE ); if( fd->ambig ) { Error( ERR_NONE, LIT( ERR_AMBIG_SRC_FILE ), fd->name, fd->len ); } } fd->found_a_file = TRUE; switch( LineCue( mod, fd->id, CurrGet.li.name.len, 0, ch ) ) { case SR_EXACT: HDLAssign( cue, fd->best_ch, ch ); fd->best_line = CurrGet.li.name.len; return( WR_STOP ); case SR_CLOSEST: curr_line = CueLine( ch ); if( curr_line < CurrGet.li.name.len && curr_line > fd->best_line ) { HDLAssign( cue, fd->best_ch, ch ); fd->best_line = CurrGet.li.name.len; } break; case SR_FAIL: return( WR_FAIL ); } return( WR_CONTINUE ); }
extern bool SrcMoveDot( a_window *wnd, address addr ) { unsigned line; mod_handle mod; file_window *file; DIPHDL( cue, ch ); if( wnd == NULL ) return( FALSE ); file = WndFile( wnd ); if( file->mod == NO_MOD && !file->track ) return( FALSE ); if( IS_NIL_ADDR( addr ) ) { WndScrollAbs( wnd, 0 ); return( FALSE ); } DeAliasAddrMod( addr, &mod ); if( DeAliasAddrCue( mod, addr, ch ) == SR_NONE ) { if( LineCue( mod, 0, 0, 0, ch ) == SR_NONE ) return( FALSE ); } line = CueLine( ch ); if( mod != file->mod || CueFileId( ch ) != file->file_id ) { if( !file->track ) return( FALSE ); FileTrack( wnd, ch ); } --line; WndScrollAbs( wnd, line ); // WndMoveCurrent( wnd, line, PIECE_SOURCE ); FileSetDotAddr( wnd, addr ); FileSetTitle( wnd, CueMod( ch ) ); return( TRUE ); }
static remap_return ReMapOnePoint( brkp *bp, image_entry *image ) { mod_handle himage, mod; bool ok; address addr; DIPHDL( cue, ch ); DIPHDL( cue, ch2 ); remap_return rc = REMAP_REMAPPED; if( !bp->status.b.unmapped ) return( REMAP_WRONG_IMAGE ); if( bp->image_name == NULL || bp->mod_name == NULL ) { if( image == NULL ) { if( ReMapAddress( &bp->loc ) ) { rc = REMAP_REMAPPED; } else { rc = REMAP_ERROR; } } else { rc = ReMapImageAddress( &bp->loc, image ); } } else { himage = LookupImageName( bp->image_name, strlen( bp->image_name ) ); if( himage == NO_MOD ) return( REMAP_ERROR ); mod = LookupModName( himage, bp->mod_name, strlen( bp->mod_name ) ); if( mod == NO_MOD ) return( REMAP_ERROR ); ok = GetBPSymAddr( bp, &addr ); if( !ok ) return( REMAP_ERROR ); if( bp->cue_diff != 0 ) { if( DeAliasAddrCue( mod, addr, ch ) != SR_EXACT ) return( REMAP_ERROR ); if( LineCue( mod, CueFileId( ch ), CueLine( ch ) + bp->cue_diff, 0, ch2 ) != SR_EXACT ) return( REMAP_ERROR ); addr = CueAddr( ch2 ); } if( bp->addr_diff != 0 ) { addr.mach.offset += bp->addr_diff; } bp->loc.addr = addr; rc = REMAP_REMAPPED; } if( rc == REMAP_REMAPPED ) { bp->status.b.unmapped = false; } SetPointAddr( bp, bp->loc.addr ); if( bp->status.b.activate_on_remap ) { ActPoint( bp, true ); } return( rc ); }
extern a_window *WndModInspect( mod_handle mod ) { a_window *wnd; DIPHDL( cue, ch ); wnd = WndFindExisting( WND_SOURCE ); if( wnd == NULL && LineCue( mod, 0, 0, 0, ch ) != SR_NONE ) { wnd = DoWndSrcOpen( ch, true ); } if( wnd != NULL ) { SrcMoveDot( wnd, ModFirstAddr( mod ) ); } return( wnd ); }
address GetRowAddrDirectly( mod_handle mod, cue_fileid file_id, int row, bool exact ) { DIPHDL( cue, ch ); if( mod == NO_MOD || row < 0 ) return( NilAddr ); switch( LineCue( mod, file_id, row+1, 0, ch ) ) { case SR_NONE: return( NilAddr ); case SR_CLOSEST: if( exact ) return( NilAddr ); break; } return( CueAddr( ch ) ); }
static address GetRowAddr( file_window *file, wnd_row row, bool exact ) { DIPHDL( cue, ch ); if( file->mod == NO_MOD || row < 0 ) return( NilAddr ); switch( LineCue( file->mod, file->file_id, row+1, 0, ch ) ) { case SR_NONE: return( NilAddr ); case SR_CLOSEST: if( exact ) return( NilAddr ); break; } return( CueAddr( ch ) ); }
/** * WalkFileList callback, the module pass. * * @returns WR_CONTINUE * @param cue The file. * @param ignored Unused user argument. */ static walk_result File2Callback( cue_handle *cue, void *ignored ) { address prev_addr = {0}; long prev_line = -1; cue_handle *next_cue = alloca( DIPHandleSize( HK_CUE, false ) ); cue_handle *prev_cue = NULL; cue_handle *cue2 = alloca( DIPHandleSize( HK_CUE, false ) ); mod_handle mod = CueMod( cue ); cue_fileid file_id = CueFileId( cue ); search_result search_rc; char buff[1024]; size_t len; dip_status rc; /* filename */ buff[0] = '\0'; len = CueFile( cue, buff, sizeof( buff ) ); if( len > 0 ) { printf( " %lx %s\n", file_id, buff ); } else { printf( " %lx (len=%u)\n", file_id, len ); } /* check the LineCue function */ if( Opts.do_cue_tests ) { search_rc = LineCue( mod, file_id, 0, 0, cue2 ); CompareCues( cue, cue2, SR_EXACT, search_rc, true, false, true, false, "LineCue(,,0,)" ); } /* lines */ do { long line = CueLine( cue ); unsigned column = CueColumn( cue ); address addr = CueAddr( cue ); printf( " Line %5ld ", line ); if( column ) { printf( "Col %2d ", column ); } printf( "at %04x:%08lx%s\n", addr.mach.segment, (long)addr.mach.offset, prev_line >= 0 && addr.mach.offset < prev_addr.mach.offset ? "^" : prev_line >= 0 && line < prev_line ? "!" : "" ); /* do tests */ if( Opts.do_cue_tests ) { if( CueFileId( cue ) != file_id ) { printf( "ERROR: file id changed! new:%#lx old:%#lx\n", (long)CueFileId( cue ), (long)file_id ); } if( CueMod( cue ) != mod ) { printf( "ERROR: module changed! new:%#lx old:%#lx\n", (long)CueMod( cue ), (long)file_id ); } /* line searches */ search_rc = LineCue( mod, file_id, line, 0, cue2 ); CompareCues( cue, cue2, SR_EXACT, search_rc, true, false, false, false, "LineCue(,,n,)" ); if( line > prev_line + 1 && prev_line >= 0 ) { search_rc = LineCue( mod, file_id, line - 1, 0, cue2 ); CompareCues( prev_cue, cue2, prev_line == line - 1 ? SR_EXACT : SR_CLOSEST, search_rc, true, false, false, false, "LineCue(,,n-1,)" ); } /* address searches */ search_rc = AddrCue( mod, addr, cue2 ); CompareCues( cue, cue2, SR_EXACT, search_rc, false, false, true, false, "AddrCue(,,n,)" ); } /* next */ rc = CueAdjust( cue, 1, next_cue ); prev_cue = cue; cue = next_cue; next_cue = prev_cue; prev_addr = addr; prev_line = line; } while( rc == DS_OK ); return( WR_CONTINUE ); }
static bool FileGetLine( a_window *wnd, int row, int piece, wnd_line_piece *line ) { int len; file_window *file = WndFile( wnd ); address addr; brkp *bp; bool curr; DIPHDL( cue, ch ); line->text = LIT_ENG( Empty ); if( file->viewhndl == NULL && ModHasInfo( file->mod, HK_CUE ) != DS_OK ) { return( false ); } curr = ( row == file->active && ContextMod == file->mod ); switch( piece ) { case PIECE_BREAK: line->tabstop = false; if( row >= file->eof ) return( false ); if( file->mod == NO_MOD ) return( true ); addr = NilAddr; if( !WndDoingSearch ) { // too expensive addr = GetRowAddr( file, row, true ); } if( !IS_NIL_ADDR( addr ) ) { bp = FindBreakByLine( file->mod, file->file_id, row+1 ); FileBreakGadget( wnd, line, curr, bp ); } return( true ); case PIECE_SOURCE: line->text = TxtBuff; line->extent = WND_MAX_EXTEND; if( curr ) line->attr = WND_STANDOUT; if( file->mod != NO_MOD ) { line->indent = MaxGadgetLength; } if( file->viewhndl == NULL ) { Format( TxtBuff, LIT_DUI( No_Source_Line ), row+1 ); if( LineCue( file->mod, file->file_id, 0, 0, ch ) != SR_NONE ) { if( (CueAdjust( ch, -1, ch ) & DS_ERR) ) { file->eof = CueLine( ch ); } } return( true ); } len = FReadLine( file->viewhndl, row+1, 0, TxtBuff, MAX_LINE_LEN ); if( len < 0 ) { file->eof = row; return( false ); } if( len == MAX_LINE_LEN ) { StrCopy( " ...", TxtBuff + MAX_LINE_LEN ); } else { TxtBuff[len] = NULLCHAR; } if( row >= file->rows ) { file->rows = row + 1; file->rows_offset = FLastOffset( file->viewhndl ); } return( true ); default: return( false ); } }
wp_asmfile *WPAsmOpen( sio_data * curr_sio, int src_row, bool quiet ) /*******************************************************************/ { wp_asmfile * wpasm_file; cue_handle * ch; cue_handle * ch2; mod_info * curr_mod; file_info * curr_file; massgd_sample_addr * samp_data; wp_asmline * asm_line; mod_handle mh; file_handle fh; address addr; cue_fileid fid; search_result cue_find; int rows; int asm_group; int asm_row; int file_index; int addr_cmp; clicks_t addr_tick_index; quiet=quiet; ch = alloca( DIPHandleSize( HK_CUE ) ); ch2 = alloca( DIPHandleSize( HK_CUE ) ); curr_file = curr_sio->curr_file; curr_mod = curr_sio->curr_mod; if( curr_file->fid == 0 || LineCue( curr_mod->mh, curr_sio->curr_file->fid, src_row, 0, ch2 ) == SR_NONE ) { ch2 = NULL; } fh = ExeOpen( curr_sio->curr_image->name ); if( fh == -1 ) { ErrorMsg( LIT( Exe_Not_Found ), curr_sio->curr_image->name ); return( NULL ); } wpasm_file = ProfCAlloc( sizeof(wp_asmfile) ); curr_sio->asm_file = wpasm_file; wpasm_file->asm_buff = ProfAlloc( MAX_ASM_BUFF_LEN ); wpasm_file->asm_buff_len = MAX_ASM_BUFF_LEN; SetNumBytes( 0 ); SetExeFile( fh, false ); wpasm_file->fh = fh; addr = ModAddr( curr_mod->mh ); SetExeOffset( addr ); wpasm_file->max_time = 0; addr_tick_index = curr_mod->first_tick_index - 1; samp_data = WPGetMassgdSampData( curr_sio, addr_tick_index++ ); wpasm_file->asm_data = ProfAlloc( sizeof(wp_asm_groups) ); wpasm_file->asm_data[0].asm_lines = ProfAlloc( MAX_ASM_LINE_SIZE ); wpasm_file->asm_groups = 0; rows = 0; for( ;; ) { mh = curr_mod->mh; if( EndOfSegment() || AddrMod( addr, &mh ) == SR_NONE || mh != curr_mod->mh ) break; cue_find = (AddrCue( curr_mod->mh, addr, ch ) == SR_EXACT); if( ch2 != NULL && CueCmp( ch, ch2 ) == 0 ) { wpasm_file->entry_line = rows; ch2 = NULL; } asm_line = WPGetAsmLoc( wpasm_file, rows, &asm_group, &asm_row ); if( cue_find ) { asm_line->source_line = true; asm_line->u.src.line = CueLine( ch ); asm_line->u.src.src_file = NULL; if( !curr_file->unknown_file ) { fid = CueFileId( ch ); file_index = 0; while( file_index < curr_mod->file_count ) { curr_file = curr_mod->mod_file[file_index]; if( curr_file->fid == fid ) { asm_line->u.src.src_file = FOpenSource( curr_file->name, mh, fid ); break; } file_index++; } } rows++; asm_line = WPGetAsmLoc( wpasm_file, rows, &asm_group, &asm_row ); } asm_line = &wpasm_file->asm_data[asm_group].asm_lines[asm_row]; asm_line->source_line = false; asm_line->u.asm_line.addr = addr; asm_line->u.asm_line.tick_count = 0; for( ;; ) { if( samp_data == NULL ) break; addr_cmp = AddrCmp( &addr, samp_data->raw ); if( addr_cmp < 0 ) break; if( addr_cmp == 0 ) { asm_line->u.asm_line.tick_count = samp_data->hits; if( asm_line->u.asm_line.tick_count > wpasm_file->max_time ) { wpasm_file->max_time = asm_line->u.asm_line.tick_count; } } samp_data = WPGetMassgdSampData( curr_sio, addr_tick_index++ ); } rows++; CodeAdvance( &addr ); } WPGetAsmLoc( wpasm_file, rows, &asm_group, &asm_row ); wpasm_file->asm_data[asm_group].asm_lines = ProfRealloc( wpasm_file->asm_data[asm_group].asm_lines, sizeof(wp_asmline)*(asm_row+1) ); wpasm_file->asm_rows = rows; return( wpasm_file ); }