dbg.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 517 行 · 第 1/2 页
C
517 行
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_PAINT:
/*
* Window contents are drawn here in WM_PAINT processing.
*/
{
HPS hps; /* Presentation Space handle */
RECTL rc; /* Rectangle coordinates */
POINTL pt; /* String screen coordinates */
char buff[256];
/* Create a presentation space */
hps = WinBeginPaint( hwnd, 0L, &rc );
pt.x = 0; pt.y = 50; /* Set the text coordinates, */
GpiSetColor( hps, CLR_NEUTRAL ); /* colour of the text, */
GpiSetBackColor( hps, CLR_BACKGROUND ); /* its background and */
GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */
/* and draw the string...*/
GpiCharStringAt( hps, &pt, (LONG)strlen( szString ), szString );
WinEndPaint( hps ); /* Drawing is complete */
break;
}
case WM_CLOSE:
/*
* This is the place to put your termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/
break;
default:
/*
* Everything else comes here. This call MUST exist
* in your window procedure.
*/
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
/**************************************************************************
*
* Name : AbortHello
*
* Description: Report an error returned from an API service
*
* Concepts : use of message box to display information
*
* API's : DosBeep
* WinGetErrorInfo
* WinMessageBox
* WinFreeErrorInfo
* WinPostMsg
*
* Parameters : hwndFrame = frame window handle
* hwndClient = client window handle
*
* Return : [none]
*
*************************************************************************/
VOID AbortHello(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(Hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End of AbortHello */
/*********************** End of the hello.c *******************************/
/*********************** Start of my debugger stuff ***********************/
#define DBG_N_Breakpoint -100
#define DBG_N_SStep -101
#define DBG_N_Signal -102
void DebugExecute( uDB_t *buff, ULONG cmd )
{
EXCEPTIONREPORTRECORD ex;
ULONG value;
ULONG stopvalue;
ULONG notify=0;
BOOL got_second_notification;
ULONG fcp;
CONTEXTRECORD fcr;
ULONG ExceptNum;
buff->Cmd = cmd;
value = buff->Value;
if( cmd == DBG_C_Go ) {
value = 0;
}
stopvalue = XCPT_CONTINUE_EXECUTION;
got_second_notification = FALSE;
if( cmd == DBG_C_Stop ) {
stopvalue = XCPT_CONTINUE_STOP;
}
while( 1 ) {
buff->Value = value;
buff->Cmd = cmd;
DosDebug( buff );
value = stopvalue;
cmd = DBG_C_Continue;
/*
* handle the preemptive notifications
*/
switch( buff->Cmd ) {
case DBG_N_ModuleLoad:
break;
case DBG_N_ModuleFree:
break;
case DBG_N_NewProc:
break;
case DBG_N_ProcTerm:
value = XCPT_CONTINUE_STOP; /* halt us */
notify = DBG_N_ProcTerm;
break;
case DBG_N_ThreadCreate:
break;
case DBG_N_ThreadTerm:
break;
case DBG_N_AliasFree:
break;
case DBG_N_Exception:
if( buff->Value == DBG_X_STACK_INVALID ) {
value = XCPT_CONTINUE_SEARCH;
break;
}
fcp = buff->Len;
if( buff->Value == DBG_X_PRE_FIRST_CHANCE ) {
ExceptNum = buff->Buffer;
if( ExceptNum == XCPT_BREAKPOINT ) {
notify = DBG_N_Breakpoint;
value = XCPT_CONTINUE_STOP;
break;
} else if( ExceptNum == XCPT_SINGLE_STEP ) {
notify = DBG_N_SStep;
value = XCPT_CONTINUE_STOP;
break;
}
}
//
// NOTE: Going to second chance causes OS/2 to report the
// exception in the debugee. However, if you report
// the fault at the first chance notification, the
// debugee's own fault handlers will not get invoked!
//
value = XCPT_CONTINUE_SEARCH;
break;
default:
if( notify != 0 ) {
buff->Cmd = notify;
}
return;
}
}
}
extern long __far16 __pascal WinQueueFromID( long, short pid, short tid );
extern long __far16 __pascal WinReplyMsg( long, long, long, long );
extern long __far16 __pascal WinThreadAssocQueue( long, long );
extern long __far16 __pascal WinQuerySendMsg( long, long, long, void* );
DebugIt( void *crap )
{
STARTDATA start;
int code;
SWCNTRL SW;
HSWITCH hswitch;
PPIB pib;
PTIB tib;
HWND hwndme;
QMSG qmsg; /* Message from message queue */
int i;
PID Pid = 0;
ULONG SID;
uDB_t Buff;
TID tid;
HMQ the_q;
DosGetInfoBlocks(&tib,&pib);
start.Length = offsetof( STARTDATA, IconFile ); /* default for the rest */
start.Related = 1;
start.FgBg = 1;
start.TraceOpt = 1;
start.PgmTitle = (PSZ) "Test Session";
start.PgmName = "HELLO.EXE";
start.PgmInputs = "hi there";
start.TermQ = 0;
start.Environment = NULL;
start.InheritOpt = 1;
start.SessionType = SSF_TYPE_PM;
code = DosStartSession( &start, &SID, &Pid );
Buff.Pid = Pid;
Buff.Tid = 0;
Buff.Cmd = DBG_C_Connect;
Buff.Value = DBG_L_386;
DosDebug( &Buff );
Buff.Pid = Pid;
Buff.Tid = 1;
DebugExecute( &Buff, DBG_C_Stop );
if( Buff.Cmd != DBG_N_Success ) {
return;
}
DebugExecute( &Buff, DBG_C_Go );
if( Buff.Cmd != DBG_N_Breakpoint ) {
return;
}
#if 0
Buff.Cmd = DBG_C_Stop;
DosDebug( &Buff );
Buff.Cmd = DBG_C_ReadReg;
DosDebug( &Buff );
Buff.EIP++;
Buff.Cmd = DBG_C_WriteReg;
DosDebug( &Buff );
#endif
the_q = WinQueueFromID( Hab, Buff.Pid, Buff.Tid );
#if 0
for( ;; ) {
hmq = WinQuerySendMsg( Hab, 0, Q, &qmsg );
if( hmq == 0 ) break;
WinReplyMsg( Hab, hmq, Q, 1 );
}
#endif
WinThreadAssocQueue( Hab, the_q );
while( 1 ) {
if( !WinGetMsg( Hab, &qmsg, 0L, 0, 0 ) ) break;
}
WinThreadAssocQueue( Hab, 0 );
for( ;; ) DosSleep( 100 );
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?