int WPAsmFindSrcLine( sio_data * curr_sio, int line ) /***************************************************/ { wp_asmfile * wpasm_file; wp_asmline * asm_line; int asm_group; int asm_row; wpasm_file = curr_sio->asm_file; while( line >= 0 ) { asm_line = WPGetAsmLoc( wpasm_file, line, &asm_group, &asm_row ); if( asm_line->source_line ) { return( asm_line->u.src.line ); } line--; } return( 0 ); }
char * WPAsmGetLine( a_window * wnd, int line ) /*********************************************/ { sio_data * curr_sio; wp_asmfile * wpasm_file; src_info * src; wp_asmline * asm_line; int asm_group; int asm_row; int buff_len; curr_sio = WndExtra( wnd ); wpasm_file = curr_sio->asm_file; if( line >= wpasm_file->asm_rows ) { return( NULL ); } asm_line = WPGetAsmLoc( wpasm_file, line, &asm_group, &asm_row ); if( asm_line->source_line ) { src = &asm_line->u.src; if( src->src_file == NULL ) { strcpy( wpasm_file->asm_buff, LIT( Unable_To_Open_Src ) ); } else { for( ;; ) { buff_len = FReadLine( src->src_file, src->line, 0, wpasm_file->asm_buff, wpasm_file->asm_buff_len ); if( buff_len != wpasm_file->asm_buff_len ) break; wpasm_file->asm_buff_len += 120; wpasm_file->asm_buff = ProfRealloc( wpasm_file->asm_buff, wpasm_file->asm_buff_len ); } if( buff_len < 0 ) { buff_len = 0; } wpasm_file->asm_buff[buff_len] = NULLCHAR; } } else { SetNumBytes( 0 ); SetExeFile( wpasm_file->fh, false ); SetExeImage( curr_sio->curr_image ); GetFullInstruct( asm_line->u.asm_line.addr, wpasm_file->asm_buff, wpasm_file->asm_buff_len-1 ); } return( wpasm_file->asm_buff ); }
STATIC bool sasmGetLine( a_window *wnd, int row ) /***********************************************/ { sio_data *curr_sio; wp_asmfile *wpasm_file; wp_asmline *asm_line; int asm_group; int asm_row; curr_sio = WndExtra( wnd ); if( curr_sio->asm_file == NULL ) { return( false ); } sampNewRow = row != curr_sio->curr_proc_row; if( sampNewRow ) { curr_sio->curr_proc_row = row; dispName = WPAsmGetLine( wnd, row ); if( dispName == NULL ) { return( false ); } wpasm_file = curr_sio->asm_file; asm_line = WPGetAsmLoc( wpasm_file, row, &asm_group, &asm_row ); dispHighLight = asm_line->source_line; if( dispHighLight ) { dispCount = 0; } else { dispCount = asm_line->u.asm_line.tick_count; } localTicks = curr_sio->curr_mod->agg_count; maxTime = wpasm_file->max_time; barMaxTime = curr_sio->asm_src_info.bar_max; absGraphBar = curr_sio->asm_src_info.abs_bar; relGraphBar = curr_sio->asm_src_info.rel_bar; } else if( dispName == NULL ) { return( false ); } return( true ); }
void WPAsmClose( wp_asmfile * wpasm_file ) /****************************************/ { wp_asmline * asm_line; int row; int asm_group; int asm_row; if( wpasm_file != NULL ) { if( wpasm_file->asm_data != NULL ) { row = 0; while( row < wpasm_file->asm_rows ) { asm_line = WPGetAsmLoc( wpasm_file, row, &asm_group, &asm_row ); if( asm_line->source_line ) { FDoneSource( asm_line->u.src.src_file ); } row++; } row = wpasm_file->asm_rows; asm_group = 0; for( ;; ) { ProfFree( wpasm_file->asm_data[asm_group++].asm_lines ); row -= MAX_ASM_LINE_INDEX; if( row < 0 ) break; } ProfFree( wpasm_file->asm_data ); } if( wpasm_file->asm_buff != NULL ) { ProfFree( wpasm_file->asm_buff ); } if( wpasm_file->fh != 0 ) { ExeClose( wpasm_file->fh ); } ProfFree( wpasm_file ); } }
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 ); }