1/* 2 * Copyright (c) 2009 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 File: DebugMacros.h 25 26 Contains: xxx put contents here xxx 27 28 Version: xxx put version here xxx 29 30 Copyright: � 1999 by Apple Computer, Inc., all rights reserved. 31 32 File Ownership: 33 34 DRI: xxx put dri here xxx 35 36 Other Contact: xxx put other contact here xxx 37 38 Technology: xxx put technology here xxx 39 40 Writers: 41 42 (RS) Richard Sepulveda 43 44 Change History (most recent first): 45 46 <2> 6/28/99 RS Added new macro FailMessageVal(). 47 <1> 6/7/99 RS first checked in 48 <2> 6/7/99 RS Added additional debug macros that will allow the programmer to 49 include an additional string and value in the DebugStr message. 50*/ 51 52#ifndef __DEBUGMACROS__ 53#define __DEBUGMACROS__ 54 55#include <DriverServices.h> 56#include <NumberFormatting.h> 57 58#include "OxcartDebug.h" 59 60#undef AssertionFailed 61 62// if/branch macro 63#define BranchIf(condition, label) if((condition)) goto label; 64 65#define AssertionMessage(cond, file, line, handler) \ 66 "\pAssertion \"" #cond "\" failed in " #file " at line " #line " goto " #handler 67 68#define AssertionFailed(cond, file, line, handler) \ 69 OXCART_DEBUGSTR( (StringPtr) AssertionMessage (cond, file, line, handler) ); 70 71#define AssertionMessageString(cond, file, line, handler) \ 72 "\pAssertion \"" #cond "\" failed in " #file " at line " #line " goto " #handler " value -> " 73 74#define AssertionFailedString(cond, file, line, handler, str) \ 75 { \ 76 Str255 mystr21; \ 77 PStrCopy( mystr21, AssertionMessageString (cond, file, line, handler)); \ 78 PStrCat( mystr21, str); \ 79 DebugStr( mystr21); \ 80 } 81 82#ifdef DEBUG 83#define FailWithVal(cond, handler, num) \ 84 if (cond) { \ 85 Str255 mystr; \ 86 NumToString( num, mystr); \ 87 AssertionFailedString(cond, __FILE__, __LINE__, handler, mystr) \ 88 goto handler; \ 89 } 90#else 91#define FailWithVal(cond, handler,num) \ 92 if (cond) { \ 93 goto handler; \ 94 } 95#endif DEBUG 96 97#ifdef DEBUG 98#define FailWithStringVal(cond, handler, str, num) \ 99 if (cond) { \ 100 Str255 mystr, mystr2; \ 101 NumToString( num, mystr); \ 102 PStrCopy( mystr2, str); \ 103 PStrCat( mystr2, mystr); \ 104 AssertionFailedString(cond, __FILE__, __LINE__, handler, mystr2) \ 105 goto handler; \ 106 } 107#else 108#define FailWithStringVal(cond, handler, str, num) \ 109 if (cond) { \ 110 goto handler; \ 111 } 112#endif DEBUG 113 114#ifdef DEBUG 115#define FailWithString(cond, handler, str) \ 116 if (cond) { \ 117 AssertionFailedString(cond, __FILE__, __LINE__, handler, str) \ 118 goto handler; \ 119 } 120#else 121#define FailWithString(cond, handler, str, num) \ 122 if (cond) { \ 123 goto handler; \ 124 } 125#endif DEBUG 126 127// This checks for the exception, and if true then goto handler 128#ifdef DEBUG 129#define FailIf(cond, handler) \ 130 if (cond) { \ 131 AssertionFailed(cond, __FILE__, __LINE__, handler) \ 132 goto handler; \ 133 } 134#else 135#define FailIf(cond, handler) \ 136 if (cond) { \ 137 goto handler; \ 138 } 139#endif 140 141#ifdef DEBUG 142#define FailWithActionVal(cond, action, handler, num) \ 143 if (cond) { \ 144 Str255 mystr; \ 145 NumToString( num, mystr); \ 146 AssertionFailedString(cond, __FILE__, __LINE__, handler, mystr) \ 147 { action; } \ 148 goto handler; \ 149 } 150#else 151#define FailWithActionVal(cond, action, handler, num) \ 152 if (cond) { \ 153 { action; } \ 154 goto handler; \ 155 } 156#endif DEBUG 157 158// This checks for the exception, and if true do the action and goto handler 159#ifdef DEBUG 160#define FailWithAction(cond, action, handler) \ 161 if (cond) { \ 162 AssertionFailed(cond, __FILE__, __LINE__, handler) \ 163 { action; } \ 164 goto handler; \ 165 } 166#else 167#define FailWithAction(cond, action, handler) \ 168 if (cond) { \ 169 { action; } \ 170 goto handler; \ 171 } 172#endif 173 174// This will insert debugging code in the application to check conditions 175// and displays the condition in the debugger if true. This code is 176// completely removed in non-debug builds. 177 178#ifdef DEBUG 179#define FailMessage(cond) if (cond) AssertionFailed(cond, __FILE__, __LINE__, handler) 180#else 181#define FailMessage(cond) {} 182#endif 183 184#ifdef DEBUG 185#define FailMessageVal(cond, num) \ 186 if (cond) { \ 187 Str255 __mystr; \ 188 NumToString( num, __mystr); \ 189 AssertionFailedString(cond, __FILE__, __LINE__, handler, __mystr) \ 190 } 191#else 192#define FailMessageVal(cond, num) {} 193#endif 194 195// This allows you to test for the result of a condition (i.e. CloseComponent) 196// and break if it returns a non zero result, otherwise it ignores the result. 197// When a non-debug build is done, the result is ignored. 198 199#ifdef DEBUG 200#define ErrorMessage(cond) if (cond) AssertionFailed(cond, __FILE__, __LINE__, handler) 201#else 202#define ErrorMessage(cond) (cond) 203#endif 204 205// This will display a given message in the debugger, this code is completely 206// removed in non-debug builds. 207 208#ifdef DEBUG 209#define DebugMessage(s) DebugString((ConstStr255Param)s) 210#else 211#define DebugMessage(s) {} 212#endif 213 214// ��� THESE MACROS ARE ONLY ACTIVE IF DEBUGVERBOSE IS DEFINED ��� 215// This checks for the exception, and if true then goto handler 216 217#if defined(DEBUG) && defined(DEBUGVERBOSE) 218#define FailIfVerbose(cond, handler) \ 219 if (cond) { \ 220 AssertionFailed(cond, __FILE__, __LINE__, handler) \ 221 goto handler; \ 222 } 223#else 224#define FailIfVerbose(cond, handler) \ 225 if (cond) { \ 226 goto handler; \ 227 } 228#endif 229 230// This checks for the exception, and if true do the action and goto handler 231 232#if defined(DEBUG) && defined(DEBUGVERBOSE) 233#define FailWithActionVerbose(cond, action, handler) \ 234 if (cond) { \ 235 AssertionFailed(cond, __FILE__, __LINE__, handler) \ 236 { action; } \ 237 goto handler; \ 238 } 239#else 240#define FailWithActionVerbose(cond, action, handler) \ 241 if (cond) { \ 242 { action; } \ 243 goto handler; \ 244 } 245#endif 246 247// This will insert debugging code in the application to check conditions 248// and displays the condition in the debugger if true. This code is 249// completely removed in non-debug builds. 250 251#if defined(DEBUG) && defined(DEBUGVERBOSE) 252#define FailMessageVerbose(cond) if (cond) AssertionFailed(cond, __FILE__, __LINE__, handler) 253#else 254#define FailMessageVerbose(cond) {} 255#endif 256 257// This allows you to test for the result of a condition (i.e. CloseComponent) 258// and break if it returns a non zero result, otherwise it ignores the result. 259// When a non-debug build is done, the result is ignored. 260 261#if defined(DEBUG) && defined(DEBUGVERBOSE) 262#define ErrorMessageVerbose(cond) if (cond) AssertionFailed(cond, __FILE__, __LINE__, handler) 263#else 264#define ErrorMessageVerbose(cond) (cond) 265#endif 266 267// This will insert debugging code in the application to check conditions 268// and displays the condition in the debugger if true. This code is 269// completely removed in non-debug builds. 270 271#ifdef DEBUG 272#define VDQFailMessage(cond,s) \ 273 if (cond) { \ 274 DebugStr ((ConstStr255Param)"\p"#s); \ 275 } 276#else 277#define VDQFailMessage(cond, s) \ 278 ((void) 0) 279#endif DEBUG 280 281// This allows you to test for the result of a condition (i.e. CloseComponent) 282// and break if it returns a non zero result, otherwise it ignores the result. 283// When a non-debug build is done, the result is ignored. 284 285#ifdef DEBUG 286#define VDQErrorMessage(cond) if (cond) DebugStr((ConstStr255Param)"\p"#cond) 287#else 288#define VDQErrorMessage(cond) (cond) 289#endif DEBUG 290 291// This will display a given message in the debugger, this code is completely 292// removed in non-debug builds. 293 294#ifdef DEBUG 295#define VDQDebugMessage(s) DebugStr ((ConstStr255Param)"\p"#s) 296#else 297#define VDQDebugMessage(s) ((void) 0) 298#endif DEBUG 299 300 301#if 0 302//#ifdef DEBUG 303 304#undef DisposHandle 305#define DisposeHandle(thandle) { DisposeHandle(thandle); if (MemError() != noErr) DebugMessage(wackyHandle); } 306#define DisposHandle DisposeHandle 307 308#undef DisposPtr 309#define DisposePtr(tptr) { DisposePtr(tptr); if (MemError() != noErr) DebugMessage(wackyPointer); } 310#define DisposPtr DisposePtr 311 312#endif 313 314#endif 315