ocdebug.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
  2. See the COPYRIGHT file for more information. */
  3. #ifndef OCOCDBG_H
  4. #define OCOCDBG_H
  5. #include <stdarg.h>
  6. #if 0
  7. #define OCDEBUG
  8. #define DAPDEBUG 1
  9. #endif
  10. #ifdef OCDEBUG
  11. #define OCVERBOSE
  12. #endif
  13. /* OCCATCHERROR is used to detect errors as close
  14. to their point of origin as possible. When
  15. enabled, one can set a breakpoint in ocbreakpoint()
  16. to catch the failure. Turing it on incurs a significant
  17. performance penalty, so it is off by default.*/
  18. #define OCCATCHERROR
  19. #define OCPANIC(msg) assert(ocpanic(msg))
  20. #define OCPANIC1(msg,arg) assert(ocpanic(msg,arg))
  21. #define OCPANIC2(msg,arg1,arg2) assert(ocpanic(msg,arg1,arg2))
  22. /* Make it possible to catch assertion failures by breakpointing ocpanic*/
  23. #define OCASSERT(expr) if(!(expr)) {OCPANIC((#expr));} else {}
  24. /* Need some syntactic trickery to make these macros work*/
  25. #ifdef OCDEBUG
  26. #define OCDBG(l,msg) {oc_log(LOGDBG,msg);}
  27. #define OCDBG1(l,msg,arg) {oc_log(LOGDBG,msg,arg);}
  28. #define OCDBG2(l,msg,arg1,arg2) {oc_log(LOGDBG,msg,arg1,arg2);}
  29. #define OCDBGTEXT(l,text) {oc_logtext(LOGNOTE,text);} else {}
  30. #define OCDBGCODE(l,code) {code;}
  31. #else
  32. #define OCDBG(l,msg)
  33. #define OCDBG1(l,msg,arg)
  34. #define OCDBG2(l,msg,arg1,arg2)
  35. #define OCDBGTEXT(l,text)
  36. #define OCDBGCODE(l,code)
  37. #endif
  38. /*
  39. OCPROGRESS attempts to provide some info
  40. about how IO is getting along.
  41. */
  42. #undef OCPROGRESS
  43. extern int ocdebug;
  44. extern int cedebug;
  45. /*extern char* dent2(int n);*/
  46. /*/extern char* dent(int n);*/
  47. extern int ocpanic(const char* fmt, ...);
  48. extern int xdrerror(void);
  49. /*
  50. Provide wrapped versions of calloc and malloc.
  51. The wrapped version panics if memory
  52. is exhausted. It also guarantees that the
  53. memory has been zero'd.
  54. */
  55. extern void* occalloc(size_t size, size_t nelems);
  56. extern void* ocmalloc(size_t size);
  57. extern void ocfree(void*);
  58. #define MEMCHECK(var,throw) {if((var)==NULL) return (throw);}
  59. #ifdef OCCATCHERROR
  60. /* Place breakpoint on ocbreakpoint to catch errors close to where they occur*/
  61. #define OCTHROW(e) octhrow(e)
  62. #define OCTHROWCHK(e) (void)octhrow(e)
  63. #define OCGOTO(label) {ocbreakpoint(-1); goto label;}
  64. extern int ocbreakpoint(int err);
  65. extern int octhrow(int err);
  66. #else
  67. #define OCTHROW(e) (e)
  68. #define OCTHROWCHK(e)
  69. #define OCGOTO(label) goto label
  70. #endif
  71. #endif /*OCOCDBG_H*/