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. void bh_assert_internal(int v, const char *file_name, int line_number,
  18. const char *expr_string)
  19. {
  20. if (v)
  21. return;
  22. if (!file_name)
  23. file_name = "NULL FILENAME";
  24. if (!expr_string)
  25. expr_string = "NULL EXPR_STRING";
  26. printf("\nASSERTION FAILED: %s, at FILE=%s, LINE=%d\n", expr_string,
  27. file_name, line_number);
  28. #ifdef BH_TEST
  29. longjmp(bh_test_jb, 1);
  30. #endif
  31. abort();
  32. }
  33. void bh_debug_internal(const char *file_name, int line_number, const char *fmt,
  34. ...)
  35. {
  36. #ifndef JEFF_TEST_VERIFIER
  37. va_list args;
  38. va_start(args, fmt);
  39. bh_assert(file_name);
  40. printf("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  41. vprintf(fmt, args);
  42. va_end(args);
  43. printf("\n");
  44. #endif
  45. }