1da2e3ebdSchin /*********************************************************************** 2da2e3ebdSchin * * 3da2e3ebdSchin * This software is part of the ast package * 4*3e14f97fSRoger A. Faulkner * Copyright (c) 1985-2010 AT&T Intellectual Property * 5da2e3ebdSchin * and is licensed under the * 6da2e3ebdSchin * Common Public License, Version 1.0 * 77c2fbfb3SApril Chin * by AT&T Intellectual Property * 8da2e3ebdSchin * * 9da2e3ebdSchin * A copy of the License is available at * 10da2e3ebdSchin * http://www.opensource.org/licenses/cpl1.0.txt * 11da2e3ebdSchin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12da2e3ebdSchin * * 13da2e3ebdSchin * Information and Software Systems Research * 14da2e3ebdSchin * AT&T Research * 15da2e3ebdSchin * Florham Park NJ * 16da2e3ebdSchin * * 17da2e3ebdSchin * Glenn Fowler <gsf@research.att.com> * 18da2e3ebdSchin * David Korn <dgk@research.att.com> * 19da2e3ebdSchin * Phong Vo <kpv@research.att.com> * 20da2e3ebdSchin * * 21da2e3ebdSchin ***********************************************************************/ 22da2e3ebdSchin #pragma prototyped 23da2e3ebdSchin /* 24da2e3ebdSchin * common ast debug definitions 25da2e3ebdSchin * include after the ast headers 26da2e3ebdSchin */ 27da2e3ebdSchin 28da2e3ebdSchin #ifndef _DEBUG_H 29da2e3ebdSchin #define _DEBUG_H 30da2e3ebdSchin 31da2e3ebdSchin #include <ast.h> 32da2e3ebdSchin #include <error.h> 33da2e3ebdSchin 347c2fbfb3SApril Chin #if !defined(DEBUG) && _BLD_DEBUG 357c2fbfb3SApril Chin #define DEBUG _BLD_DEBUG 367c2fbfb3SApril Chin #endif 377c2fbfb3SApril Chin 38da2e3ebdSchin #if DEBUG || _BLD_DEBUG 397c2fbfb3SApril Chin 40da2e3ebdSchin #define debug(x) x 41da2e3ebdSchin #define message(x) do if (error_info.trace < 0) { error x; } while (0) 42da2e3ebdSchin #define messagef(x) do if (error_info.trace < 0) { errorf x; } while (0) 437c2fbfb3SApril Chin 447c2fbfb3SApril Chin #define DEBUG_BEGTIME() debug_elapsed(1) 457c2fbfb3SApril Chin #define DEBUG_GETTIME() debug_elapsed(0) 467c2fbfb3SApril Chin #define DEBUG_ASSERT(p) ((p) ? 0 : (debug_fatal(__FILE__, __LINE__),0)) 477c2fbfb3SApril Chin #define DEBUG_COUNT(n) ((n) += 1) 487c2fbfb3SApril Chin #define DEBUG_TALLY(c,n,v) ((c) ? ((n) += (v)) : (n)) 4934f9b3eeSRoland Mainz #define DEBUG_INCREASE(n) ((n) += 1) 5034f9b3eeSRoland Mainz #define DEBUG_DECREASE(n) ((n) -= 1) 517c2fbfb3SApril Chin #define DEBUG_DECLARE(t,v) t v 527c2fbfb3SApril Chin #define DEBUG_SET(n,v) ((n) = (v)) 537c2fbfb3SApril Chin #define DEBUG_PRINT(fd,s,v) do {char _b[1024];write(fd,_b,sfsprintf(_b,sizeof(_b),s,v));} while(0) 547c2fbfb3SApril Chin #define DEBUG_WRITE(fd,d,n) write((fd),(d),(n)) 557c2fbfb3SApril Chin #define DEBUG_TEMP(temp) (temp) /* debugging stuff that should be removed */ 5634f9b3eeSRoland Mainz #define DEBUG_BREAK break 5734f9b3eeSRoland Mainz #define DEBUG_CONTINUE continue 587c2fbfb3SApril Chin #define DEBUG_GOTO(label) do { debug_fatal(__FILE__, __LINE__); goto label; } while(0) 5934f9b3eeSRoland Mainz #define DEBUG_RETURN(x) do { debug_fatal(__FILE__, __LINE__); return(x); } while(0) 607c2fbfb3SApril Chin 61da2e3ebdSchin #else 627c2fbfb3SApril Chin 63da2e3ebdSchin #define debug(x) 64da2e3ebdSchin #define message(x) 65da2e3ebdSchin #define messagef(x) 667c2fbfb3SApril Chin 677c2fbfb3SApril Chin #define DEBUG_BEGTIME() 687c2fbfb3SApril Chin #define DEBUG_GETTIME() 697c2fbfb3SApril Chin #define DEBUG_ASSERT(p) 707c2fbfb3SApril Chin #define DEBUG_COUNT(n) 717c2fbfb3SApril Chin #define DEBUG_TALLY(c,n,v) 7234f9b3eeSRoland Mainz #define DEBUG_INCREASE(n) 7334f9b3eeSRoland Mainz #define DEBUG_DECREASE(n) 747c2fbfb3SApril Chin #define DEBUG_DECLARE(t,v) 757c2fbfb3SApril Chin #define DEBUG_SET(n,v) 767c2fbfb3SApril Chin #define DEBUG_PRINT(fd,s,v) 777c2fbfb3SApril Chin #define DEBUG_WRITE(fd,d,n) 7834f9b3eeSRoland Mainz #define DEBUG_TEMP(x) 797c2fbfb3SApril Chin #define DEBUG_BREAK break 8034f9b3eeSRoland Mainz #define DEBUG_CONTINUE continue 817c2fbfb3SApril Chin #define DEBUG_GOTO(label) goto label 8234f9b3eeSRoland Mainz #define DEBUG_RETURN(x) return(x) 837c2fbfb3SApril Chin 84da2e3ebdSchin #endif 85da2e3ebdSchin 8634f9b3eeSRoland Mainz #ifndef BREAK 8734f9b3eeSRoland Mainz #define BREAK DEBUG_BREAK 8834f9b3eeSRoland Mainz #endif 8934f9b3eeSRoland Mainz #ifndef CONTINUE 9034f9b3eeSRoland Mainz #define CONTINUE DEBUG_CONTINUE 9134f9b3eeSRoland Mainz #endif 9234f9b3eeSRoland Mainz #ifndef GOTO 9334f9b3eeSRoland Mainz #define GOTO(label) DEBUG_GOTO(label) 9434f9b3eeSRoland Mainz #endif 9534f9b3eeSRoland Mainz #ifndef RETURN 9634f9b3eeSRoland Mainz #define RETURN(x) DEBUG_RETURN(x) 9734f9b3eeSRoland Mainz #endif 9834f9b3eeSRoland Mainz 99da2e3ebdSchin #if _BLD_ast && defined(__EXPORT__) 100da2e3ebdSchin #define extern __EXPORT__ 101da2e3ebdSchin #endif 102da2e3ebdSchin 1037c2fbfb3SApril Chin extern double debug_elapsed(int); 1047c2fbfb3SApril Chin extern void debug_fatal(const char*, int); 105da2e3ebdSchin extern void systrace(const char*); 106da2e3ebdSchin 107da2e3ebdSchin #undef extern 108da2e3ebdSchin 109da2e3ebdSchin #endif 110