Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcos_assert.h 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*=============================================================================
  26. VideoCore OS Abstraction Layer - Assertion and error-handling macros.
  27. =============================================================================*/
  28. #ifndef VCOS_ASSERT_H
  29. #define VCOS_ASSERT_H
  30. /*
  31. * Macro:
  32. * vcos_assert(cond)
  33. * vcos_assert_msg(cond, fmt, ...)
  34. * Use:
  35. * Detecting programming errors by ensuring that assumptions are correct.
  36. * On failure:
  37. * Performs a platform-dependent "breakpoint", usually with an assert-style
  38. * message. The '_msg' variant expects a printf-style format string and
  39. * parameters.
  40. * If a failure is detected, the code should be fixed and rebuilt.
  41. * In release builds:
  42. * Generates no code, i.e. does not evaluate 'cond'.
  43. * Returns:
  44. * Nothing.
  45. *
  46. * Macro:
  47. * vcos_demand(cond)
  48. * vcos_demand_msg(cond, fmt, ...)
  49. * Use:
  50. * Detecting fatal system errors that require a reboot.
  51. * On failure:
  52. * Performs a platform-dependent "breakpoint", usually with an assert-style
  53. * message, then calls vcos_abort (see below).
  54. * In release builds:
  55. * Calls vcos_abort() if 'cond' is false.
  56. * Returns:
  57. * Nothing (never, on failure).
  58. *
  59. * Macro:
  60. * vcos_verify(cond)
  61. * vcos_verify_msg(cond, fmt, ...)
  62. * Use:
  63. * Detecting run-time errors and interesting conditions, normally within an
  64. * 'if' statement to catch the failures, i.e.
  65. * if (!vcos_verify(cond)) handle_error();
  66. * On failure:
  67. * Generates a message and optionally stops at a platform-dependent
  68. * "breakpoint" (usually disabled). See vcos_verify_bkpts_enable below.
  69. * In release builds:
  70. * Just evaluates and returns 'cond'.
  71. * Returns:
  72. * Non-zero if 'cond' is true, otherwise zero.
  73. *
  74. * Macro:
  75. * vcos_static_assert(cond)
  76. * Use:
  77. * Detecting compile-time errors.
  78. * On failure:
  79. * Generates a compiler error.
  80. * In release builds:
  81. * Generates a compiler error.
  82. *
  83. * Function:
  84. * void vcos_abort(void)
  85. * Use:
  86. * Invokes the fatal error handling mechanism, alerting the host where
  87. * applicable.
  88. * Returns:
  89. * Never.
  90. *
  91. * Macro:
  92. * VCOS_VERIFY_BKPTS
  93. * Use:
  94. * Define in a module (before including vcos.h) to specify an alternative
  95. * flag to control breakpoints on vcos_verify() failures.
  96. * Returns:
  97. * Non-zero values enable breakpoints.
  98. *
  99. * Function:
  100. * int vcos_verify_bkpts_enable(int enable);
  101. * Use:
  102. * Sets the global flag controlling breakpoints on vcos_verify failures,
  103. * enabling the breakpoints iff 'enable' is non-zero.
  104. * Returns:
  105. * The previous state of the flag.
  106. *
  107. * Function:
  108. * int vcos_verify_bkpts_enabled(void);
  109. * Use:
  110. * Queries the state of the global flag enabling breakpoints on vcos_verify
  111. * failures.
  112. * Returns:
  113. * The current state of the flag.
  114. *
  115. * Examples:
  116. *
  117. * int my_breakpoint_enable_flag = 1;
  118. *
  119. * #define VCOS_VERIFY_BKPTS my_breakpoint_enable_flag
  120. *
  121. * #include "vcos.h"
  122. *
  123. * vcos_static_assert((sizeof(object) % 32) == 0);
  124. *
  125. * // ...
  126. *
  127. * vcos_assert_msg(postcondition_is_true, "Coding error");
  128. *
  129. * if (!vcos_verify_msg(buf, "Buffer allocation failed (%d bytes)", size))
  130. * {
  131. * // Tidy up
  132. * // ...
  133. * return OUT_OF_MEMORY;
  134. * }
  135. *
  136. * vcos_demand(*p++==GUARDWORDHEAP);
  137. */
  138. #ifdef __cplusplus
  139. extern "C" {
  140. #endif
  141. #include "vcos_types.h"
  142. #ifdef __COVERITY__
  143. #include "user_nodefs.h"
  144. extern void __coverity_panic__(void);
  145. #undef VCOS_ASSERT_BKPT
  146. #define VCOS_ASSERT_BKPT __coverity_panic__()
  147. #endif
  148. /*
  149. * ANDROID should NOT be defined for files built for Videocore, but currently it
  150. * is. FIXME When that's fixed, remove the __VIDEOCORE__ band-aid.
  151. */
  152. #if (defined(ANDROID) && !defined(__VIDEOCORE__))
  153. # include "assert.h"
  154. # define vcos_assert assert
  155. #endif
  156. #ifndef VCOS_VERIFY_BKPTS
  157. #define VCOS_VERIFY_BKPTS vcos_verify_bkpts_enabled()
  158. #endif
  159. #ifndef VCOS_BKPT
  160. #if defined(__VIDEOCORE__) && !defined(VCOS_ASSERT_NO_BKPTS)
  161. #define VCOS_BKPT _bkpt()
  162. #else
  163. #define VCOS_BKPT (void )0
  164. #endif
  165. #endif
  166. #ifndef VCOS_ASSERT_BKPT
  167. #define VCOS_ASSERT_BKPT VCOS_BKPT
  168. #endif
  169. #ifndef VCOS_VERIFY_BKPT
  170. #define VCOS_VERIFY_BKPT (VCOS_VERIFY_BKPTS ? VCOS_BKPT : (void)0)
  171. #endif
  172. VCOSPRE_ int VCOSPOST_ vcos_verify_bkpts_enabled(void);
  173. VCOSPRE_ int VCOSPOST_ vcos_verify_bkpts_enable(int enable);
  174. VCOSPRE_ void VCOSPOST_ vcos_abort(void);
  175. #ifndef VCOS_ASSERT_MSG
  176. #ifdef LOGGING
  177. extern void logging_assert(const char *file, const char *func, int line, const char *format, ...);
  178. extern void logging_assert_dump(void);
  179. #define VCOS_ASSERT_MSG(...) ((VCOS_ASSERT_LOGGING && !VCOS_ASSERT_LOGGING_DISABLE) ? logging_assert_dump(), logging_assert(__FILE__, __func__, __LINE__, __VA_ARGS__) : (void)0)
  180. #else
  181. #define VCOS_ASSERT_MSG(...) ((void)0)
  182. #endif
  183. #endif
  184. #ifndef VCOS_VERIFY_MSG
  185. #define VCOS_VERIFY_MSG(...) VCOS_ASSERT_MSG(__VA_ARGS__)
  186. #endif
  187. #ifndef VCOS_ASSERT_LOGGING
  188. #define VCOS_ASSERT_LOGGING 0
  189. #endif
  190. #ifndef VCOS_ASSERT_LOGGING_DISABLE
  191. #define VCOS_ASSERT_LOGGING_DISABLE 0
  192. #endif
  193. #if !defined(NDEBUG) || defined(VCOS_RELEASE_ASSERTS)
  194. #define VCOS_ASSERT_ENABLED 1
  195. #define VCOS_VERIFY_ENABLED 1
  196. #else
  197. #define VCOS_ASSERT_ENABLED 0
  198. #define VCOS_VERIFY_ENABLED 0
  199. #endif
  200. #define VCOS_DEMAND_ENABLED 1
  201. #if VCOS_ASSERT_ENABLED
  202. #ifndef vcos_assert
  203. #define vcos_assert(cond) \
  204. ( (cond) ? (void)0 : (VCOS_ASSERT_MSG("%s", #cond), VCOS_ASSERT_BKPT) )
  205. #endif
  206. #ifndef vcos_assert_msg
  207. #define vcos_assert_msg(cond, ...) \
  208. ( (cond) ? (void)0 : (VCOS_ASSERT_MSG(__VA_ARGS__), VCOS_ASSERT_BKPT) )
  209. #endif
  210. #else /* VCOS_ASSERT_ENABLED */
  211. #ifndef vcos_assert
  212. #define vcos_assert(cond) (void)0
  213. #endif
  214. #ifndef vcos_assert_msg
  215. #define vcos_assert_msg(cond, ...) (void)0
  216. #endif
  217. #endif /* VCOS_ASSERT_ENABLED */
  218. #if VCOS_DEMAND_ENABLED
  219. #ifndef vcos_demand
  220. #define vcos_demand(cond) \
  221. ( (cond) ? (void)0 : (VCOS_ASSERT_MSG("%s", #cond), VCOS_ASSERT_BKPT, vcos_abort()) )
  222. #endif
  223. #ifndef vcos_demand_msg
  224. #define vcos_demand_msg(cond, ...) \
  225. ( (cond) ? (void)0 : (VCOS_ASSERT_MSG(__VA_ARGS__), VCOS_ASSERT_BKPT, vcos_abort()) )
  226. #endif
  227. #else /* VCOS_DEMAND_ENABLED */
  228. #ifndef vcos_demand
  229. #define vcos_demand(cond) \
  230. ( (cond) ? (void)0 : vcos_abort() )
  231. #endif
  232. #ifndef vcos_demand_msg
  233. #define vcos_demand_msg(cond, ...) \
  234. ( (cond) ? (void)0 : vcos_abort() )
  235. #endif
  236. #endif /* VCOS_DEMAND_ENABLED */
  237. #if VCOS_VERIFY_ENABLED
  238. #ifndef vcos_verify
  239. #define vcos_verify(cond) \
  240. ( (cond) ? 1 : (VCOS_VERIFY_MSG("%s", #cond), VCOS_VERIFY_BKPT, 0) )
  241. #endif
  242. #ifndef vcos_verify_msg
  243. #define vcos_verify_msg(cond, ...) \
  244. ( (cond) ? 1 : (VCOS_VERIFY_MSG(__VA_ARGS__), VCOS_VERIFY_BKPT, 0) )
  245. #endif
  246. #else /* VCOS_VERIFY_ENABLED */
  247. #ifndef vcos_verify
  248. #define vcos_verify(cond) (cond)
  249. #endif
  250. #ifndef vcos_verify_msg
  251. #define vcos_verify_msg(cond, ...) (cond)
  252. #endif
  253. #endif /* VCOS_VERIFY_ENABLED */
  254. #ifndef vcos_static_assert
  255. #if defined(__GNUC__)
  256. #define vcos_static_assert(cond) __attribute__((unused)) extern int vcos_static_assert[(cond)?1:-1]
  257. #else
  258. #define vcos_static_assert(cond) extern int vcos_static_assert[(cond)?1:-1]
  259. #endif
  260. #endif
  261. #ifndef vc_assert
  262. #define vc_assert(cond) vcos_assert(cond)
  263. #endif
  264. #define vcos_unreachable() vcos_assert(0)
  265. #define vcos_not_impl() vcos_assert(0)
  266. /** Print out a backtrace, on supported platforms.
  267. */
  268. extern void vcos_backtrace_self(void);
  269. #ifdef __cplusplus
  270. }
  271. #endif
  272. #endif /* VCOS_ASSERT_H */