requireToOptionalDebugger.c from redshed at Krugle
Show requireToOptionalDebugger.c syntax highlighted
/****************************************************************************************
requireToOptionalDebugger.c $Revision: 3 $
<http://rentzsch.com/require>
Copyright © 1997-2002 Red Shed Software. All rights reserved.
by Jonathan 'Wolf' Rentzsch (jon at redshed dot net)
Reports requirement failures via DebugStr() if a debugger is installed. Otherwise the
failure is not reported.
************************************************************************************/
#include "requireImplementation.c"
Boolean
IsDebuggerCallable();
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Mon, Jul 21, 1997 Created.
************************************************************************************/
void
RequireNotice(
const char *msg,
const char *code,
const char *note,
long nmbr,
const char *file,
long line,
long errn )
{
Str255 outStr = "\p";
if( IsDebuggerCallable() ) {
#define out outStr, sizeof( Str255 ) - 1
// Message line.
if( msg )
RAppendCStringToPString( msg, out );
else
RAppendPStringToPString( "\pGeneric Require Failure", out );
// Note line.
if( note ) {
RAppendPStringToPString( "\p\r note: ", out );
RAppendCStringToPString( note, out );
}
// File line.
if( file ) {
RAppendPStringToPString( "\p\r file: ", out );
RAppendCStringToPString( file, out );
}
// Line line.
if( line ) {
RAppendPStringToPString( "\p\r line: ", out );
RAppendLongToPString( line, out );
}
// Errn line.
if( errn ) {
RAppendPStringToPString( "\p\r errn: ", out );
RAppendLongToPString( errn, out );
}
// Nmbr line.
if( nmbr ) {
RAppendPStringToPString( "\p\r nmbr: ", out );
RAppendLongToPString( nmbr, out );
}
// Code line.
if( code ) {
RAppendPStringToPString( "\p\r code: ", out );
RAppendCStringToPString( code, out );
}
#undef out
DebugStr( outStr );
}
}
/****************************************************************************************
Commenter Date Comment
--------- ----------------- -----------------------------------------------------
wolf Sun, Jan 30, 2000 Created.
Stolen from Debugging.h:
"Tech Q&A PLAT-30 says to check bit 5 of the byte at 0xbff to
determine whether Macsbug ( or any other low level debugger )
is installed; I also check that MacJmp ( which points to the
entry point for the debugger ) is not nil and not -1.
MacJmpFlag:
Bit 5 should be set to indicate the debugger is installed.
Bit 6 should be set to indicate the debugger is initialized.
Bit 7 should be clear to indicate that the debugger is NOT busy
Dr. Macsbug says to also check that the byte at 0xBFF isn't 0xFF."
This probably isn't kosher under Mac OS X...
************************************************************************************/
Boolean
IsDebuggerCallable()
{
UInt32 macJmp = *(UInt32*)0x0120;
UInt8 macJmpFlag = *(UInt8*)0x0BFF;
return( macJmpFlag != 0xFF
&& (macJmpFlag & 0xE0) == 0x60
&& macJmp != 0
&& macJmp != 0xFFFFFFFF );
}
See more files for this project here