bh_assert.c 1.2 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. #define FIXED_BUFFER_SIZE (1<<9)
  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. bh_printf_sgx("\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. char msg[FIXED_BUFFER_SIZE] = { '\0' };
  40. va_start(args, fmt);
  41. vsnprintf(msg, FIXED_BUFFER_SIZE, fmt, args);
  42. va_end(args);
  43. bh_printf_sgx("\nDebug info FILE=%s, LINE=%d: ", file_name, line_number);
  44. bh_printf_sgx(msg);
  45. bh_printf_sgx("\n");
  46. #endif
  47. }