Debugging.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:42k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       Debugging.h
  3.  
  4.      Contains:   Macros to handle exceptions and assertions.
  5.  
  6.      Version:    Technology: Carbon
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1989-2001 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __DEBUGGING__
  18. #define __DEBUGGING__
  19. #ifndef __MACTYPES__
  20. #include "MacTypes.h"
  21. #endif
  22. #ifndef __FILES__
  23. #include "Files.h"
  24. #endif
  25. /*______________________________________________________________________________________*/
  26. /*                                                                                      */
  27. /*  This file defines standard exception handling and assertion macros for              */
  28. /*  system-level programming in C.  Originally used in QuickDraw GX, and heavily        */
  29. /*  modified since, these macros are used extensively throughout Mac OS system          */
  30. /*  software.  Now *you* can look and feel like a system software engineer.             */
  31. /*                                                                                      */
  32. /*  To activate debugger breaks, #define DEBUG to 1 (one) before including this file.   */
  33. /*  Five further levels of debugging are available, selected by #defining one           */
  34. /*  of the following conditionals to 1 after DEBUG is defined to 1.                     */
  35. /*                                                                                      */
  36. /*      DEBUG_INTERNAL      the default; includes file and line number information      */
  37. /*                                                                                      */
  38. /*      DEBUG_EXTERNAL      used for code which must ship to developers outside         */
  39. /*                          your organization; no file or line number information is    */
  40. /*                          included in asserts                                         */
  41. /*                                                                                      */
  42. /*      DEBUG_BREAK_ONLY    where an assertion would normally be sent to the debugger,  */
  43. /*                          send an empty string instead.                               */
  44. /*                                                                                      */
  45. /*      PRODUCTION          used for shipping code; no debugger breaks are emitted      */
  46. /*                                                                                      */
  47. /*      PERFORMANCE         same as PRODUCTION                                          */
  48. /*                                                                                      */
  49. /*  #defining DEBUG to 0 is equivalent to #defining PRODUCTION 1 when DEBUG is 1.       */
  50. /*  (No code for debugger breaks is emitted in either case.)                            */
  51. /*                                                                                      */
  52. /*  Of the multitude of macros, the preferred ones are:                                 */
  53. /*                                                                                      */
  54. /*  debug_string(c-string)                                                              */
  55. /*      If debugging is on, c-string is printed in the debugger.                        */
  56. /*      In production builds, debug_string() does nothing.                              */
  57. /*                                                                                      */
  58. /*  check(expression)                                                                   */
  59. /*  check_noerr(error)                                                                  */
  60. /*      If (expression) evaluates to false, break into the debugger.                    */
  61. /*      In production builds, check() does nothing.                                     */
  62. /*      Code inside check() statements is not compiled into production builds.          */
  63. /*                                                                                      */
  64. /*  require(expression, label)                                                          */
  65. /*  require_noerr(expression, label)                                                    */
  66. /*      If (expression) evaluates to false, announce this fact via the                  */
  67. /*      debugger and then goto label.  In production builds, does not call              */
  68. /*      the debugger but still goes to label if expression is false.                    */
  69. /*                                                                                      */
  70. /*  require_action(expression, label, action)                                           */
  71. /*  require_noerr_action(expression, label, action)                                     */
  72. /*      Same as require, but executes (action) before jumping to label.                 */
  73. /*                                                                                      */
  74. /*  check_string(expression, c-string)                                                  */
  75. /*  require_string(expression, label, c-string)                                         */
  76. /*  require_noerr_string(expression, label, c-string)                                   */
  77. /*      If expression evaluates to false, print string and then proceed as in           */
  78. /*      a normal check/require statement                                                */
  79. /*                                                                                      */
  80. /*  verify(expression)                                                                  */
  81. /*  verify_noerr(error)                                                                 */
  82. /*      If debugging is on, verify is the same as check(expression).                    */
  83. /*      If debugging is off, verify still evaluates (expression)                        */
  84. /*      but ignores the result.  Code inside verify() statements                        */
  85. /*      is executed in both production and debug builds.                                */
  86. /*                                                                                      */
  87. /*  Common usage:                                                                       */
  88. /*                                                                                      */
  89. /*      // my pixmap is not purgeable, so locking it should never fail                  */
  90. /*      verify( LockPixels(myPixMap) );                                                 */
  91. /*      verify_noerr( DisposeThread(myThread, &threadResult, true) );                   */
  92. /*______________________________________________________________________________________*/
  93. /*______________________________________________________________________________________*/
  94. /*                                                                                      */
  95. /* Before including this file, #define kCompentSignatureString to a C-string            */
  96. /* containing the name of your client.                                                  */
  97. /*                                                                                      */
  98. /* example: #define kComponentSignatureString "SurfWriter"                              */
  99. /*______________________________________________________________________________________*/
  100. #ifndef kComponentSignatureString
  101. #define kComponentSignatureString "Third Party Client"
  102. #endif
  103. #define DEBUG_LEVEL_PRODUCTION 0
  104. #define DEBUG_LEVEL_BREAK_ONLY    1
  105. #define DEBUG_LEVEL_EXTERNAL  3
  106. #define DEBUG_LEVEL_INTERNAL  4
  107. #define DEBUGFULL             DEBUG_LEVEL_INTERNAL
  108. #define DEBUG_NO_OPTIONS       0
  109. #ifdef DEBUGLEVEL
  110. #undef DEBUGLEVEL
  111. #endif
  112. #if DEBUG
  113.   #if     PRODUCTION
  114.      #define DEBUGLEVEL DEBUG_LEVEL_PRODUCTION
  115.   #elif   DEBUG_EXTERNAL
  116.      #define DEBUGLEVEL DEBUG_LEVEL_EXTERNAL
  117.     #elif   DEBUG_INTERNAL
  118.      #define DEBUGLEVEL DEBUG_LEVEL_INTERNAL
  119.     #elif   PERFORMANCE
  120.         #define DEBUGLEVEL DEBUG_LEVEL_PRODUCTION
  121.   #elif   DEBUG_BREAK_ONLY
  122.        #define DEBUGLEVEL DEBUG_LEVEL_BREAK_ONLY
  123.   #else
  124.       #define DEBUGLEVEL DEBUG_LEVEL_INTERNAL
  125.     #endif
  126. #endif
  127. #ifndef  DEBUGLEVEL
  128. #define DEBUGLEVEL DEBUG_LEVEL_PRODUCTION
  129. #endif
  130. #ifndef COMPONENT_SIGNATURE
  131. #define COMPONENT_SIGNATURE '?*?*'
  132. #endif
  133. #define QuoteExceptionString(x) #x
  134. /*______________________________________________________________________________________*/
  135. /*                                                                                      */
  136. /*  DEBUGASSERTMSG - all error reporting is routed through this macro, which calls the  */
  137. /*  system routine DebugAssert().  If you wish to use your own assertion/debugger break */
  138. /*  routine, you can override DEBUGASSERTMSG by defining it before including this file. */
  139. /*______________________________________________________________________________________*/
  140. #if PRAGMA_ONCE
  141. #pragma once
  142. #endif
  143. #ifdef __cplusplus
  144. extern "C" {
  145. #endif
  146. #if PRAGMA_IMPORT
  147. #pragma import on
  148. #endif
  149. #if PRAGMA_STRUCT_ALIGN
  150.     #pragma options align=mac68k
  151. #elif PRAGMA_STRUCT_PACKPUSH
  152.     #pragma pack(push, 2)
  153. #elif PRAGMA_STRUCT_PACK
  154.     #pragma pack(2)
  155. #endif
  156. EXTERN_API( void )
  157. DebugAssert                     (OSType                 componentSignature,
  158.                                  UInt32                 options,
  159.                                  char *                 assertionString,
  160.                                  char *                 exceptionString,
  161.                                  char *                 errorString,
  162.                                  char *                 fileName,
  163.                                  long                   lineNumber,
  164.                                  void *                 value)                              TWOWORDINLINE(0x7000, 0xAA7E);
  165. #ifndef DEBUGASSERTMSG
  166. #if DEBUGLEVEL == DEBUG_LEVEL_BREAK_ONLY
  167. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value ) 
  168.     Debugger()
  169. #elif DEBUGLEVEL == DEBUG_LEVEL_EXTERNAL
  170. /* exclude code structure information */
  171. #if (applec && (!__powerc))
  172. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value ) 
  173.     DebugAssert(componentSignature, options, kComponentSignatureString, assertionString, nil, nil, 0, value )
  174. #else
  175. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value ) 
  176.  DebugAssert(componentSignature, options, kComponentSignatureString ": " assertionString, nil, nil, nil, 0, value )
  177. #endif
  178. #elif DEBUGLEVEL == DEBUG_LEVEL_INTERNAL
  179. /* include all info */
  180. #if (applec && (!__powerc))
  181. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value ) 
  182.    DebugAssert(componentSignature, options, kComponentSignatureString, assertionString, nil, nil, 0, value )
  183. #else
  184. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value ) 
  185.  DebugAssert(componentSignature, options, kComponentSignatureString ": " assertionString, exceptionString, errorString, fileName, lineNumber, value )
  186. #endif
  187. #else
  188. /* no debugger message */
  189. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value )
  190. #endif
  191. #endif
  192. /*
  193.     kBlessedBusErrorBait is an address that will never be mapped
  194.     by Mac OS 8 or 9. It is close to the middle of the 64K range from
  195.     0x68F10000 to 0x68F1FFFF that is unmapped and cannot be accessed 
  196.     without causing an exception. Thus, it's a good value to use for
  197.     filling uninitialized pointers, etc.
  198. */
  199. enum {
  200.     kBlessedBusErrorBait        = 0x68F168F1
  201. };
  202. /*  TaskLevel masks*/
  203. enum {
  204.     k68kInterruptLevelMask      = 0x00000007,
  205.     kInVBLTaskMask              = 0x00000010,
  206.     kInDeferredTaskMask         = 0x00000020,
  207.     kInSecondaryIntHandlerMask  = 0x00000040
  208. };
  209. enum {
  210.     kComponentDebugOption       = 0                             /* optionSelectorNum to turn breaks for component on/off*/
  211. };
  212. enum {
  213.     kGetDebugOption             = 1,                            /* get current debug option setting*/
  214.     kSetDebugOption             = 2                             /* set debug option*/
  215. };
  216. /*
  217.     DebugComponentCallback
  218.     DebugComponentCallback is the callback into a component that registers with DebugLib.
  219.     It is called to get the debug option setting, or to turn a debug option on or off.
  220.         Inputs:
  221.             optionSelectorNum   The component debug option to set
  222.             command             The command:
  223.                                     kGetDebugOption     - get current debug option setting
  224.                                     kSetDebugOption     - set debug option
  225.         Outputs:
  226.             optionSetting       The current setting if kGetDebugOption;
  227.                                 the new debug option if kSetDebugOption
  228. */
  229. typedef CALLBACK_API( void , DebugComponentCallbackProcPtr )(SInt32 optionSelectorNum, UInt32 command, Boolean *optionSetting);
  230. typedef STACK_UPP_TYPE(DebugComponentCallbackProcPtr)           DebugComponentCallbackUPP;
  231. #if OPAQUE_UPP_TYPES
  232.     EXTERN_API(DebugComponentCallbackUPP)
  233.     NewDebugComponentCallbackUPP    (DebugComponentCallbackProcPtr userRoutine);
  234.     EXTERN_API(void)
  235.     DisposeDebugComponentCallbackUPP    (DebugComponentCallbackUPP userUPP);
  236.     EXTERN_API(void)
  237.     InvokeDebugComponentCallbackUPP    (SInt32              optionSelectorNum,
  238.                                     UInt32                  command,
  239.                                     Boolean *               optionSetting,
  240.                                     DebugComponentCallbackUPP userUPP);
  241. #else
  242.     enum { uppDebugComponentCallbackProcInfo = 0x00000FC0 };        /* pascal no_return_value Func(4_bytes, 4_bytes, 4_bytes) */
  243.     #define NewDebugComponentCallbackUPP(userRoutine)               (DebugComponentCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebugComponentCallbackProcInfo, GetCurrentArchitecture())
  244.     #define DisposeDebugComponentCallbackUPP(userUPP)               DisposeRoutineDescriptor(userUPP)
  245.     #define InvokeDebugComponentCallbackUPP(optionSelectorNum, command, optionSetting, userUPP)  CALL_THREE_PARAMETER_UPP((userUPP), uppDebugComponentCallbackProcInfo, (optionSelectorNum), (command), (optionSetting))
  246. #endif
  247. /* support for pre-Carbon UPP routines: NewXXXProc and CallXXXProc */
  248. #define NewDebugComponentCallbackProc(userRoutine)              NewDebugComponentCallbackUPP(userRoutine)
  249. #define CallDebugComponentCallbackProc(userRoutine, optionSelectorNum, command, optionSetting) InvokeDebugComponentCallbackUPP(optionSelectorNum, command, optionSetting, userRoutine)
  250. /*
  251.     TaskLevel
  252.     TaskLevel returns 0 if we're (probably) running at non-interrupt time.
  253.     There's no way to make this perfect, but this is as close as we can get.
  254.     If TaskLevel doesn't return 0, then the following masks can be used to learn more:
  255.         k68kInterruptLevelMask      = 0x00000007,
  256.         kInVBLTaskMask              = 0x00000010,
  257.         kInDeferredTaskMask         = 0x00000020,
  258.         kInSecondaryIntHandlerMask  = 0x00000040
  259. */
  260. EXTERN_API( UInt32 )
  261. TaskLevel                       (void)                                                      TWOWORDINLINE(0x7001, 0xAA7E);
  262. #define    ATTASKLEVEL0()  ( TaskLevel() == 0 )
  263. /*
  264.     NewDebugComponent
  265.     NewDebugComponent registers a component with DebugLib.
  266.         Inputs:
  267.             componentSignature  The unique signature of component
  268.             componentName       The displayable string naming the component
  269.             componentCallback   The callback into component for working with options
  270.         Result:
  271.             noErr                           no error
  272.             memFullErr                      could not allocate memory
  273.             debuggingExecutionContextErr    routine cannot be called at this time
  274.             debuggingDuplicateSignatureErr  componentSignature already registered
  275.             debuggingInvalidNameErr         componentName is invalid (NULL)
  276. */
  277. EXTERN_API( OSStatus )
  278. NewDebugComponent               (OSType                 componentSignature,
  279.                                  ConstStr255Param       componentName,
  280.                                  DebugComponentCallbackUPP  componentCallback)              TWOWORDINLINE(0x7002, 0xAA7E);
  281. /*
  282.     NewDebugOption
  283.     NewDebugOption registers a debug option with DebugLib.
  284.         Inputs:
  285.             componentSignature  The signature of component to register a debug option for
  286.             optionSelectorNum   The selector number of this debug option
  287.             optionName          The displayable string naming this debug option
  288.         Result:
  289.             noErr                           no error
  290.             memFullErr                      could not allocate memory
  291.             debuggingExecutionContextErr    called at interrupt time
  292.             debuggingDuplicateOptionErr     optionSelectorNum already registered
  293.             debuggingInvalidSignatureErr    componentSignature not registered
  294.             debuggingInvalidNameErr         optionName is invalid (NULL)
  295.             debuggingNoCallbackErr          debugging component has no callback
  296. */
  297. EXTERN_API( OSStatus )
  298. NewDebugOption                  (OSType                 componentSignature,
  299.                                  SInt32                 optionSelectorNum,
  300.                                  ConstStr255Param       optionName)                         TWOWORDINLINE(0x7003, 0xAA7E);
  301. /*
  302.     DisposeDebugComponent
  303.     DisposeDebugComponent removes a component registration and all related debug options from DebugLib.
  304.         Input:
  305.             componentSignature  The unique signature of a component
  306.         Result:
  307.             noErr                           no error
  308.             debuggingExecutionContextErr    called at interrupt time
  309.             debuggingInvalidSignatureErr    componentSignature not registered
  310. */
  311. EXTERN_API( OSStatus )
  312. DisposeDebugComponent           (OSType                 componentSignature)                 TWOWORDINLINE(0x7004, 0xAA7E);
  313. /*
  314.     GetDebugComponentInfo
  315.     GetDebugComponentInfo returns a component registered with DebugLib.
  316.         Inputs:
  317.             index               The index into the list of registered components (1-based)
  318.         Outputs:
  319.             componentSignature  The unique signature of a component
  320.             componentName       The displayable string naming a component
  321.         Result:
  322.             noErr                           no error
  323.             debuggingNoMatchErr             debugging component not found at this index
  324. */
  325. EXTERN_API( OSStatus )
  326. GetDebugComponentInfo           (UInt32                 index,
  327.                                  OSType *               componentSignature,
  328.                                  Str255                 componentName)                      TWOWORDINLINE(0x7005, 0xAA7E);
  329. /*
  330.     GetDebugOptionInfo
  331.     GetDebugOptionInfo returns a debug option registered with DebugLib.
  332.         Inputs:
  333.             index               The index into the list of registered debug options (0-based);
  334.                                     0 = kComponentDebugOption 
  335.             componentSignature  The unique signature of a component
  336.         Outputs:
  337.             optionSelectorNum   The selector number of this debug option
  338.             optionName          The displayable string naming this debug option
  339.             optionSetting       The current debug option setting
  340.         Result:
  341.             noErr                           no error
  342.             debuggingInvalidSignatureErr    componentSignature not registered
  343.             debuggingNoMatchErr             option not found at this index
  344. */
  345. EXTERN_API( OSStatus )
  346. GetDebugOptionInfo              (UInt32                 index,
  347.                                  OSType                 componentSignature,
  348.                                  SInt32 *               optionSelectorNum,
  349.                                  Str255                 optionName,
  350.                                  Boolean *              optionSetting)                      TWOWORDINLINE(0x7006, 0xAA7E);
  351. /*
  352.     SetDebugOptionValue
  353.     SetDebugOptionValue sets a debug option registered with DebugLib.
  354.         Inputs:
  355.             componentSignature  The unique signature of a component
  356.             optionSelectorNum   The selector number of this debug option
  357.             newOptionSetting    The new debug option setting
  358.         Result:
  359.             noErr                           no error
  360.             debuggingInvalidSignatureErr    componentSignature not registered
  361.             debuggingInvalidOptionErr       optionSelectorNum is not registered
  362. */
  363. EXTERN_API( OSStatus )
  364. SetDebugOptionValue             (OSType                 componentSignature,
  365.                                  SInt32                 optionSelectorNum,
  366.                                  Boolean                newOptionSetting)                   TWOWORDINLINE(0x7007, 0xAA7E);
  367. /*
  368.     DebugAssertOutputHandler
  369.     DebugAssertOutputHandler is the callback that registers with DebugLib to handle the
  370.     output from DebugAssert.
  371.         Inputs:
  372.             "componentSignature" through "value" are the raw values passed to DebugAssert
  373.                 when an exception occurs.
  374.             outputMsg is the string DebugAssert build which would normally be passed to
  375.                 DebugStr if a DebugAssertOutputHandler isn't installed.
  376. */
  377. typedef CALLBACK_API( void , DebugAssertOutputHandlerProcPtr )(OSType componentSignature, UInt32 options, char *assertionString, char *exceptionString, char *errorString, char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg);
  378. typedef STACK_UPP_TYPE(DebugAssertOutputHandlerProcPtr)         DebugAssertOutputHandlerUPP;
  379. #if OPAQUE_UPP_TYPES
  380.     EXTERN_API(DebugAssertOutputHandlerUPP)
  381.     NewDebugAssertOutputHandlerUPP    (DebugAssertOutputHandlerProcPtr userRoutine);
  382.     EXTERN_API(void)
  383.     DisposeDebugAssertOutputHandlerUPP    (DebugAssertOutputHandlerUPP userUPP);
  384.     EXTERN_API(void)
  385.     InvokeDebugAssertOutputHandlerUPP    (OSType            componentSignature,
  386.                                     UInt32                  options,
  387.                                     char *                  assertionString,
  388.                                     char *                  exceptionString,
  389.                                     char *                  errorString,
  390.                                     char *                  fileName,
  391.                                     long                    lineNumber,
  392.                                     void *                  value,
  393.                                     ConstStr255Param        outputMsg,
  394.                                     DebugAssertOutputHandlerUPP userUPP);
  395. #else
  396.     enum { uppDebugAssertOutputHandlerProcInfo = 0x00FFFFC0 };      /* pascal no_return_value Func(4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes, 4_bytes) */
  397.     #define NewDebugAssertOutputHandlerUPP(userRoutine)             (DebugAssertOutputHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebugAssertOutputHandlerProcInfo, GetCurrentArchitecture())
  398.     #define DisposeDebugAssertOutputHandlerUPP(userUPP)             DisposeRoutineDescriptor(userUPP)
  399.     #define InvokeDebugAssertOutputHandlerUPP(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value, outputMsg, userUPP)  CALL_NINE_PARAMETER_UPP((userUPP), uppDebugAssertOutputHandlerProcInfo, (componentSignature), (options), (assertionString), (exceptionString), (errorString), (fileName), (lineNumber), (value), (outputMsg))
  400. #endif
  401. /* support for pre-Carbon UPP routines: NewXXXProc and CallXXXProc */
  402. #define NewDebugAssertOutputHandlerProc(userRoutine)            NewDebugAssertOutputHandlerUPP(userRoutine)
  403. #define CallDebugAssertOutputHandlerProc(userRoutine, componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value, outputMsg) InvokeDebugAssertOutputHandlerUPP(componentSignature, options, assertionString, exceptionString, errorString, fileName, lineNumber, value, outputMsg, userRoutine)
  404. /*
  405.     InstallDebugAssertOutputHandler
  406.     InstallDebugAssertOutputHandler installs a DebugAssertOutputHandler which DebugAssert calls
  407.     instead of DebugStr.
  408.         Inputs:
  409.             handler     the DebugAssertOutputHandler to install or NULL to switch back to
  410.                         the default handler (DebugStr).
  411. */
  412. EXTERN_API( void )
  413. InstallDebugAssertOutputHandler (DebugAssertOutputHandlerUPP  handler)                      TWOWORDINLINE(0x7008, 0xAA7E);
  414. /*______________________________________________________________________________________*/
  415. /*                                                                                      */
  416. /*  Tech Q&A PLAT-30 says to check bit 5 of the byte at 0xbff to                        */
  417. /*  determine whether Macsbug ( or any other low level debugger )                       */
  418. /*  is installed; I also check that MacJmp ( which points to the                        */
  419. /*  entry point for the debugger ) is not nil and not -1.                               */
  420. /*                                                                                      */
  421. /*  MacJmpFlag:                                                                         */
  422. /*      Bit 5 should be set to indicate the debugger is installed.                      */
  423. /*      Bit 6 should be set to indicate the debugger is initialized.                    */
  424. /*      Bit 7 should be clear to indicate that the debugger is NOT busy                 */
  425. /*                                                                                      */
  426. /*  Dr. Macsbug says to also check that the byte at 0xBFF isn't 0xFF.                   */
  427. /*______________________________________________________________________________________*/
  428. #define LocalLMGetMacJmp() (*(( unsigned long *)0x0120))
  429. #define LocalLMGetMacJmpFlag() (*(( UInt8 *)0x0BFF))
  430. #define ISLOWLEVELDEBUGGERCALLABLE()                                    
  431.   ( ( LocalLMGetMacJmpFlag() != (UInt8) 0xff ) &&                     
  432.     ( (LocalLMGetMacJmpFlag() & (UInt8) 0xe0) == (UInt8) 0x60 ) &&    
  433.     ( LocalLMGetMacJmp() != 0 ) &&                                    
  434.     ( LocalLMGetMacJmp() != (unsigned long) 0xffffffff ) )
  435.    
  436. #if DEBUG
  437.  
  438. #define    DEBUGGER()                                                      
  439.   do {                                                                
  440.       if ( ISLOWLEVELDEBUGGERCALLABLE() )                             
  441.           Debugger();                                                 
  442.   } while ( false )
  443.   
  444. #define    DEBUGSTR(str)                                                   
  445.   do {                                                                
  446.       if ( ISLOWLEVELDEBUGGERCALLABLE() )                             
  447.           DebugStr ( str );                                           
  448.   } while ( false )
  449. #else
  450. #define   DEBUGGER()
  451. #define DEBUGSTR(str)
  452. #endif
  453. /* no-op asserts for production code*/
  454. #if DEBUGLEVEL == DEBUG_LEVEL_PRODUCTION
  455. #define check(assertion)
  456. #define check_string( assertion, cstring )
  457. #define check_noerr(err)
  458. #define check_noerr_string( error, cstring )
  459. #define debug_string( cstring )
  460. #define require( assertion, label )                             do { if( !(assertion) ) goto label; } while(false)
  461. #define require_string( assertion, label, string )                       require(assertion, label)
  462. #define require_quiet( assertion, label )                     require( assertion, label )
  463. #define require_noerr( error, label )                           do { if( (error) != noErr ) goto label; } while(false)
  464. #define require_noerr_quiet( assertion, label )                  require_noerr( assertion, label )
  465. #define require_noerr_action( error, label, action )          do { if( (error) != noErr ) { {action;}; goto label; } } while(false)
  466. #define require_noerr_action_quiet( assertion, label, action )    require_noerr_action( assertion, label, action )
  467. #define require_action( assertion, label, action )                     do { if( !(assertion) ) { {action;}; goto label; } } while(false)
  468. #define require_action_quiet( assertion, label, action )      require_action( assertion, label, action )
  469. #define require_action_string( assertion, label, action, cstring )                       do { if( !(assertion) ) { {action;}; goto label; } } while(false)
  470. #else
  471. /*______________________________________________________________________________________*/
  472. #define debug_string(string)                                           
  473.   do {                                                                
  474.       DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,           
  475.                   QuoteExceptionString(string), nil, nil,             
  476.                   __FILE__, __LINE__, 0);                             
  477.   } while (false)
  478. /*______________________________________________________________________________________*/
  479. #define check(assertion)                                               
  480.   do {                                                                
  481.       if (assertion) ;                                                
  482.       else {                                                          
  483.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  484.                       QuoteExceptionString(assertion), nil, nil,      
  485.                       __FILE__, __LINE__, 0);                         
  486.       }                                                               
  487.   } while (false)
  488. /*______________________________________________________________________________________*/
  489. #define check_string(assertion, cstring)                                           
  490.   do {                                                                
  491.       if (assertion) ;                                                
  492.       else {                                                          
  493.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  494.                       QuoteExceptionString(assertion), cstring, nil,  
  495.                       __FILE__, __LINE__, 0);                         
  496.       }                                                               
  497.   } while (false)
  498. /*______________________________________________________________________________________*/
  499. #define check_noerr(error)                                                     
  500.   do {                                                                    
  501.       OSStatus localError = error;                                        
  502.       if (localError == noErr) ;                                          
  503.       else {                                                              
  504.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,           
  505.                       QuoteExceptionString(error) "== noErr", nil, nil,   
  506.                       __FILE__, __LINE__, (void *)localError);            
  507.       }                                                                   
  508.   } while (false)
  509. /*______________________________________________________________________________________*/
  510. #define check_noerr_string(error, cstring)                                             
  511.   do {                                                                            
  512.       OSStatus localError = error;                                                
  513.       if (localError == noErr) ;                                                  
  514.       else {                                                                      
  515.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,                   
  516.                       QuoteExceptionString(error) "== noErrn", cstring, nil, 
  517.                       __FILE__, __LINE__, (void *)localError);                    
  518.       }                                                                           
  519.   } while (false)
  520. /*______________________________________________________________________________________*/
  521. #define require(assertion, exception)                                      
  522.   do {                                                                
  523.       if (assertion) ;                                                
  524.       else {                                                          
  525.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  526.                       QuoteExceptionString(assertion),                
  527.                       QuoteExceptionString(exception),                
  528.                       nil, __FILE__, __LINE__, 0);                    
  529.           goto exception;                                             
  530.       }                                                               
  531.   } while (false)
  532. /*______________________________________________________________________________________*/
  533. #define require_noerr(error, exception)                                
  534.   do {                                                                
  535.       OSStatus localError = error;                                    
  536.       if (localError == noErr) ;                                      
  537.       else {                                                          
  538.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  539.                       QuoteExceptionString(error) "== noErr",         
  540.                       QuoteExceptionString(exception),                
  541.                       nil, __FILE__, __LINE__, (void *)localError );  
  542.           goto exception;                                             
  543.       }                                                               
  544.   } while (false)
  545. /*______________________________________________________________________________________*/
  546. #define require_string(assertion, exception, string)                   
  547.   do {                                                                
  548.       if (assertion) ;                                                
  549.       else {                                                          
  550.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  551.                       string, QuoteExceptionString(exception),        
  552.                       QuoteExceptionString(exception),                
  553.                       __FILE__, __LINE__, 0 );        
  554.           goto exception;                                             
  555.       }                                                               
  556.   } while (false)
  557. /*______________________________________________________________________________________*/
  558. #define require_noerr_action(error, exception, action)                 
  559.   do {                                                                
  560.       OSStatus localError = error;                                    
  561.       if (localError == noErr) ;                                      
  562.       else {                                                          
  563.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  564.                       QuoteExceptionString(error) "== noErr",         
  565.                       QuoteExceptionString(exception),                
  566.                       nil, __FILE__, __LINE__, (void *)localError );  
  567.           { action; }                                                 
  568.           goto exception;                                             
  569.       }                                                               
  570.   } while (false)
  571. /*______________________________________________________________________________________*/
  572. #define require_noerr_quiet(error, exception)                              
  573.   do {                                                                
  574.       if (error == noErr) ;                                           
  575.       else {                                                          
  576.           goto exception;                                             
  577.       }                                                               
  578.   } while (false)
  579. /*______________________________________________________________________________________*/
  580. #define require_noerr_action_quiet(error, exception, action)           
  581.   do {                                                                
  582.       if (error == noErr) ;                                           
  583.       else {                                                          
  584.           { action; }                                                 
  585.           goto exception;                                             
  586.       }                                                               
  587.   } while (false)
  588. /*______________________________________________________________________________________*/
  589. #define require_action(assertion, exception, action)               
  590.   do {                                                            
  591.       if (assertion) ;                                            
  592.       else {                                                      
  593.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  594.                       QuoteExceptionString(assertion),            
  595.                       QuoteExceptionString(exception),            
  596.                       nil, __FILE__, __LINE__, 0);                
  597.           { action; }                                             
  598.           goto exception;                                         
  599.       }                                                           
  600.   } while (false)
  601. /*______________________________________________________________________________________*/
  602. #define require_action_string(assertion, exception, action, cstring)   
  603.   do {                                                                
  604.       if (assertion) ;                                                
  605.       else {                                                          
  606.           DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS,       
  607.                       cstring ": " QuoteExceptionString(assertion),   
  608.                       QuoteExceptionString(exception),                
  609.                       nil, __FILE__, __LINE__, 0);                    
  610.           { action; }                                                 
  611.           goto exception;                                             
  612.       }                                                               
  613.   } while (false)
  614. /*______________________________________________________________________________________*/
  615. #define require_quiet(assertion, exception)                        
  616.   do {                                                            
  617.       if (assertion) ;                                            
  618.       else {                                                      
  619.           goto exception;                                         
  620.       }                                                           
  621.   } while (false)
  622. /*______________________________________________________________________________________*/
  623. #define require_action_quiet(assertion, exception, action)             
  624.   do {                                                            
  625.       if (assertion) ;                                            
  626.       else {                                                      
  627.           { action; }                                             
  628.           goto exception;                                         
  629.       }                                                           
  630.   } while (false)
  631. #endif /* DEBUG_LEVEL_PRODUCTION */
  632. /*    Define these in terms of the check() and require macros.  In non-debug builds, the check calls
  633.  go away and the require macros are mostly checks and jumps.
  634. */
  635. #define check_tasklevel0( )                                          check( ATTASKLEVEL0() )
  636. #define check_tasklevel0_string( string )                           check_string( ATTASKLEVEL0(), string )
  637. #define require_tasklevel0( label )                                 require( ATTASKLEVEL0(), label )
  638. #define require_tasklevel0_string( label, string )                 require_string( ATTASKLEVEL0(), label, string )
  639. #define require_tasklevel0_action( label, string, action )          require_action( ATTASKLEVEL0(), label, action )
  640. #define require_tasklevel0_action_string( label, string, action )   require_action_string( ATTASKLEVEL0(), label, action, string )
  641. /*______________________________________________________________________________________*/
  642. #if DEBUGLEVEL > DEBUG_LEVEL_PRODUCTION
  643.    #define verify(assertion)       check(assertion)
  644.    #define verify_noerr(assertion) check_noerr( (assertion) )
  645. #else
  646.    #define verify(assertion)       do { (void) (assertion); } while (0)
  647.    #define verify_noerr(assertion) verify(assertion)
  648. #endif
  649. /*______________________________________________________________________________________*/
  650. #define ncheck(assertion)                                      check( !(assertion) )
  651. #define ncheck_string(assertion, cstring)                     check_string( !(assertion), cstring )
  652. #define nrequire(assertion, exception)                            require( !(assertion), exception )
  653. #define nrequire_action(assertion, exception, action)            require_action( !(assertion), exception, action )
  654. #define nrequire_quiet(assertion, exception)                  require_quiet( !(assertion), exception )
  655. #define nrequire_action_quiet(assertion, exception, action)        require_action_quiet( !(assertion), exception, action )
  656. #define nrequire_string(assertion, exception, string)           require_string( !(assertion), exception, string )
  657. #if PRAGMA_STRUCT_ALIGN
  658.     #pragma options align=reset
  659. #elif PRAGMA_STRUCT_PACKPUSH
  660.     #pragma pack(pop)
  661. #elif PRAGMA_STRUCT_PACK
  662.     #pragma pack()
  663. #endif
  664. #ifdef PRAGMA_IMPORT_OFF
  665. #pragma import off
  666. #elif PRAGMA_IMPORT
  667. #pragma import reset
  668. #endif
  669. #ifdef __cplusplus
  670. }
  671. #endif
  672. #endif /* __DEBUGGING__ */