bh_assert.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "bh_platform.h"
  6. #include "bh_assert.h"
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #ifdef BH_TEST
  11. #include <setjmp.h>
  12. #endif
  13. #ifdef BH_TEST
  14. /* for exception throwing */
  15. jmp_buf bh_test_jb;
  16. #endif
  17. extern void abort(void);
  18. void bh_assert_internal(int v, const char *file_name, int line_number,
  19. const char *expr_string)
  20. {
  21. if (v)
  22. return;
  23. if (!file_name)
  24. file_name = "NULL FILENAME";
  25. if (!expr_string)
  26. expr_string = "NULL EXPR_STRING";
  27. printk("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string,
  28. file_name, line_number);
  29. #ifdef BH_TEST
  30. longjmp(bh_test_jb, 1);
  31. #endif
  32. abort();
  33. }
  34. void bh_debug_internal(const char *file_name, int line_number, const char *fmt,
  35. ...)
  36. {
  37. #ifndef JEFF_TEST_VERIFIER
  38. va_list args;
  39. va_start(args, fmt);
  40. bh_assert(file_name);
  41. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  42. vprintf(fmt, args);
  43. va_end(args);
  44. printf("\n");
  45. #endif
  46. }