home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / DesktopDoubler / Common / Sources / DebugUtils.c next >
Encoding:
C/C++ Source or Header  |  1999-06-25  |  1.7 KB  |  118 lines  |  [TEXT/CWIE]

  1. #include <stdarg.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <Timer.h>
  5. #include "DebugUtils.h"
  6.  
  7.  
  8.  
  9.  
  10.  
  11. #if DEBUG && CALLTRACE
  12.     #if TARGET_RT_MAC_CFM
  13.         UInt32                CallTrace::fLevel = 0;
  14.     #elif TARGET_CPU_68K
  15.         #ifdef __cplusplus
  16.         extern "C" {
  17.         #endif
  18.         
  19.         static UInt32 GetCallTraceStorage(void);
  20.         #define fLevel        *((UInt32*)GetCallTraceStorage())
  21.         
  22.         #ifdef __cplusplus
  23.         }
  24.         #endif
  25.     #endif
  26. #endif
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #if DEBUG && CALLTRACE
  33.     CallTrace::CallTrace(char *func)
  34.     {
  35.         dprintf(kDConPrefix "%*s=> %s\n",2 * fLevel,"",func);
  36.         fLevel += 1;
  37.         fName = func;
  38.         
  39.         #if CALLTRACE_TIMER
  40.             Microseconds((UnsignedWide*)&fTime);
  41.         #endif
  42.     }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.     CallTrace::~CallTrace(void)
  49.     {
  50.         #if CALLTRACE_TIMER
  51.             UInt64    time;
  52.             Microseconds((UnsignedWide*)&time);
  53.         #endif
  54.         
  55.         fLevel -= 1;
  56.         
  57.         #if CALLTRACE_TIMER
  58.             dprintf(kDConPrefix "%*s<= %s %.03fms\n",2 * fLevel,"",fName,((double)time - (double)fTime) / 1000.0);
  59.         #else
  60.             dprintf(kDConPrefix "%*s<= %s\n",2 * fLevel,"",fName);
  61.         #endif
  62.     }
  63. #endif
  64.  
  65.  
  66.  
  67.  
  68.  
  69. #if DEBUG && CALLTRACE && TARGET_CPU_68K && !CALLTRACE_GLOBALS
  70.     asm UInt32 GetCallTraceStorage(void)
  71.     {
  72.         LEA        @Storage,A0
  73.         MOVE.L    A0,D0
  74.         RTS
  75.                 
  76.     @Storage:
  77.         DC.L    0x00000000
  78.     }
  79. #endif
  80.  
  81.  
  82.  
  83.  
  84.  
  85. #if DEBUG
  86.     void DebugStrf(char *format,...)
  87.     {
  88.         Str255        text;
  89.         va_list        args;
  90.         
  91.         
  92.         // Convert to pstring.
  93.         va_start(args,format);
  94.         text[0] = vsprintf((char*)&text[1],format,args);
  95.         va_end(args);
  96.         
  97.         DebugStr(text);
  98.     }
  99.     
  100.     void BinaryPrintout(UInt32 val, int numBits)
  101.     {
  102.         int i;
  103.         
  104.         // Output the bit numbers, one every 3 characters
  105.         dprintf(kDConPrefix "Bit  ");
  106.         for (i=numBits-1; i>=0; --i)
  107.             dprintf(" %2d",i);
  108.         dprintf("\n");
  109.         
  110.         // Now output the actual bits
  111.         dprintf(kDConPrefix "Value");
  112.         for (i=numBits-1; i>=0; --i)
  113.             dprintf(" %2d", (val>>i)&1);
  114.         dprintf("\n");
  115.     }
  116. #endif
  117.  
  118.