debug.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*------------------------------------------------------------------------
  2. * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net>
  3. *
  4. * This file is part of the ZBar Bar Code Reader.
  5. *
  6. * The ZBar Bar Code Reader is free software; you can redistribute it
  7. * and/or modify it under the terms of the GNU Lesser Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * The ZBar Bar Code Reader is distributed in the hope that it will be
  12. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser Public License
  17. * along with the ZBar Bar Code Reader; if not, write to the Free
  18. * Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  19. * Boston, MA 02110-1301 USA
  20. *
  21. * http://sourceforge.net/projects/zbar
  22. *------------------------------------------------------------------------*/
  23. /* varargs variations on compile time debug spew */
  24. #if 1
  25. #define dprintf(...)
  26. #define zassert(condition, retval, format, ...) //assert(condition)
  27. #define assert(x) if( ( x ) == 0 ) { __disable_irq(); DBG_Trace("\r\nassert %s,%d", __FUNCTION__, __LINE__); for( ;; ); }
  28. #define zprintf(level, format, y...) DBG_Printf(format, ##y)
  29. #define CHECK() Core_DebugMem(0, __FUNCTION__, __LINE__);
  30. #else
  31. #ifndef DEBUG_LEVEL
  32. # ifdef __GNUC__
  33. /* older versions of gcc (< 2.95) require a named varargs parameter */
  34. # define dprintf(args...)
  35. # else
  36. /* unfortunately named vararg parameter is a gcc-specific extension */
  37. # define dprintf(...)
  38. # endif
  39. #else
  40. # include <stdio.h>
  41. # ifdef __GNUC__
  42. # define dprintf(level, args...) \
  43. if((level) <= DEBUG_LEVEL) \
  44. fprintf(stderr, args)
  45. # else
  46. # define dprintf(level, ...) \
  47. if((level) <= DEBUG_LEVEL) \
  48. fprintf(stderr, __VA_ARGS__)
  49. # endif
  50. #endif /* DEBUG_LEVEL */
  51. /* spew warnings for non-fatal assertions.
  52. * returns specified error code if assertion fails.
  53. * NB check/return is still performed for NDEBUG
  54. * only the message is inhibited
  55. * FIXME don't we need varargs hacks here?
  56. */
  57. #ifndef NDEBUG
  58. # include <stdio.h>
  59. #if __STDC_VERSION__ < 199901L && !defined(__func__)
  60. # if __GNUC__ >= 2
  61. # define __func__ __FUNCTION__
  62. # else
  63. # define __func__ "<unknown>"
  64. # endif
  65. #endif
  66. # define zassert(condition, retval, format, ...) do { \
  67. if(!(condition)) { \
  68. fprintf(stderr, "WARNING: %s:%d: %s:" \
  69. " Assertion \"%s\" failed.\n\t" format, \
  70. __FILE__, __LINE__, __func__, #condition , \
  71. ##__VA_ARGS__); \
  72. return(retval); \
  73. } \
  74. } while(0)
  75. #else
  76. # define zassert(condition, retval, format, ...) do { \
  77. if(!(condition)) \
  78. return(retval); \
  79. } while(0)
  80. #endif
  81. #endif