home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / DEBUG / DEBUG.H < prev    next >
C/C++ Source or Header  |  1996-01-05  |  4KB  |  114 lines

  1. /****************************************************************************
  2.     $Id: debug.h 501.0 1995/03/07 12:26:50 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:     Ron van der Wal
  8.  
  9.     Macros and auxiliary functions for debugging purposes. Normally, these
  10.     macros are defined, but #defining NDEBUG prior to including this file
  11.     will turn them into empty space or null statements, as appropriate.
  12.  
  13.     Debugging macros
  14.     ----------------
  15.  
  16.     TLX_DEBUG_BREAK;
  17.  
  18.          - Inserts a debugger breakpoint.
  19.  
  20.     TLX_DEBUG_CODE( code )
  21.  
  22.     - Inserts 'code' as source code if debugging, else discards it.
  23.  
  24.     TLX_DEBUG_BLOCK { code }
  25.  
  26.     - Creates a source block (with its own private scope) if debugging,
  27.       else turns into a never-executed (and probably optimized away)
  28.       statement.
  29.  
  30.     Warning for Macintosh users:
  31.  
  32.         The code for the TLX_DEBUG_BREAK macro (if defined) executes the
  33.         Macintosh Toolbox Debugger() trap. If no debugger is running at
  34.         the time the trap is executed, a system error (ID = -12) will
  35.         occur and the system must be restarted. Therefore, be sure to
  36.         use TLX_DEBUG_BREAK only if you are running the program with a
  37.     debugger or have MacsBug or another resident debugger installed.
  38.  
  39.         If NDEBUG is #defined, TLX_DEBUG_BREAK does not generate any code
  40.     and may be used safely with any system configuration.
  41.  
  42.         There seems to be no reliable way to check whether the debugger
  43.         trap is implemented; the TrapAvailable() function fails to find
  44.         the trap installed when the THINK C/C++ debugger is running,
  45.         although that debugger will catch the trap if it is executed.
  46.  
  47.     $Log: debug.h $
  48.     Revision 501.0  1995/03/07 12:26:50  RON
  49.     Updated for TLX 5.01
  50.     Revision 1.2  1995/02/28 15:18:16  RON
  51.     Update for release 012
  52.     Added partial support for SunPro C++ compiler
  53.     Revision 1.1  1995/01/05  15:35:52  ron
  54.     Initial revision
  55.  
  56.     Revision 1.1  1994/11/16  15:25:52  ron
  57.     Initial revision
  58.  
  59. ****************************************************************************/
  60.  
  61. #ifndef _TLX_DEBUG_H
  62. #define _TLX_DEBUG_H
  63.  
  64. #ifndef _TLX_TLX_H
  65. #include <tlx\501\tlx.h>
  66. #endif
  67.  
  68. #ifdef NDEBUG
  69. /*---------------------------------------------------------------------------
  70.     Debugging macros when not debugging - resolve to null code
  71. ---------------------------------------------------------------------------*/
  72.  
  73. #define TLX_DEBUG_CODE(x)
  74. #define TLX_DEBUG_BLOCK        while (0)
  75. #define TLX_DEBUG_BREAK        ((void)0)
  76.  
  77. #else
  78. /*---------------------------------------------------------------------------
  79.     Debugging macros when debugging - resolve to actual code
  80. ---------------------------------------------------------------------------*/
  81.  
  82. #define TLX_DEBUG_CODE(x)    x
  83. #define TLX_DEBUG_BLOCK
  84.  
  85. #if _CPU_I86
  86.   #if defined(__IBMCPP__)
  87.     #ifndef __builtin_h
  88.     #include <builtin.h>
  89.     #endif
  90.     #define _tlBreak() _interrupt(3)
  91.   #elif defined(__TURBOC__)
  92.     #define _tlBreak() __emit__((byte_t)0xCC)
  93.   #elif defined(__WATCOMC__)
  94.     extern void _tlBreak(void);
  95.     #pragma aux _tlBreak = "int 3"
  96.   #elif defined(__ZTC__) && __ZTC__ < 0x700
  97.     #define _tlBreak() asm((byte_t)0xCC)
  98.   #else
  99.     #define _tlBreak() do { _asm { int 3 } } while(0)
  100.   #endif
  101. #elif OS_MAC
  102.     inline void _tlBreak() { Debugger(); }
  103. #elif _CPU_SPARC
  104.     #define _tlBreak()        // Leave undefined for now
  105. #else
  106.     #error Unsupported CPU type; contact Tarma Software Research
  107. #endif
  108.  
  109. #define TLX_DEBUG_BREAK          _tlBreak()
  110.  
  111. #endif  // NDEBUG
  112.  
  113. #endif    // _TLX_DEBUG_H
  114.