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 bool ExactCueAt( asm_window *asw, address addr, cue_handle *ch ) { if( !asw->source ) return( FALSE ); if( DeAliasAddrCue( NO_MOD, addr, ch ) == SR_NONE ) return( FALSE ); if( AddrComp( CueAddr( ch ), addr ) ) return( FALSE ); 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 ); }
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 ) ); }
/** * Compares two cues, the first one being the one which information we use * searching for the 2nd. * * @param cue The first cue. * @param cue2 The result cue (depends on search_rc). * @param expected_rc The expected search result. * @param actual_rc The actual search result. * @param exp_exact_line Set if we're to expect a matching line number. * @param exp_le_line Set if we're to expect a less or equal line number. * @param exp_exact_addr Set if we're to expect a matching address. * @param exp_le_line Set if we're to expect a less or equal address. * @param operation The name of the search operation. */ static void CompareCues( cue_handle *cue, cue_handle *cue2, search_result expected_rc, search_result actual_rc, bool exp_exact_line, bool exp_le_line, bool exp_exact_addr, bool exp_le_addr, const char *operation ) { if( actual_rc != expected_rc ) { printf( "FAILED: %s returned %d instead of %d\n", operation, actual_rc, expected_rc ); } if( actual_rc == SR_CLOSEST || actual_rc == SR_EXACT ) { address addr = CueAddr( cue ); unsigned long line = CueLine( cue ); address addr2 = CueAddr( cue2 ); unsigned long line2 = CueLine( cue2 ); int failed; failed = CueFileId( cue2 ) != CueFileId( cue ); failed |= exp_exact_line && line2 != line; failed |= exp_le_line && line2 <= line; failed |= exp_exact_addr && ( addr2.mach.segment != addr.mach.segment || addr2.mach.offset != addr.mach.offset ); failed |= exp_le_addr && ( addr2.mach.segment != addr.mach.segment || addr2.mach.offset <= addr.mach.offset ); if( failed ) { printf( "FAILED: %s: cue2:{file=%#x line=%lu addr=%04x:%08lx}\n" " %*s != cue:{file=%#x line=%lu addr=%04x:%08lx}\n", operation, CueFileId( cue2 ), line2, addr2.mach.segment, (long)addr2.mach.offset, strlen( operation ), "", CueFileId( cue ), line, addr.mach.segment, (long)addr.mach.offset ); } } }
static unsigned MechGet( unsigned select, unsigned parm ) { unsigned result; DIPHDL( cue, ch ); sym_list *sym; address addr; unsigned old; char *save_scan; char *mod_name; unsigned mod_len; unsigned mod_spec_token; result = FALSE; switch( select ) { case 0: /* init */ memset( &CurrGet, 0, sizeof( CurrGet ) ); CurrGet.li.mod = NO_MOD; if( _IsOn( SW_CASE_SENSITIVE ) ) { CurrGet.li.case_sensitive = TRUE; } else { CurrGet.li.case_sensitive = FALSE; } break; case 1: /* fini */ switch( CurrGet.kind ) { case GET_NAME: PushName( &CurrGet.li ); break; case GET_OPERATOR: CurrGet.li.type = ST_OPERATOR; PushName( &CurrGet.li ); break; case GET_LNUM: switch( FindACue( ch ) ) { case SR_EXACT: break; case SR_CLOSEST: if( ClosestLineOk ) break; default: Error( ERR_NONE, LIT( ERR_NO_CODE ), CurrGet.li.name.len ); } PushAddr( CueAddr( ch ) ); break; } break; case 2: /* mod curr */ case 3: /* mod name lookup */ //NYI: temporary gunk CurrGet.multi_module = TRUE; CurrGet.li.mod = NO_MOD; save_scan = ScanPos(); ReScan( "@" ); mod_spec_token = CurrToken; ReScan( save_scan ); if( CurrToken == T_NAME ) { mod_name = NamePos(); mod_len = NameLen(); Scan(); } else { mod_name = NULL; mod_len = 0; } if( CurrToken == mod_spec_token ) { if( select == 2 ) { CurrGet.li.mod = ImagePrimary()->dip_handle; if( CurrGet.li.mod == NO_MOD ) { CurrGet.li.mod = ILL_MOD; /* cause lookup to fail */ } } else { CurrGet.li.mod = LookupImageName( CurrGet.li.name.start, CurrGet.li.name.len ); if( CurrGet.li.mod == NO_MOD ) { #define ANY_IMAGE_NAME "_anyimage" #define ANY_IMAGE_NAME_LEN (sizeof(ANY_IMAGE_NAME)-1) if( CurrGet.li.name.len != ANY_IMAGE_NAME_LEN || memicmp( CurrGet.li.name.start, ANY_IMAGE_NAME, ANY_IMAGE_NAME_LEN ) != 0 ) { Error( ERR_NONE, LIT( ERR_NO_IMAGE ), CurrGet.li.name.start, CurrGet.li.name.len ); } else { CurrGet.any_image = TRUE; } } } CurrGet.li.name.start = mod_name; CurrGet.li.name.len = mod_len; Scan(); } else { ReScan( save_scan ); } if( CurrGet.li.name.start != NULL ) { CurrGet.li.mod = LookupModName( CurrGet.li.mod, CurrGet.li.name.start, CurrGet.li.name.len ); if( CurrGet.li.mod == NO_MOD ) { Error( ERR_NONE, LIT( ERR_NO_MODULE ), CurrGet.li.name.start, CurrGet.li.name.len ); } CurrGet.multi_module = FALSE; } else if( !CurrGet.any_image && CurrGet.li.mod == NO_MOD ) { CurrGet.li.mod = CodeAddrMod; CurrGet.multi_module = FALSE; } break; case 4: /* file scope */ CurrGet.li.file_scope = TRUE; break; case 5: /* given scope */ CurrGet.li.file_scope = FALSE; break; case 6: /* scope lookup */ CurrGet.li.scope.start = CurrGet.li.name.start; CurrGet.li.scope.len = CurrGet.li.name.len; break; case 7: /* get name >>bool */ if( CurrToken == T_NAME ) { CurrGet.kind = GET_NAME; CurrGet.li.name.start = NamePos(); CurrGet.li.name.len = NameLen(); Scan(); result = TRUE; } break; case 8: /* get operator name */ CurrGet.kind = GET_OPERATOR; CurrGet.li.name.start = NamePos(); CurrGet.li.name.len = NameLen(); Scan(); break; case 9: /* get line number >>bool */ if( CurrToken == T_LEFT_BRACE ) { size_t len; /* Get a specfic file name for the module */ ScanQuote( &CurrGet.li.source.start, &len ); CurrGet.li.source.len = len; } if( CurrToken == T_INT_NUM ) { unsigned_64 tmp; result = TRUE; CurrGet.kind = GET_LNUM; old = SetCurrRadix( 10 ); tmp = IntNumVal(); CurrGet.li.name.len = U32FetchTrunc( tmp ); Scan(); SetCurrRadix( old ); } break; case 10: /* GetDtorName >>bool */ if( CurrToken == T_NAME ) { CurrGet.kind = GET_NAME; CurrGet.li.name.start = NamePos(); CurrGet.li.name.len = NameLen(); CurrGet.li.type = ST_DESTRUCTOR; addr = Context.execution; sym = LookupSymList( SS_SCOPED, &addr, FALSE, &CurrGet.li ); if( sym != NULL ) { PurgeSymHandles(); Scan(); result = TRUE; } else { CurrGet.li.type = ST_NONE; } } break; case 11: /* GetSetNameType(symbol_type) */ CurrGet.li.type = parm; break; case 12: /* GetQueryName >>bool */ CurrGet.kind = GET_NAME; addr = Context.execution; sym = LookupSymList( SS_SCOPED, &addr, FALSE, &CurrGet.li ); if( sym != NULL ) { PurgeSymHandles(); result = TRUE; } else { CurrGet.li.type = ST_NONE; } break; case 13: /* GetAddScope */ if( CurrGet.li.scope.len == 0 ) { CurrGet.li.scope = CurrGet.li.name; } else { CurrGet.li.scope.len = (CurrGet.li.name.start-CurrGet.li.scope.start) + CurrGet.li.name.len; } break; } return( result ); }
/** * 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 ); }
void SetPointAddr( brkp *bp, address addr ) { DIPHDL( cue, ch ); image_entry *image; mod_handle mod; char const *start; bool ok; if( bp->status.b.unmapped ) return; _Free( bp->source_line ); bp->source_line = NULL; bp->loc.addr = addr; _Free( bp->mod_name ); bp->mod_name = NULL; _Free( bp->image_name ); bp->image_name = NULL; _Free( bp->sym_name ); bp->sym_name = NULL; bp->cue_diff = 0; bp->addr_diff = 0; if( !IS_BP_EXECUTE( bp->th ) ) { GetWPVal( bp ); } else if( DeAliasAddrMod( addr, &mod ) != SR_NONE ) { image = ImageEntry( mod ); if( image == NULL ) return; ModName( mod, TxtBuff, TXT_LEN ); bp->mod_name = DupStr( TxtBuff ); if( image->image_name != NULL ) { start = SkipPathInfo( image->image_name, OP_REMOTE ); bp->image_name = DupStrLen( start, ExtPointer( start, OP_REMOTE ) - start ); } else { bp->image_name = NULL; } switch( DeAliasAddrCue( NO_MOD, addr, ch ) ) { case SR_EXACT: bp->source_line = CopySourceLine( ch ); Format( TxtBuff, "%d", CueLine( ch ) ); bp->sym_name = DupStr( TxtBuff ); ok = GetBPSymAddr( bp, &addr ); break; case SR_CLOSEST: Format( TxtBuff, "%d", CueLine( ch ) ); bp->sym_name = DupStr( TxtBuff ); bp->addr_diff = addr.mach.offset - CueAddr( ch ).mach.offset; ok = GetBPSymAddr( bp, &addr ); break; default: ok = false; } if( !ok ) { _Free( bp->image_name ); _Free( bp->mod_name ); _Free( bp->sym_name ); bp->image_name = NULL; bp->mod_name = NULL; bp->sym_name = NULL; } } }