void D32DebugSetBreak( OFFSET32 off, SELECTOR sel, int translate, unsigned char far *to, unsigned char far *from ) { Fptr32 fp; char temp[4]; if( translate ) { fp.sel = sel; fp.off = off; D32Relocate( &fp ); sel = fp.sel; off = fp.off; } peek32( off, sel, temp, 1 ); /* Don't set a breakpoint if there's already one there, or we lose the previously saved byte. */ if( *temp != *to ) { *from = *temp; poke32( off, sel, to, 1 ); } }
unsigned ReqMap_addr() { Fptr32 fp; map_addr_req *acc; map_addr_ret *ret; unsigned i; _DBG1(( "AccMapAddr\n" )); acc = GetInPtr(0); ret = GetOutPtr(0); ret->lo_bound = 0; ret->hi_bound = ~(addr48_off)0; fp.off = acc->in_addr.offset; fp.sel = acc->in_addr.segment; switch( fp.sel ) { case MAP_FLAT_CODE_SELECTOR: case MAP_FLAT_DATA_SELECTOR: fp.sel = 1; fp.off += ObjInfo[0].start; for( i = 0; i < NumObjects; ++i ) { if( ObjInfo[i].start <= fp.off && (ObjInfo[i].start + ObjInfo[i].size) > fp.off ) { fp.sel = i + 1; fp.off -= ObjInfo[i].start; ret->lo_bound = ObjInfo[i].start - ObjInfo[0].start; ret->hi_bound = ret->lo_bound + ObjInfo[i].size - 1; break; } } break; } D32Relocate(&fp); ret->out_addr.segment = fp.sel; ret->out_addr.offset = fp.off; return( sizeof( *ret ) ); }
void StartProg( char *cmd, char *prog, char *full_args, char *dos_args ) { seg_offset where; int error_num; char buff[BSIZE]; Fptr32 fp; short initial_cs; int len; cmd = cmd; SampleIndex = 0; CurrTick = 0L; D32HookTimer( TimerMult ); /* ask for timer - before D32DebugInit!! */ D32DebugBreakOp(&Break); /* Get the 1 byte break op */ error_num = D32DebugInit( &Proc ); if( error_num == 0 ) { strcpy( buff, full_args ); error_num = D32DebugLoad( prog, buff, &Proc ); } if( error_num != 0 ) { Output( MsgArray[MSG_SAMPLE_2-ERR_FIRST_MESSAGE] ); Output( prog ); Output( "\r\n" ); MsgFini(); exit(1); } where.offset = 0; where.segment = 0; WriteCodeLoad( where, ExeName, SAMP_MAIN_LOAD ); fp.sel = 1; fp.off = 0; D32Relocate(&fp); WriteAddrMap( 1, fp.sel, fp.off ); initial_cs = Proc.cs; for( ;; ) { D32DebugRun( &Proc ); if( SampleIndex > Margin && Proc.cs == initial_cs ) { StopAndSave(); } if( Proc.int_id == 8 ) { ++InsiderTime; RecordSample( Proc.eip, Proc.cs ); --InsiderTime; } else if( Proc.int_id == 3 && (Proc.edx & 0xffff) != 0 ) { len = 0; /* this is a mark */ where.segment = Proc.edx & 0xffff; where.offset = Proc.eax; for( ;; ) { if( !D32AddressCheck( where.segment, where.offset, 1, NULL ) ) break; D32DebugRead( where.offset, where.segment, 0, &buff[len], 1 ); if( len == BSIZE ) break; if( buff[len] == '\0' ) break; len++; where.offset++; } buff[len] = '\0'; where.segment = Proc.cs; where.offset = Proc.eip; WriteMark( buff, where ); Proc.eip++; } else if( Proc.int_id == 3 ) { /* remember common storage */ CommonAddr.segment = Proc.ecx & 0xffff; /* area ... */ CommonAddr.offset = Proc.ebx; Proc.eip++; } else { break; } } D32UnHookTimer(); if( Proc.int_id != 0x21 ) { Output( MsgArray[MSG_SAMPLE_1-ERR_FIRST_MESSAGE] ); Output( MsgArray[Exceptions[Proc.int_id]+MSG_EXCEPT_0-ERR_FIRST_MESSAGE] ); Output( "\r\n" ); } D32DebugTerm(); report(); }