dbgexec.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 593 行 · 第 1/2 页
C
593 行
flags = RemoteGetMsgText( TxtBuff, TXT_LEN );
p2 = TxtBuff;
for( p=TxtBuff;*p != '\0' ;p++ ) {
if( *p != '\r' && *p != '\n' ) {
*p2++ = *p;
}
}
if( MsgText != NULL ) {
DUIDlgTxt( MsgText );
DbgFree( MsgText );
MsgText = NULL;
}
*p2++ = '\n';
*p2 = '\0';
rc = SetMsgText( TxtBuff, conditions );
} while( flags & MSG_MORE );
return( rc );
}
typedef enum {
ES_NORMAL,
ES_STEP_ONE,
ES_FORCE_BREAK
} execute_state;
unsigned ExecProg( bool tracing, bool do_flip, bool want_wps )
{
bool have_brk_at_ip;
bool act_wps;
bool first_time;
mad_trace_how how;
execute_state es;
unsigned conditions;
unsigned run_conditions;
bool already_stopping;
bool force_stop;
if( !want_wps ) ++InCall;
tracing = TraceStart( tracing );
WriteDbgRegs();
first_time = TRUE;
es = ES_NORMAL;
run_conditions = 0;
DUIPlayDead( TRUE );
for( ;; ) {
switch( es ) {
case ES_FORCE_BREAK:
case ES_NORMAL:
if( tracing ) {
how = TraceHow( FALSE );
} else {
_SwitchOn( SW_EXECUTE_LONG );
how = MTRH_BREAK;
}
break;
case ES_STEP_ONE:
how = TraceHow( TRUE );
break;
}
if( how == MTRH_STOP ) break;
switch( how ) {
case MTRH_BREAK:
DbgUpdate( UP_CSIP_JUMPED );
_SwitchOn( SW_TOUCH_SCREEN_BUFF );
/* fall through */
case MTRH_SIMULATE:
case MTRH_STEP:
case MTRH_STEPBREAK:
if( _IsOff( SW_TOUCH_SCREEN_BUFF ) ) break;
/* fall through */
default:
if( !(ScrnState & USR_SCRN_ACTIVE) && do_flip ) {
DUIStop();
}
_SwitchOff( SW_TOUCH_SCREEN_BUFF );
break;
}
if( first_time ) {
/* got to be down here so that SW_EXECUTE_LONG is properly set */
SetThreadStates();
first_time = FALSE;
}
have_brk_at_ip = InsertBPs( (es == ES_FORCE_BREAK) );
act_wps = UpdateWPs();
if( how == MTRH_BREAK ) {
if( have_brk_at_ip ) {
es = ES_STEP_ONE;
RemoveBPs();
continue; /* back to top */
}
if( act_wps && want_wps ) {
InsertWPs();
}
}
SetMemBefore( tracing );
switch( how ) {
case MTRH_SIMULATE:
if( TraceSimulate() ) {
conditions = COND_TRACE;
break;
}
/* fall through */
case MTRH_STEP:
/* only updates stack/execution */
conditions = MakeProgRun( TRUE );
break;
default:
/* only updates stack/execution */
conditions = MakeProgRun( FALSE );
break;
}
if( _IsOn( SW_EXECUTE_LONG ) ) {
if( ScrnState & DBG_SCRN_ACTIVE ) {
_SwitchOn( SW_MIGHT_HAVE_LOST_DISPLAY );
}
_SwitchOff( SW_EXECUTE_LONG );
}
SetMemAfter( tracing );
run_conditions &= ~COND_WATCH;
run_conditions |= conditions;
RemoveBPs();
if( conditions & COND_MESSAGE ) {
if( !RecordMsgText( &conditions ) ) {
conditions &= ~COND_MESSAGE;
}
}
conditions = CheckBPs( conditions, run_conditions );
if( _IsOn( SW_BREAK_ON_DEBUG_MESSAGE ) && ( conditions & COND_MESSAGE ) ) {
conditions |= COND_STOP;
}
if( how == MTRH_STEPBREAK && (conditions & COND_BREAK) && DbgTmpBrk.status.b.hit ) {
conditions &= ~COND_BREAK;
conditions |= COND_TRACE;
}
if( conditions & COND_LIBRARIES ) {
already_stopping = ( conditions & COND_STOPPERS ) != 0;
conditions &= ~COND_LIBRARIES;
force_stop = FALSE;
if( AddLibInfo( already_stopping, &force_stop ) ) {
if( force_stop || DLLMatch() ) {
conditions |= COND_STOP | COND_LIBRARIES;
}
}
ReMapPoints( NULL );
}
if( conditions & COND_SECTIONS ) {
SectTblRead( DbgRegs );
InvalidateTblCache();
}
if( (es == ES_STEP_ONE) && (conditions & COND_TRACE) ) {
conditions &= ~COND_TRACE;
}
if( tracing ) {
conditions = TraceCheck( conditions );
}
if( !(conditions & COND_STOPPERS) && TBreak() ) {
conditions |= COND_USER;
break;
}
if( conditions & COND_STOPPERS ) break;
switch( es ) {
case ES_STEP_ONE:
es = ES_FORCE_BREAK;
break;
case ES_FORCE_BREAK:
es = ES_NORMAL;
break;
}
if( (run_conditions & COND_WATCH) && es == ES_NORMAL ) {
/*
We got a spurious watch point indication. Make the
next instruction single step since we might be
dealing with a control flow opcode on a machine without
a T-bit (e.g. Alpha).
*/
es = ES_STEP_ONE;
}
}
TraceStop( tracing );
DUIPlayDead( FALSE );
SetProgState( run_conditions );
_SwitchOff( SW_KNOW_EMULATOR );
if( !want_wps ) --InCall;
return( conditions );
}
static void DisplayMsgText( void )
/********************************/
{
if( MsgText != NULL ) {
DUIDlgTxt( MsgText );
DbgFree( MsgText );
MsgText = NULL;
}
}
bool ReportTrap( unsigned conditions, bool stack_cmds )
{
bool cmds_pushed;
char *p;
if( conditions & COND_EXCEPTION ) {
RecordMsgText( &conditions ); // get the 'access violation, etc' message
p = StrCopy( LIT( Task_Exception ), TxtBuff );
if( MsgText != NULL ) StrCopy( MsgText, p );
MsgText = DbgRealloc( MsgText, strlen( TxtBuff ) + 1 );
StrCopy( TxtBuff, MsgText );
DUIMsgBox( MsgText );
}
if( conditions & (COND_EXCEPTION|COND_TERMINATE) ) {
Ring();
}
DisplayMsgText();
if( conditions & COND_USER ) {
DUIInfoBox( LIT( User_Interupt ) );
PurgeInpStack();
RecordAsynchEvent();
} else if( conditions & COND_TERMINATE ) {
DUIInfoBox( LIT( Task_Completed ) );
_SwitchOff( SW_HAVE_TASK );
} else if( conditions & COND_LIBRARIES ) {
Format( TxtBuff, "%s '%s'", LIT( Break_on_DLL_Load ), GetLastImageName() );
DUIInfoBox( TxtBuff );
} else {
DUIStatusText( LIT( Empty ) );
}
cmds_pushed = DispBPMsg( stack_cmds );
DbgUpdate( UP_MEM_CHANGE | UP_CSIP_CHANGE | UP_REG_CHANGE |
UP_CODE_EXECUTED | UP_THREAD_STATE );
return( cmds_pushed );
}
unsigned Execute( bool tracing, bool do_flip )
{
unsigned conditions;
bool stack_cmds;
static unsigned executing = 0;
if( !CheckStackPos() ) return( COND_USER );
if( !AdvMachState( ACTION_EXECUTE ) ) return( COND_USER );
if( executing == 0 ) {
++executing;
HookNotify( TRUE, HOOK_EXEC_START );
--executing;
}
/* get rid of useless pending input information */
for( ;; ) {
if( CurrToken != T_LINE_SEPARATOR ) break;
if( InpStack == NULL ) break;
if( InpStack->type & (INP_HOLD|INP_STOP_PURGE) ) break;
if( InpStack->rtn( InpStack->handle, INP_RTN_EOL ) ) continue;
PopInpStack();
}
_SwitchOff( SW_TRAP_CMDS_PUSHED );
conditions = ExecProg( tracing, do_flip, TRUE );
SetCodeDot( GetRegIP() );
stack_cmds = TRUE;
if( tracing && (conditions & COND_BREAK) ) stack_cmds = FALSE;
if( ReportTrap( conditions, stack_cmds ) ) {
_SwitchOn( SW_TRAP_CMDS_PUSHED );
}
if( executing == 0 ) {
++executing;
HookNotify( TRUE, HOOK_EXEC_END );
--executing;
}
if( conditions & COND_TERMINATE ) {
HookNotify( TRUE, HOOK_PROG_END );
}
return( conditions );
}
unsigned Go( bool do_flip )
{
char *p;
unsigned conditions;
p = StrCopy( GetCmdName( CMD_GO ), TxtBuff );
if( UserTmpBrk.status.b.active ) {
p = Format( p, " %A", UserTmpBrk.loc.addr );
RecordEvent( TxtBuff );
} else {
RecordGo( TxtBuff );
}
conditions = Execute( FALSE, do_flip );
CheckEventRecorded();
return( conditions );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?