Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1073 lines
38 KiB

  1. /*
  2. File: Debugging.h
  3. Contains: Macros to handle exceptions and assertions.
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1989-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef __DEBUGGING__
  11. #define __DEBUGGING__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15. #ifndef __MIXEDMODE__
  16. #include <MixedMode.h>
  17. #endif
  18. #ifndef __MACERRORS__
  19. #include <MacErrors.h>
  20. #endif
  21. #include <Events.h>
  22. #ifndef __GESTALT__
  23. #include <Gestalt.h>
  24. #endif
  25. #if PRAGMA_ONCE
  26. #pragma once
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #if PRAGMA_IMPORT
  32. #pragma import on
  33. #endif
  34. /*
  35. This file supplies standard debugging routines and macros to Carbon and
  36. Classic Mac OS programs. Other C programs which wish to use the
  37. exception handling and assertion macros should include AssertMacros.h
  38. instead of this file.
  39. To activate debugger breaks, #define DEBUG to 1 (one) before including this
  40. file. Five further levels of debugging are available, selected by #defining
  41. one of the following conditionals to 1 after DEBUG is defined to 1.
  42. DEBUG_INTERNAL the default; asserts include file and line number
  43. information
  44. DEBUG_EXTERNAL used for code which must ship to developers outside
  45. your organization; no file or line number
  46. information is included in asserts
  47. DEBUG_BREAK_ONLY where an assertion string would normally be sent to
  48. the debugger; call Debugger() instead.
  49. PRODUCTION used for shipping code; no debugger breaks are
  50. emitted
  51. PERFORMANCE same as PRODUCTION
  52. #defining DEBUG to 0 is equivalent to #defining PRODUCTION 1 when
  53. DEBUG is 1. (No code for debugger breaks is emitted in either case.)
  54. #defining DEBUG to 1 without specifying a level is equivalent to #defining
  55. DEBUG_INTERNAL 1.
  56. In addition, these macros should also be #defined (they are described in detail below):
  57. kComponentSignatureString
  58. COMPONENT_SIGNATURE
  59. */
  60. /*
  61. * Before including this file, #define kComponentSignatureString to a C-string
  62. * containing the name of your client and #define COMPONENT_SIGNATURE to your
  63. * client's unique signature (i.e., your program's registered creator type).
  64. * For example:
  65. *
  66. * #define kComponentSignatureString "SurfWriter"
  67. * #define COMPONENT_SIGNATURE 'WAVE'
  68. *
  69. * If you don't define kComponentSignatureString and COMPONENT_SIGNATURE, the
  70. * default kComponentSignatureString and COMPONENT_SIGNATURE values will be
  71. * used by the DEBUGASSERTMSG macros below.
  72. */
  73. #ifndef kComponentSignatureString
  74. #define kComponentSignatureString "Third Party Client"
  75. #endif
  76. #ifndef COMPONENT_SIGNATURE
  77. #define COMPONENT_SIGNATURE '?*?*'
  78. #endif
  79. #define QuoteExceptionString(x) #x
  80. /*
  81. * The DEBUGLEVEL's
  82. */
  83. #define DEBUG_LEVEL_PRODUCTION 0
  84. #define DEBUG_LEVEL_BREAK_ONLY 1
  85. #define DEBUG_LEVEL_EXTERNAL 3
  86. #define DEBUG_LEVEL_INTERNAL 4
  87. #define DEBUGFULL DEBUG_LEVEL_INTERNAL
  88. /*
  89. * define DEBUGLEVEL
  90. */
  91. #if DEBUG
  92. #if PRODUCTION
  93. #define DEBUGLEVEL DEBUG_LEVEL_PRODUCTION
  94. #elif PERFORMANCE
  95. #define DEBUGLEVEL DEBUG_LEVEL_PRODUCTION
  96. #elif DEBUG_BREAK_ONLY
  97. #define DEBUGLEVEL DEBUG_LEVEL_BREAK_ONLY
  98. #elif DEBUG_EXTERNAL
  99. #define DEBUGLEVEL DEBUG_LEVEL_EXTERNAL
  100. #elif DEBUG_INTERNAL
  101. #define DEBUGLEVEL DEBUG_LEVEL_INTERNAL
  102. #else
  103. /* default to DEBUG_LEVEL_INTERNAL */
  104. #define DEBUGLEVEL DEBUG_LEVEL_INTERNAL
  105. #endif
  106. #endif
  107. #ifndef DEBUGLEVEL
  108. #define DEBUGLEVEL DEBUG_LEVEL_PRODUCTION
  109. #endif
  110. /*
  111. * The options parameter to DebugAssert and DEBUGASSERTMSG is currently reserved (must be zero).
  112. */
  113. #define DEBUG_NO_OPTIONS 0
  114. /*
  115. * DEBUGASSERTMSG()
  116. *
  117. * Summary:
  118. * All error reporting is routed through this macro, which calls the system
  119. * routine DebugAssert(). If you wish to use your own assertion break
  120. * routine, you can override DEBUGASSERTMSG by defining it before including
  121. * this file.
  122. *
  123. * Parameters:
  124. *
  125. * componentSignature:
  126. * The unique signature of component causing the assertion.
  127. *
  128. * options:
  129. * reserved.
  130. *
  131. * assertionString:
  132. * A pointer to a string constant containing the assertion.
  133. * This must be a string constant (and not a string variable or
  134. * NULL) because the Proeprocessor concatenates it with other
  135. * string constants
  136. *
  137. * exceptionLabelString:
  138. * A pointer to a string containing the exceptionLabel, or NULL.
  139. *
  140. * errorString:
  141. * A pointer to the error string, or NULL. DEBUGASSERTMSG macros
  142. * must not attempt to concatenate this string with constant
  143. * character strings.
  144. *
  145. * fileName:
  146. * A pointer to the fileName or pathname (generated by the
  147. * preprocessor __FILE__ identifier), or NULL.
  148. *
  149. * lineNumber:
  150. * The line number in the file (generated by the preprocessor
  151. * __LINE__ identifier), or 0 (zero).
  152. *
  153. * value:
  154. * A value associated with the assertion, or NULL.
  155. */
  156. #ifndef DEBUGASSERTMSG
  157. #if DEBUGLEVEL == DEBUG_LEVEL_PRODUCTION
  158. /* no debugger message */
  159. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value)
  160. #elif DEBUGLEVEL == DEBUG_LEVEL_BREAK_ONLY
  161. /* call Debugger() if it is available */
  162. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value) \
  163. Debugger()
  164. #elif DEBUGLEVEL == DEBUG_LEVEL_EXTERNAL
  165. /* exclude fileName and lineNumber */
  166. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value) \
  167. DebugAssert(componentSignature, options, assertionString, exceptionLabelString, errorString, 0, 0, (void*)value)
  168. #else
  169. /* include all info */
  170. #define DEBUGASSERTMSG(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value) \
  171. DebugAssert(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, (void*)value)
  172. #endif
  173. #endif
  174. /*
  175. * Define the three inputs to AssertMacros.h
  176. */
  177. #ifndef DEBUG_ASSERT_COMPONENT_NAME_STRING
  178. #define DEBUG_ASSERT_COMPONENT_NAME_STRING kComponentSignatureString
  179. #endif
  180. #ifndef DEBUG_ASSERT_PRODUCTION_CODE
  181. #define DEBUG_ASSERT_PRODUCTION_CODE (DEBUGLEVEL==0)
  182. #endif
  183. #ifndef DEBUG_ASSERT_MESSAGE
  184. #define DEBUG_ASSERT_MESSAGE(componentNameString, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value) \
  185. DEBUGASSERTMSG(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS, componentNameString ": " assertionString, exceptionLabelString, errorString, fileName, lineNumber, value)
  186. #endif
  187. /*
  188. * Include AssertMacros.h where all of the check, verify, and require macros are defined
  189. */
  190. #include <AssertMacros.h>
  191. /*
  192. * The following check, verify, and require macros assert that TaskLevel is 0.
  193. */
  194. #define ATTASKLEVEL0() \
  195. (TaskLevel() == 0)
  196. #define check_tasklevel0() \
  197. check(ATTASKLEVEL0())
  198. #define check_tasklevel0_string(cstring) \
  199. check_string(ATTASKLEVEL0(), cstring)
  200. #define verify_tasklevel0() \
  201. verify(ATTASKLEVEL0())
  202. #define verify_tasklevel0_string(cstring) \
  203. verify_string(ATTASKLEVEL0(), cstring)
  204. #define require_tasklevel0(exceptionLabel) \
  205. require(ATTASKLEVEL0(), exceptionLabel)
  206. #define require_tasklevel0_action(exceptionLabel, action) \
  207. require_action(ATTASKLEVEL0(), exceptionLabel, action)
  208. #define require_tasklevel0_quiet(exceptionLabel) \
  209. require_quiet(ATTASKLEVEL0(), exceptionLabel)
  210. #define require_tasklevel0_action_quiet(exceptionLabel, action) \
  211. require_action_quiet(ATTASKLEVEL0(), exceptionLabel, action)
  212. #define require_tasklevel0_string(exceptionLabel, cstring) \
  213. require_string(ATTASKLEVEL0(), exceptionLabel, cstring)
  214. #define require_tasklevel0_action_string(exceptionLabel, action, cstring) \
  215. require_action_string(ATTASKLEVEL0(), exceptionLabel, action, cstring)
  216. /*
  217. * SafeDebugger and SafeDebugStr work like Debugger and DebugStr in both
  218. * production and non-preduction builds, but only call the debugger
  219. * if the debugger is installed.
  220. */
  221. #if CALL_NOT_IN_CARBON
  222. /* Make sure a low level debugger is installed on Mac OS 8 or 9 */
  223. #define SafeDebugger() \
  224. do \
  225. { \
  226. if ( ((*((UInt8 *)0x0BFF)) != (UInt8)0xff) && \
  227. (((*((UInt8 *)0x0BFF)) & (UInt8)0xe0) == (UInt8)0x60) && \
  228. ((*((unsigned long *)0x0120)) != 0) && \
  229. ((*((unsigned long *)0x0120)) != (unsigned long)0xffffffff) ) \
  230. { \
  231. Debugger(); \
  232. } \
  233. } while ( false )
  234. #else
  235. /* Debugger() is always safe on Carbon under Mac OS X */
  236. /* Otherwise we must make sure a low level debugger is installed */
  237. #define SafeDebugger() \
  238. do \
  239. { \
  240. long response; \
  241. if ( (Gestalt(gestaltSystemVersion, &response) == noErr) && \
  242. (response >= 0x1000) ) \
  243. { \
  244. Debugger(); \
  245. } \
  246. else \
  247. { \
  248. if ( ((*((UInt8 *)0x0BFF)) != (UInt8)0xff) && \
  249. (((*((UInt8 *)0x0BFF)) & (UInt8)0xe0) == (UInt8)0x60) && \
  250. ((*((unsigned long *)0x0120)) != 0) && \
  251. ((*((unsigned long *)0x0120)) != (unsigned long)0xffffffff) ) \
  252. { \
  253. Debugger(); \
  254. } \
  255. } \
  256. } while ( false )
  257. #endif
  258. #if CALL_NOT_IN_CARBON
  259. /* Make sure low level debugger is installed on Mac OS 8 or 9 */
  260. #define SafeDebugStr(str) \
  261. do \
  262. { \
  263. if ( ((*((UInt8 *)0x0BFF)) != (UInt8)0xff) && \
  264. (((*((UInt8 *)0x0BFF)) & (UInt8)0xe0) == (UInt8)0x60) && \
  265. ((*((unsigned long *)0x0120)) != 0) && \
  266. ((*((unsigned long *)0x0120)) != (unsigned long)0xffffffff) ) \
  267. { \
  268. DebugStr(str); \
  269. } \
  270. } while ( false )
  271. #else
  272. /* DebugStr() is always safe on Carbon under Mac OS X */
  273. /* Otherwise we must make sure a low level debugger is installed */
  274. #define SafeDebugStr(str) \
  275. do \
  276. { \
  277. long response; \
  278. if ( (Gestalt(gestaltSystemVersion, &response) == noErr) && \
  279. (response >= 0x1000) ) \
  280. { \
  281. DebugStr(str); \
  282. } \
  283. else \
  284. { \
  285. if ( ((*((UInt8 *)0x0BFF)) != (UInt8)0xff) && \
  286. (((*((UInt8 *)0x0BFF)) & (UInt8)0xe0) == (UInt8)0x60) && \
  287. ((*((unsigned long *)0x0120)) != 0) && \
  288. ((*((unsigned long *)0x0120)) != (unsigned long)0xffffffff) ) \
  289. { \
  290. DebugStr(str); \
  291. } \
  292. } \
  293. } while ( false )
  294. #endif
  295. /*
  296. * DEBUGGER and DEBUGSTR call SafeDebugger and SafeDebugStr only
  297. * in DEBUG builds.
  298. *
  299. * DEBUGGER and DEBUGSTR are defined only if they are not already defined to
  300. * prevent conflicts with developer code.
  301. */
  302. #ifndef DEBUGGER
  303. #if DEBUG
  304. #define DEBUGGER() \
  305. SafeDebugger()
  306. #else
  307. #define DEBUGGER()
  308. #endif
  309. #endif
  310. #ifndef DEBUGSTR
  311. #if DEBUG
  312. #define DEBUGSTR(str) \
  313. SafeDebugStr(str)
  314. #else
  315. #define DEBUGSTR(str)
  316. #endif
  317. #endif
  318. /*
  319. * CapsLockDebugger and CapsLockDebugStr call SafeDebugger and SafeDebugStr
  320. * only if the Caps Lock key is down.
  321. */
  322. #define CapsLockDebugger() \
  323. do \
  324. { \
  325. KeyMap theKeys; \
  326. GetKeys(theKeys); \
  327. if ( ((theKeys[1] >> 1) & 0x01) != 0 ) \
  328. { \
  329. SafeDebugger(); \
  330. } \
  331. } while ( false )
  332. #define CapsLockDebugStr(str) \
  333. do \
  334. { \
  335. KeyMap theKeys; \
  336. GetKeys(theKeys); \
  337. if ( ((theKeys[1] >> 1) & 0x01) != 0 ) \
  338. { \
  339. SafeDebugStr(str); \
  340. } \
  341. } while ( false )
  342. /*
  343. * ISCAPSLOCKKEYDOWN and ISLOWLEVELDEBUGGERCALLABLE are convenience macros
  344. * which are only defined for non-Carbon builds because they access
  345. * low memory addresses directly. They have been left in this file for
  346. * use by existing non-Carbon code.
  347. *
  348. * ISCAPSLOCKKEYDOWN and ISLOWLEVELDEBUGGERCALLABLE are defined only
  349. * if they are not already defined to prevent conflicts with developer code.
  350. */
  351. #if CALL_NOT_IN_CARBON
  352. #ifndef ISCAPSLOCKKEYDOWN
  353. #define ISCAPSLOCKKEYDOWN() \
  354. ((((UInt16 *)(0x0174))[3] & 0x0002) == 0x0002)
  355. #endif
  356. #ifndef ISLOWLEVELDEBUGGERCALLABLE
  357. #define ISLOWLEVELDEBUGGERCALLABLE() \
  358. ( ((*((UInt8 *)0x0BFF)) != (UInt8)0xff) && \
  359. (((*((UInt8 *)0x0BFF)) & (UInt8)0xe0) == (UInt8)0x60) && \
  360. ((*((unsigned long *)0x0120)) != 0) && \
  361. ((*((unsigned long *)0x0120)) != (unsigned long)0xffffffff) )
  362. #endif
  363. #endif
  364. /*
  365. * You can use DPRINTF as a dprintf which goes away in production builds.
  366. * DPRINTF is not supported by Carbon because dprintf
  367. * is not supported by Carbon.
  368. *
  369. * To use it, double-parenthesize the argument - i.e., use:
  370. *
  371. * DPRINTF(("formatString %d", 5 ));
  372. *
  373. * This is sadly necessary because a macro can not have a variable number
  374. * of arguments.
  375. *
  376. * DPRINTF is defined only if it is not already defined to
  377. * prevent conflicts with developer code.
  378. */
  379. #if DEBUG
  380. #define DPRINTF(x) dprintf x
  381. #else
  382. #define DPRINTF(x) { }
  383. #endif
  384. /*
  385. * kBlessedBusErrorBait is an address that will never be mapped by
  386. * Mac OS 8 or 9. It is close to the middle of the 64K range from 0x68F10000
  387. * to 0x68F1FFFF that is unmapped and cannot be accessed without causing an
  388. * exception. Thus, it's a good value to use for filling uninitialized
  389. * pointers, etc.
  390. *
  391. * Mac OS X programs should NOT use kBlessedBusErrorBait and should use
  392. * zero (0) instead, since by default, page 0 is read and write protected
  393. * for user code.
  394. */
  395. enum {
  396. kBlessedBusErrorBait = 0x68F168F1
  397. };
  398. /*
  399. * DebugAssert()
  400. *
  401. * Summary:
  402. * DebugAssert is the system routine that the DEBUGASSERTMSG macro
  403. * calls (by default) to display assertion messsages. The output
  404. * from DebugAssert can be redirected by installing a
  405. * DebugAssertOutputHandler with InstallDebugAssertOutputHandler.
  406. *
  407. * Parameters:
  408. *
  409. * componentSignature:
  410. * The unique signature of component causing the assertion.
  411. *
  412. * options:
  413. * reserved.
  414. *
  415. * assertionString:
  416. * A pointer to a string containing the assertion, or NULL.
  417. *
  418. * exceptionLabelString:
  419. * A pointer to a string containing the exceptionLabel, or NULL.
  420. *
  421. * errorString:
  422. * A pointer to the error string, or NULL.
  423. *
  424. * fileName:
  425. * A pointer to the fileName or pathname (generated by the
  426. * preprocessor __FILE__ identifier), or NULL.
  427. *
  428. * lineNumber:
  429. * The line number in the file (generated by the preprocessor
  430. * __LINE__ identifier), or 0 (zero).
  431. *
  432. * value:
  433. * A value associated with the assertion, or NULL.
  434. *
  435. * Availability:
  436. * Non-Carbon CFM: in DebugLib 1.0 and later
  437. * CarbonLib: in CarbonLib 1.0 and later
  438. * Mac OS X: in version 10.0 and later
  439. */
  440. EXTERN_API( void )
  441. DebugAssert(
  442. OSType componentSignature,
  443. UInt32 options,
  444. const char * assertionString,
  445. const char * exceptionLabelString,
  446. const char * errorString,
  447. const char * fileName,
  448. long lineNumber,
  449. void * value) TWOWORDINLINE(0x7000, 0xAA7E);
  450. /*
  451. * TaskLevel masks
  452. */
  453. enum {
  454. k68kInterruptLevelMask = 0x00000007, /* 68K interrupt levels 0 through 7 */
  455. kInVBLTaskMask = 0x00000010, /* VBLs are executing */
  456. kInDeferredTaskMask = 0x00000020, /* Deferred tasks are executing */
  457. kInSecondaryIntHandlerMask = 0x00000040, /* Secondary interrupt handlers are executing */
  458. kInNestedInterruptMask = 0x00000080 /* The system is handling an interrupt */
  459. };
  460. /*
  461. * TaskLevel()
  462. *
  463. * Summary:
  464. * TaskLevel returns 0 if we're (probably) running at non-interrupt
  465. * time. There's no way to make this perfect, but this is as close
  466. * as we can get. If TaskLevel doesn't return 0, then one of the
  467. * TaskLevel masks can be used to learn more.
  468. *
  469. * Result:
  470. * The current task level.
  471. *
  472. * Availability:
  473. * Non-Carbon CFM: in DebugLib 1.0 and later
  474. * CarbonLib: in CarbonLib 1.0 and later
  475. * Mac OS X: in version 10.0 and later
  476. */
  477. EXTERN_API( UInt32 )
  478. TaskLevel(void) TWOWORDINLINE(0x7001, 0xAA7E);
  479. /*
  480. * Constants used by the DebugComponent functions
  481. */
  482. enum {
  483. kComponentDebugOption = 0 /* optionSelectorNum to turn breaks for component On or Off*/
  484. };
  485. enum {
  486. kGetDebugOption = 1, /* get current debug option setting*/
  487. kSetDebugOption = 2 /* set debug option*/
  488. };
  489. /*
  490. * DebugComponentCallbackProcPtr
  491. *
  492. * Discussion:
  493. * DebugComponentCallback is the callback into a component that
  494. * registers with DebugLib. It is called to get the debug option
  495. * setting, or to turn a debug option on or off.
  496. *
  497. * Parameters:
  498. *
  499. * optionSelectorNum:
  500. * The component debug option to set.
  501. *
  502. * command:
  503. * The command the DebugComponentCallbackProc must handle:
  504. * kGetDebugOption - get current debug option setting
  505. * kSetDebugOption - set debug option
  506. *
  507. * optionSetting:
  508. * A pointer to a Boolean where the DebugComponentCallbackProc
  509. * must return the option setting: the current setting if command
  510. * is kGetDebugOption; the new debug option if command is
  511. * kSetDebugOption
  512. */
  513. typedef CALLBACK_API( void , DebugComponentCallbackProcPtr )(SInt32 optionSelectorNum, UInt32 command, Boolean *optionSetting);
  514. typedef STACK_UPP_TYPE(DebugComponentCallbackProcPtr) DebugComponentCallbackUPP;
  515. /*
  516. * NewDebugComponent()
  517. *
  518. * Summary:
  519. * NewDebugComponent registers a component with DebugLib.
  520. *
  521. * Parameters:
  522. *
  523. * componentSignature:
  524. * The unique signature of component.
  525. *
  526. * componentName:
  527. * The displayable string naming the component.
  528. *
  529. * componentCallback:
  530. * The callback into component for working with options.
  531. *
  532. * Result:
  533. * An operating system result code: noErr, memFullErr,
  534. * debuggingExecutionContextErr, debuggingDuplicateSignatureErr, or
  535. * debuggingInvalidNameErr.
  536. *
  537. * Availability:
  538. * Non-Carbon CFM: in DebugLib 1.0 and later
  539. * CarbonLib: in CarbonLib 1.0 and later
  540. * Mac OS X: in version 10.0 and later
  541. */
  542. EXTERN_API( OSStatus )
  543. NewDebugComponent(
  544. OSType componentSignature,
  545. ConstStr255Param componentName,
  546. DebugComponentCallbackUPP componentCallback) TWOWORDINLINE(0x7002, 0xAA7E);
  547. /*
  548. * NewDebugOption()
  549. *
  550. * Summary:
  551. * NewDebugOption registers a debug option with DebugLib.
  552. *
  553. * Parameters:
  554. *
  555. * componentSignature:
  556. * The signature of component to register a debug option for.
  557. *
  558. * optionSelectorNum:
  559. * The selector number of this debug option.
  560. *
  561. * optionName:
  562. * The displayable string naming this debug option.
  563. *
  564. * Result:
  565. * An operating system result code: noErr, memFullErr,
  566. * debuggingExecutionContextErr, debuggingDuplicateOptionErr,
  567. * debuggingInvalidSignatureErr, debuggingInvalidNameErr, or
  568. * debuggingNoCallbackErr.
  569. *
  570. * Availability:
  571. * Non-Carbon CFM: in DebugLib 1.0 and later
  572. * CarbonLib: in CarbonLib 1.0 and later
  573. * Mac OS X: in version 10.0 and later
  574. */
  575. EXTERN_API( OSStatus )
  576. NewDebugOption(
  577. OSType componentSignature,
  578. SInt32 optionSelectorNum,
  579. ConstStr255Param optionName) TWOWORDINLINE(0x7003, 0xAA7E);
  580. /*
  581. * DisposeDebugComponent()
  582. *
  583. * Summary:
  584. * DisposeDebugComponent removes a component registration and all
  585. * related debug options from DebugLib.
  586. *
  587. * Parameters:
  588. *
  589. * componentSignature:
  590. * The unique signature of a component.
  591. *
  592. * Result:
  593. * An operating system result code: noErr,
  594. * debuggingExecutionContextErr, or debuggingInvalidSignatureErr.
  595. *
  596. * Availability:
  597. * Non-Carbon CFM: in DebugLib 1.0 and later
  598. * CarbonLib: in CarbonLib 1.0 and later
  599. * Mac OS X: in version 10.0 and later
  600. */
  601. EXTERN_API( OSStatus )
  602. DisposeDebugComponent(OSType componentSignature) TWOWORDINLINE(0x7004, 0xAA7E);
  603. /*
  604. * GetDebugComponentInfo()
  605. *
  606. * Summary:
  607. * GetDebugComponentInfo returns a component registered with
  608. * DebugLib.
  609. *
  610. * Parameters:
  611. *
  612. * index:
  613. * The index into the list of registered components (1-based).
  614. *
  615. * componentSignature:
  616. * A pointer to an OSType where the unique signature of a
  617. * component is returned.
  618. *
  619. * componentName:
  620. * A pointer to an Str255 where the displayable string naming a
  621. * component is returned.
  622. *
  623. * Result:
  624. * An operating system result code: noErr or debuggingNoMatchErr.
  625. *
  626. * Availability:
  627. * Non-Carbon CFM: in DebugLib 1.0 and later
  628. * CarbonLib: in CarbonLib 1.0 and later
  629. * Mac OS X: in version 10.0 and later
  630. */
  631. EXTERN_API( OSStatus )
  632. GetDebugComponentInfo(
  633. UInt32 index,
  634. OSType * componentSignature,
  635. Str255 componentName) TWOWORDINLINE(0x7005, 0xAA7E);
  636. /*
  637. * GetDebugOptionInfo()
  638. *
  639. * Summary:
  640. * GetDebugOptionInfo returns a debug option registered with
  641. * DebugLib.
  642. *
  643. * Parameters:
  644. *
  645. * index:
  646. * The index into the list of registered debug options (0-based);
  647. * 0 = kComponentDebugOption.
  648. *
  649. * componentSignature:
  650. * The unique signature of a component.
  651. *
  652. * optionSelectorNum:
  653. * A pointer to an SInt32 where the selector number of this debug
  654. * option is returned.
  655. *
  656. * optionName:
  657. * A pointer to an Str255 where the displayable string naming this
  658. * debug option is returned.
  659. *
  660. * optionSetting:
  661. * A pointer to an Boolean where the current debug option setting
  662. * is returned.
  663. *
  664. * Result:
  665. * An operating system result code: noErr,
  666. * debuggingInvalidSignatureErr, or debuggingNoMatchErr.
  667. *
  668. * Availability:
  669. * Non-Carbon CFM: in DebugLib 1.0 and later
  670. * CarbonLib: in CarbonLib 1.0 and later
  671. * Mac OS X: in version 10.0 and later
  672. */
  673. EXTERN_API( OSStatus )
  674. GetDebugOptionInfo(
  675. UInt32 index,
  676. OSType componentSignature,
  677. SInt32 * optionSelectorNum,
  678. Str255 optionName,
  679. Boolean * optionSetting) TWOWORDINLINE(0x7006, 0xAA7E);
  680. /*
  681. * SetDebugOptionValue()
  682. *
  683. * Summary:
  684. * SetDebugOptionValue sets a debug option registered with DebugLib.
  685. *
  686. * Parameters:
  687. *
  688. * componentSignature:
  689. * The unique signature of a component.
  690. *
  691. * optionSelectorNum:
  692. * The selector number of this debug option.
  693. *
  694. * newOptionSetting:
  695. * The new debug option setting.
  696. *
  697. * Result:
  698. * An operating system result code: noErr,
  699. * debuggingInvalidSignatureErr, or debuggingInvalidOptionErr.
  700. *
  701. * Availability:
  702. * Non-Carbon CFM: in DebugLib 1.0 and later
  703. * CarbonLib: in CarbonLib 1.0 and later
  704. * Mac OS X: in version 10.0 and later
  705. */
  706. EXTERN_API( OSStatus )
  707. SetDebugOptionValue(
  708. OSType componentSignature,
  709. SInt32 optionSelectorNum,
  710. Boolean newOptionSetting) TWOWORDINLINE(0x7007, 0xAA7E);
  711. /*
  712. * DebugAssertOutputHandlerProcPtr
  713. *
  714. * Discussion:
  715. * DebugAssertOutputHandler is the callback that registers with
  716. * DebugLib to handle the output from DebugAssert. The
  717. * "componentSignature" through "value" parameters are the raw
  718. * values passed to DebugAssert when an exception occurs.
  719. *
  720. * Parameters:
  721. *
  722. * componentSignature:
  723. * The unique signature of component causing the assertion.
  724. *
  725. * options:
  726. * reserved.
  727. *
  728. * assertionString:
  729. * A pointer to a string containing the assertion, or NULL.
  730. *
  731. * exceptionLabelString:
  732. * A pointer to a string containing the exceptionLabel, or NULL.
  733. *
  734. * errorString:
  735. * A pointer to the error string, or NULL.
  736. *
  737. * fileName:
  738. * A pointer to the fileName or pathname (generated by the
  739. * preprocessor __FILE__ identifier), or NULL.
  740. *
  741. * lineNumber:
  742. * The line number in the file (generated by the preprocessor
  743. * __LINE__ identifier), or 0 (zero).
  744. *
  745. * value:
  746. * A value associated with the assertion, or NULL.
  747. *
  748. * outputMsg:
  749. * The string DebugAssert build which would normally be passed to
  750. * DebugStr if a DebugAssertOutputHandler isn't installed.
  751. */
  752. typedef CALLBACK_API( void , DebugAssertOutputHandlerProcPtr )(OSType componentSignature, UInt32 options, const char *assertionString, const char *exceptionLabelString, const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg);
  753. typedef STACK_UPP_TYPE(DebugAssertOutputHandlerProcPtr) DebugAssertOutputHandlerUPP;
  754. /*
  755. * InstallDebugAssertOutputHandler()
  756. *
  757. * Summary:
  758. * InstallDebugAssertOutputHandler installs a
  759. * DebugAssertOutputHandler which DebugAssert calls instead of
  760. * DebugStr.
  761. *
  762. * Parameters:
  763. *
  764. * handler:
  765. * The DebugAssertOutputHandler to install or NULL to switch back
  766. * to the default handler (DebugStr).
  767. *
  768. * Availability:
  769. * Non-Carbon CFM: in DebugLib 1.0 and later
  770. * CarbonLib: in CarbonLib 1.0 and later
  771. * Mac OS X: in version 10.0 and later
  772. */
  773. EXTERN_API( void )
  774. InstallDebugAssertOutputHandler(DebugAssertOutputHandlerUPP handler) TWOWORDINLINE(0x7008, 0xAA7E);
  775. #if CALL_NOT_IN_CARBON
  776. /*
  777. * dprintf()
  778. *
  779. * Summary:
  780. * printf takes a variable argument list and 'prints' that to the
  781. * debugging output handler. Calling dprintf() from anything but C
  782. * or C++ is tricky.
  783. *
  784. * Parameters:
  785. *
  786. * format:
  787. * The format string.
  788. *
  789. * ...:
  790. * The arguments to the format string.
  791. *
  792. * Availability:
  793. * Non-Carbon CFM: in DebugLib 1.1 and later
  794. * CarbonLib: not available
  795. * Mac OS X: not available
  796. */
  797. EXTERN_API_C( void )
  798. dprintf(const char * format, ...) SIXWORDINLINE(0x2057, 0x43EF, 0x0004, 0x303C, 0x000A, 0xAA7E);
  799. /*
  800. * vdprintf()
  801. *
  802. * Summary:
  803. * vdprintf takes a va_args list and 'prints' that to the debugging
  804. * output handler.
  805. *
  806. * Parameters:
  807. *
  808. * format:
  809. * The format string.
  810. *
  811. * va_args_list:
  812. * The va_args list.
  813. *
  814. * Availability:
  815. * Non-Carbon CFM: in DebugLib 1.1 and later
  816. * CarbonLib: not available
  817. * Mac OS X: not available
  818. */
  819. EXTERN_API( void )
  820. vdprintf(
  821. const char * format,
  822. char * va_args_list) TWOWORDINLINE(0x7009, 0xAA7E);
  823. #endif /* CALL_NOT_IN_CARBON */
  824. /*
  825. * NewDebugComponentCallbackUPP()
  826. *
  827. * Availability:
  828. * Non-Carbon CFM: available as macro/inline
  829. * CarbonLib: in CarbonLib 1.0 and later
  830. * Mac OS X: in version 10.0 and later
  831. */
  832. EXTERN_API_C( DebugComponentCallbackUPP )
  833. NewDebugComponentCallbackUPP(DebugComponentCallbackProcPtr userRoutine);
  834. #if !OPAQUE_UPP_TYPES
  835. enum { uppDebugComponentCallbackProcInfo = 0x00000FC0 }; /* pascal no_return_value Func(4_bytes, 4_bytes, 4_bytes) */
  836. #ifdef __cplusplus
  837. inline DEFINE_API_C(DebugComponentCallbackUPP) NewDebugComponentCallbackUPP(DebugComponentCallbackProcPtr userRoutine) { return (DebugComponentCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebugComponentCallbackProcInfo, GetCurrentArchitecture()); }
  838. #else
  839. #define NewDebugComponentCallbackUPP(userRoutine) (DebugComponentCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebugComponentCallbackProcInfo, GetCurrentArchitecture())
  840. #endif
  841. #endif
  842. /*
  843. * NewDebugAssertOutputHandlerUPP()
  844. *
  845. * Availability:
  846. * Non-Carbon CFM: available as macro/inline
  847. * CarbonLib: in CarbonLib 1.0 and later
  848. * Mac OS X: in version 10.0 and later
  849. */
  850. EXTERN_API_C( DebugAssertOutputHandlerUPP )
  851. NewDebugAssertOutputHandlerUPP(DebugAssertOutputHandlerProcPtr userRoutine);
  852. #if !OPAQUE_UPP_TYPES
  853. 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) */
  854. #ifdef __cplusplus
  855. inline DEFINE_API_C(DebugAssertOutputHandlerUPP) NewDebugAssertOutputHandlerUPP(DebugAssertOutputHandlerProcPtr userRoutine) { return (DebugAssertOutputHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebugAssertOutputHandlerProcInfo, GetCurrentArchitecture()); }
  856. #else
  857. #define NewDebugAssertOutputHandlerUPP(userRoutine) (DebugAssertOutputHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebugAssertOutputHandlerProcInfo, GetCurrentArchitecture())
  858. #endif
  859. #endif
  860. /*
  861. * DisposeDebugComponentCallbackUPP()
  862. *
  863. * Availability:
  864. * Non-Carbon CFM: available as macro/inline
  865. * CarbonLib: in CarbonLib 1.0 and later
  866. * Mac OS X: in version 10.0 and later
  867. */
  868. EXTERN_API_C( void )
  869. DisposeDebugComponentCallbackUPP(DebugComponentCallbackUPP userUPP);
  870. #if !OPAQUE_UPP_TYPES
  871. #ifdef __cplusplus
  872. inline DEFINE_API_C(void) DisposeDebugComponentCallbackUPP(DebugComponentCallbackUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  873. #else
  874. #define DisposeDebugComponentCallbackUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  875. #endif
  876. #endif
  877. /*
  878. * DisposeDebugAssertOutputHandlerUPP()
  879. *
  880. * Availability:
  881. * Non-Carbon CFM: available as macro/inline
  882. * CarbonLib: in CarbonLib 1.0 and later
  883. * Mac OS X: in version 10.0 and later
  884. */
  885. EXTERN_API_C( void )
  886. DisposeDebugAssertOutputHandlerUPP(DebugAssertOutputHandlerUPP userUPP);
  887. #if !OPAQUE_UPP_TYPES
  888. #ifdef __cplusplus
  889. inline DEFINE_API_C(void) DisposeDebugAssertOutputHandlerUPP(DebugAssertOutputHandlerUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  890. #else
  891. #define DisposeDebugAssertOutputHandlerUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  892. #endif
  893. #endif
  894. /*
  895. * InvokeDebugComponentCallbackUPP()
  896. *
  897. * Availability:
  898. * Non-Carbon CFM: available as macro/inline
  899. * CarbonLib: in CarbonLib 1.0 and later
  900. * Mac OS X: in version 10.0 and later
  901. */
  902. EXTERN_API_C( void )
  903. InvokeDebugComponentCallbackUPP(
  904. SInt32 optionSelectorNum,
  905. UInt32 command,
  906. Boolean * optionSetting,
  907. DebugComponentCallbackUPP userUPP);
  908. #if !OPAQUE_UPP_TYPES
  909. #ifdef __cplusplus
  910. inline DEFINE_API_C(void) InvokeDebugComponentCallbackUPP(SInt32 optionSelectorNum, UInt32 command, Boolean * optionSetting, DebugComponentCallbackUPP userUPP) { CALL_THREE_PARAMETER_UPP(userUPP, uppDebugComponentCallbackProcInfo, optionSelectorNum, command, optionSetting); }
  911. #else
  912. #define InvokeDebugComponentCallbackUPP(optionSelectorNum, command, optionSetting, userUPP) CALL_THREE_PARAMETER_UPP((userUPP), uppDebugComponentCallbackProcInfo, (optionSelectorNum), (command), (optionSetting))
  913. #endif
  914. #endif
  915. /*
  916. * InvokeDebugAssertOutputHandlerUPP()
  917. *
  918. * Availability:
  919. * Non-Carbon CFM: available as macro/inline
  920. * CarbonLib: in CarbonLib 1.0 and later
  921. * Mac OS X: in version 10.0 and later
  922. */
  923. EXTERN_API_C( void )
  924. InvokeDebugAssertOutputHandlerUPP(
  925. OSType componentSignature,
  926. UInt32 options,
  927. const char * assertionString,
  928. const char * exceptionLabelString,
  929. const char * errorString,
  930. const char * fileName,
  931. long lineNumber,
  932. void * value,
  933. ConstStr255Param outputMsg,
  934. DebugAssertOutputHandlerUPP userUPP);
  935. #if !OPAQUE_UPP_TYPES
  936. #ifdef __cplusplus
  937. inline DEFINE_API_C(void) InvokeDebugAssertOutputHandlerUPP(OSType componentSignature, UInt32 options, const char * assertionString, const char * exceptionLabelString, const char * errorString, const char * fileName, long lineNumber, void * value, ConstStr255Param outputMsg, DebugAssertOutputHandlerUPP userUPP) { CALL_NINE_PARAMETER_UPP(userUPP, uppDebugAssertOutputHandlerProcInfo, componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value, outputMsg); }
  938. #else
  939. #define InvokeDebugAssertOutputHandlerUPP(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value, outputMsg, userUPP) CALL_NINE_PARAMETER_UPP((userUPP), uppDebugAssertOutputHandlerProcInfo, (componentSignature), (options), (assertionString), (exceptionLabelString), (errorString), (fileName), (lineNumber), (value), (outputMsg))
  940. #endif
  941. #endif
  942. #if CALL_NOT_IN_CARBON || OLDROUTINENAMES
  943. /* support for pre-Carbon UPP routines: New...Proc and Call...Proc */
  944. #define NewDebugComponentCallbackProc(userRoutine) NewDebugComponentCallbackUPP(userRoutine)
  945. #define NewDebugAssertOutputHandlerProc(userRoutine) NewDebugAssertOutputHandlerUPP(userRoutine)
  946. #define CallDebugComponentCallbackProc(userRoutine, optionSelectorNum, command, optionSetting) InvokeDebugComponentCallbackUPP(optionSelectorNum, command, optionSetting, userRoutine)
  947. #define CallDebugAssertOutputHandlerProc(userRoutine, componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value, outputMsg) InvokeDebugAssertOutputHandlerUPP(componentSignature, options, assertionString, exceptionLabelString, errorString, fileName, lineNumber, value, outputMsg, userRoutine)
  948. #endif /* CALL_NOT_IN_CARBON */
  949. #ifdef PRAGMA_IMPORT_OFF
  950. #pragma import off
  951. #elif PRAGMA_IMPORT
  952. #pragma import reset
  953. #endif
  954. #ifdef __cplusplus
  955. }
  956. #endif
  957. #endif /* __DEBUGGING__ */