debugin.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * @file debugin.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * Object for detecting wrong call paths.
  25. */
  26. #ifndef BADVPN_MISC_DEBUGIN_H
  27. #define BADVPN_MISC_DEBUGIN_H
  28. #include <misc/debug.h>
  29. /**
  30. * Object for detecting wrong call paths.
  31. */
  32. typedef struct {
  33. #ifndef NDEBUG
  34. int in;
  35. #endif
  36. } DebugIn;
  37. /**
  38. * Initializes the object.
  39. * The object is initialized in not in state.
  40. *
  41. * @param o the object
  42. */
  43. static void DebugIn_Init (DebugIn *o);
  44. /**
  45. * Puts the object into in state.
  46. * The object must be in not in state.
  47. * The object enters in state.
  48. *
  49. * @param o the object
  50. */
  51. static void DebugIn_GoIn (DebugIn *o);
  52. /**
  53. * Puts the object into not in state.
  54. * The object must be in in state.
  55. * The object enters not in state.
  56. *
  57. * @param o the object
  58. */
  59. static void DebugIn_GoOut (DebugIn *o);
  60. /**
  61. * Does nothing.
  62. * The object must be in in state.
  63. *
  64. * @param o the object
  65. */
  66. static void DebugIn_AmIn (DebugIn *o);
  67. /**
  68. * Does nothing.
  69. * The object must be in not in state.
  70. *
  71. * @param o the object
  72. */
  73. static void DebugIn_AmOut (DebugIn *o);
  74. #ifndef NDEBUG
  75. /**
  76. * Checks if the object is in in state.
  77. * Only available if NDEBUG is not defined.
  78. *
  79. * @param o the object
  80. * @return 1 if in in state, 0 if in not in state
  81. */
  82. static int DebugIn_In (DebugIn *o);
  83. #endif
  84. void DebugIn_Init (DebugIn *o)
  85. {
  86. #ifndef NDEBUG
  87. o->in = 0;
  88. #endif
  89. }
  90. void DebugIn_GoIn (DebugIn *o)
  91. {
  92. ASSERT(o->in == 0)
  93. #ifndef NDEBUG
  94. o->in = 1;
  95. #endif
  96. }
  97. void DebugIn_GoOut (DebugIn *o)
  98. {
  99. ASSERT(o->in == 1)
  100. #ifndef NDEBUG
  101. o->in = 0;
  102. #endif
  103. }
  104. void DebugIn_AmIn (DebugIn *o)
  105. {
  106. ASSERT(o->in == 1)
  107. }
  108. void DebugIn_AmOut (DebugIn *o)
  109. {
  110. ASSERT(o->in == 0)
  111. }
  112. #ifndef NDEBUG
  113. int DebugIn_In (DebugIn *o)
  114. {
  115. ASSERT(o->in == 0 || o->in == 1)
  116. return o->in;
  117. }
  118. #endif
  119. #endif