📄 dbgrpt.c
字号:
nCode = __crtMessageBoxA(szOutMessage,
"Microsoft Visual C++ Debug Library",
MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
/* Abort: abort the program */
if (IDABORT == nCode)
{
/* raise abort signal */
raise(SIGABRT);
/* We usually won't get here, but it's possible that
SIGABRT was ignored. So exit the program anyway. */
_exit(3);
}
/* Retry: return 1 to call the debugger */
if (IDRETRY == nCode)
return 1;
/* Ignore: continue execution */
return 0;
}
#elif defined (_M_MPPC)
/* Definitions */
#define NIL 0
/* Portable Types */
typedef unsigned char Char;
typedef unsigned long Word;
QDGlobals qd;
static void BlinkButton(int count,Rect *r)
{
long n;
while (count--) {
InvertRoundRect(r,10,10);
Delay(4,&n);
}
}
static int ButtonClicked(Rect *r)
{
int state = 0;
Point pt;
do {
GetMouse(&pt);
if (PtInRect(pt,r)) {
if (0 == state) {
state = 1;
BlinkButton(1,r);
}
}
else if (1 == state) {
state = 0;
BlinkButton(1,r);
}
} while (Button());
if (state)
BlinkButton(3,r);
return state;
}
static int CrtMessageWindow(
int nRptType,
const char * szFile,
const char * szLine,
const char * szModule,
const char * szUserMessage
)
{
#define LEFTMARGIN 15
#define ALINE 14
char szOutMessage[MAX_MSG];
Rect abort,retry,ignore,r;
GrafPtr oldPort;
WindowPtr window;
EventRecord event;
long total, contig;
short currHeight = 20;
int numLines = 13 +
4 * (_CRT_ASSERT == nRptType) +
2 * (szUserMessage[0] != '\0') +
(szModule != NULL) +
2 * (szFile != NULL);
/* center a rectangle on the screen, near the top of the screen */
r.top = 50;
r.bottom = r.top + numLines * ALINE;
r.left = qd.screenBits.bounds.right/2 - 170;
r.right = qd.screenBits.bounds.right/2 + 170;
/*
* NewWindow will hang in insufficient memory conditions. Must
* confirm available memory before use.
*/
contig = 0;
PurgeSpace(&total, &contig);
if (contig < 1024)
return -1;
/* create the window and setup the port */
if ((window = NewWindow(NIL,&r,"\p",TRUE,dBoxProc,(WindowPtr)-1,TRUE,0))
== NULL)
return -1;
GetPort(&oldPort);
SetPort(window);
InitCursor();
TextFont(systemFont);
MoveTo(LEFTMARGIN,currHeight);
TextFace(underline);
DrawString("\pMicrosoft Visual C++ Debug Library");
TextFace(0);
currHeight += 2 * ALINE;
_snprintf(szOutMessage, MAX_MSG, "Debug %s!", _CrtDbgModeMsg[nRptType]);
_c2pstr(szOutMessage);
MoveTo(LEFTMARGIN,currHeight);
TextFace(bold);
DrawString(szOutMessage);
TextFace(0);
currHeight += 2 * ALINE;
MoveTo(LEFTMARGIN,currHeight);
DrawString("\pProgram: ");
DrawString(LMGetCurApName());
currHeight += ALINE;
if (szModule) {
_snprintf(szOutMessage, MAX_MSG, "Module: %s", szModule);
_c2pstr(szOutMessage);
MoveTo(LEFTMARGIN,currHeight);
DrawString(szOutMessage);
currHeight += ALINE;
}
if (szFile) {
_snprintf(szOutMessage, MAX_MSG, "File: %s", szFile);
_c2pstr(szOutMessage);
MoveTo(LEFTMARGIN,currHeight);
DrawString(szOutMessage);
currHeight += ALINE;
}
if (szLine) {
_snprintf(szOutMessage, MAX_MSG, "Line: %s", szLine);
_c2pstr(szOutMessage);
MoveTo(LEFTMARGIN,currHeight);
DrawString(szOutMessage);
currHeight += ALINE;
}
currHeight += ALINE;
if (szUserMessage[0])
{
_snprintf(szOutMessage, MAX_MSG, "%s%s",
(_CRT_ASSERT == nRptType) ? "Expression: " : "",
szUserMessage);
r.top = currHeight-10;
r.bottom = currHeight - 5;
r.left = LEFTMARGIN - 2;
r.right = window->portRect.right - LEFTMARGIN - 2;
TextFace(condense);
TextBox(szOutMessage, strlen(szOutMessage), &r, teJustLeft);
TextFace(0);
currHeight += 2*ALINE;
}
currHeight += ALINE;
if (_CRT_ASSERT == nRptType)
{
MoveTo(LEFTMARGIN,currHeight);
DrawString("\pFor more information on how your program");
currHeight += ALINE;
MoveTo(LEFTMARGIN,currHeight);
DrawString("\pcan cause an assertion failure, see the");
currHeight += ALINE;
MoveTo(LEFTMARGIN,currHeight);
DrawString("\pVisual C++ documentation on asserts.");
currHeight += 2*ALINE;
MoveTo(LEFTMARGIN,currHeight);
DrawString("\p(Press Retry to debug the application)");
currHeight += 2*ALINE;
}
else {
MoveTo(LEFTMARGIN,currHeight);
DrawString("\p(Press Retry to debug the application)");
currHeight += 2*ALINE;
}
/* draw abort button */
abort.top = currHeight;
abort.bottom = abort.top + 20;
abort.left = LEFTMARGIN;
abort.right = abort.left + 75;
FrameRoundRect(&abort,10,10);
MoveTo((short)(abort.left+20),(short)(abort.bottom-6));
DrawString("\pAbort");
/* draw retry button */
retry.top = currHeight;
retry.bottom = retry.top + 20;
retry.left = LEFTMARGIN + 110;
retry.right = retry.left + 75;
FrameRoundRect(&retry,10,10);
MoveTo((short)(retry.left+20),(short)(retry.bottom-6));
DrawString("\pRetry");
/* draw ignore button */
ignore.top = currHeight;
ignore.bottom = ignore.top + 20;
ignore.left = LEFTMARGIN + 110 * 2;
ignore.right = ignore.left + 75;
FrameRoundRect(&ignore,10,10);
MoveTo((short)(ignore.left+17),(short)(ignore.bottom-6));
DrawString("\pIgnore");
/* event loop */
while (TRUE) {
if (GetNextEvent(mDownMask+keyDownMask,&event)) {
if (event.what == keyDown) { /* keyboard shortcuts */
char c = (char)event.message;
/* abort */
if (c == 'a') {
BlinkButton(3,&abort);
ExitToShell();
}
/* retry */
else if (c == 'r') {
BlinkButton(3,&retry);
Debugger();
break;
}
/* ignore */
else if (c == 'i') {
BlinkButton(3,&ignore);
break;
}
}
if (event.what == mouseDown) {
GlobalToLocal(&event.where);
if (PtInRect(event.where,&abort) && ButtonClicked(&abort))
ExitToShell();
else if (PtInRect(event.where,&retry) && ButtonClicked(&retry)) {
Debugger();
break;
}
else if (PtInRect(event.where,&ignore) && ButtonClicked(&ignore))
break;
}
}
}
DisposeWindow(window);
SetPort(oldPort);
/* ignore */
return 0;
}
#define WLMD_STR 1
#define LMGetMacJmp() (*(ProcPtr*) 0x120)
enum
{
uppGestaltDebugProcInfo = kCStackBased
| STACK_ROUTINE_PARAMETER (1, SIZE_CODE (sizeof (int)))
| STACK_ROUTINE_PARAMETER (2, SIZE_CODE (sizeof (StringPtr)))
| STACK_ROUTINE_PARAMETER (3, SIZE_CODE (sizeof (char*)))
| STACK_ROUTINE_PARAMETER (4, SIZE_CODE (sizeof (char*)))
};
static UniversalProcPtr pfnGestaltDebugger;
/***
*void _CleanStr - clean string
*
*Purpose:
* Cleans a string of characters that aren't useful. Always removes '\r'. If
* the string is going to MacsBug, replaces semicolons with periods, and
* removes trailing newlines, since MacsBug always advances to the next line
* after a _DebugStr.
*
*Entry:
* StringPtr st - the string to clean
* int fMacsBug - whether the string is going to MacsBug
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
static void __cdecl _CleanStr(StringPtr st, int fMacsBug)
{
int i;
/* change semi-colons to periods (semi-colons hose MacsBug) */
if (fMacsBug)
{
for (i = 0; i < StrLength(st); i++)
{
/* skip MB chars */
if (_ismbblead(st[i+1]))
{
i++;
continue;
}
if (st[i + 1] == ';')
st[i + 1] = '.';
}
}
for (i = StrLength(st); i >= 1; i--)
{
/* if trail byte, stop processing */
if (_ismbstrail(&st[1], &st[i]))
break;
/* remove trailing newlines */
if (st[i] == '\n')
{
if (fMacsBug)
st[0]--;
}
/* remove trailing carriage returns */
else if (st[i] == '\r')
{
st[0]--;
}
/* otherwise, stop processing */
else
{
break;
}
}
}
/***
*void _ConfirmVCDebugger
*
*Purpose:
* Determines if a 'WLMD' Gestalt selector is registered.
*
*Entry:
*
*Exit:
* Current VC++ Debug Output function or NULL.
*
*Exceptions:
*
*******************************************************************************/
static UniversalProcPtr __cdecl _ConfirmVCDebugger(void)
{
/* The VC++ Debug Ouput facilities are registered as "WLMD" */
if (Gestalt('WLMD', (long*) &pfnGestaltDebugger) != noErr)
pfnGestaltDebugger = NULL;
return pfnGestaltDebugger;
}
/***
*int _IsMSVCDebugger
*
*Purpose:
* Determines if a 'MSVC' Gestalt selector is registered, or if there
* is a low level debugger in the system
*
* Only call a macsbug-like debugger if it's going to be around to
* handle the DebugStr
*
*Entry:
*
*Exit:
* TRUE: If MSVC debugger registered
* FALSE: Otherwise
*
*Exceptions:
*
*******************************************************************************/
static int __cdecl _IsLowLevelDebugger(void)
{
#define mskBeingDebugged 1
#define mskPreviousDebugger 2
unsigned long caps;
/* See if VC++ Debugger is running */
if(Gestalt('MSVC', (long*) &caps) == noErr)
{
if((caps & mskBeingDebugged) || (caps & mskPreviousDebugger))
return 1;
else
return 0;
}
/* See if MacsBug is running */
else if (LMGetMacJmp() != NULL)
return 1;
else
return 0;
#undef mskBeingDebugged
#undef mskPreviousDebugger
}
/***
*void _CrtOutputDebugString - output Debug String
*
*Purpose:
* Does the actual output of a string to the debugger.
*
*Entry:
* char * sz -- message to output
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
static void __cdecl _CrtOutputDebugString(char * sz)
{
Str255 stDebug;
long cchTotal;
short cchCur;
const char* pchCur;
EventRecord er;
_ConfirmVCDebugger();
OSEventAvail(0, &er);
cchTotal = strlen(sz);
pchCur = sz;
/* output string in edible portions */
while (cchTotal > 0)
{
cchCur = (short) min(cchTotal, 253);
_ASSERTE(cchCur > 0);
/* put back orphaned lead byte */
if (_ismbslead(pchCur, pchCur+cchCur-1))
cchCur--;
/* convert CString to PascalString */
stDebug[0] = (unsigned char) cchCur;
BlockMoveData(pchCur, &stDebug[1], cchCur);
/* See if VC++ Debug Output facility is running */
if (pfnGestaltDebugger != NULL)
{
_CleanStr(stDebug, 0);
/* if the Control key is down, we break into MacsBug before
sending the string to the Gestalt debugger */
if ((er.modifiers & controlKey) != 0)
Debugger();
CallUniversalProc(pfnGestaltDebugger, uppGestaltDebugProcInfo, WLMD_STR, stDebug,
NULL, NULL);
}
/* See if VC++ Debugger or MacsBug is running */
else if (_IsLowLevelDebugger())
{
short cchSt;
_CleanStr(stDebug, 1);
/* _CleanStr may have changed the length of stDebug */
cchSt = StrLength(stDebug);
/* if the Control key is down, we always stop in the debugger */
if ((er.modifiers & controlKey) == 0)
{
stDebug[cchSt + 1] = ';';
stDebug[cchSt + 2] = 'g';
stDebug[0] += 2;
}
DebugStr(stDebug);
}
cchTotal -= cchCur;
pchCur += cchCur;
}
}
#endif /* defined (_M_MPPC) */
#endif /* _DEBUG */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -