|
Mac OS 9
|
Macros to handle exceptions and assertions. More...
Go to the source code of this file.
Macros | |
| #define | kComponentSignatureString "Third Party Client" |
| #define | DEBUG_LEVEL_PRODUCTION 0 |
| #define | DEBUG_LEVEL_BREAK_ONLY 1 |
| #define | DEBUG_LEVEL_EXTERNAL 3 |
| #define | DEBUG_LEVEL_INTERNAL 4 |
| #define | DEBUGFULL DEBUG_LEVEL_INTERNAL |
| #define | DEBUG_NO_OPTIONS 0 |
| #define | DEBUGLEVEL DEBUG_LEVEL_PRODUCTION |
| #define | COMPONENT_SIGNATURE '?*?*' |
| #define | QuoteExceptionString(x) #x |
| #define | DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value) |
| #define | ATTASKLEVEL0() (TaskLevel() == 0) |
| #define | DPRINTF(x) |
| #define | NewDebugComponentCallbackUPP(userRoutine) |
| #define | NewDebugAssertOutputHandlerUPP(userRoutine) |
| #define | DisposeDebugComponentCallbackUPP(userUPP) DisposeRoutineDescriptor(userUPP) |
| #define | DisposeDebugAssertOutputHandlerUPP(userUPP) DisposeRoutineDescriptor(userUPP) |
| #define | InvokeDebugComponentCallbackUPP(optionSelectorNum, command, optionSetting, userUPP) |
| #define | InvokeDebugAssertOutputHandlerUPP( componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value, outputMsg, userUPP) |
| #define | NewDebugComponentCallbackProc(userRoutine) NewDebugComponentCallbackUPP(userRoutine) |
| #define | NewDebugAssertOutputHandlerProc(userRoutine) NewDebugAssertOutputHandlerUPP(userRoutine) |
| #define | CallDebugComponentCallbackProc(userRoutine, optionSelectorNum, command, optionSetting) |
| #define | CallDebugAssertOutputHandlerProc( userRoutine, componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value, outputMsg) |
| #define | LocalLMGetMacJmp() (*((unsigned long *)0x0120)) |
| #define | LocalLMGetMacJmpFlag() (*((UInt8 *)0x0BFF)) |
| #define | LocalLMKeyMap ((UInt16 *)(0x0174)) |
| #define | ISCAPSLOCKKEYDOWN() ((LocalLMKeyMap[3] & 0x0002) == 0x0002) |
| #define | ISLOWLEVELDEBUGGERCALLABLE() |
| #define | SafeDebugger() |
| #define | SafeDebugStr(str) |
| #define | CapsLockDebugger() |
| #define | CapsLockDebugStr(str) |
| #define | DEBUGGER() |
| #define | DEBUGSTR(str) |
| #define | check(assertion) |
| #define | check_string(assertion, cstring) |
| #define | check_noerr(err) |
| #define | check_noerr_string(error, cstring) |
| #define | debug_string(cstring) |
| #define | require(assertion, label) |
| #define | require_string(assertion, label, string) require(assertion, label) |
| #define | require_quiet(assertion, label) require(assertion, label) |
| #define | require_noerr(error, label) |
| #define | require_noerr_quiet(assertion, label) require_noerr(assertion, label) |
| #define | require_noerr_action(error, label, action) |
| #define | require_noerr_action_quiet(assertion, label, action) require_noerr_action(assertion, label, action) |
| #define | require_action(assertion, label, action) |
| #define | require_action_quiet(assertion, label, action) require_action(assertion, label, action) |
| #define | require_action_string(assertion, label, action, cstring) |
| #define | check_tasklevel0() check(ATTASKLEVEL0()) |
| #define | check_tasklevel0_string(string) check_string(ATTASKLEVEL0(), string) |
| #define | require_tasklevel0(label) require(ATTASKLEVEL0(), label) |
| #define | require_tasklevel0_string(label, string) require_string(ATTASKLEVEL0(), label, string) |
| #define | require_tasklevel0_action(label, string, action) require_action(ATTASKLEVEL0(), label, action) |
| #define | require_tasklevel0_action_string(label, string, action) require_action_string(ATTASKLEVEL0(), label, action, string) |
| #define | verify(assertion) |
| #define | verify_noerr(assertion) verify(assertion) |
| #define | ncheck(assertion) check(!(assertion)) |
| #define | ncheck_string(assertion, cstring) check_string(!(assertion), cstring) |
| #define | nrequire(assertion, exception) require(!(assertion), exception) |
| #define | nrequire_action(assertion, exception, action) require_action(!(assertion), exception, action) |
| #define | nrequire_quiet(assertion, exception) require_quiet(!(assertion), exception) |
| #define | nrequire_action_quiet(assertion, exception, action) require_action_quiet(!(assertion), exception, action) |
| #define | nrequire_string(assertion, exception, string) require_string(!(assertion), exception, string) |
Typedefs | |
| typedef UInt32 | command |
| typedef UInt32 Boolean * | optionSetting |
| typedef UInt32 | options |
| typedef UInt32 const char * | assertionString |
| typedef UInt32 const char const char * | exceptionString |
| typedef UInt32 const char const char const char * | errorString |
| typedef UInt32 const char const char const char const char * | fileName |
| typedef UInt32 const char const char const char const char long | lineNumber |
| typedef UInt32 const char const char const char const char long void * | value |
| typedef UInt32 const char const char const char const char long void ConstStr255Param | outputMsg |
Enumerations | |
| enum | { kBlessedBusErrorBait = 0x68F168F1 } |
| enum | { k68kInterruptLevelMask = 0x00000007 , kInVBLTaskMask = 0x00000010 , kInDeferredTaskMask = 0x00000020 , kInSecondaryIntHandlerMask = 0x00000040 , kInNestedInterruptMask = 0x00000080 } |
| enum | { kComponentDebugOption } |
| enum | { kGetDebugOption = 1 , kSetDebugOption = 2 } |
| enum | { uppDebugComponentCallbackProcInfo = 0x00000FC0 } |
| enum | { uppDebugAssertOutputHandlerProcInfo = 0x00FFFFC0 } |
Functions | |
| void | DebugAssert (OSType componentSignature, UInt32 options, const char *assertionString, const char *exceptionString, const char *errorString, const char *fileName, long lineNumber, void *value) |
| typedef | CALLBACK_API (void, DebugComponentCallbackProcPtr)(SInt32 optionSelectorNum |
| typedef | STACK_UPP_TYPE (DebugComponentCallbackProcPtr) DebugComponentCallbackUPP |
| UInt32 | TaskLevel (void) |
| OSStatus | NewDebugComponent (OSType componentSignature, ConstStr255Param componentName, DebugComponentCallbackUPP componentCallback) |
| OSStatus | NewDebugOption (OSType componentSignature, SInt32 optionSelectorNum, ConstStr255Param optionName) |
| OSStatus | DisposeDebugComponent (OSType componentSignature) |
| OSStatus | GetDebugComponentInfo (UInt32 index, OSType *componentSignature, Str255 componentName) |
| OSStatus | GetDebugOptionInfo (UInt32 index, OSType componentSignature, SInt32 *optionSelectorNum, Str255 optionName, Boolean *optionSetting) |
| OSStatus | SetDebugOptionValue (OSType componentSignature, SInt32 optionSelectorNum, Boolean newOptionSetting) |
| typedef | CALLBACK_API (void, DebugAssertOutputHandlerProcPtr)(OSType componentSignature |
| typedef | STACK_UPP_TYPE (DebugAssertOutputHandlerProcPtr) DebugAssertOutputHandlerUPP |
| void | InstallDebugAssertOutputHandler (DebugAssertOutputHandlerUPP handler) |
| void | dprintf (const char *format,...) |
| void | vdprintf (const char *format, char *va_args_list) |
| DebugComponentCallbackUPP | NewDebugComponentCallbackUPP (DebugComponentCallbackProcPtr userRoutine) |
| DebugAssertOutputHandlerUPP | NewDebugAssertOutputHandlerUPP (DebugAssertOutputHandlerProcPtr userRoutine) |
| void | DisposeDebugComponentCallbackUPP (DebugComponentCallbackUPP userUPP) |
| void | DisposeDebugAssertOutputHandlerUPP (DebugAssertOutputHandlerUPP userUPP) |
| void | InvokeDebugComponentCallbackUPP (SInt32 optionSelectorNum, UInt32 command, Boolean *optionSetting, DebugComponentCallbackUPP userUPP) |
| void | InvokeDebugAssertOutputHandlerUPP (OSType componentSignature, UInt32 options, const char *assertionString, const char *exceptionString, const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg, DebugAssertOutputHandlerUPP userUPP) |
Macros to handle exceptions and assertions.
For bug reports, consult the following page on the World Wide Web:
http://developer.apple.com/bugreporter/
| #define CallDebugAssertOutputHandlerProc | ( | userRoutine, | |
| componentSignature, | |||
| options, | |||
| assertionString, | |||
| exceptionString, | |||
| errorString, | |||
| fileName, | |||
| lineNumber, | |||
| value, | |||
| outputMsg | |||
| ) |
| #define CallDebugComponentCallbackProc | ( | userRoutine, | |
| optionSelectorNum, | |||
| command, | |||
| optionSetting | |||
| ) |
| #define CapsLockDebugger | ( | ) |
| #define CapsLockDebugStr | ( | str | ) |
| #define check | ( | assertion | ) |
CALL_NOT_IN_CARBON no-op asserts for production code
| #define check_tasklevel0 | ( | ) | check(ATTASKLEVEL0()) |
DEBUG_LEVEL_PRODUCTION Define these in terms of the check() and require macros. In non-debug builds, the check calls go away and the require macros are mostly checks and jumps.
| #define DEBUGASSERTMSG | ( | componentSignature, | |
| options, | |||
| assertionString, | |||
| exceptionString, | |||
| errorString, | |||
| fileName, | |||
| lineNumber, | |||
| value | |||
| ) |
no debugger message
| #define DEBUGGER | ( | ) |
DEBUGGER and DEBUGSTR call the debugger if it is installed ONLY in DEBUG builds.
| #define DPRINTF | ( | x | ) |
CALL_NOT_IN_CARBON
| #define InvokeDebugAssertOutputHandlerUPP | ( | componentSignature, | |
| options, | |||
| assertionString, | |||
| exceptionString, | |||
| errorString, | |||
| fileName, | |||
| lineNumber, | |||
| value, | |||
| outputMsg, | |||
| userUPP | |||
| ) |
| #define InvokeDebugComponentCallbackUPP | ( | optionSelectorNum, | |
| command, | |||
| optionSetting, | |||
| userUPP | |||
| ) |
| #define ISLOWLEVELDEBUGGERCALLABLE | ( | ) |
| #define kComponentSignatureString "Third Party Client" |
This file defines standard exception handling and assertion macros for system-level programming in C. Originally used in QuickDraw GX, and heavily modified since, these macros are used extensively throughout Mac OS system software. Now you can look and feel like a system software engineer.
To activate debugger breaks, #define DEBUG to 1 (one) before including this file. Five further levels of debugging are available, selected by #defining one of the following conditionals to 1 after DEBUG is defined to 1.
DEBUG_INTERNAL the default; includes file and line number
information
DEBUG_EXTERNAL used for code which must ship to developers outside
your organization; no file or line number
information is included in asserts
DEBUG_BREAK_ONLY where an assertion would normally be sent to the
debugger, send an empty string instead.
PRODUCTION used for shipping code; no debugger breaks are
emitted
PERFORMANCE same as PRODUCTION
#defining DEBUG to 0 is equivalent to #defining PRODUCTION 1 when DEBUG is 1. (No code for debugger breaks is emitted in either case.)
Of the multitude of macros, the preferred ones are:
debug_string(c-string) If debugging is on, c-string is printed in the debugger. In production builds, debug_string() does nothing.
check(expression) check_noerr(error) If (expression) evaluates to false, break into the debugger. In production builds, check() does nothing. Code inside check() statements is not compiled into production builds.
require(expression, label) require_noerr(expression, label) If (expression) evaluates to false, announce this fact via the debugger and then goto label. In production builds, does not call the debugger but still goes to label if expression is false.
require_action(expression, label, action) require_noerr_action(expression, label, action) Same as require, but executes (action) before jumping to label.
check_string(expression, c-string) require_string(expression, label, c-string) require_noerr_string(expression, label, c-string) If expression evaluates to false, print string and then proceed as in a normal check/require statement
verify(expression) verify_noerr(error) If debugging is on, verify is the same as check(expression). If debugging is off, verify still evaluates (expression) but ignores the result. Code inside verify() statements is executed in both production and debug builds.
Common usage:
my pixmap is not purgeable, so locking it should never fail verify( LockPixels(myPixMap) ); verify_noerr( DisposeThread(myThread, &threadResult, true) );
Before including this file, #define kComponentSignatureString to a C-string containing the name of your client.
example: #define kComponentSignatureString "SurfWriter"
| #define LocalLMGetMacJmp | ( | ) | (*((unsigned long *)0x0120)) |
CALL_NOT_IN_CARBON
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.
| #define ncheck | ( | assertion | ) | check(!(assertion)) |
| #define NewDebugAssertOutputHandlerUPP | ( | userRoutine | ) |
pascal no_return_value Func(4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes)
| #define NewDebugComponentCallbackProc | ( | userRoutine | ) | NewDebugComponentCallbackUPP(userRoutine) |
support for pre-Carbon UPP routines: New...Proc and Call...Proc
| #define NewDebugComponentCallbackUPP | ( | userRoutine | ) |
pascal no_return_value Func(4_bytes, 4_bytes, 4_bytes)
| #define require | ( | assertion, | |
| label | |||
| ) |
| #define require_action | ( | assertion, | |
| label, | |||
| action | |||
| ) |
| #define require_action_string | ( | assertion, | |
| label, | |||
| action, | |||
| cstring | |||
| ) |
| #define require_noerr | ( | error, | |
| label | |||
| ) |
| #define require_noerr_action | ( | error, | |
| label, | |||
| action | |||
| ) |
| #define SafeDebugger | ( | ) |
SafeDebugger and SafeDebugStr ALWAYS call the debugger if it is installed.
| #define SafeDebugStr | ( | str | ) |
| #define verify | ( | assertion | ) |
| anonymous enum |
kBlessedBusErrorBait is an address that will never be mapped by Mac OS 8 or 9. It is close to the middle of the 64K range from 0x68F10000 to 0x68F1FFFF that is unmapped and cannot be accessed without causing an exception. Thus, it's a good value to use for filling uninitialized pointers, etc.
| anonymous enum |
TaskLevel masks
| typedef CALLBACK_API | ( | void | , |
| DebugAssertOutputHandlerProcPtr | |||
| ) |
DebugAssertOutputHandler DebugAssertOutputHandler is the callback that registers with DebugLib to handle the output from DebugAssert. Inputs: "componentSignature" through "value" are the raw values passed to DebugAssert when an exception occurs. outputMsg is the string DebugAssert build which would normally be passed to DebugStr if a DebugAssertOutputHandler isn't installed.
| typedef CALLBACK_API | ( | void | , |
| DebugComponentCallbackProcPtr | |||
| ) |
DebugComponentCallback DebugComponentCallback is the callback into a component that registers with DebugLib. It is called to get the debug option setting, or to turn a debug option on or off. Inputs: optionSelectorNum The component debug option to set command The command: kGetDebugOption - get current debug option setting kSetDebugOption - set debug option Outputs: optionSetting The current setting if kGetDebugOption; the new debug option if kSetDebugOption
| void DebugAssert | ( | OSType | componentSignature, |
| UInt32 | options, | ||
| const char * | assertionString, | ||
| const char * | exceptionString, | ||
| const char * | errorString, | ||
| const char * | fileName, | ||
| long | lineNumber, | ||
| void * | value | ||
| ) |
DEBUGASSERTMSG - all error reporting is routed through this macro, which calls the system routine DebugAssert(). If you wish to use your own assertion/debugger break routine, you can override DEBUGASSERTMSG by defining it before including this file.
| void DisposeDebugAssertOutputHandlerUPP | ( | DebugAssertOutputHandlerUPP | userUPP | ) |
DisposeDebugAssertOutputHandlerUPP()
| OSStatus DisposeDebugComponent | ( | OSType | componentSignature | ) |
DisposeDebugComponent DisposeDebugComponent removes a component registration and all related debug options from DebugLib. Input: componentSignature The unique signature of a component Result: noErr no error debuggingExecutionContextErr called at interrupt time debuggingInvalidSignatureErr componentSignature not registered DisposeDebugComponent()
| void DisposeDebugComponentCallbackUPP | ( | DebugComponentCallbackUPP | userUPP | ) |
DisposeDebugComponentCallbackUPP()
| void dprintf | ( | const char * | format, |
| ... | |||
| ) |
| OSStatus GetDebugComponentInfo | ( | UInt32 | index, |
| OSType * | componentSignature, | ||
| Str255 | componentName | ||
| ) |
GetDebugComponentInfo GetDebugComponentInfo returns a component registered with DebugLib. Inputs: index The index into the list of registered components (1-based) Outputs: componentSignature The unique signature of a component componentName The displayable string naming a component Result: noErr no error debuggingNoMatchErr debugging component not found at this index GetDebugComponentInfo()
| OSStatus GetDebugOptionInfo | ( | UInt32 | index, |
| OSType | componentSignature, | ||
| SInt32 * | optionSelectorNum, | ||
| Str255 | optionName, | ||
| Boolean * | optionSetting | ||
| ) |
GetDebugOptionInfo GetDebugOptionInfo returns a debug option registered with DebugLib. Inputs: index The index into the list of registered debug options (0-based); 0 = kComponentDebugOption componentSignature The unique signature of a component Outputs: optionSelectorNum The selector number of this debug option optionName The displayable string naming this debug option optionSetting The current debug option setting Result: noErr no error debuggingInvalidSignatureErr componentSignature not registered debuggingNoMatchErr option not found at this index GetDebugOptionInfo()
| void InstallDebugAssertOutputHandler | ( | DebugAssertOutputHandlerUPP | handler | ) |
InstallDebugAssertOutputHandler InstallDebugAssertOutputHandler installs a DebugAssertOutputHandler which DebugAssert calls instead of DebugStr. Inputs: handler the DebugAssertOutputHandler to install or NULL to switch back to the default handler (DebugStr). InstallDebugAssertOutputHandler()
| void InvokeDebugAssertOutputHandlerUPP | ( | OSType | componentSignature, |
| UInt32 | options, | ||
| const char * | assertionString, | ||
| const char * | exceptionString, | ||
| const char * | errorString, | ||
| const char * | fileName, | ||
| long | lineNumber, | ||
| void * | value, | ||
| ConstStr255Param | outputMsg, | ||
| DebugAssertOutputHandlerUPP | userUPP | ||
| ) |
InvokeDebugAssertOutputHandlerUPP()
| void InvokeDebugComponentCallbackUPP | ( | SInt32 | optionSelectorNum, |
| UInt32 | command, | ||
| Boolean * | optionSetting, | ||
| DebugComponentCallbackUPP | userUPP | ||
| ) |
InvokeDebugComponentCallbackUPP()
| DebugAssertOutputHandlerUPP NewDebugAssertOutputHandlerUPP | ( | DebugAssertOutputHandlerProcPtr | userRoutine | ) |
NewDebugAssertOutputHandlerUPP()
| OSStatus NewDebugComponent | ( | OSType | componentSignature, |
| ConstStr255Param | componentName, | ||
| DebugComponentCallbackUPP | componentCallback | ||
| ) |
NewDebugComponent NewDebugComponent registers a component with DebugLib. Inputs: componentSignature The unique signature of component componentName The displayable string naming the component componentCallback The callback into component for working with options Result: noErr no error memFullErr could not allocate memory debuggingExecutionContextErr routine cannot be called at this time debuggingDuplicateSignatureErr componentSignature already registered debuggingInvalidNameErr componentName is invalid (NULL) NewDebugComponent()
| DebugComponentCallbackUPP NewDebugComponentCallbackUPP | ( | DebugComponentCallbackProcPtr | userRoutine | ) |
NewDebugComponentCallbackUPP()
| OSStatus NewDebugOption | ( | OSType | componentSignature, |
| SInt32 | optionSelectorNum, | ||
| ConstStr255Param | optionName | ||
| ) |
NewDebugOption NewDebugOption registers a debug option with DebugLib. Inputs: componentSignature The signature of component to register a debug option for optionSelectorNum The selector number of this debug option optionName The displayable string naming this debug option Result: noErr no error memFullErr could not allocate memory debuggingExecutionContextErr called at interrupt time debuggingDuplicateOptionErr optionSelectorNum already registered debuggingInvalidSignatureErr componentSignature not registered debuggingInvalidNameErr optionName is invalid (NULL) debuggingNoCallbackErr debugging component has no callback NewDebugOption()
| OSStatus SetDebugOptionValue | ( | OSType | componentSignature, |
| SInt32 | optionSelectorNum, | ||
| Boolean | newOptionSetting | ||
| ) |
SetDebugOptionValue SetDebugOptionValue sets a debug option registered with DebugLib. Inputs: componentSignature The unique signature of a component optionSelectorNum The selector number of this debug option newOptionSetting The new debug option setting Result: noErr no error debuggingInvalidSignatureErr componentSignature not registered debuggingInvalidOptionErr optionSelectorNum is not registered SetDebugOptionValue()
| UInt32 TaskLevel | ( | void | ) |
TaskLevel TaskLevel returns 0 if we're (probably) running at non-interrupt time. There's no way to make this perfect, but this is as close as we can get. If TaskLevel doesn't return 0, then the following masks can be used to learn more: k68kInterruptLevelMask = 0x00000007 kInVBLTaskMask = 0x00000010 kInDeferredTaskMask = 0x00000020 kInSecondaryIntHandlerMask = 0x00000040 kInNestedInterruptMask = 0x00000080 TaskLevel()
| void vdprintf | ( | const char * | format, |
| char * | va_args_list | ||
| ) |
vdprintf() takes a va_args list and 'prints' that to the debugging output handler. vdprintf()