home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / include / Crtdbg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-02  |  15.3 KB  |  581 lines

  1. /***
  2. *crtdbg.h - Supports debugging features of the C runtime library.
  3. *
  4. *       Copyright (c) 1994-1995, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Support CRT debugging features.
  8. *
  9. *       [Public]
  10. *
  11. ****/
  12.  
  13. #ifndef _INC_CRTDBG
  14. #define _INC_CRTDBG
  15.  
  16. #if !defined(_WIN32) && !defined(_MAC)
  17. #error ERROR: Only Mac or Win32 targets supported!
  18. #endif
  19.  
  20.  
  21. #ifdef  __cplusplus
  22. extern "C" {
  23. #endif /* __cplusplus */
  24.  
  25.  
  26. #ifndef _DEBUG
  27.  
  28.  /****************************************************************************
  29.  *
  30.  * Debug OFF
  31.  * Debug OFF
  32.  * Debug OFF
  33.  *
  34.  ***************************************************************************/
  35.  
  36. #define _ASSERT(expr) ((void)0)
  37.  
  38. #define _ASSERTE(expr) ((void)0)
  39.  
  40.  
  41. #define _RPT0(rptno, msg)
  42.  
  43. #define _RPT1(rptno, msg, arg1)
  44.  
  45. #define _RPT2(rptno, msg, arg1, arg2)
  46.  
  47. #define _RPT3(rptno, msg, arg1, arg2, arg3)
  48.  
  49. #define _RPT4(rptno, msg, arg1, arg2, arg3, arg4)
  50.  
  51.  
  52. #define _RPTF0(rptno, msg)
  53.  
  54. #define _RPTF1(rptno, msg, arg1)
  55.  
  56. #define _RPTF2(rptno, msg, arg1, arg2)
  57.  
  58. #define _RPTF3(rptno, msg, arg1, arg2, arg3)
  59.  
  60. #define _RPTF4(rptno, msg, arg1, arg2, arg3, arg4)
  61.  
  62. #define _malloc_dbg(s, t, f, l)         malloc(s)
  63. #define _calloc_dbg(c, s, t, f, l)      calloc(c, s)
  64. #define _realloc_dbg(p, s, t, f, l)     realloc(p, s)
  65. #define _expand_dbg(p, s, t, f, l)      _expand(p, s)
  66. #define _free_dbg(p, t)                 free(p)
  67. #define _msize_dbg(p, t)                _msize(p)
  68. #define _strdup_dbg(s,t,f,l)            strdup(s)
  69. #define __strdup_dbg(s,t,f,l)           _strdup(s)
  70. #define __wcsdup_dbg(s,t,f,l)           _wcsdup(s)
  71. #define unmangle_pt_dbg(s,t,f,l)        unmangle_pt(s)
  72. #define unmangle_ident_dbg(s,t,f,l)     unmangle_ident(s)
  73.  
  74.  
  75. #define _CrtSetReportHook(f)                ((void)0)
  76. #define _CrtSetReportMode(t, f)             ((int)0)
  77. #define _CrtSetReportFile(t, f)             ((void)0)
  78.  
  79. #define _CrtDbgBreak()                      ((void)0)
  80.  
  81. #define _CrtSetBreakAlloc(a)                ((long)0)
  82.  
  83. #define _CrtSetAllocHook(f)                 ((void)0)
  84.  
  85. #define _CrtCheckMemory()                   ((int)1)
  86. #define _CrtSetDbgFlag(f)                   ((int)0)
  87. #define _CrtDoForAllClientObjects(f, c)     ((void)0)
  88. #define _CrtIsValidPointer(p, n, r)         ((int)1)
  89. #define _CrtIsValidHeapPointer(p)           ((int)1)
  90. #define _CrtIsMemoryBlock(p, t, r, f, l)    ((int)1)
  91.  
  92. #define _CrtSetDumpClient(f)                ((void)0)
  93.  
  94. #define _CrtMemCheckpoint(s)                ((void)0)
  95. #define _CrtMemDifference(s1, s2, s3)       ((int)0)
  96. #define _CrtMemDumpAllObjectsSince(s)       ((void)0)
  97. #define _CrtMemDumpStatistics(s)            ((void)0)
  98. #define _CrtDumpMemoryLeaks()               ((int)0)
  99.  
  100.  
  101. #else /* _DEBUG */
  102.  
  103.  
  104.  /****************************************************************************
  105.  *
  106.  * Debug ON
  107.  * Debug ON
  108.  * Debug ON
  109.  *
  110.  ***************************************************************************/
  111.  
  112.  
  113. /* Define _CRTIMP */
  114.  
  115. #ifndef _CRTIMP
  116. #ifdef  _NTSDK
  117. /* definition compatible with NT SDK */
  118. #define _CRTIMP
  119. #else   /* ndef _NTSDK */
  120. /* current definition */
  121. #ifdef  _DLL
  122. #define _CRTIMP __declspec(dllimport)
  123. #else   /* ndef _DLL */
  124. #define _CRTIMP
  125. #endif  /* _DLL */
  126. #endif  /* _NTSDK */
  127. #endif  /* _CRTIMP */
  128.  
  129. #ifndef _SIZE_T_DEFINED
  130. typedef unsigned int size_t;
  131. #define _SIZE_T_DEFINED
  132. #endif
  133.  
  134. /* Define NULL pointer value */
  135.  
  136. #ifndef NULL
  137. #ifdef  __cplusplus
  138. #define NULL    0
  139. #else
  140. #define NULL    ((void *)0)
  141. #endif
  142. #endif
  143.  
  144.  /****************************************************************************
  145.  *
  146.  * Debug Reporting
  147.  *
  148.  ***************************************************************************/
  149.  
  150. typedef void *_HFILE; /* file handle pointer */
  151.  
  152. #define _CRT_WARN           0
  153. #define _CRT_ERROR          1
  154. #define _CRT_ASSERT         2
  155. #define _CRT_ERRCNT         3
  156.  
  157. #define _CRTDBG_MODE_FILE      0x1
  158. #define _CRTDBG_MODE_DEBUG     0x2
  159. #define _CRTDBG_MODE_WNDW      0x4
  160. #define _CRTDBG_REPORT_MODE    -1
  161.  
  162. #define _CRTDBG_INVALID_HFILE ((_HFILE)-1)
  163. #define _CRTDBG_HFILE_ERROR   ((_HFILE)-2)
  164. #define _CRTDBG_FILE_STDOUT   ((_HFILE)-4)
  165. #define _CRTDBG_FILE_STDERR   ((_HFILE)-5)
  166. #define _CRTDBG_REPORT_FILE   ((_HFILE)-6)
  167.  
  168. #if     defined(_DLL) && defined(_M_IX86)
  169. #define _crtAssertBusy   (*__p__crtAssertBusy())
  170. _CRTIMP long * __cdecl __p__crtAssertBusy(void);
  171. #else   /* !(defined(_DLL) && defined(_M_IX86)) */
  172. _CRTIMP extern long _crtAssertBusy;
  173. #endif  /* defined(_DLL) && defined(_M_IX86) */
  174.  
  175. typedef int (__cdecl * _CRT_REPORT_HOOK)(int, char *, int *);
  176.  
  177. _CRTIMP _CRT_REPORT_HOOK __cdecl _CrtSetReportHook(
  178.         _CRT_REPORT_HOOK
  179.         );
  180.  
  181. _CRTIMP int __cdecl _CrtSetReportMode(
  182.         int,
  183.         int
  184.         );
  185.  
  186. _CRTIMP _HFILE __cdecl _CrtSetReportFile(
  187.         int,
  188.         _HFILE
  189.         );
  190.  
  191. _CRTIMP int __cdecl _CrtDbgReport(
  192.         int,
  193.         const char *,
  194.         int,
  195.         const char *,
  196.         const char *,
  197.         ...);
  198.  
  199. /* Asserts */
  200.  
  201. #define _ASSERT(expr) \
  202.         do { if (!(expr) && \
  203.                 (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, NULL))) \
  204.              _CrtDbgBreak(); } while (0)
  205.  
  206. #define _ASSERTE(expr) \
  207.         do { if (!(expr) && \
  208.                 (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, #expr))) \
  209.              _CrtDbgBreak(); } while (0)
  210.  
  211.  
  212. /* Reports with no file/line info */
  213.  
  214. #define _RPT0(rptno, msg) \
  215.         do { if ((1 == _CrtDbgReport(rptno, NULL, 0, NULL, "%s", msg))) \
  216.                 _CrtDbgBreak(); } while (0)
  217.  
  218. #define _RPT1(rptno, msg, arg1) \
  219.         do { if ((1 == _CrtDbgReport(rptno, NULL, 0, NULL, msg, arg1))) \
  220.                 _CrtDbgBreak(); } while (0)
  221.  
  222. #define _RPT2(rptno, msg, arg1, arg2) \
  223.         do { if ((1 == _CrtDbgReport(rptno, NULL, 0, NULL, msg, arg1, arg2))) \
  224.                 _CrtDbgBreak(); } while (0)
  225.  
  226. #define _RPT3(rptno, msg, arg1, arg2, arg3) \
  227.         do { if ((1 == _CrtDbgReport(rptno, NULL, 0, NULL, msg, arg1, arg2, arg3))) \
  228.                 _CrtDbgBreak(); } while (0)
  229.  
  230. #define _RPT4(rptno, msg, arg1, arg2, arg3, arg4) \
  231.         do { if ((1 == _CrtDbgReport(rptno, NULL, 0, NULL, msg, arg1, arg2, arg3, arg4))) \
  232.                 _CrtDbgBreak(); } while (0)
  233.  
  234.  
  235. /* Reports with file/line info */
  236.  
  237. #define _RPTF0(rptno, msg) \
  238.         do { if ((1 == _CrtDbgReport(rptno, __FILE__, __LINE__, NULL, "%s", msg))) \
  239.                 _CrtDbgBreak(); } while (0)
  240.  
  241. #define _RPTF1(rptno, msg, arg1) \
  242.         do { if ((1 == _CrtDbgReport(rptno, __FILE__, __LINE__, NULL, msg, arg1))) \
  243.                 _CrtDbgBreak(); } while (0)
  244.  
  245. #define _RPTF2(rptno, msg, arg1, arg2) \
  246.         do { if ((1 == _CrtDbgReport(rptno, __FILE__, __LINE__, NULL, msg, arg1, arg2))) \
  247.                 _CrtDbgBreak(); } while (0)
  248.  
  249. #define _RPTF3(rptno, msg, arg1, arg2, arg3) \
  250.         do { if ((1 == _CrtDbgReport(rptno, __FILE__, __LINE__, NULL, msg, arg1, arg2, arg3))) \
  251.                 _CrtDbgBreak(); } while (0)
  252.  
  253. #define _RPTF4(rptno, msg, arg1, arg2, arg3, arg4) \
  254.         do { if ((1 == _CrtDbgReport(rptno, __FILE__, __LINE__, NULL, msg, arg1, arg2, arg3, arg4))) \
  255.                 _CrtDbgBreak(); } while (0)
  256.  
  257. #if     defined(_M_IX86) && !defined(_CRT_PORTABLE)
  258. #define _CrtDbgBreak() __asm { int 3 }
  259. #elif   defined(_M_ALPHA) && !defined(_CRT_PORTABLE)
  260. void _BPT();
  261. #pragma intrinsic(_BPT)
  262. #define _CrtDbgBreak() _BPT()
  263. #else
  264. _CRTIMP void __cdecl _CrtDbgBreak(
  265.         void
  266.         );
  267. #endif
  268.  
  269.  /****************************************************************************
  270.  *
  271.  * Heap routines
  272.  *
  273.  ***************************************************************************/
  274.  
  275. #ifdef _CRTDBG_MAP_ALLOC
  276.  
  277. #define   malloc(s)             _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
  278. #define   calloc(c, s)          _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  279. #define   realloc(p, s)         _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  280. #define   _expand(p, s)         _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  281. #define   free(p)               _free_dbg(p, _NORMAL_BLOCK)
  282. #define   _msize(p)             _msize_dbg(p, _NORMAL_BLOCK)
  283. #define   _strdup(s)            __strdup_dbg(s,_NORMAL_BLOCK,__FILE__, __LINE__)
  284. #define   strdup(s)             _strdup_dbg(s,_NORMAL_BLOCK,__FILE__,__LINE__)
  285. #define   _wcsdup(s)            __wcsdup_dbg(s,_NORMAL_BLOCK,__FILE__,__LINE__)
  286. #define   handle_malloc(s)      _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
  287. #define   handle_calloc(c)      _calloc_dbg((c), 1, _NORMAL_BLOCK, __FILE__, __LINE__)
  288. #define   handle_realloc(p,s)   _realloc_dbg((p), (s), _NORMAL_BLOCK, __FILE__, __LINE__)
  289. #define   handle_free(p)        _free_dbg(p, _NORMAL_BLOCK)
  290. #define   handle_strdup(s)        _strdup_dbg(s,_NORMAL_BLOCK,__FILE__,__LINE__)
  291. #define   unmangle_pt(s)        unmangle_pt_dbg(s,_NORMAL_BLOCK,__FILE__,__LINE__)
  292. #define   unmangle_ident(s)     unmangle_ident_dbg(s,_NORMAL_BLOCK,__FILE__,__LINE__)
  293. #define   __UNMANGLE_DEFINED   1
  294.  
  295. #endif /* _CRTDBG_MAP_ALLOC */
  296.  
  297. #if     defined(_DLL) && defined(_M_IX86)
  298. #define _crtBreakAlloc   (*__p__crtBreakAlloc())
  299. _CRTIMP long * __cdecl __p__crtBreakAlloc(void);
  300. #else   /* !(defined(_DLL) && defined(_M_IX86)) */
  301. _CRTIMP extern long _crtBreakAlloc;      /* Break on this allocation */
  302. #endif  /* defined(_DLL) && defined(_M_IX86) */
  303.  
  304. _CRTIMP long __cdecl _CrtSetBreakAlloc(
  305.         long
  306.         );
  307.  
  308. /*
  309.  * Prototypes for malloc, free, realloc, etc are in malloc.h
  310.  */
  311.  
  312. _CRTIMP void * __cdecl _malloc_dbg(
  313.         size_t,
  314.         int,
  315.         const char *,
  316.         int
  317.         );
  318.  
  319. _CRTIMP void * __cdecl _calloc_dbg(
  320.         size_t,
  321.         size_t,
  322.         int,
  323.         const char *,
  324.         int
  325.         );
  326.  
  327. _CRTIMP void * __cdecl _realloc_dbg(
  328.         void *,
  329.         size_t,
  330.         int,
  331.         const char *,
  332.         int
  333.         );
  334.  
  335. _CRTIMP void * __cdecl _expand_dbg(
  336.         void *,
  337.         size_t,
  338.         int,
  339.         const char *,
  340.         int
  341.         );
  342.  
  343. _CRTIMP void __cdecl _free_dbg(
  344.         void *,
  345.         int
  346.         );
  347.  
  348. _CRTIMP size_t __cdecl _msize_dbg (
  349.         void *,
  350.         int
  351.         );
  352.  
  353. _CRTIMP char * __cdecl _strdup_dbg(
  354.         const char *,
  355.         int,
  356.         const char *,
  357.         int
  358.         );
  359.  
  360.  
  361. _CRTIMP char * __cdecl __strdup_dbg(
  362.         const char *,
  363.         int,
  364.         const char *,
  365.         int
  366.         );
  367.  
  368.  
  369. #if !defined(_WCHAR_T_DEFINED)
  370. typedef unsigned short wchar_t;
  371. #define _WCHAR_T_DEFINED 1
  372. #endif
  373.  
  374.  
  375. _CRTIMP wchar_t * __cdecl __wcsdup_dbg(
  376.         const wchar_t *,
  377.         int,
  378.         const char *,
  379.         int
  380.         );
  381.  
  382. _CRTIMP char * __cdecl unmangle_pt_dbg(
  383.         const char **,
  384.         int,
  385.         const char *,
  386.         int
  387.         );
  388.  
  389. _CRTIMP char * __cdecl unmangle_ident_dbg(
  390.         const char *,
  391.         int,
  392.         const char *,
  393.         int
  394.         );
  395.  
  396.  /****************************************************************************
  397.  *
  398.  * Client-defined allocation hook
  399.  *
  400.  ***************************************************************************/
  401.  
  402. #define _HOOK_ALLOC     1
  403. #define _HOOK_REALLOC   2
  404. #define _HOOK_FREE      3
  405.  
  406. typedef int (__cdecl * _CRT_ALLOC_HOOK)(int, void *, size_t, int, long, const char *, int);
  407.  
  408. _CRTIMP _CRT_ALLOC_HOOK __cdecl _CrtSetAllocHook(
  409.         _CRT_ALLOC_HOOK
  410.         );
  411.  
  412.  
  413.  /****************************************************************************
  414.  *
  415.  * Memory management
  416.  *
  417.  ***************************************************************************/
  418.  
  419. /*
  420.  * Bitfield flag that controls CRT heap behavior
  421.  * Default setting is _CRTDBG_ALLOC_MEM_DF
  422.  */
  423.  
  424. #if     defined(_DLL) && defined(_M_IX86)
  425. #define _crtDbgFlag   (*__p__crtDbgFlag())
  426. _CRTIMP int * __cdecl __p__crtDbgFlag(void);
  427. #else   /* !(defined(_DLL) && defined(_M_IX86)) */
  428. _CRTIMP extern int _crtDbgFlag;
  429. #endif  /* defined(_DLL) && defined(_M_IX86) */
  430.  
  431. /*
  432.  * Bit values for _crtDbgFlag flag:
  433.  *
  434.  * These bitflags control debug heap behavior.
  435.  */
  436.  
  437. #define _CRTDBG_ALLOC_MEM_DF        0x01  /* Turn on debug allocation */
  438. #define _CRTDBG_DELAY_FREE_MEM_DF   0x02  /* Don't actually free memory */
  439. #define _CRTDBG_CHECK_ALWAYS_DF     0x04  /* Check heap every alloc/dealloc */
  440. #define _CRTDBG_RESERVED_DF         0x08  /* Reserved - do not use */
  441. #define _CRTDBG_CHECK_CRT_DF        0x10  /* Leak check/diff CRT blocks */
  442. #define _CRTDBG_LEAK_CHECK_DF       0x20  /* Leak check at program exit */
  443.  
  444. #define _CRTDBG_REPORT_FLAG     -1    /* Query bitflag status */
  445.  
  446. #define _BLOCK_TYPE(block)       (block & 0xFFFF)
  447. #define _BLOCK_SUBTYPE(block)    (block >> 16 & 0xFFFF)
  448.  
  449. _CRTIMP int __cdecl _CrtCheckMemory(
  450.         void
  451.         );
  452.  
  453. _CRTIMP int __cdecl _CrtSetDbgFlag(
  454.         int
  455.         );
  456.  
  457. _CRTIMP void __cdecl _CrtDoForAllClientObjects(
  458.         void (*pfn)(void *, void *),
  459.         void *
  460.         );
  461.  
  462. _CRTIMP int __cdecl _CrtIsValidPointer(
  463.         const void *,
  464.         unsigned int,
  465.         int
  466.         );
  467.  
  468. _CRTIMP int __cdecl _CrtIsValidHeapPointer(
  469.         const void *
  470.         );
  471.  
  472. _CRTIMP int __cdecl _CrtIsMemoryBlock(
  473.         const void *,
  474.         unsigned int,
  475.         long *,
  476.         char **,
  477.         int *
  478.         );
  479.  
  480.  
  481.  /****************************************************************************
  482.  *
  483.  * Memory state
  484.  *
  485.  ***************************************************************************/
  486.  
  487. /* Memory block identification */
  488. #define _FREE_BLOCK      0
  489. #define _NORMAL_BLOCK    1
  490. #define _CRT_BLOCK       2
  491. #define _IGNORE_BLOCK    3
  492. #define _CLIENT_BLOCK    4
  493. #define _MAX_BLOCKS      5
  494.  
  495. typedef void (__cdecl * _CRT_DUMP_CLIENT)(void *, size_t);
  496.  
  497. _CRTIMP _CRT_DUMP_CLIENT __cdecl _CrtSetDumpClient(
  498.         _CRT_DUMP_CLIENT
  499.         );
  500.  
  501. typedef struct _CrtMemState
  502. {
  503.         struct _CrtMemBlockHeader * pBlockHeader;
  504.         unsigned long lCounts[_MAX_BLOCKS];
  505.         unsigned long lSizes[_MAX_BLOCKS];
  506.         unsigned long lHighWaterCount;
  507.         unsigned long lTotalCount;
  508. } _CrtMemState;
  509.  
  510.  
  511. _CRTIMP void __cdecl _CrtMemCheckpoint(
  512.         _CrtMemState *
  513.         );
  514.  
  515. _CRTIMP int __cdecl _CrtMemDifference(
  516.         _CrtMemState *,
  517.         const _CrtMemState *,
  518.         const _CrtMemState *
  519.         );
  520.  
  521. _CRTIMP void __cdecl _CrtMemDumpAllObjectsSince(
  522.         const _CrtMemState *
  523.         );
  524.  
  525. _CRTIMP void __cdecl _CrtMemDumpStatistics(
  526.         const _CrtMemState *
  527.         );
  528.  
  529. _CRTIMP int __cdecl _CrtDumpMemoryLeaks(
  530.         void
  531.         );
  532.  
  533. #endif /* _DEBUG */
  534.  
  535. #ifdef __cplusplus
  536. }
  537.  
  538. #ifndef _DEBUG
  539.  
  540.  /****************************************************************************
  541.  *
  542.  * Debug OFF
  543.  * Debug OFF
  544.  * Debug OFF
  545.  *
  546.  ***************************************************************************/
  547.  
  548. inline void* __cdecl operator new(unsigned int s, int, const char *, int)
  549.         { return ::operator new(s); }
  550.  
  551. #else /* _DEBUG */
  552.  
  553.  /****************************************************************************
  554.  *
  555.  * Debug ON
  556.  * Debug ON
  557.  * Debug ON
  558.  *
  559.  ***************************************************************************/
  560.  
  561.  void * __cdecl operator new(
  562.         unsigned int,
  563.         int,
  564.         const char *,
  565.         int
  566.         );
  567.  
  568. #ifdef _CRTDBG_MAP_ALLOC
  569.  
  570. inline void* __cdecl operator new(unsigned int s)
  571.         { return ::operator new(s, _NORMAL_BLOCK, __FILE__, __LINE__); }
  572.  
  573. #endif /* _CRTDBG_MAP_ALLOC */
  574.  
  575. #endif /* _DEBUG */
  576.  
  577. #endif /* __cplusplus */
  578.  
  579.  
  580. #endif /* _INC_CRTDBG */
  581.